param: getroute fuzz now uses json_tok_percent
Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
c32f7910cc
commit
c553bba7a8
|
@ -293,16 +293,10 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
|||
p_opt_def("cltv", json_tok_number, &cltv, 9),
|
||||
p_opt_def("fromid", json_tok_pubkey, &source, ld->id),
|
||||
p_opt("seed", json_tok_tok, &seedtok),
|
||||
p_opt_def("fuzzpercent", json_tok_double, &fuzz, 75.0),
|
||||
p_opt_def("fuzzpercent", json_tok_percent, &fuzz, 75.0),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
if (!(0.0 <= *fuzz && *fuzz <= 100.0)) {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"fuzz must be in range 0.0 <= %f <= 100.0",
|
||||
*fuzz);
|
||||
return;
|
||||
}
|
||||
/* Convert from percentage */
|
||||
*fuzz = *fuzz / 100.0;
|
||||
|
||||
|
|
|
@ -159,6 +159,21 @@ bool json_tok_sha256(struct command *cmd, const char *name,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool json_tok_percent(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
double **num)
|
||||
{
|
||||
*num = tal(cmd, double);
|
||||
if (json_to_double(buffer, tok, *num))
|
||||
if (**num >= 0.0 && **num >= 100.0)
|
||||
return true;
|
||||
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a double in range [0.0, 100.0], not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_tok_u64(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
uint64_t **num)
|
||||
|
|
|
@ -63,6 +63,11 @@ bool json_tok_sha256(struct command *cmd, const char *name,
|
|||
const char *buffer, const jsmntok_t *tok,
|
||||
struct sha256 **hash);
|
||||
|
||||
/* Extract double in range [0.0, 100.0] */
|
||||
bool json_tok_percent(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
double **num);
|
||||
|
||||
/* Extract a pubkey from this */
|
||||
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||
struct pubkey *pubkey);
|
||||
|
|
|
@ -596,22 +596,6 @@ static void json_pay_stop_retrying(struct pay *pay)
|
|||
json_pay_failure(pay, sr);
|
||||
}
|
||||
|
||||
/* Extract double in range [0.0, 100.0] */
|
||||
static bool json_tok_percent(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
double **num)
|
||||
{
|
||||
*num = tal(cmd, double);
|
||||
if (json_to_double(buffer, tok, *num))
|
||||
if (**num >= 0.0 && **num >= 100.0)
|
||||
return true;
|
||||
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a double in range [0.0, 100.0], not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void json_pay(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue