Skip to content

Commit

Permalink
JSON-API: fundchannel_start uses amount fieldname to replace `sat…
Browse files Browse the repository at this point in the history
…oshi`
  • Loading branch information
trueptolemy authored and niftynei committed Oct 9, 2019
1 parent 25583ff commit d149ba2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 18 deletions.
38 changes: 29 additions & 9 deletions contrib/pylightning/lightning/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,43 @@ def _fundchannel(node_id, amount, feerate=None, announce=True, minconf=None, utx

return _fundchannel(node_id, *args, **kwargs)

def fundchannel_start(self, node_id, satoshi, feerate=None, announce=True):
def _deprecated_fundchannel_start(self, node_id, satoshi, feerate=None, announce=True):
warnings.warn("fundchannel_start: the 'satoshi' field is renamed 'amount' : expect removal"
" in Mid-2020",
DeprecationWarning)

payload = {
"id": node_id,
"satoshi": satoshi,
"feerate": feerate,
"announce": announce,
}
return self.call("fundchannel_start", payload)

def fundchannel_start(self, node_id, *args, **kwargs):
"""
Start channel funding with {id} for {satoshi} satoshis
Start channel funding with {id} for {amount} satoshis
with feerate of {feerate} (uses default feerate if unset).
If {announce} is False, don't send channel announcements.
Returns a Bech32 {funding_address} for an external wallet
to create a funding transaction for. Requires a call to
'fundchannel_complete' to complete channel establishment
with peer.
"""
payload = {
"id": node_id,
"satoshi": satoshi,
"feerate": feerate,
"announce": announce,
}
return self.call("fundchannel_start", payload)

if 'satoshi' in kwargs:
return self._deprecated_fundchannel_start(node_id, *args, **kwargs)

def _fundchannel_start(node_id, amount, feerate=None, announce=True):
payload = {
"id": node_id,
"amount": amount,
"feerate": feerate,
"announce": announce
}
return self.call("fundchannel_start", payload)

return _fundchannel_start(node_id, *args, **kwargs)

def fundchannel_cancel(self, node_id):
"""
Expand Down
42 changes: 34 additions & 8 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <lightningd/log.h>
#include <lightningd/notification.h>
#include <lightningd/opening_control.h>
#include <lightningd/options.h>
#include <lightningd/peer_control.h>
#include <lightningd/plugin_hook.h>
#include <lightningd/subd.h>
Expand Down Expand Up @@ -1069,16 +1070,41 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
fc->cancels = tal_arr(fc, struct command *, 0);
fc->uc = NULL;
fc->inflight = false;
if (!param(fc->cmd, buffer, params,
p_req("id", param_node_id, &id),
p_req("satoshi", param_sat, &amount),
p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", param_bool, &announce_channel, true),
NULL))
return command_param_failed();

/* For generating help, give new-style. */
if (!params || !deprecated_apis || params->type == JSMN_ARRAY) {
if (!param(fc->cmd, buffer, params,
p_req("id", param_node_id, &id),
p_req("amount", param_sat, &amount),
p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", param_bool, &announce_channel, true),
NULL))
return command_param_failed();
} else {
/* For json object type when allow deprecated api, 'check' command
* can't find the error if we don't set 'amount' nor 'satoshi'.
*/
struct amount_sat *satoshi;
if (!param(fc->cmd, buffer, params,
p_req("id", param_node_id, &id),
p_opt("amount", param_sat, &amount),
p_opt("satoshi", param_sat, &satoshi),
p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", param_bool, &announce_channel, true),
NULL))
return command_param_failed();

if (!amount) {
if (satoshi)
amount = satoshi;
else
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Need set 'amount' field");
}
}

if (amount_sat_greater(*amount, max_funding_satoshi))
return command_fail(cmd, FUND_MAX_EXCEEDED,
return command_fail(cmd, FUND_MAX_EXCEEDED,
"Amount exceeded %s",
type_to_string(tmpctx, struct amount_sat,
&max_funding_satoshi));
Expand Down
6 changes: 5 additions & 1 deletion plugins/fundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ static struct command_result *fundchannel_start(struct command *cmd,

json_out_start(ret, NULL, '{');
json_out_addstr(ret, "id", node_id_to_hexstr(tmpctx, fr->id));
json_out_addstr(ret, "satoshi", fr->funding_str);

if (deprecated_apis)
json_out_addstr(ret, "satoshi", fr->funding_str);
else
json_out_addstr(ret, "amount", fr->funding_str);

if (fr->feerate_str)
json_out_addstr(ret, "feerate", fr->feerate_str);
Expand Down

0 comments on commit d149ba2

Please sign in to comment.