From feb92cf4e2e31cbacb4e5d1744efb0b2a107b4ec Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Feb 2019 13:08:51 +1030 Subject: [PATCH] sendpay: allow 'amount_msat' We're about to add 'amount_msat' to getroute, but it's common to feed 'getroute' back into 'sendpay', so sendpay should allow it. If both are specified, make sure they're the same! Signed-off-by: Rusty Russell --- lightningd/pay.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index d06f2224d..3f58a0cb8 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -754,21 +754,45 @@ static struct command_result *json_sendpay(struct command *cmd, route = tal_arr(cmd, struct route_hop, routetok->size); json_for_each_arr(i, t, routetok) { - u64 *amount; + struct amount_msat *msat, *amount_msat; struct pubkey *id; struct short_channel_id *channel; unsigned *delay, *direction; if (!param(cmd, buffer, t, - p_req("msatoshi", param_u64, &amount), - p_req("id", param_pubkey, &id), - p_req("delay", param_number, &delay), - p_req("channel", param_short_channel_id, &channel), + /* Only *one* of these is required */ + p_opt("msatoshi", param_msat, &msat), + p_opt("amount_msat", param_msat, &amount_msat), + /* These three actually required */ + p_opt("id", param_pubkey, &id), + p_opt("delay", param_number, &delay), + p_opt("channel", param_short_channel_id, &channel), p_opt("direction", param_number, &direction), NULL)) return command_param_failed(); - route[i].amount = *amount; + if (!msat && !amount_msat) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "route[%zi]: must have msatoshi" + " or amount_msat", i); + if (!id || !channel || !delay) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "route[%zi]: must have id, channel" + " and delay", i); + if (msat && amount_msat && !amount_msat_eq(*msat, *amount_msat)) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "route[%zi]: msatoshi %s != amount_msat %s", + i, + type_to_string(tmpctx, + struct amount_msat, + msat), + type_to_string(tmpctx, + struct amount_msat, + amount_msat)); + if (!msat) + msat = amount_msat; + + route[i].amount = msat->millisatoshis; route[i].nodeid = *id; route[i].delay = *delay; route[i].channel_id = *channel;