Browse Source

wally: Add a consistency check for old and new style txs

During the migration to `libwally` we want to make absolutely sure that both
transactions are generated identical, and can eventually be switched over.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pr-2587
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
3937b17e2b
  1. 21
      bitcoin/tx.c
  2. 8
      bitcoin/tx.h

21
bitcoin/tx.c

@ -63,6 +63,27 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
return i;
}
bool bitcoin_tx_check(const struct bitcoin_tx *tx)
{
u8 *oldtx = linearize_tx(tmpctx, tx);
u8 *newtx;
size_t written;
if (wally_tx_get_length(tx->wtx, WALLY_TX_FLAG_USE_WITNESS, &written) !=
WALLY_OK)
return false;
newtx = tal_arr(tmpctx, u8, written);
if (wally_tx_to_bytes(tx->wtx, WALLY_TX_FLAG_USE_WITNESS, newtx, written,
&written) != WALLY_OK)
return false;
if (written != tal_bytelen(newtx))
return false;
return memeq(oldtx, tal_bytelen(oldtx), newtx, tal_bytelen(newtx));
}
static void push_tx_input(const struct bitcoin_tx_input *input,
const u8 *input_script,
void (*push)(const void *, size_t, void *), void *pushp)

8
bitcoin/tx.h

@ -92,4 +92,12 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
u32 outnum, u32 sequence,
const struct amount_sat *amount, u8 *script);
/**
* Check a transaction for consistency.
*
* Mainly for the transition from `bitcoin_tx` to the `wally_tx`. Checks that
* both transactions serialize to two identical representations.
*/
bool bitcoin_tx_check(const struct bitcoin_tx *tx);
#endif /* LIGHTNING_BITCOIN_TX_H */

Loading…
Cancel
Save