mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
lightningd: use bitcoin_outpoint in watch.
This makes more sense than two args. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
2bb13bacc2
commit
b24b7f90c4
@@ -72,10 +72,10 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
|||||||
|
|
||||||
/* Tell them if it spends a txo we care about. */
|
/* Tell them if it spends a txo we care about. */
|
||||||
for (j = 0; j < tx->wtx->num_inputs; j++) {
|
for (j = 0; j < tx->wtx->num_inputs; j++) {
|
||||||
struct txwatch_output out;
|
struct bitcoin_outpoint out;
|
||||||
struct txowatch *txo;
|
struct txowatch *txo;
|
||||||
bitcoin_tx_input_get_txid(tx, j, &out.txid);
|
bitcoin_tx_input_get_txid(tx, j, &out.txid);
|
||||||
out.index = tx->wtx->inputs[j].index;
|
out.n = tx->wtx->inputs[j].index;
|
||||||
|
|
||||||
txo = txowatch_hash_get(&topo->txowatches, &out);
|
txo = txowatch_hash_get(&topo->txowatches, &out);
|
||||||
if (txo) {
|
if (txo) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct txowatch {
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
/* Output to watch. */
|
/* Output to watch. */
|
||||||
struct txwatch_output out;
|
struct bitcoin_outpoint out;
|
||||||
|
|
||||||
/* A new tx. */
|
/* A new tx. */
|
||||||
enum watch_result (*cb)(struct channel *channel,
|
enum watch_result (*cb)(struct channel *channel,
|
||||||
@@ -71,24 +71,24 @@ struct txwatch {
|
|||||||
unsigned int depth);
|
unsigned int depth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct txwatch_output *txowatch_keyof(const struct txowatch *w)
|
const struct bitcoin_outpoint *txowatch_keyof(const struct txowatch *w)
|
||||||
{
|
{
|
||||||
return &w->out;
|
return &w->out;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t txo_hash(const struct txwatch_output *out)
|
size_t txo_hash(const struct bitcoin_outpoint *out)
|
||||||
{
|
{
|
||||||
/* This hash-in-one-go trick only works if they're consecutive. */
|
/* This hash-in-one-go trick only works if they're consecutive. */
|
||||||
BUILD_ASSERT(offsetof(struct txwatch_output, index)
|
BUILD_ASSERT(offsetof(struct bitcoin_outpoint, n)
|
||||||
== sizeof(((struct txwatch_output *)NULL)->txid));
|
== sizeof(((struct bitcoin_outpoint *)NULL)->txid));
|
||||||
return siphash24(siphash_seed(), &out->txid,
|
return siphash24(siphash_seed(), out,
|
||||||
sizeof(out->txid) + sizeof(out->index));
|
sizeof(out->txid) + sizeof(out->n));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out)
|
bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out)
|
||||||
{
|
{
|
||||||
return bitcoin_txid_eq(&w->out.txid, &out->txid)
|
return bitcoin_txid_eq(&w->out.txid, &out->txid)
|
||||||
&& w->out.index == out->index;
|
&& w->out.n == out->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_txowatch(struct txowatch *w)
|
static void destroy_txowatch(struct txowatch *w)
|
||||||
@@ -198,7 +198,7 @@ struct txowatch *watch_txo(const tal_t *ctx,
|
|||||||
|
|
||||||
w->topo = topo;
|
w->topo = topo;
|
||||||
w->out.txid = *txid;
|
w->out.txid = *txid;
|
||||||
w->out.index = output;
|
w->out.n = output;
|
||||||
w->channel = channel;
|
w->channel = channel;
|
||||||
w->cb = cb;
|
w->cb = cb;
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ void txowatch_fire(const struct txowatch *txow,
|
|||||||
log_debug(txow->channel->log,
|
log_debug(txow->channel->log,
|
||||||
"Got UTXO spend for %s:%u: %s",
|
"Got UTXO spend for %s:%u: %s",
|
||||||
type_to_string(tmpctx, struct bitcoin_txid, &txow->out.txid),
|
type_to_string(tmpctx, struct bitcoin_txid, &txow->out.txid),
|
||||||
txow->out.index,
|
txow->out.n,
|
||||||
type_to_string(tmpctx, struct bitcoin_txid, &txid));
|
type_to_string(tmpctx, struct bitcoin_txid, &txid));
|
||||||
|
|
||||||
r = txow->cb(txow->channel, tx, input_num, block);
|
r = txow->cb(txow->channel, tx, input_num, block);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
#include <ccan/htable/htable_type.h>
|
#include <ccan/htable/htable_type.h>
|
||||||
|
|
||||||
struct bitcoin_tx;
|
|
||||||
struct block;
|
struct block;
|
||||||
struct channel;
|
struct channel;
|
||||||
struct chain_topology;
|
struct chain_topology;
|
||||||
@@ -17,14 +16,9 @@ enum watch_result {
|
|||||||
KEEP_WATCHING = -2
|
KEEP_WATCHING = -2
|
||||||
};
|
};
|
||||||
|
|
||||||
struct txwatch_output {
|
const struct bitcoin_outpoint *txowatch_keyof(const struct txowatch *w);
|
||||||
struct bitcoin_txid txid;
|
size_t txo_hash(const struct bitcoin_outpoint *out);
|
||||||
unsigned int index;
|
bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out);
|
||||||
};
|
|
||||||
|
|
||||||
const struct txwatch_output *txowatch_keyof(const struct txowatch *w);
|
|
||||||
size_t txo_hash(const struct txwatch_output *out);
|
|
||||||
bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out);
|
|
||||||
|
|
||||||
HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
|
HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
|
||||||
txowatch_hash);
|
txowatch_hash);
|
||||||
|
|||||||
Reference in New Issue
Block a user