Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v082 deprecations #3603

Merged
merged 5 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
json_add_u64(response, "last_timestamp",
nodes[i]->last_timestamp);
if (deprecated_apis)
json_add_hex_talarr(response, "globalfeatures",
nodes[i]->features);
json_add_hex_talarr(response, "features", nodes[i]->features);
json_array_start(response, "addresses");
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
Expand Down
46 changes: 9 additions & 37 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,43 +1128,15 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
fc->uc = NULL;
fc->inflight = false;

/* 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),
p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script),
p_opt("push_msat", param_msat, &push_msat),
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),
p_opt("push_msat", param_msat, &push_msat),
NULL))
return command_param_failed();

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

/* No upfront shutdown script option for deprecated API */
fc->our_upfront_shutdown_script = NULL;
}
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),
p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script),
p_opt("push_msat", param_msat, &push_msat),
NULL))
return command_param_failed();

if (amount_sat_greater(*amount, chainparams->max_funding))
return command_fail(cmd, FUND_MAX_EXCEEDED,
Expand Down
54 changes: 11 additions & 43 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,53 +1206,21 @@ static struct command_result *json_sendpay(struct command *cmd,
struct sha256 *rhash;
struct route_hop *route;
struct amount_msat *msat;
const char *b11str, *label = NULL;
const char *b11str, *label;
u64 *partid;
struct secret *payment_secret;

/* For generating help, give new-style. */
if (!params || !deprecated_apis) {
if (!param(cmd, buffer, params,
p_req("route", param_array, &routetok),
p_req("payment_hash", param_sha256, &rhash),
p_opt("label", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
p_opt_def("partid", param_u64, &partid, 0),
NULL))
return command_param_failed();
} else if (params->type == JSMN_ARRAY) {
if (!param(cmd, buffer, params,
p_req("route", param_array, &routetok),
p_req("payment_hash", param_sha256, &rhash),
p_opt("label_or_description", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
p_opt_def("partid", param_u64, &partid, 0),
NULL))
return command_param_failed();
} else {
const char *desc = NULL;
if (!param(cmd, buffer, params,
p_req("route", param_array, &routetok),
p_req("payment_hash", param_sha256, &rhash),
p_opt("label", param_escaped_string, &label),
p_opt("description", param_escaped_string, &desc),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
p_opt_def("partid", param_u64, &partid, 0),
NULL))
return command_param_failed();

if (!label && desc)
label = desc;
}
if (!param(cmd, buffer, params,
p_req("route", param_array, &routetok),
p_req("payment_hash", param_sha256, &rhash),
p_opt("label", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret, &payment_secret),
p_opt_def("partid", param_u64, &partid, 0),
NULL))
return command_param_failed();

if (routetok->size == 0)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Empty route");
Expand Down
205 changes: 9 additions & 196 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,6 @@ peer_connected_serialize(struct peer_connected_hook_payload *payload,
json_add_string(
stream, "addr",
type_to_string(stream, struct wireaddr_internal, &payload->addr));
if (deprecated_apis) {
json_add_hex_talarr(stream, "globalfeatures", NULL);
json_add_hex_talarr(stream, "localfeatures", p->features);
}
json_add_hex_talarr(stream, "features", p->features);
json_object_end(stream); /* .peer */
}
Expand Down Expand Up @@ -1124,11 +1120,6 @@ static void json_add_peer(struct lightningd *ld,
struct wireaddr_internal,
&p->addr));
json_array_end(response);
if (deprecated_apis) {
json_add_hex_talarr(response, "globalfeatures", NULL);
json_add_hex_talarr(response, "localfeatures",
p->features);
}
json_add_hex_talarr(response, "features", p->features);
}

Expand Down Expand Up @@ -1227,61 +1218,6 @@ command_find_channel(struct command *cmd,
}
}

/* param_tok_timeout_or_force and param_tok_dest_or_timeout are made to
* support 'check' command for array type parameters.
*
* But the parameters are mixed with the old style and new style(like
* close {id} {force} {destination}), 'check' is unable to tell the error.
*/
static struct command_result *param_tok_timeout_or_force(
struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok,
const jsmntok_t **out)
{
if (command_check_only(cmd)) {
unsigned int timeout;
bool force;
if (!json_to_bool(buffer, tok, &force)) {
if (!json_to_number(buffer, tok, &timeout))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Expected unilerataltimeout to be a number");
}
return NULL;
}

*out = tok;
return NULL;
}

static struct command_result *param_tok_dest_or_timeout(
struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok,
const jsmntok_t **out)
{
if (command_check_only(cmd)) {
unsigned int timeout;
const u8 *script;
if (!json_to_number(buffer, tok, &timeout)) {
enum address_parse_result res;
res = json_to_address_scriptpubkey(cmd,
chainparams,
buffer, tok,
&script);
if (res == ADDRESS_PARSE_UNRECOGNIZED)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Could not parse destination address");
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s",
chainparams->network_name);
}
return NULL;
}

*out = tok;
return NULL;
}

