Browse Source

bitcoind: routine to broadcast a transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
d5328c7577
  1. 29
      daemon/bitcoind.c
  2. 3
      daemon/bitcoind.h

29
daemon/bitcoind.c

@ -229,3 +229,32 @@ void bitcoind_txid_lookup_(struct lightningd_state *dstate,
start_bitcoin_cli(dstate, process_rawtx, cb, arg, start_bitcoin_cli(dstate, process_rawtx, cb, arg,
"getrawtransaction", txidhex, NULL); "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);
}

3
daemon/bitcoind.h

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

Loading…
Cancel
Save