mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
JSON-API: fundchannel_start
uses amount
fieldname to replace satoshi
This commit is contained in:
parent
25583ffe37
commit
d149ba2f3a
3 changed files with 69 additions and 19 deletions
|
@ -540,16 +540,11 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||||
|
|
||||||
return _fundchannel(node_id, *args, **kwargs)
|
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"
|
||||||
Start channel funding with {id} for {satoshi} satoshis
|
" in Mid-2020",
|
||||||
with feerate of {feerate} (uses default feerate if unset).
|
DeprecationWarning)
|
||||||
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 = {
|
payload = {
|
||||||
"id": node_id,
|
"id": node_id,
|
||||||
"satoshi": satoshi,
|
"satoshi": satoshi,
|
||||||
|
@ -558,6 +553,31 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||||
}
|
}
|
||||||
return self.call("fundchannel_start", payload)
|
return self.call("fundchannel_start", payload)
|
||||||
|
|
||||||
|
def fundchannel_start(self, node_id, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
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):
|
def fundchannel_cancel(self, node_id):
|
||||||
"""
|
"""
|
||||||
Cancel a 'started' fundchannel with node {id}.
|
Cancel a 'started' fundchannel with node {id}.
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
#include <lightningd/notification.h>
|
#include <lightningd/notification.h>
|
||||||
#include <lightningd/opening_control.h>
|
#include <lightningd/opening_control.h>
|
||||||
|
#include <lightningd/options.h>
|
||||||
#include <lightningd/peer_control.h>
|
#include <lightningd/peer_control.h>
|
||||||
#include <lightningd/plugin_hook.h>
|
#include <lightningd/plugin_hook.h>
|
||||||
#include <lightningd/subd.h>
|
#include <lightningd/subd.h>
|
||||||
|
@ -1069,13 +1070,38 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
|
||||||
fc->cancels = tal_arr(fc, struct command *, 0);
|
fc->cancels = tal_arr(fc, struct command *, 0);
|
||||||
fc->uc = NULL;
|
fc->uc = NULL;
|
||||||
fc->inflight = false;
|
fc->inflight = false;
|
||||||
|
|
||||||
|
/* For generating help, give new-style. */
|
||||||
|
if (!params || !deprecated_apis || params->type == JSMN_ARRAY) {
|
||||||
if (!param(fc->cmd, buffer, params,
|
if (!param(fc->cmd, buffer, params,
|
||||||
p_req("id", param_node_id, &id),
|
p_req("id", param_node_id, &id),
|
||||||
p_req("satoshi", param_sat, &amount),
|
p_req("amount", param_sat, &amount),
|
||||||
p_opt("feerate", param_feerate, &feerate_per_kw),
|
p_opt("feerate", param_feerate, &feerate_per_kw),
|
||||||
p_opt_def("announce", param_bool, &announce_channel, true),
|
p_opt_def("announce", param_bool, &announce_channel, true),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
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))
|
if (amount_sat_greater(*amount, max_funding_satoshi))
|
||||||
return command_fail(cmd, FUND_MAX_EXCEEDED,
|
return command_fail(cmd, FUND_MAX_EXCEEDED,
|
||||||
|
|
|
@ -312,7 +312,11 @@ static struct command_result *fundchannel_start(struct command *cmd,
|
||||||
|
|
||||||
json_out_start(ret, NULL, '{');
|
json_out_start(ret, NULL, '{');
|
||||||
json_out_addstr(ret, "id", node_id_to_hexstr(tmpctx, fr->id));
|
json_out_addstr(ret, "id", node_id_to_hexstr(tmpctx, fr->id));
|
||||||
|
|
||||||
|
if (deprecated_apis)
|
||||||
json_out_addstr(ret, "satoshi", fr->funding_str);
|
json_out_addstr(ret, "satoshi", fr->funding_str);
|
||||||
|
else
|
||||||
|
json_out_addstr(ret, "amount", fr->funding_str);
|
||||||
|
|
||||||
if (fr->feerate_str)
|
if (fr->feerate_str)
|
||||||
json_out_addstr(ret, "feerate", fr->feerate_str);
|
json_out_addstr(ret, "feerate", fr->feerate_str);
|
||||||
|
|
Loading…
Add table
Reference in a new issue