Skip to content

Commit

Permalink
JSON: Remove description fields.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Sep 6, 2019
1 parent acf3952 commit 884f4fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 87 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ changes.
### Removed

- JSON API: `short_channel_id` parameters in JSON commands with `:` separators (deprecated since 0.7.0).
- JSON API: `description` parameters in `pay` and `sendpay` (deprecated since 0.7.0).
- JSON API: `description` output field in `waitsendpay` and `sendpay` (deprecated since 0.7.0).

### Fixed

Expand Down
49 changes: 9 additions & 40 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ json_add_payment_fields(struct json_stream *response,
json_add_hex(response, "payment_preimage",
t->payment_preimage,
sizeof(*t->payment_preimage));
if (t->label) {
if (deprecated_apis)
json_add_string(response, "description", t->label);
if (t->label)
json_add_string(response, "label", t->label);
}
if (t->bolt11)
json_add_string(response, "bolt11", t->bolt11);
}
Expand Down Expand Up @@ -778,42 +775,14 @@ static struct command_result *json_sendpay(struct command *cmd,
const char *b11str, *label;
struct command_result *res;

/* If by array, or 'check' command, use 'label' as param name */
if (!params || 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", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
NULL))
return command_param_failed();
} else {
const char *description_deprecated;

/* If by keyword, treat description and label as
* separate parameters. */
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,
&description_deprecated),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
NULL))
return command_param_failed();

if (description_deprecated) {
if (!deprecated_apis)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Deprecated parameter description, use label");
if (label)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Cannot specify both description and label");
label = description_deprecated;
}
}
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),
NULL))
return command_param_failed();

if (routetok->size == 0)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Empty route");
Expand Down
60 changes: 13 additions & 47 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ static struct command_result *json_pay(struct command *cmd,
{
struct amount_msat *msat;
struct bolt11 *b11;
const char *b11str, *description_deprecated;
const char *b11str;
char *fail;
double *riskfactor;
unsigned int *retryfor;
Expand All @@ -964,54 +964,20 @@ static struct command_result *json_pay(struct command *cmd,
unsigned int *maxdelay;
struct amount_msat *exemptfee;

/* If params is array, label takes place of description. For
* keywords, its a separate parameter. */
if (!params || params->type == JSMN_ARRAY) {
if (!param(cmd, buf, params,
p_req("bolt11", param_string, &b11str),
p_opt("msatoshi", param_msat, &msat),
p_opt("label", param_string, &pc->label),
p_opt_def("riskfactor", param_double, &riskfactor, 10),
p_opt_def("maxfeepercent", param_percent, &maxfeepercent, 0.5),
p_opt_def("retry_for", param_number, &retryfor, 60),
p_opt_def("maxdelay", param_number, &maxdelay,
maxdelay_default),
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
NULL))
return NULL;

/* This works because bolt11_decode ignores unneeded descriptions */
if (deprecated_apis)
description_deprecated = pc->label;
else
description_deprecated = NULL;
} else {
/* If by keyword, treat description and label as
* separate parameters. */
if (!param(cmd, buf, params,
p_req("bolt11", param_string, &b11str),
p_opt("msatoshi", param_msat, &msat),
p_opt("description", param_string,
&description_deprecated),
p_opt_def("riskfactor", param_double, &riskfactor, 10),
p_opt_def("maxfeepercent", param_percent, &maxfeepercent, 0.5),
p_opt_def("retry_for", param_number, &retryfor, 60),
p_opt_def("maxdelay", param_number, &maxdelay,
maxdelay_default),
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
p_opt("label", param_string, &pc->label),
NULL))
if (!param(cmd, buf, params,
p_req("bolt11", param_string, &b11str),
p_opt("msatoshi", param_msat, &msat),
p_opt("label", param_string, &pc->label),
p_opt_def("riskfactor", param_double, &riskfactor, 10),
p_opt_def("maxfeepercent", param_percent, &maxfeepercent, 0.5),
p_opt_def("retry_for", param_number, &retryfor, 60),
p_opt_def("maxdelay", param_number, &maxdelay,
maxdelay_default),
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
NULL))
return NULL;

if (description_deprecated && !deprecated_apis)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Deprecated parameter description, use label");
if (description_deprecated && pc->label)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Cannot specify both description and label");
}

b11 = bolt11_decode(cmd, b11str, description_deprecated, &fail);
b11 = bolt11_decode(cmd, b11str, NULL, &fail);
if (!b11) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid bolt11: %s", fail);
Expand Down

0 comments on commit 884f4fa

Please sign in to comment.