From 4ba1599494bb57e0972a7ed17927d966a37e3875 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 23 Aug 2017 10:28:44 +0930 Subject: [PATCH] txowatch: include block in which spending tx is found. onchaind wants the block height, for example. Signed-off-by: Rusty Russell --- daemon/chaintopology.c | 2 +- daemon/peer.c | 2 ++ daemon/watch.c | 6 ++++-- daemon/watch.h | 9 +++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index 8c649839f..8c33ee8b3 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -110,7 +110,7 @@ static void connect_block(struct chain_topology *topo, txo = txowatch_hash_get(&topo->txowatches, &out); if (txo) - txowatch_fire(topo, txo, tx, j); + txowatch_fire(topo, txo, tx, j, b); } /* We did spends first, in case that tells us to watch tx. */ diff --git a/daemon/peer.c b/daemon/peer.c index 8041b0e49..c08bfd688 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -3787,6 +3787,7 @@ static enum watch_result our_unilateral_depth(struct peer *peer, static enum watch_result our_htlc_spent(struct peer *peer, const struct bitcoin_tx *tx, size_t input_num, + const struct block *block, struct htlc *h) { struct sha256 sha; @@ -4199,6 +4200,7 @@ static struct sha256 *get_rhash(struct peer *peer, u64 commit_num, static enum watch_result anchor_spent(struct peer *peer, const struct bitcoin_tx *tx, size_t input_num, + const struct block *block, void *unused) { Pkt *err; diff --git a/daemon/watch.c b/daemon/watch.c index 8853c65bf..1b8467dde 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -141,6 +141,7 @@ struct txowatch *watch_txo_(const tal_t *ctx, enum watch_result (*cb)(struct peer *peer, const struct bitcoin_tx *tx, size_t input_num, + const struct block *block, void *), void *cbdata) { @@ -204,7 +205,8 @@ void txwatch_fire(struct chain_topology *topo, void txowatch_fire(struct chain_topology *topo, const struct txowatch *txow, const struct bitcoin_tx *tx, - size_t input_num) + size_t input_num, + const struct block *block) { struct sha256_double txid; enum watch_result r; @@ -220,7 +222,7 @@ void txowatch_fire(struct chain_topology *topo, txid.sha.u.u8[1], txid.sha.u.u8[2], txid.sha.u.u8[3]); - r = txow->cb(txow->peer, tx, input_num, txow->cbdata); + r = txow->cb(txow->peer, tx, input_num, block, txow->cbdata); switch (r) { case DELETE_WATCH: tal_free(txow); diff --git a/daemon/watch.h b/daemon/watch.h index d783e6389..2f18eb0b7 100644 --- a/daemon/watch.h +++ b/daemon/watch.h @@ -9,6 +9,7 @@ #include struct bitcoin_tx; +struct block; struct lightningd_state; enum watch_result { @@ -35,6 +36,7 @@ struct txowatch { enum watch_result (*cb)(struct peer *peer, const struct bitcoin_tx *tx, size_t input_num, + const struct block *block, void *cbdata); void *cbdata; @@ -119,6 +121,7 @@ struct txowatch *watch_txo_(const tal_t *ctx, enum watch_result (*cb)(struct peer *peer, const struct bitcoin_tx *tx, size_t input_num, + const struct block *block, void *), void *cbdata); @@ -128,7 +131,8 @@ struct txowatch *watch_txo_(const tal_t *ctx, (cb), (cbdata), \ struct peer *, \ const struct bitcoin_tx *, \ - size_t), \ + size_t, \ + const struct block *block), \ (cbdata)) void txwatch_fire(struct chain_topology *topo, @@ -137,7 +141,8 @@ void txwatch_fire(struct chain_topology *topo, void txowatch_fire(struct chain_topology *topo, const struct txowatch *txow, - const struct bitcoin_tx *tx, size_t input_num); + const struct bitcoin_tx *tx, size_t input_num, + const struct block *block); bool watching_txid(const struct chain_topology *topo, const struct sha256_double *txid);