@ -501,38 +501,18 @@ char *bitcoin_tx_to_psbt_base64(const tal_t *ctx, struct bitcoin_tx *tx)
struct bitcoin_tx * bitcoin_tx_with_psbt ( const tal_t * ctx , struct wally_psbt * psbt STEALS )
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 ,
struct bitcoin_tx * tx = bitcoin_tx ( ctx , chainparams ,
psbt - > tx - > num_inputs ,
psbt - > tx - > num_inputs ,
psbt - > tx - > num_outputs ,
psbt - > tx - > num_outputs ,
psbt - > tx - > locktime ) ;
psbt - > tx - > locktime ) ;
wally_tx_free ( tx - > wtx ) ;
wally_tx_free ( tx - > wtx ) ;
tx - > wtx = psbt_finalize ( psbt , false ) ;
/* We want the 'finalized' tx since that includes any signature
if ( ! tx - > wtx & & wally_tx_clone ( psbt - > tx , & tx - > wtx ) ! = WALLY_OK )
* 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 )
return NULL ;
if ( wally_finalize_psbt ( tmppsbt ) ! = WALLY_OK ) {
wally_psbt_free ( tmppsbt ) ;
return NULL ;
}
if ( psbt_is_finalized ( tmppsbt ) ) {
if ( wally_extract_psbt ( tmppsbt , & tx - > wtx ) ! = WALLY_OK ) {
wally_psbt_free ( tmppsbt ) ;
return NULL ;
}
} else if ( wally_tx_clone ( psbt - > tx , & tx - > wtx ) ! = WALLY_OK ) {
wally_psbt_free ( tmppsbt ) ;
return NULL ;
return NULL ;
}
wally_psbt_free ( tmppsbt ) ;
tal_free ( tx - > psbt ) ;
tal_free ( tx - > psbt ) ;
tx - > psbt = tal_steal ( tx , psbt ) ;
tx - > psbt = tal_steal ( tx , psbt ) ;
return tx ;
return tx ;
}
}