mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
daemon/bitcoind: bitcoind_sendrawtx to send hex string.
This can fail. Real cases include both sides dumping their commitment txs in testing (only one can succeed). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8fe2ba0ab3
commit
c1dc0e54fa
@ -220,7 +220,7 @@ void bitcoind_estimate_fee_(struct lightningd_state *dstate,
|
||||
"estimatefee", "2", NULL);
|
||||
}
|
||||
|
||||
static void process_sendrawrx(struct bitcoin_cli *bcli)
|
||||
static void process_sendtx(struct bitcoin_cli *bcli)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
const char *out = (char *)bcli->output;
|
||||
@ -243,11 +243,34 @@ void bitcoind_send_tx(struct lightningd_state *dstate,
|
||||
u8 *raw = linearize_tx(dstate, tx);
|
||||
char *hex = tal_hexstr(raw, raw, tal_count(raw));
|
||||
|
||||
start_bitcoin_cli(dstate, process_sendrawrx, false, NULL, NULL,
|
||||
start_bitcoin_cli(dstate, process_sendtx, false, NULL, NULL,
|
||||
"sendrawtransaction", hex, NULL);
|
||||
tal_free(raw);
|
||||
}
|
||||
|
||||
static void process_sendrawtx(struct bitcoin_cli *bcli)
|
||||
{
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const char *msg, void *) = bcli->cb;
|
||||
const char *msg = tal_strndup(bcli, (char *)bcli->output,
|
||||
bcli->output_bytes);
|
||||
|
||||
log_debug(bcli->dstate->base_log, "sendrawtx exit %u, gave %s",
|
||||
*bcli->exitstatus, msg);
|
||||
|
||||
cb(bcli->dstate, msg, bcli->cb_arg);
|
||||
}
|
||||
|
||||
void bitcoind_sendrawtx_(struct lightningd_state *dstate,
|
||||
const char *hextx,
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const char *msg, void *),
|
||||
void *arg)
|
||||
{
|
||||
start_bitcoin_cli(dstate, process_sendrawtx, true, cb, arg,
|
||||
"sendrawtransaction", hextx, NULL);
|
||||
}
|
||||
|
||||
static void process_chaintips(struct bitcoin_cli *bcli)
|
||||
{
|
||||
const jsmntok_t *tokens, *t, *end;
|
||||
|
@ -30,6 +30,20 @@ void bitcoind_estimate_fee_(struct lightningd_state *dstate,
|
||||
void bitcoind_send_tx(struct lightningd_state *dstate,
|
||||
const struct bitcoin_tx *tx);
|
||||
|
||||
void bitcoind_sendrawtx_(struct lightningd_state *dstate,
|
||||
const char *hextx,
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
const char *msg, void *),
|
||||
void *arg);
|
||||
|
||||
#define bitcoind_sendrawtx(dstate, hextx, cb, arg) \
|
||||
bitcoind_sendrawtx_((dstate), (hextx), \
|
||||
typesafe_cb_preargs(void, void *, \
|
||||
(cb), (arg), \
|
||||
struct lightningd_state *, \
|
||||
const char *), \
|
||||
(arg))
|
||||
|
||||
void bitcoind_get_chaintips_(struct lightningd_state *dstate,
|
||||
void (*cb)(struct lightningd_state *dstate,
|
||||
struct sha256_double *blockids,
|
||||
|
Loading…
Reference in New Issue
Block a user