mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-03 22:34:21 +01:00
bitcoind: routine to broadcast a transaction.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user