Browse Source

JSON-API: `fundchannel_start` uses `amount` fieldname to replace `satoshi`

travis-debug
trueptolemy 5 years ago
committed by neil saitug
parent
commit
d149ba2f3a
  1. 38
      contrib/pylightning/lightning/lightning.py
  2. 42
      lightningd/opening_control.c
  3. 6
      plugins/fundchannel.c

38
contrib/pylightning/lightning/lightning.py

@ -540,9 +540,22 @@ class LightningRpc(UnixDomainSocketRpc):
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
@ -550,13 +563,20 @@ class LightningRpc(UnixDomainSocketRpc):
'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):
"""

42
lightningd/opening_control.c

@ -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>
@ -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));

6
plugins/fundchannel.c

@ -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);

Loading…
Cancel
Save