mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 17:14:28 +01:00
fundpsbt: add option to filter out wrapped p2sh inputs
We need to be able to only use non-wrapped inputs for v2/interactive tx protocol. Changelog-Added: JSONRPC: `fundpsbt` option `nonwrapped` filters out p2sh wrapped inputs
This commit is contained in:
@@ -47,6 +47,9 @@ the actual witness weight will be used.
|
||||
*excess\_as\_change* is an optional boolean to flag to add a change output
|
||||
for the excess sats.
|
||||
|
||||
*nonwrapped* is an optional boolean to signal to filter out any p2sh-wrapped
|
||||
inputs from funding this PSBT.
|
||||
|
||||
EXAMPLE USAGE
|
||||
-------------
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
||||
u32 *feerate_per_kw;
|
||||
u32 *minconf, *weight, *min_witness_weight;
|
||||
struct amount_sat *amount, input, diff;
|
||||
bool all, *excess_as_change;
|
||||
bool all, *excess_as_change, *nonwrapped;
|
||||
u32 *locktime, *reserve, maxheight;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
@@ -458,6 +458,8 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
||||
&min_witness_weight, 0),
|
||||
p_opt_def("excess_as_change", param_bool,
|
||||
&excess_as_change, false),
|
||||
p_opt_def("nonwrapped", param_bool,
|
||||
&nonwrapped, false),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
@@ -479,6 +481,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
||||
&diff,
|
||||
*feerate_per_kw,
|
||||
maxheight,
|
||||
*nonwrapped,
|
||||
cast_const2(const struct utxo **, utxos));
|
||||
if (utxo) {
|
||||
utxo_weight = utxo_spend_weight(utxo,
|
||||
|
||||
@@ -1050,13 +1050,14 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
||||
/* Arbitrarily set scriptpubkey len to 20 */
|
||||
u.scriptPubkey = tal_arr(w, u8, 20);
|
||||
memset(u.scriptPubkey, 1, 20);
|
||||
CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh),
|
||||
CHECK_MSG(wallet_add_utxo(w, &u, our_change),
|
||||
"wallet_add_utxo with close_info");
|
||||
|
||||
/* Now select them */
|
||||
utxos = tal_arr(w, const struct utxo *, 0);
|
||||
while ((one_utxo = wallet_find_utxo(w, w, 100, NULL, 253,
|
||||
0 /* no confirmations required */,
|
||||
false,
|
||||
utxos)) != NULL) {
|
||||
tal_arr_expand(&utxos, one_utxo);
|
||||
}
|
||||
@@ -1145,6 +1146,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
||||
utxos = tal_arr(w, const struct utxo *, 0);
|
||||
while ((one_utxo = wallet_find_utxo(w, w, 100, NULL, 253,
|
||||
0 /* no confirmations required */,
|
||||
false,
|
||||
utxos)) != NULL) {
|
||||
tal_arr_expand(&utxos, one_utxo);
|
||||
}
|
||||
@@ -1166,6 +1168,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
||||
utxos = tal_arr(w, const struct utxo *, 0);
|
||||
while ((one_utxo = wallet_find_utxo(w, w, 104, NULL, 253,
|
||||
0 /* no confirmations required */,
|
||||
false,
|
||||
utxos)) != NULL) {
|
||||
tal_arr_expand(&utxos, one_utxo);
|
||||
}
|
||||
@@ -1183,6 +1186,35 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
||||
/* Now un-reserve them */
|
||||
tal_free(utxos);
|
||||
|
||||
/* Check that nonwrapped flag works */
|
||||
utxos = tal_arr(w, const struct utxo *, 0);
|
||||
while ((one_utxo = wallet_find_utxo(w, w, 100, NULL, 253,
|
||||
0 /* no confirmations required */,
|
||||
true,
|
||||
utxos)) != NULL) {
|
||||
tal_arr_expand(&utxos, one_utxo);
|
||||
}
|
||||
/* No nonwrapped outputs available */
|
||||
CHECK(tal_count(utxos) == 0);
|
||||
tal_free(utxos);
|
||||
|
||||
/* So we add one... */
|
||||
memset(&u.outpoint, 4, sizeof(u.outpoint));
|
||||
u.amount = AMOUNT_SAT(4);
|
||||
u.close_info = tal_free(u.close_info);
|
||||
CHECK_MSG(wallet_add_utxo(w, &u, p2wpkh),
|
||||
"wallet_add_utxo failed, p2wpkh");
|
||||
|
||||
utxos = tal_arr(w, const struct utxo *, 0);
|
||||
while ((one_utxo = wallet_find_utxo(w, w, 100, NULL, 253,
|
||||
0 /* no confirmations required */,
|
||||
true,
|
||||
utxos)) != NULL) {
|
||||
tal_arr_expand(&utxos, one_utxo);
|
||||
}
|
||||
/* And that's what comes back */
|
||||
CHECK(tal_count(utxos) == 1);
|
||||
|
||||
db_commit_transaction(w->db);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -530,6 +530,7 @@ struct utxo *wallet_find_utxo(const tal_t *ctx, struct wallet *w,
|
||||
struct amount_sat *amount_hint,
|
||||
unsigned feerate_per_kw,
|
||||
u32 maxheight,
|
||||
bool nonwrapped,
|
||||
const struct utxo **excludes)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
@@ -569,6 +570,7 @@ struct utxo *wallet_find_utxo(const tal_t *ctx, struct wallet *w,
|
||||
while (!utxo && db_step(stmt)) {
|
||||
utxo = wallet_stmt2output(ctx, stmt);
|
||||
if (excluded(excludes, utxo)
|
||||
|| (nonwrapped && utxo->is_p2sh)
|
||||
|| !deep_enough(maxheight, utxo, current_blockheight))
|
||||
utxo = tal_free(utxo);
|
||||
|
||||
|
||||
@@ -473,6 +473,7 @@ struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx,
|
||||
* @amount_we_are_short: optional amount.
|
||||
* @feerate_per_kw: feerate we are using.
|
||||
* @maxheight: zero (if caller doesn't care) or maximum blockheight to accept.
|
||||
* @nonwrapped: filter out p2sh-wrapped inputs
|
||||
* @excludes: UTXOs not to consider.
|
||||
*
|
||||
* If @amount_we_are_short is not NULL, we try to get something very close
|
||||
@@ -486,6 +487,7 @@ struct utxo *wallet_find_utxo(const tal_t *ctx, struct wallet *w,
|
||||
struct amount_sat *amount_we_are_short,
|
||||
unsigned feerate_per_kw,
|
||||
u32 maxheight,
|
||||
bool nonwrapped,
|
||||
const struct utxo **excludes);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user