From 24578c7fea8a48f0f86defa9d125b910aa0f8fe3 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 9 Sep 2020 16:26:47 -0500 Subject: [PATCH] elementsd: use the elements version of a 'witness utxo' Elements requires the witness utxo to include the asset and value info, in order for the signing hash to be constructed correctly Changelog-Fixed: elementsd: PSBTs include correct witness_utxo struct for elements transactions --- bitcoin/psbt.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index ad9d2d05f..f6c88d0c6 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -257,13 +257,29 @@ void psbt_input_set_wit_utxo(struct wally_psbt *psbt, size_t in, assert(in < psbt->num_inputs); assert(tal_bytelen(scriptPubkey) > 0); - wally_err = wally_tx_output_init(amt.satoshis, /* Raw: type conv */ - scriptPubkey, - tal_bytelen(scriptPubkey), - &tx_out); + if (is_elements(chainparams)) { + u8 value[9]; + wally_err = + wally_tx_confidential_value_from_satoshi(amt.satoshis, /* Raw: wally API */ + value, + sizeof(value)); + assert(wally_err == WALLY_OK); + wally_err = + wally_tx_elements_output_init(scriptPubkey, + tal_bytelen(scriptPubkey), + chainparams->fee_asset_tag, + ELEMENTS_ASSET_LEN, + value, sizeof(value), + NULL, 0, NULL, 0, + NULL, 0, &tx_out); + + } else + wally_err = wally_tx_output_init(amt.satoshis, /* Raw: type conv */ + scriptPubkey, + tal_bytelen(scriptPubkey), + &tx_out); assert(wally_err == WALLY_OK); - wally_err = wally_psbt_input_set_witness_utxo(&psbt->inputs[in], - &tx_out); + wally_err = wally_psbt_input_set_witness_utxo(&psbt->inputs[in], &tx_out); assert(wally_err == WALLY_OK); }