| 577 | } |
| 578 | |
| 579 | void watch_check_block_added(const struct chain_topology *topo, u32 blockheight) |
| 580 | { |
| 581 | struct blockdepthwatch_hash_iter it; |
| 582 | |
| 583 | /* With ccan/htable, deleting during iteration is safe: adding isn't! */ |
| 584 | blockdepthwatch_hash_lock(topo->blockdepthwatches); |
| 585 | for (struct blockdepthwatch *w = blockdepthwatch_hash_first(topo->blockdepthwatches, &it); |
| 586 | w; |
| 587 | w = blockdepthwatch_hash_next(topo->blockdepthwatches, &it)) { |
| 588 | /* You are not supposed to watch future blocks! */ |
| 589 | assert(blockheight >= w->height); |
| 590 | |
| 591 | u32 depth = blockheight - w->height + 1; |
| 592 | enum watch_result r = w->depthcb(topo->ld, depth, w->arg); |
| 593 | |
| 594 | switch (r) { |
| 595 | case DELETE_WATCH: |
| 596 | tal_free(w); |
| 597 | continue; |
| 598 | case KEEP_WATCHING: |
| 599 | continue; |
| 600 | } |
| 601 | fatal("blockdepthwatch depth callback %p returned %i", w->depthcb, r); |
| 602 | } |
| 603 | blockdepthwatch_hash_unlock(topo->blockdepthwatches); |
| 604 | } |
| 605 | |
| 606 | void watch_check_block_removed(const struct chain_topology *topo, u32 blockheight) |
| 607 | { |
no test coverage detected