From 14de198bd1645cf7257af3e770c95e73d8c62867 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 2 Jul 2020 15:53:51 -0500 Subject: [PATCH] wally-tx: add type-to-string for a wally-tx and then use it to print out things --- bitcoin/tx.c | 9 +++++++++ common/type_to_string.h | 1 + wallet/walletrpc.c | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index b2ea98c54..375a4a203 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -632,8 +632,17 @@ static char *fmt_bitcoin_txid(const tal_t *ctx, const struct bitcoin_txid *txid) return hexstr; } +static char *fmt_wally_tx(const tal_t *ctx, const struct wally_tx *tx) +{ + u8 *lin = linearize_wtx(ctx, tx); + char *s = tal_hex(ctx, lin); + tal_free(lin); + return s; +} + REGISTER_TYPE_TO_STRING(bitcoin_tx, fmt_bitcoin_tx); REGISTER_TYPE_TO_STRING(bitcoin_txid, fmt_bitcoin_txid); +REGISTER_TYPE_TO_STRING(wally_tx, fmt_wally_tx); void fromwire_bitcoin_txid(const u8 **cursor, size_t *max, struct bitcoin_txid *txid) diff --git a/common/type_to_string.h b/common/type_to_string.h index ce134b946..440678d74 100644 --- a/common/type_to_string.h +++ b/common/type_to_string.h @@ -37,6 +37,7 @@ union printable_types { const struct fee_states *fee_states; const char *charp_; const struct wally_psbt *wally_psbt; + const struct wally_tx *wally_tx; }; #define type_to_string(ctx, type, ptr) \ diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index afbad92a9..0644c7826 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -99,8 +99,9 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED, was_pending(command_success(cmd, response)); } else { was_pending(command_fail(cmd, LIGHTNINGD, - "Error broadcasting transaction: %s. Unsent tx discarded", - output)); + "Error broadcasting transaction: %s. Unsent tx discarded %s", + output, + type_to_string(tmpctx, struct wally_tx, txb->wtx))); } }