mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-11 01:54:25 +01:00
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 <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user