bitcoind: routine to broadcast a transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-01-22 06:41:49 +10:30
parent fc49e3fd74
commit d5328c7577
2 changed files with 32 additions and 0 deletions

View File

@@ -229,3 +229,32 @@ void bitcoind_txid_lookup_(struct lightningd_state *dstate,
start_bitcoin_cli(dstate, process_rawtx, cb, arg,
"getrawtransaction", txidhex, NULL);
}
static void process_sendrawrx(struct bitcoin_cli *bcli)
{
struct sha256_double txid;
const char *out = (char *)bcli->output;
/* We expect a txid, plus \n */
if (bcli->output_bytes == 0
|| !bitcoin_txid_from_hex(out, bcli->output_bytes-1, &txid))
fatal("sendrawtransaction failed: %.*s",
(int)bcli->output_bytes, out);
log_debug(bcli->dstate->base_log, "sendrawtx gave %.*s",
(int)bcli->output_bytes, out);
/* FIXME: Compare against expected txid? */
}
void bitcoind_send_tx(struct lightningd_state *dstate,
const struct bitcoin_tx *tx)
{
u8 *raw = linearize_tx(dstate, tx);
char *hex = tal_arr(raw, char, hex_str_size(tal_count(raw)));
hex_encode(raw, tal_count(raw), hex, tal_count(hex));
start_bitcoin_cli(dstate, process_sendrawrx, NULL, NULL,
"sendrawtransaction", hex, NULL);
tal_free(raw);
}

View File

@@ -30,4 +30,7 @@ void bitcoind_txid_lookup_(struct lightningd_state *dstate,
const struct bitcoin_tx *), \
(arg))
void bitcoind_send_tx(struct lightningd_state *dstate,
const struct bitcoin_tx *tx);
#endif /* LIGHTNING_DAEMON_BITCOIND_H */