|
@ -355,77 +355,6 @@ void bitcoind_sendrawtx_(struct bitcoind *bitcoind, |
|
|
"sendrawtransaction", hextx, NULL); |
|
|
"sendrawtransaction", hextx, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void process_chaintips(struct bitcoin_cli *bcli) |
|
|
|
|
|
{ |
|
|
|
|
|
const jsmntok_t *tokens, *t, *end; |
|
|
|
|
|
bool valid; |
|
|
|
|
|
size_t i; |
|
|
|
|
|
struct bitcoin_blkid tip; |
|
|
|
|
|
void (*cb)(struct bitcoind *bitcoind, |
|
|
|
|
|
struct bitcoin_blkid *tipid, |
|
|
|
|
|
void *arg) = bcli->cb; |
|
|
|
|
|
|
|
|
|
|
|
tokens = json_parse_input(bcli->output, bcli->output_bytes, &valid); |
|
|
|
|
|
if (!tokens) |
|
|
|
|
|
fatal("%s: %s response", |
|
|
|
|
|
bcli_args(bcli), |
|
|
|
|
|
valid ? "partial" : "invalid"); |
|
|
|
|
|
|
|
|
|
|
|
if (tokens[0].type != JSMN_ARRAY) |
|
|
|
|
|
fatal("%s: gave non-array (%.*s)?", |
|
|
|
|
|
bcli_args(bcli), |
|
|
|
|
|
(int)bcli->output_bytes, bcli->output); |
|
|
|
|
|
|
|
|
|
|
|
valid = false; |
|
|
|
|
|
end = json_next(tokens); |
|
|
|
|
|
for (i = 0, t = tokens + 1; t < end; t = json_next(t), i++) { |
|
|
|
|
|
const jsmntok_t *status = json_get_member(bcli->output, t, "status"); |
|
|
|
|
|
const jsmntok_t *hash = json_get_member(bcli->output, t, "hash"); |
|
|
|
|
|
|
|
|
|
|
|
if (!status || !hash) { |
|
|
|
|
|
log_broken(bcli->bitcoind->log, |
|
|
|
|
|
"%s: No status & hash: %.*s", |
|
|
|
|
|
bcli_args(bcli), |
|
|
|
|
|
(int)bcli->output_bytes, bcli->output); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!json_tok_streq(bcli->output, status, "active")) { |
|
|
|
|
|
/* Ignoring this chaintip since it's not active */ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (valid) { |
|
|
|
|
|
log_unusual(bcli->bitcoind->log, |
|
|
|
|
|
"%s: Two active chaintips? %.*s", |
|
|
|
|
|
bcli_args(bcli), |
|
|
|
|
|
(int)bcli->output_bytes, bcli->output); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (!bitcoin_blkid_from_hex(bcli->output + hash->start, |
|
|
|
|
|
hash->end - hash->start, |
|
|
|
|
|
&tip)) |
|
|
|
|
|
fatal("%s: gave bad hash for %zu'th tip (%.*s)?", |
|
|
|
|
|
bcli_args(bcli), i, |
|
|
|
|
|
(int)bcli->output_bytes, bcli->output); |
|
|
|
|
|
valid = true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!valid) |
|
|
|
|
|
fatal("%s: gave no active chaintips (%.*s)?", |
|
|
|
|
|
bcli_args(bcli), (int)bcli->output_bytes, bcli->output); |
|
|
|
|
|
|
|
|
|
|
|
cb(bcli->bitcoind, &tip, bcli->cb_arg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void bitcoind_get_chaintip_(struct bitcoind *bitcoind, |
|
|
|
|
|
void (*cb)(struct bitcoind *bitcoind, |
|
|
|
|
|
const struct bitcoin_blkid *tipid, |
|
|
|
|
|
void *arg), |
|
|
|
|
|
void *arg) |
|
|
|
|
|
{ |
|
|
|
|
|
start_bitcoin_cli(bitcoind, NULL, process_chaintips, false, cb, arg, |
|
|
|
|
|
"getchaintips", NULL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void process_rawblock(struct bitcoin_cli *bcli) |
|
|
static void process_rawblock(struct bitcoin_cli *bcli) |
|
|
{ |
|
|
{ |
|
|
struct bitcoin_block *blk; |
|
|
struct bitcoin_block *blk; |
|
|