psbt: move channels.last_tx field to be a psbt

note: missing migration at the moment lol
This commit is contained in:
niftynei
2020-05-21 22:18:33 -05:00
committed by Christian Decker
parent 052d40ae98
commit 8fa04a710a
5 changed files with 60 additions and 15 deletions

View File

@@ -494,6 +494,38 @@ char *bitcoin_tx_to_psbt_base64(const tal_t *ctx, struct bitcoin_tx *tx)
return ret_val;
}
struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psbt STEALS)
{
struct wally_psbt *tmppsbt;
struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams,
psbt->tx->num_inputs,
psbt->tx->num_outputs,
psbt->tx->locktime);
wally_tx_free(tx->wtx);
/* We want the 'finalized' tx since that includes any signature
* data, not the global tx. But 'finalizing' a tx destroys some fields
* so we 'clone' it first and then finalize it */
if (wally_psbt_clone(psbt, &tmppsbt) != WALLY_OK)
abort();
if (wally_finalize_psbt(tmppsbt) != WALLY_OK)
abort();
if (psbt_is_finalized(tmppsbt)) {
if (wally_extract_psbt(tmppsbt, &tx->wtx) != WALLY_OK)
abort();
} else if (wally_tx_clone(psbt->tx, &tx->wtx) != WALLY_OK)
abort();
wally_psbt_free(tmppsbt);
tal_free(tx->psbt);
tx->psbt = tal_steal(tx, psbt);
return tx;
}
struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
size_t *max)
{

View File

@@ -65,6 +65,9 @@ bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
bool bitcoin_txid_to_hex(const struct bitcoin_txid *txid,
char *hexstr, size_t hexstr_len);
/* Create a bitcoin_tx from a psbt */
struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psbt);
/* Internal de-linearization functions. */
struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx,
const u8 **cursor, size_t *max);