mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
bitcoind: tell bitcoind_poll_transactions's callback if tx is a coinbase.
In this case, the inputs aren't valid transactions, so don't try to find them. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5b9f8d8bbd
commit
0dbbd81430
@ -167,7 +167,7 @@ static void process_transactions(struct bitcoin_cli *bcli)
|
||||
bool valid;
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
int confirmations) = bcli->cb;
|
||||
int confirmations, bool is_coinbase) = bcli->cb;
|
||||
|
||||
tokens = json_parse_input(bcli->output, bcli->output_bytes, &valid);
|
||||
if (!tokens)
|
||||
@ -183,12 +183,13 @@ static void process_transactions(struct bitcoin_cli *bcli)
|
||||
end = json_next(tokens);
|
||||
for (t = tokens + 1; t < end; t = json_next(t)) {
|
||||
struct sha256_double txid;
|
||||
const jsmntok_t *txidtok, *conftok;
|
||||
long int conf;
|
||||
char *end;
|
||||
const jsmntok_t *txidtok, *conftok, *blkindxtok;
|
||||
unsigned int conf;
|
||||
bool is_coinbase;
|
||||
|
||||
txidtok = json_get_member(bcli->output, t, "txid");
|
||||
conftok = json_get_member(bcli->output, t, "confirmations");
|
||||
blkindxtok = json_get_member(bcli->output, t, "blockindex");
|
||||
if (!txidtok || !conftok)
|
||||
fatal("listtransactions: no %s field!",
|
||||
txidtok ? "confirmations" : "txid");
|
||||
@ -199,27 +200,39 @@ static void process_transactions(struct bitcoin_cli *bcli)
|
||||
(int)(txidtok->end - txidtok->start),
|
||||
bcli->output + txidtok->start);
|
||||
}
|
||||
conf = strtol(bcli->output + conftok->start, &end, 10);
|
||||
if (end != bcli->output + conftok->end)
|
||||
if (!json_tok_number(bcli->output, conftok, &conf))
|
||||
fatal("listtransactions: bad confirmations '%.*s'",
|
||||
(int)(conftok->end - conftok->start),
|
||||
bcli->output + conftok->start);
|
||||
|
||||
/* This can happen with zero conf. */
|
||||
blkindxtok = json_get_member(bcli->output, t, "blockindex");
|
||||
if (!blkindxtok)
|
||||
is_coinbase = false;
|
||||
else {
|
||||
unsigned int blkidx;
|
||||
if (!json_tok_number(bcli->output, blkindxtok, &blkidx))
|
||||
fatal("listtransactions: bad blockindex '%.*s'",
|
||||
(int)(blkindxtok->end - blkindxtok->start),
|
||||
bcli->output + blkindxtok->start);
|
||||
is_coinbase = (blkidx == 0);
|
||||
}
|
||||
/* FIXME: log txid */
|
||||
log_debug(bcli->dstate->base_log,
|
||||
"txid %02x%02x%02x%02x..., conf %li",
|
||||
"txid %02x%02x%02x%02x..., conf %u, coinbase %u",
|
||||
txid.sha.u.u8[0], txid.sha.u.u8[1],
|
||||
txid.sha.u.u8[2], txid.sha.u.u8[3],
|
||||
conf);
|
||||
conf, is_coinbase);
|
||||
|
||||
cb(bcli->dstate, &txid, conf);
|
||||
cb(bcli->dstate, &txid, conf, is_coinbase);
|
||||
}
|
||||
}
|
||||
|
||||
void bitcoind_poll_transactions(struct lightningd_state *dstate,
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
int confirmations))
|
||||
int confirmations,
|
||||
bool is_coinbase))
|
||||
{
|
||||
/* FIXME: Iterate and detect duplicates. */
|
||||
start_bitcoin_cli(dstate, process_transactions, cb, NULL,
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/typesafe_cb/typesafe_cb.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct sha256_double;
|
||||
struct lightningd_state;
|
||||
@ -16,7 +17,8 @@ void bitcoind_watch_addr(struct lightningd_state *dstate,
|
||||
void bitcoind_poll_transactions(struct lightningd_state *dstate,
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
int confirmations));
|
||||
int confirmations,
|
||||
bool is_coinbase));
|
||||
|
||||
void bitcoind_txid_lookup_(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
|
@ -187,7 +187,9 @@ static void tx_watched_inputs(struct lightningd_state *dstate,
|
||||
|
||||
static void watched_transaction(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
int confirmations)
|
||||
int confirmations,
|
||||
bool is_coinbase)
|
||||
|
||||
{
|
||||
struct txwatch *txw;
|
||||
|
||||
@ -206,7 +208,8 @@ static void watched_transaction(struct lightningd_state *dstate,
|
||||
insert_txwatch(dstate, dstate, NULL, txid, NULL, NULL);
|
||||
|
||||
/* Maybe it spent an output we're watching? */
|
||||
bitcoind_txid_lookup(dstate, txid, tx_watched_inputs, NULL);
|
||||
if (!is_coinbase)
|
||||
bitcoind_txid_lookup(dstate, txid, tx_watched_inputs, NULL);
|
||||
}
|
||||
|
||||
static struct timeout watch_timeout;
|
||||
|
Loading…
Reference in New Issue
Block a user