static struct command_result *json_close(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
Expand All @@ -1294,140 +1230,17 @@ static struct command_result *json_close(struct command *cmd,
bool force = true;
bool do_timeout;
const u8 *close_to_script = NULL;
unsigned int *old_timeout;
bool *old_force, close_script_set;

/* For generating help, give new-style. */
if (!params || !deprecated_apis) {
if (!param(cmd, buffer, params,
p_req("id", param_tok, &idtok),
p_opt_def("unilateraltimeout", param_number,
&timeout, 48 * 3600),
p_opt("destination", param_bitcoin_address,
&close_to_script),
NULL))
return command_param_failed();
do_timeout = (*timeout != 0);
} else if (params->type == JSMN_ARRAY) {
const jsmntok_t *firsttok, *secondtok;
bool old_style;

/* Could be new or old style; get as tok. */
if (!param(cmd, buffer, params,
p_req("id", param_tok, &idtok),
p_opt("unilateraltimeout_or_force",
param_tok_timeout_or_force, &firsttok),
p_opt("destination_or_timeout",
param_tok_dest_or_timeout, &secondtok),
NULL))
return command_param_failed();

if (firsttok) {
/* old-style force bool? */
if (json_to_bool(buffer, firsttok, &force)) {
old_style = true;
timeout = tal(cmd, unsigned int);

/* Old default timeout */
if (!secondtok)
*timeout = 30;
else {
if (!json_to_number(buffer, secondtok, timeout))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"close: Expected timeout to be a number. "
"This argument ordering is deprecated!");
}
/* New-style timeout */
} else {
old_style = false;
timeout = tal(cmd, unsigned int);
if (!json_to_number(buffer, firsttok, timeout))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Expected unilerataltimeout to be a number");

if (secondtok) {
enum address_parse_result res;
res = json_to_address_scriptpubkey(cmd,
chainparams,
buffer, secondtok,
&close_to_script);
if (res == ADDRESS_PARSE_UNRECOGNIZED)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Could not parse destination address");
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s",
chainparams->network_name);
}
}
} else if (secondtok) {
unsigned int *tmp_timeout = tal(tmpctx, unsigned int);

if (json_to_number(buffer, secondtok, tmp_timeout)) {
old_style = true;
timeout = tal_steal(cmd, tmp_timeout);
} else {
old_style = false;
enum address_parse_result res;

res = json_to_address_scriptpubkey(cmd,
chainparams,
buffer, secondtok,
&close_to_script);
if (res == ADDRESS_PARSE_UNRECOGNIZED)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Could not parse destination address");
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s",
chainparams->network_name);
}
} else
old_style = false;
bool close_script_set;

/* If they didn't specify timeout, it's the (new) default */
if (!timeout) {
timeout = tal(cmd, unsigned int);
*timeout = 48 * 3600;
}
/* New style: do_timeout unless it's 0 */
if (!old_style)
do_timeout = (*timeout != 0);
else
do_timeout = true;
} else {
/* Named parameters are easy to distinguish */
if (!param(cmd, buffer, params,
p_req("id", param_tok, &idtok),
p_opt_def("unilateraltimeout", param_number,
&timeout, 48 * 3600),
p_opt("destination", param_bitcoin_address,
&close_to_script),
p_opt("force", param_bool, &old_force),
p_opt("timeout", param_number, &old_timeout),
NULL))
return command_param_failed();

/* Old style has lower priority. */
if (!close_to_script) {
/* Old style. */
if (old_timeout) {
*timeout = *old_timeout;
}
if (old_force) {
/* Use old default */
if (!old_timeout)
*timeout = 30;
force = *old_force;
}
}
if (!param(cmd, buffer, params,
p_req("id", param_tok, &idtok),
p_opt_def("unilateraltimeout", param_number, &timeout,
48 * 3600),
p_opt("destination", param_bitcoin_address, &close_to_script),
NULL))
return command_param_failed();

/* New style: do_timeout unless it's 0 */
if (!old_timeout && !old_force)
do_timeout = (*timeout != 0);
else
do_timeout = true;
}
do_timeout = (*timeout != 0);

peer = peer_from_json(cmd->ld, buffer, idtok);
if (peer)
Expand Down
Loading