From cb00cbac7ca3eaed1883a401cb6cb3533fd1b81f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 8 Jun 2020 13:53:24 +0200 Subject: [PATCH] paymod: Add support for the msatoshi override argument --- plugins/pay.c | 19 +++++++++++++++---- tests/test_pay.py | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/pay.c b/plugins/pay.c index c8284007f..6772bfc53 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1858,7 +1858,7 @@ static struct command_result *json_paymod(struct command *cmd, char *fail; u64 *maxfee_pct_millionths; u32 *maxdelay; - struct amount_msat *exemptfee; + struct amount_msat *exemptfee, *msat; const char *label; #if DEVELOPER bool *use_shadow; @@ -1870,6 +1870,7 @@ static struct command_result *json_paymod(struct command *cmd, * would add them to the `param()` call below, and have them be * initialized directly that way. */ if (!param(cmd, buf, params, p_req("bolt11", param_string, &b11str), + p_opt("msatoshi", param_msat, &msat), p_opt("label", param_string, &label), p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)), p_opt_def("maxdelay", param_number, &maxdelay, @@ -1897,10 +1898,20 @@ static struct command_result *json_paymod(struct command *cmd, if (time_now().ts.tv_sec > b11->timestamp + b11->expiry) return command_fail(cmd, PAY_INVOICE_EXPIRED, "Invoice expired"); - if (b11->msat) + if (b11->msat) { + if (msat) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "msatoshi parameter unnecessary"); + } p->amount = *b11->msat; - else - abort(); + + } else { + if (!msat) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "msatoshi parameter required"); + } + p->amount = *msat; + } /* Sanity check */ if (feature_offered(b11->features, OPT_VAR_ONION) diff --git a/tests/test_pay.py b/tests/test_pay.py index 1fb9a4b2b..1aa210035 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3077,7 +3077,7 @@ def test_pay_modifiers(node_factory): # Make sure that the dummy param is in the help (and therefore assigned to # the modifier data). hlp = l1.rpc.help("paymod")['help'][0] - assert(hlp['command'] == 'paymod bolt11 [label] [exemptfee] [maxdelay] [maxfeepercent] [use_shadow]') + assert(hlp['command'] == 'paymod bolt11 [msatoshi] [label] [exemptfee] [maxdelay] [maxfeepercent] [use_shadow]') inv = l2.rpc.invoice(123, 'lbl', 'desc')['bolt11'] r = l1.rpc.paymod(inv)