From 1e63605bb5dd6477eadde861226bbb3904b672e1 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 21 Feb 2019 20:34:49 +0100 Subject: [PATCH] jsonrpc: Expose the minconf parameter for fundchannel and withdraw Signed-off-by: Christian Decker --- common/wallet_tx.h | 9 +++++++++ lightningd/opening_control.c | 12 +++++++----- wallet/walletrpc.c | 17 ++++++++++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/common/wallet_tx.h b/common/wallet_tx.h index 87b684321..2c3ec62a6 100644 --- a/common/wallet_tx.h +++ b/common/wallet_tx.h @@ -31,4 +31,13 @@ struct command_result *wtx_select_utxos(struct wallet_tx *tx, u32 fee_rate_per_kw, size_t out_len, u32 maxheight); + +static inline u32 minconf_to_maxheight(u32 minconf, struct lightningd *ld) +{ + /* No confirmations is special, we need to disable the check in the + * selection */ + if (minconf == 0) + return 0; + return ld->topology->tip->height - minconf + 1; +} #endif /* LIGHTNING_COMMON_WALLET_TX_H */ diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 5c782cd22..c53efe08a 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -830,7 +830,7 @@ static struct command_result *json_fund_channel(struct command *cmd, struct pubkey *id; struct peer *peer; struct channel *channel; - u32 *feerate_per_kw; + u32 *feerate_per_kw, *minconf, maxheight; bool *announce_channel; u8 *msg; struct amount_sat max_funding_satoshi; @@ -845,6 +845,7 @@ static struct command_result *json_fund_channel(struct command *cmd, p_req("satoshi", param_wtx, &fc->wtx), p_opt("feerate", param_feerate, &feerate_per_kw), p_opt_def("announce", param_bool, &announce_channel, true), + p_opt_def("minconf", param_number, &minconf, 0), NULL)) return command_param_failed(); @@ -890,8 +891,9 @@ static struct command_result *json_fund_channel(struct command *cmd, type_to_string(fc, struct pubkey, id)); } + maxheight = minconf_to_maxheight(*minconf, cmd->ld); res = wtx_select_utxos(&fc->wtx, *feerate_per_kw, - BITCOIN_SCRIPTPUBKEY_P2WSH_LEN, 0); + BITCOIN_SCRIPTPUBKEY_P2WSH_LEN, maxheight); if (res) return res; @@ -917,9 +919,9 @@ static struct command_result *json_fund_channel(struct command *cmd, } static const struct json_command fund_channel_command = { - "fundchannel", - json_fund_channel, - "Fund channel with {id} using {satoshi} (or 'all') satoshis, at optional {feerate}" + "fundchannel", json_fund_channel, + "Fund channel with {id} using {satoshi} (or 'all') satoshis, at optional " + "{feerate}. Only use outputs that have {minconf} confirmations." }; AUTODATA(json_command, &fund_channel_command); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 4fbd74897..083cc12a8 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -101,6 +101,7 @@ static struct command_result *json_withdraw(struct command *cmd, struct pubkey pubkey; enum address_parse_result addr_parse; struct command_result *res; + u32 *minconf, maxheight; withdraw->cmd = cmd; wtx_init(cmd, &withdraw->wtx, AMOUNT_SAT(-1ULL)); @@ -109,6 +110,7 @@ static struct command_result *json_withdraw(struct command *cmd, p_req("destination", param_tok, &desttok), p_req("satoshi", param_wtx, &withdraw->wtx), p_opt("feerate", param_feerate, &feerate_per_kw), + p_opt_def("minconf", param_number, &minconf, 0), NULL)) return command_param_failed(); @@ -138,8 +140,9 @@ static struct command_result *json_withdraw(struct command *cmd, get_chainparams(cmd->ld)->network_name); } + maxheight = minconf_to_maxheight(*minconf, cmd->ld); res = wtx_select_utxos(&withdraw->wtx, *feerate_per_kw, - tal_count(withdraw->destination), 0); + tal_count(withdraw->destination), maxheight); if (res) return res; @@ -180,10 +183,14 @@ static struct command_result *json_withdraw(struct command *cmd, } static const struct json_command withdraw_command = { - "withdraw", - json_withdraw, - "Send to {destination} address {satoshi} (or 'all') amount via Bitcoin transaction, at optional {feerate}", - false, "Send funds from the internal wallet to the specified address. Either specify a number of satoshis to send or 'all' to sweep all funds in the internal wallet to the address." + "withdraw", json_withdraw, + "Send to {destination} address {satoshi} (or 'all') amount via Bitcoin " + "transaction, at optional {feerate}", + false, + "Send funds from the internal wallet to the specified address. Either " + "specify a number of satoshis to send or 'all' to sweep all funds in the " + "internal wallet to the address. Only use outputs that have at least " + "{minconf} confirmations." }; AUTODATA(json_command, &withdraw_command);