From 303263d381b4bb7fd295acf229d4fbc56b01daa4 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 9 Sep 2020 19:40:29 +0930 Subject: [PATCH] psbt: clean up interface for setting metadata on PSBT inputs it's just neater if it's not all wrapped up together, simplifies the interface a smidge --- bitcoin/psbt.c | 193 +++------------------- bitcoin/psbt.h | 19 ++- bitcoin/test/run-bitcoin_block_from_hex.c | 12 -- bitcoin/test/run-tx-encode.c | 12 -- bitcoin/tx.c | 21 ++- cli/test/run-large-input.c | 3 - cli/test/run-remove-hint.c | 3 - common/psbt_open.c | 2 +- common/test/run-bigsize.c | 3 - common/test/run-cryptomsg.c | 3 - common/test/run-derive_basepoints.c | 3 - common/test/run-features.c | 3 - common/test/run-gossip_rcvd_filter.c | 3 - common/test/run-ip_port_parsing.c | 3 - common/test/run-json_remove.c | 3 - common/test/run-key_derive.c | 3 - common/test/run-lock.c | 3 - common/test/run-psbt_diff.c | 2 +- common/test/run-softref.c | 3 - common/test/run-sphinx.c | 3 - connectd/test/run-initiator-success.c | 3 - connectd/test/run-responder-success.c | 3 - hsmd/hsmd.c | 9 +- onchaind/test/run-grind_feerate-bug.c | 5 +- onchaind/test/run-grind_feerate.c | 4 +- openingd/dualopend.c | 19 ++- wallet/db.c | 15 +- wallet/db_postgres_sqlgen.c | 2 +- wallet/db_sqlite3_sqlgen.c | 2 +- wallet/reservation.c | 6 +- wallet/statements_gettextgen.po | 4 +- 31 files changed, 92 insertions(+), 280 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index f3aebb2bf..806707225 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -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 *txout) +void psbt_input_set_wit_utxo(struct wally_psbt *psbt, size_t in, + const u8 *scriptPubkey, struct amount_sat amt) { + 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) diff --git a/bitcoin/psbt.h b/bitcoin/psbt.h index 2047ee8ee..8f08858e2 100644 --- a/bitcoin/psbt.h +++ b/bitcoin/psbt.h @@ -90,11 +90,18 @@ 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); +/* psbt_input_set_wit_utxo - Set the witness_utxo field for this PSBT */ +void psbt_input_set_wit_utxo(struct wally_psbt *psbt, size_t in, + const u8 *scriptPubkey, struct amount_sat amt); + +/* psbt_elements_input_set_asset - Set the asset/value fields for an + * Elements PSBT (PSET, technically */ +void psbt_elements_input_set_asset(struct wally_psbt *psbt, size_t in, + struct amount_asset *asset); + void psbt_rm_input(struct wally_psbt *psbt, size_t remove_at); @@ -123,13 +130,7 @@ WARN_UNUSED_RESULT bool psbt_input_set_signature(struct wally_psbt *psbt, size_t const struct pubkey *pubkey, const struct bitcoin_signature *sig); -void psbt_input_set_prev_utxo(struct wally_psbt *psbt, - size_t in, - const u8 *wscript, - struct amount_sat amt); -void psbt_input_set_prev_utxo_wscript(struct wally_psbt *psbt, size_t in, - const u8 *wscript, - struct amount_sat amt); +void psbt_input_set_witscript(struct wally_psbt *psbt, size_t in, const u8 *wscript); void psbt_elements_input_init(struct wally_psbt *psbt, size_t in, const u8 *scriptPubkey, struct amount_asset *asset, diff --git a/bitcoin/test/run-bitcoin_block_from_hex.c b/bitcoin/test/run-bitcoin_block_from_hex.c index 9f4e6f5fc..e87b879cb 100644 --- a/bitcoin/test/run-bitcoin_block_from_hex.c +++ b/bitcoin/test/run-bitcoin_block_from_hex.c @@ -7,9 +7,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } @@ -66,15 +63,6 @@ u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for is_anchor_witness_script */ bool is_anchor_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) { fprintf(stderr, "is_anchor_witness_script called!\n"); abort(); } -/* Generated stub for is_p2sh */ -bool is_p2sh(const u8 *script UNNEEDED, struct ripemd160 *addr UNNEEDED) -{ fprintf(stderr, "is_p2sh called!\n"); abort(); } -/* Generated stub for is_p2wpkh */ -bool is_p2wpkh(const u8 *script UNNEEDED, struct bitcoin_address *addr UNNEEDED) -{ fprintf(stderr, "is_p2wpkh called!\n"); abort(); } -/* Generated stub for is_p2wsh */ -bool is_p2wsh(const u8 *script UNNEEDED, struct sha256 *addr UNNEEDED) -{ fprintf(stderr, "is_p2wsh called!\n"); abort(); } /* Generated stub for pubkey_to_der */ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UNNEEDED) { fprintf(stderr, "pubkey_to_der called!\n"); abort(); } diff --git a/bitcoin/test/run-tx-encode.c b/bitcoin/test/run-tx-encode.c index 84e89078a..744333869 100644 --- a/bitcoin/test/run-tx-encode.c +++ b/bitcoin/test/run-tx-encode.c @@ -8,9 +8,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } @@ -67,15 +64,6 @@ u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for is_anchor_witness_script */ bool is_anchor_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) { fprintf(stderr, "is_anchor_witness_script called!\n"); abort(); } -/* Generated stub for is_p2sh */ -bool is_p2sh(const u8 *script UNNEEDED, struct ripemd160 *addr UNNEEDED) -{ fprintf(stderr, "is_p2sh called!\n"); abort(); } -/* Generated stub for is_p2wpkh */ -bool is_p2wpkh(const u8 *script UNNEEDED, struct bitcoin_address *addr UNNEEDED) -{ fprintf(stderr, "is_p2wpkh called!\n"); abort(); } -/* Generated stub for is_p2wsh */ -bool is_p2wsh(const u8 *script UNNEEDED, struct sha256 *addr UNNEEDED) -{ fprintf(stderr, "is_p2wsh called!\n"); abort(); } /* Generated stub for pubkey_to_der */ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UNNEEDED) { fprintf(stderr, "pubkey_to_der called!\n"); abort(); } diff --git a/bitcoin/tx.c b/bitcoin/tx.c index dea1ca143..6c069d721 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -191,14 +191,31 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, int input_num = tx->wtx->num_inputs; psbt_append_input(tx->psbt, txid, outnum, sequence, scriptSig, - amount, scriptPubkey, input_wscript, NULL); + input_wscript, NULL); + + if (input_wscript) { + scriptPubkey = scriptpubkey_p2wsh(tx->psbt, input_wscript); + } + + assert(scriptPubkey); + psbt_input_set_wit_utxo(tx->psbt, input_num, + scriptPubkey, amount); wally_err = wally_tx_add_input(tx->wtx, &tx->psbt->tx->inputs[input_num]); assert(wally_err == WALLY_OK); - /* scriptsig isn't actually store in psbt input, so add that now */ + + /* scriptsig isn't actually stored in psbt input, so add that now */ wally_tx_set_input_script(tx->wtx, input_num, scriptSig, tal_bytelen(scriptSig)); + 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_set_asset(tx->psbt, input_num, &asset); + } return input_num; } diff --git a/cli/test/run-large-input.c b/cli/test/run-large-input.c index a11611d55..a876d01af 100644 --- a/cli/test/run-large-input.c +++ b/cli/test/run-large-input.c @@ -33,9 +33,6 @@ int test_chdir(const char *path); #undef main /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/cli/test/run-remove-hint.c b/cli/test/run-remove-hint.c index 38f015e67..ff1562777 100644 --- a/cli/test/run-remove-hint.c +++ b/cli/test/run-remove-hint.c @@ -36,9 +36,6 @@ int test_chdir(const char *path); #undef main /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/psbt_open.c b/common/psbt_open.c index d26a7dbbd..d4b7595b6 100644 --- a/common/psbt_open.c +++ b/common/psbt_open.c @@ -100,7 +100,7 @@ static const u8 *linearize_output(const tal_t *ctx, /* Add a 'fake' input so this will linearize the tx */ memset(&txid, 0, sizeof(txid)); - psbt_append_input(psbt, &txid, 0, 0, NULL, AMOUNT_SAT(0), NULL, NULL, NULL); + psbt_append_input(psbt, &txid, 0, 0, NULL, NULL, NULL); if (wally_tx_add_output(psbt->tx, tx_out) != WALLY_OK) abort(); diff --git a/common/test/run-bigsize.c b/common/test/run-bigsize.c index 4a1f511d2..62d440ad6 100644 --- a/common/test/run-bigsize.c +++ b/common/test/run-bigsize.c @@ -13,9 +13,6 @@ static const char *reason; #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-cryptomsg.c b/common/test/run-cryptomsg.c index 1f32a2376..731b60359 100644 --- a/common/test/run-cryptomsg.c +++ b/common/test/run-cryptomsg.c @@ -8,9 +8,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-derive_basepoints.c b/common/test/run-derive_basepoints.c index ae82af7d9..3644581b6 100644 --- a/common/test/run-derive_basepoints.c +++ b/common/test/run-derive_basepoints.c @@ -9,9 +9,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-features.c b/common/test/run-features.c index ea5f7d43c..9efd9933d 100644 --- a/common/test/run-features.c +++ b/common/test/run-features.c @@ -8,9 +8,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-gossip_rcvd_filter.c b/common/test/run-gossip_rcvd_filter.c index 39a75cc68..135c4e967 100644 --- a/common/test/run-gossip_rcvd_filter.c +++ b/common/test/run-gossip_rcvd_filter.c @@ -5,9 +5,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-ip_port_parsing.c b/common/test/run-ip_port_parsing.c index a9a112def..eaa68e7a1 100644 --- a/common/test/run-ip_port_parsing.c +++ b/common/test/run-ip_port_parsing.c @@ -7,9 +7,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index 2408cf7fc..f58bcfc48 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -5,9 +5,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-key_derive.c b/common/test/run-key_derive.c index 49caf95d9..550bb20d6 100644 --- a/common/test/run-key_derive.c +++ b/common/test/run-key_derive.c @@ -10,9 +10,6 @@ #include "../key_derive.c" /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-lock.c b/common/test/run-lock.c index 3572f9126..934bd04a6 100644 --- a/common/test/run-lock.c +++ b/common/test/run-lock.c @@ -9,9 +9,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-psbt_diff.c b/common/test/run-psbt_diff.c index b69a66616..ffa6039ec 100644 --- a/common/test/run-psbt_diff.c +++ b/common/test/run-psbt_diff.c @@ -104,7 +104,7 @@ static void add_in_out_with_serial(struct wally_psbt *psbt, memset(&txid, default_value, sizeof(txid)); in = psbt_append_input(psbt, &txid, default_value, default_value, - NULL, AMOUNT_SAT(0), NULL, NULL, NULL); + NULL, NULL, NULL); if (!in) abort(); psbt_input_add_serial_id(in, serial_id); diff --git a/common/test/run-softref.c b/common/test/run-softref.c index 0fa9a8aed..477f1aad6 100644 --- a/common/test/run-softref.c +++ b/common/test/run-softref.c @@ -6,9 +6,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/common/test/run-sphinx.c b/common/test/run-sphinx.c index 39cc068a9..1eac47732 100644 --- a/common/test/run-sphinx.c +++ b/common/test/run-sphinx.c @@ -16,9 +16,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/connectd/test/run-initiator-success.c b/connectd/test/run-initiator-success.c index 458d9ccfb..fcbd372b8 100644 --- a/connectd/test/run-initiator-success.c +++ b/connectd/test/run-initiator-success.c @@ -12,9 +12,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/connectd/test/run-responder-success.c b/connectd/test/run-responder-success.c index 9593670f0..4eb799445 100644 --- a/connectd/test/run-responder-success.c +++ b/connectd/test/run-responder-success.c @@ -12,9 +12,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for amount_asset_extract_value */ -u8 *amount_asset_extract_value(const tal_t *ctx UNNEEDED, struct amount_asset *asset UNNEEDED) -{ fprintf(stderr, "amount_asset_extract_value called!\n"); abort(); } /* Generated stub for amount_asset_is_main */ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index fe25a542c..b5e4010db 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -1576,10 +1576,11 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) /* It's actually a P2WSH in this case. */ if (utxo->close_info && utxo->close_info->option_anchor_outputs) { - psbt_input_set_prev_utxo_wscript(psbt, j, - anchor_to_remote_redeem(tmpctx, - &pubkey), - utxo->amount); + const u8 *wscript = anchor_to_remote_redeem(tmpctx, &pubkey); + psbt_input_set_witscript(psbt, j, wscript); + psbt_input_set_wit_utxo(psbt, j, + scriptpubkey_p2wsh(psbt, wscript), + utxo->amount); } if (wally_psbt_sign(psbt, privkey.secret.data, sizeof(privkey.secret.data), diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index 2576d6995..9713db507 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -358,7 +358,10 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, assert(tx); in_amount = amount_msat_to_sat_round_down(htlc_msatoshi); - psbt_input_set_prev_utxo_wscript(tx->psbt, 0, commit_wscript, in_amount); + psbt_input_set_wit_utxo(tx->psbt, 0, + scriptpubkey_p2wsh(tx->psbt, commit_wscript), + in_amount); + psbt_input_set_witscript(tx->psbt, 0, commit_wscript); tx->chainparams = chainparams; bitcoin_tx_set_locktime(tx, cltv_expiry); diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 17aa445f3..1f9b3a13e 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -331,12 +331,14 @@ int main(int argc, char *argv[]) struct keyset *keys; struct timeabs start, end; int iterations = 1000; + u8 *spk = tal_arr(tmpctx, u8, 1); + spk[0] = 0x00; chainparams = chainparams_for_network("bitcoin"); tx = bitcoin_tx_from_hex(tmpctx, "0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000", strlen("0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000")); tx->chainparams = chainparams_for_network("regtest"); - psbt_input_set_prev_utxo(tx->psbt, 0, NULL, AMOUNT_SAT(700000)); + psbt_input_set_wit_utxo(tx->psbt, 0, spk, AMOUNT_SAT(700000)); tx->chainparams = chainparams_for_network("bitcoin"); der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01", strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01")); diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 864852f38..b66c5e2fb 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -777,15 +777,9 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb * The receiving node: * - MUST add all received inputs to the funding transaction */ - /* FIXME: elements! */ - bitcoin_tx_output_get_amount_sat(tx, outnum, &amt); - struct wally_psbt_input *in = psbt_append_input(psbt, &txid, outnum, sequence, NULL, - amt, - bitcoin_tx_output_get_script(tmpctx, - tx, outnum), NULL, redeemscript); if (!in) @@ -793,6 +787,19 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb "Unable to add input"); wally_psbt_input_set_utxo(in, tx->wtx); + + if (is_elements(chainparams)) { + struct amount_asset asset; + + bitcoin_tx_output_get_amount_sat(tx, outnum, &amt); + + /* FIXME: persist asset tags */ + asset = amount_sat_to_asset(&amt, + chainparams->fee_asset_tag); + /* FIXME: persist nonces */ + psbt_elements_input_set_asset(psbt, outnum, &asset); + } + psbt_input_add_serial_id(in, serial_id); psbt_input_add_max_witness_len(in, max_witness_len); diff --git a/wallet/db.c b/wallet/db.c index 89193bda5..894ce2760 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1322,18 +1322,19 @@ void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db, funding_wscript = bitcoin_redeem_2of2(stmt, &local_funding_pubkey, &remote_funding_pubkey); + + psbt_input_set_wit_utxo(last_tx->psbt, 0, + scriptpubkey_p2wsh(last_tx->psbt, funding_wscript), + funding_sat); + psbt_input_set_witscript(last_tx->psbt, 0, funding_wscript); if (is_elements(chainparams)) { /*FIXME: persist asset tags */ struct amount_asset asset; asset = amount_sat_to_asset(&funding_sat, chainparams->fee_asset_tag); - psbt_elements_input_init_witness(last_tx->psbt, - 0, funding_wscript, - &asset, NULL); - } else - psbt_input_set_prev_utxo_wscript(last_tx->psbt, - 0, funding_wscript, - funding_sat); + psbt_elements_input_set_asset(last_tx->psbt, 0, &asset); + } + if (!db_column_signature(stmt, 5, &last_sig.s)) abort(); diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index ef3cb5ab5..499466a7f 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1648,4 +1648,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7 +// SHA256STAMP:4b62394a2377b4aada8173bf750c6f293c84e4f0c9097c8774e625f76e17faa6 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 3ebb23094..e4589e61c 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1648,4 +1648,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7 +// SHA256STAMP:4b62394a2377b4aada8173bf750c6f293c84e4f0c9097c8774e625f76e17faa6 diff --git a/wallet/reservation.c b/wallet/reservation.c index e80fdcf9d..6d581908e 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -277,8 +277,10 @@ static struct wally_psbt *psbt_using_utxos(const tal_t *ctx, this_nsequence = nsequence; psbt_append_input(psbt, &utxos[i]->txid, utxos[i]->outnum, - this_nsequence, scriptSig, utxos[i]->amount, - scriptPubkey, NULL, redeemscript); + this_nsequence, scriptSig, + NULL, redeemscript); + + psbt_input_set_wit_utxo(psbt, i, scriptPubkey, utxos[i]->amount); } return psbt; diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 58e19111d..a882a3d84 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -602,7 +602,7 @@ msgstr "" msgid "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;" msgstr "" -#: wallet/db.c:1350 +#: wallet/db.c:1351 msgid "UPDATE channels SET last_tx = ? WHERE id = ?;" msgstr "" @@ -1085,4 +1085,4 @@ msgstr "" #: wallet/test/run-wallet.c:1355 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:a2c4fd6e26d81d871d9ee5201a844e09d94b4ea50c3690060dea4dd640ef007b +# SHA256STAMP:c0605983e2071b5f504b2bcbfd747ca305658f7a8b4f9df4176ffd0815bf7bff