mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
Modern param style for all remaining files
Removed `json_get_params`. Also added json_tok_percent and json_tok_newaddr. Probably should have been a separate PR but it was so easy. [ Squashed comment update for gcc workaround --RR ] Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Rusty Russell
parent
61ad8684a6
commit
f850849486
@@ -15,6 +15,7 @@
|
||||
#include <lightningd/jsonrpc_errors.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/log.h>
|
||||
#include <lightningd/param.h>
|
||||
#include <lightningd/subd.h>
|
||||
#include <sodium/randombytes.h>
|
||||
#include <wallet/wallet.h>
|
||||
@@ -592,29 +593,27 @@ static void json_pay_stop_retrying(struct pay *pay)
|
||||
static void json_pay(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
jsmntok_t *bolt11tok, *msatoshitok, *desctok, *riskfactortok, *maxfeetok;
|
||||
jsmntok_t *retryfortok;
|
||||
jsmntok_t *maxdelaytok;
|
||||
double riskfactor = 1.0;
|
||||
double maxfeepercent = 0.5;
|
||||
u64 msatoshi;
|
||||
const jsmntok_t *bolt11tok, *desctok;
|
||||
double riskfactor;
|
||||
double maxfeepercent;
|
||||
u64 *msatoshi;
|
||||
struct pay *pay = tal(cmd, struct pay);
|
||||
struct bolt11 *b11;
|
||||
char *fail, *b11str, *desc;
|
||||
unsigned int retryfor = 60;
|
||||
unsigned int maxdelay = cmd->ld->config.locktime_max;
|
||||
unsigned int retryfor;
|
||||
unsigned int maxdelay;
|
||||
|
||||
if (!json_get_params(cmd, buffer, params,
|
||||
"bolt11", &bolt11tok,
|
||||
"?msatoshi", &msatoshitok,
|
||||
"?description", &desctok,
|
||||
"?riskfactor", &riskfactortok,
|
||||
"?maxfeepercent", &maxfeetok,
|
||||
"?retry_for", &retryfortok,
|
||||
"?maxdelay", &maxdelaytok,
|
||||
NULL)) {
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("bolt11", json_tok_tok, &bolt11tok),
|
||||
p_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||
p_opt_tok("description", &desctok),
|
||||
p_opt_def("riskfactor", json_tok_double, &riskfactor, 1.0),
|
||||
p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
|
||||
p_opt_def("retry_for", json_tok_number, &retryfor, 60),
|
||||
p_opt_def("maxdelay", json_tok_number, &maxdelay,
|
||||
cmd->ld->config.locktime_max),
|
||||
NULL))
|
||||
return;
|
||||
}
|
||||
|
||||
b11str = tal_strndup(cmd, buffer + bolt11tok->start,
|
||||
bolt11tok->end - bolt11tok->start);
|
||||
@@ -638,78 +637,24 @@ static void json_pay(struct command *cmd,
|
||||
pay->expiry.ts.tv_sec = b11->timestamp + b11->expiry;
|
||||
pay->min_final_cltv_expiry = b11->min_final_cltv_expiry;
|
||||
|
||||
if (retryfortok && !json_tok_number(buffer, retryfortok, &retryfor)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%.*s' is not an integer",
|
||||
retryfortok->end - retryfortok->start,
|
||||
buffer + retryfortok->start);
|
||||
return;
|
||||
}
|
||||
|
||||
if (b11->msatoshi) {
|
||||
msatoshi = *b11->msatoshi;
|
||||
if (msatoshitok) {
|
||||
if (msatoshi) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"msatoshi parameter unnecessary");
|
||||
return;
|
||||
}
|
||||
msatoshi = b11->msatoshi;
|
||||
} else {
|
||||
if (!msatoshitok) {
|
||||
if (!msatoshi) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"msatoshi parameter required");
|
||||
return;
|
||||
}
|
||||
if (!json_tok_u64(buffer, msatoshitok, &msatoshi)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"msatoshi '%.*s' is not a valid number",
|
||||
msatoshitok->end-msatoshitok->start,
|
||||
buffer + msatoshitok->start);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pay->msatoshi = msatoshi;
|
||||
|
||||
if (riskfactortok
|
||||
&& !json_tok_double(buffer, riskfactortok, &riskfactor)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%.*s' is not a valid double",
|
||||
riskfactortok->end - riskfactortok->start,
|
||||
buffer + riskfactortok->start);
|
||||
return;
|
||||
}
|
||||
pay->msatoshi = *msatoshi;
|
||||
pay->riskfactor = riskfactor * 1000;
|
||||
|
||||
if (maxfeetok
|
||||
&& !json_tok_double(buffer, maxfeetok, &maxfeepercent)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%.*s' is not a valid double",
|
||||
maxfeetok->end - maxfeetok->start,
|
||||
buffer + maxfeetok->start);
|
||||
return;
|
||||
}
|
||||
/* Ensure it is in range 0.0 <= maxfeepercent <= 100.0 */
|
||||
if (!(0.0 <= maxfeepercent)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%f maxfeepercent must be non-negative",
|
||||
maxfeepercent);
|
||||
return;
|
||||
}
|
||||
if (!(maxfeepercent <= 100.0)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%f maxfeepercent must be <= 100.0",
|
||||
maxfeepercent);
|
||||
return;
|
||||
}
|
||||
pay->maxfeepercent = maxfeepercent;
|
||||
|
||||
if (maxdelaytok
|
||||
&& !json_tok_number(buffer, maxdelaytok, &maxdelay)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%.*s' is not a valid integer",
|
||||
maxdelaytok->end - maxdelaytok->start,
|
||||
buffer + maxdelaytok->start);
|
||||
return;
|
||||
}
|
||||
if (maxdelay < pay->min_final_cltv_expiry) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"maxdelay (%u) must be greater than "
|
||||
|
||||
Reference in New Issue
Block a user