mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
JSON-API: fundchannel uses amount fieldname to replace satoshi
This commit is contained in:
@@ -499,15 +499,11 @@ class LightningRpc(UnixDomainSocketRpc):
|
|||||||
}
|
}
|
||||||
return self.call("feerates", payload)
|
return self.call("feerates", payload)
|
||||||
|
|
||||||
def fundchannel(self, node_id, satoshi, feerate=None, announce=True, minconf=None, utxos=None):
|
def _deprecated_fundchannel(self, node_id, satoshi, feerate=None, announce=True, minconf=None, utxos=None):
|
||||||
"""
|
warnings.warn("fundchannel: the 'satoshi' field is renamed 'amount' : expect removal"
|
||||||
Fund channel with {id} using {satoshi} satoshis with feerate
|
" in Mid-2020",
|
||||||
of {feerate} (uses default feerate if unset).
|
DeprecationWarning)
|
||||||
If {announce} is False, don't send channel announcements.
|
|
||||||
Only select outputs with {minconf} confirmations.
|
|
||||||
If {utxos} is specified (as a list of 'txid:vout' strings),
|
|
||||||
fund a channel from these specifics utxos.
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
"id": node_id,
|
"id": node_id,
|
||||||
"satoshi": satoshi,
|
"satoshi": satoshi,
|
||||||
@@ -518,6 +514,32 @@ class LightningRpc(UnixDomainSocketRpc):
|
|||||||
}
|
}
|
||||||
return self.call("fundchannel", payload)
|
return self.call("fundchannel", payload)
|
||||||
|
|
||||||
|
def fundchannel(self, node_id, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Fund channel with {id} using {amount} satoshis with feerate
|
||||||
|
of {feerate} (uses default feerate if unset).
|
||||||
|
If {announce} is False, don't send channel announcements.
|
||||||
|
Only select outputs with {minconf} confirmations.
|
||||||
|
If {utxos} is specified (as a list of 'txid:vout' strings),
|
||||||
|
fund a channel from these specifics utxos.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if 'satoshi' in kwargs:
|
||||||
|
return self._deprecated_fundchannel(node_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def _fundchannel(node_id, amount, feerate=None, announce=True, minconf=None, utxos=None):
|
||||||
|
payload = {
|
||||||
|
"id": node_id,
|
||||||
|
"amount": amount,
|
||||||
|
"feerate": feerate,
|
||||||
|
"announce": announce,
|
||||||
|
"minconf": minconf,
|
||||||
|
"utxos": utxos
|
||||||
|
}
|
||||||
|
return self.call("fundchannel", payload)
|
||||||
|
|
||||||
|
return _fundchannel(node_id, *args, **kwargs)
|
||||||
|
|
||||||
def fundchannel_start(self, node_id, satoshi, feerate=None, announce=True):
|
def fundchannel_start(self, node_id, satoshi, feerate=None, announce=True):
|
||||||
"""
|
"""
|
||||||
Start channel funding with {id} for {satoshi} satoshis
|
Start channel funding with {id} for {satoshi} satoshis
|
||||||
|
|||||||
@@ -381,6 +381,27 @@ static struct command_result *tx_prepare_dryrun(struct command *cmd,
|
|||||||
return fundchannel_start(cmd, fr);
|
return fundchannel_start(cmd, fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We will use 'id' and 'amount' to build a output: {id: amount}.
|
||||||
|
* For array type, if we miss 'amount', next parameter will be
|
||||||
|
* mistaken for 'amount'.
|
||||||
|
* Note the check for 'output' in 'txprepare' is behind of the checks
|
||||||
|
* for other parameter, so doing a simply check for 'amount' here can
|
||||||
|
* help us locate error correctly.
|
||||||
|
*/
|
||||||
|
static struct command_result *param_string_check_sat(struct command *cmd, const char *name,
|
||||||
|
const char * buffer, const jsmntok_t *tok,
|
||||||
|
const char **str)
|
||||||
|
{
|
||||||
|
struct command_result *res;
|
||||||
|
struct amount_sat *amount;
|
||||||
|
|
||||||
|
res = param_sat_or_all(cmd, name, buffer, tok, &amount);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
return param_string(cmd, name, buffer, tok, str);
|
||||||
|
}
|
||||||
|
|
||||||
static struct command_result *json_fundchannel(struct command *cmd,
|
static struct command_result *json_fundchannel(struct command *cmd,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
@@ -388,15 +409,38 @@ static struct command_result *json_fundchannel(struct command *cmd,
|
|||||||
struct funding_req *fr = tal(cmd, struct funding_req);
|
struct funding_req *fr = tal(cmd, struct funding_req);
|
||||||
struct json_out *ret;
|
struct json_out *ret;
|
||||||
|
|
||||||
if (!param(cmd, buf, params,
|
/* For generating help, give new-style. */
|
||||||
p_req("id", param_node_id, &fr->id),
|
if (!params || !deprecated_apis || params->type == JSMN_ARRAY) {
|
||||||
p_req("satoshi", param_string, &fr->funding_str),
|
if (!param(cmd, buf, params,
|
||||||
p_opt("feerate", param_string, &fr->feerate_str),
|
p_req("id", param_node_id, &fr->id),
|
||||||
p_opt_def("announce", param_bool, &fr->announce_channel, true),
|
p_req("amount", param_string_check_sat, &fr->funding_str),
|
||||||
p_opt_def("minconf", param_number, &fr->minconf, 1),
|
p_opt("feerate", param_string, &fr->feerate_str),
|
||||||
p_opt("utxos", param_string, &fr->utxo_str),
|
p_opt_def("announce", param_bool, &fr->announce_channel, true),
|
||||||
NULL))
|
p_opt_def("minconf", param_number, &fr->minconf, 1),
|
||||||
return command_param_failed();
|
p_opt("utxos", param_string, &fr->utxo_str),
|
||||||
|
NULL))
|
||||||
|
return command_param_failed();
|
||||||
|
} else {
|
||||||
|
const char *satoshi_str;
|
||||||
|
if (!param(cmd, buf, params,
|
||||||
|
p_req("id", param_node_id, &fr->id),
|
||||||
|
p_opt("amount", param_string, &fr->funding_str),
|
||||||
|
p_opt("satoshi", param_string, &satoshi_str),
|
||||||
|
p_opt("feerate", param_string, &fr->feerate_str),
|
||||||
|
p_opt_def("announce", param_bool, &fr->announce_channel, true),
|
||||||
|
p_opt_def("minconf", param_number, &fr->minconf, 1),
|
||||||
|
p_opt("utxos", param_string, &fr->utxo_str),
|
||||||
|
NULL))
|
||||||
|
return command_param_failed();
|
||||||
|
|
||||||
|
if (!fr->funding_str) {
|
||||||
|
if (satoshi_str)
|
||||||
|
fr->funding_str = satoshi_str;
|
||||||
|
else
|
||||||
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"Need set 'amount' field");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fr->funding_all = streq(fr->funding_str, "all");
|
fr->funding_all = streq(fr->funding_str, "all");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user