mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 10:38:25 +01:00
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
This commit is contained in:
parent
169b7817dc
commit
303263d381
31 changed files with 92 additions and 280 deletions
193
bitcoin/psbt.c
193
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)
|
||||
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_prev_utxo(psbt, in, scriptPubkey, amt);
|
||||
wally_err = wally_psbt_input_set_witness_script(&psbt->inputs[in],
|
||||
wscript,
|
||||
tal_bytelen(wscript));
|
||||
assert(wally_err == WALLY_OK);
|
||||
}
|
||||
|
||||
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_elements_input_set_asset(struct wally_psbt *psbt, size_t in,
|
||||
struct amount_asset *asset)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void psbt_elements_input_init_witness(struct wally_psbt *psbt, size_t in,
|
||||
const u8 *witscript,
|
||||
struct amount_asset *asset,
|
||||
const u8 *nonce)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
#include <common/setup.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
#include <common/utils.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
21
bitcoin/tx.c
21
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -13,9 +13,6 @@ static const char *reason;
|
|||
#include <common/bigsize.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(); }
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
#include <wire/wire_io.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
#include <wally_core.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
#include <wally_core.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
#include <common/amount.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
#include <wire/wire.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
#include <wire/wire.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
#include <wire/wire.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
#include <wire/wire.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
#include <wire/wire.h>
|
||||
|
||||
/* 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(); }
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
15
wallet/db.c
15
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();
|
||||
|
|
2
wallet/db_postgres_sqlgen.c
generated
2
wallet/db_postgres_sqlgen.c
generated
|
@ -1648,4 +1648,4 @@ struct db_query db_postgres_queries[] = {
|
|||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||
|
||||
// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7
|
||||
// SHA256STAMP:4b62394a2377b4aada8173bf750c6f293c84e4f0c9097c8774e625f76e17faa6
|
||||
|
|
2
wallet/db_sqlite3_sqlgen.c
generated
2
wallet/db_sqlite3_sqlgen.c
generated
|
@ -1648,4 +1648,4 @@ struct db_query db_sqlite3_queries[] = {
|
|||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||
|
||||
// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7
|
||||
// SHA256STAMP:4b62394a2377b4aada8173bf750c6f293c84e4f0c9097c8774e625f76e17faa6
|
||||
|
|
|
@ -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;
|
||||
|
|
4
wallet/statements_gettextgen.po
generated
4
wallet/statements_gettextgen.po
generated
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue