@ -110,8 +110,6 @@ struct wally_psbt_input *psbt_append_input(struct wally_psbt *psbt,
const struct bitcoin_txid * txid ,
u32 outnum , u32 sequence ,
const u8 * scriptSig ,
struct amount_sat amount ,
const u8 * scriptPubkey ,
const u8 * input_wscript ,
const u8 * redeemscript )
{
@ -145,52 +143,7 @@ struct wally_psbt_input *psbt_append_input(struct wally_psbt *psbt,
if ( input_wscript ) {
/* Add the prev output's data into the PSBT struct */
if ( is_elements ( chainparams ) ) {
struct amount_asset asset ;
/*FIXME: persist asset tags */
asset = amount_sat_to_asset (
& amount ,
chainparams - > fee_asset_tag ) ;
psbt_elements_input_init_witness ( psbt , input_num ,
input_wscript ,
& asset , NULL ) ;
} else
psbt_input_set_prev_utxo_wscript ( psbt , input_num ,
input_wscript ,
amount ) ;
} else if ( scriptPubkey ) {
if ( is_p2wsh ( scriptPubkey , NULL ) | |
is_p2wpkh ( scriptPubkey , NULL ) | |
/* FIXME: assert that p2sh inputs are
* witness / are accompanied by a
* redeemscript + witnessscript */
is_p2sh ( scriptPubkey , NULL ) ) {
/* the only way to get here currently with
* a p2sh script is via a p2sh - p2wpkh script
* that we ' ve created . . . */
/* BIP0174:
* * * Value : The entire transaction output in
* network serialization which the
* current input spends from .
* This should only be present for
* inputs which spend segwit outputs ,
* including P2SH embedded ones .
*/
if ( is_elements ( chainparams ) ) {
struct amount_asset asset ;
/*FIXME: persist asset tags */
asset = amount_sat_to_asset (
& amount ,
chainparams - > fee_asset_tag ) ;
/* FIXME: persist nonces */
psbt_elements_input_init ( psbt , input_num ,
scriptPubkey ,
& asset , NULL ) ;
} else
psbt_input_set_prev_utxo ( psbt , input_num ,
scriptPubkey ,
amount ) ;
}
psbt_input_set_witscript ( psbt , input_num , input_wscript ) ;
}
if ( redeemscript ) {
@ -284,149 +237,43 @@ bool psbt_input_set_signature(struct wally_psbt *psbt, size_t in,
sizeof ( sig - > s . data ) ) = = WALLY_OK ;
}
static void psbt_input_set_witness _utxo ( struct wally_psbt * psbt , size_t in ,
const struct wally_tx_output * txou t )
void psbt_input_set_wit_utxo ( struct wally_psbt * psbt , size_t in ,
const u8 * scriptPubkey , struct amount_sat am t )
{
struct wally_tx_output tx_out ;
int wally_err ;
assert ( psbt - > num_inputs > in ) ;
wally_err = wally_psbt_input_set_witness_utxo ( & psbt - > inputs [ in ] ,
txout ) ;
assert ( wally_err = = WALLY_OK ) ;
}
void psbt_input_set_prev_utxo ( struct wally_psbt * psbt , size_t in ,
const u8 * scriptPubkey , struct amount_sat amt )
{
struct wally_tx_output prev_out ;
int wally_err ;
u8 * scriptpk ;
if ( scriptPubkey ) {
assert ( is_p2wsh ( scriptPubkey , NULL ) | | is_p2wpkh ( scriptPubkey , NULL )
| | is_p2sh ( scriptPubkey , NULL ) ) ;
scriptpk = cast_const ( u8 * , scriptPubkey ) ;
} else {
/* Adding a NULL scriptpubkey is an error, *however* there is the
* possiblity we ' re spending a UTXO that we didn ' t save the
* scriptpubkey data for . in this case we set it to an ' empty '
* or zero - len script */
scriptpk = tal_arr ( psbt , u8 , 1 ) ;
scriptpk [ 0 ] = 0x00 ;
}
assert ( in < psbt - > num_inputs ) ;
assert ( tal_bytelen ( scriptPubkey ) > 0 ) ;
wally_err = wally_tx_output_init ( amt . satoshis , /* Raw: type conv */
scriptpk ,
tal_bytelen ( scriptpk ) ,
& prev _out) ;
scriptPubkey ,
tal_bytelen ( scriptPubkey ) ,
& tx_out ) ;
assert ( wally_err = = WALLY_OK ) ;
psbt_input_set_witness_utxo ( psbt , in , & prev_out ) ;
}
static void psbt_input_set_elements_prev_utxo ( struct wally_psbt * psbt ,
size_t in ,
const u8 * scriptPubkey ,
struct amount_asset * asset ,
const u8 * nonce )
{
struct wally_tx_output prev_out ;
int wally_err ;
u8 * prefixed_value = amount_asset_extract_value ( psbt , asset ) ;
wally_err =
wally_tx_elements_output_init ( scriptPubkey ,
tal_bytelen ( scriptPubkey ) ,
asset - > asset ,
sizeof ( asset - > asset ) ,
prefixed_value ,
tal_bytelen ( prefixed_value ) ,
nonce ,
tal_bytelen ( nonce ) ,
NULL , 0 ,
NULL , 0 ,
& prev_out ) ;
wally_err = wally_psbt_input_set_witness_utxo ( & psbt - > inputs [ in ] ,
& tx_out ) ;
assert ( wally_err = = WALLY_OK ) ;
psbt_input_set_witness_utxo ( psbt , in , & prev_out ) ;
}
void psbt_input_set_prev_utxo_wscript ( struct wally_psbt * psbt , size_t in ,
const u8 * wscript , struct amount_sat amt )
{
int wally_err ;
const u8 * scriptPubkey ;
if ( wscript ) {
scriptPubkey = scriptpubkey_p2wsh ( psbt , wscript ) ;
wally_err = wally_psbt_input_set_witness_script ( & psbt - > inputs [ in ] ,
wscript ,
tal_bytelen ( wscript ) ) ;
assert ( wally_err = = WALLY_OK ) ;
} else
scriptPubkey = NULL ;
psbt_input_set_prev_utxo ( psbt , in , scriptPubkey , amt ) ;
}
static void
psbt_input_set_elements_prev_utxo_wscript ( struct wally_psbt * psbt ,
size_t in ,
const u8 * wscript ,
struct amount_asset * asset ,
const u8 * nonce )
void psbt_input_set_witscript ( struct wally_psbt * psbt , size_t in , const u8 * wscript )
{
int wally_err ;
const u8 * scriptPubkey ;
if ( wscript ) {
scriptPubkey = scriptpubkey_p2wsh ( psbt , wscript ) ;
wally_err = wally_psbt_input_set_witness_script (
& psbt - > inputs [ in ] ,
wscript , tal_bytelen ( wscript ) ) ;
assert ( wally_err = = WALLY_OK ) ;
} else
scriptPubkey = NULL ;
psbt_input_set_elements_prev_utxo ( psbt , in , scriptPubkey ,
asset , nonce ) ;
wally_err = wally_psbt_input_set_witness_script ( & psbt - > inputs [ in ] ,
wscript ,
tal_bytelen ( wscript ) ) ;
assert ( wally_err = = WALLY_OK ) ;
}
void psbt_elements_input_init_witness ( struct wally_psbt * psbt , size_t in ,
const u8 * witscript ,
struct amount_asset * asset ,
const u8 * nonce )
void psbt_elements_input_set_asset ( struct wally_psbt * psbt , size_t in ,
struct amount_asset * asset )
{
psbt_input_set_elements_prev_utxo_wscript (
psbt , in , witscript ,
asset , nonce ) ;
if ( asset - > value > 0 )
wally_psbt_input_set_value ( & psbt - > inputs [ in ] , asset - > value ) ;
/* PSET expects an asset tag without the prefix */
if ( wally_psbt_input_set_asset ( & psbt - > inputs [ in ] ,
asset - > asset + 1 ,
ELEMENTS_ASSET_LEN - 1 ) ! = WALLY_OK )
abort ( ) ;
}
void psbt_elements_input_init ( struct wally_psbt * psbt , size_t in ,
const u8 * scriptPubkey ,
struct amount_asset * asset ,
const u8 * nonce )
{
psbt_input_set_elements_prev_utxo ( psbt , in ,
scriptPubkey ,
asset , nonce ) ;
if ( asset - > value > 0 ) {
if ( wally_psbt_input_set_value (
& psbt - > inputs [ in ] ,
asset - > value ) ! = WALLY_OK )
if ( wally_psbt_input_set_value ( & psbt - > inputs [ in ] ,
asset - > value ) ! = WALLY_OK )
abort ( ) ;
}
/* PSET expects an asset tag without the prefix */
/* FIXME: Verify that we're sending unblinded asset tag */
if ( wally_psbt_input_set_asset ( & psbt - > inputs [ in ] ,
asset - > asset + 1 ,
ELEMENTS_ASSET_LEN - 1 ) ! = WALLY_OK )