Browse Source

param: upgraded json_tok_percent

Made it a local static since its only used once.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 7 years ago
committed by Rusty Russell
parent
commit
947752b9cc
  1. 15
      common/json.c
  2. 3
      common/json.h
  3. 2
      lightningd/param.c
  4. 22
      lightningd/payalgo.c

15
common/json.c

@ -76,21 +76,6 @@ bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num)
return true;
}
bool json_tok_percent(const char *buffer, const jsmntok_t *tok, double *num)
{
if (!json_to_double(buffer, tok, num))
return false;
/* Ensure it is in the range [0.0, 100.0] */
if (!(0.0 <= *num))
return false;
if (!(*num <= 100.0))
return false;
return true;
}
bool json_to_number(const char *buffer, const jsmntok_t *tok,
unsigned int *num)
{

3
common/json.h

@ -39,9 +39,6 @@ bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num);
bool json_tok_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
uint64_t *satoshi);
/* Extract double in range [0.0, 100.0] */
bool json_tok_percent(const char *buffer, const jsmntok_t *tok, double *num);
/* Extract sha256 hash */
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
struct sha256 *hash);

2
lightningd/param.c

@ -50,8 +50,6 @@ struct fail_format {
};
static struct fail_format fail_formats[] = {
{json_tok_percent,
"'%s' should be a double in range [0.0, 100.0], not '%.*s'"},
{json_tok_newaddr, "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'"},
{json_tok_wtx,
"'%s' should be 'all' or a positive integer greater than "

22
lightningd/payalgo.c

@ -596,12 +596,28 @@ 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)
{
const jsmntok_t *bolt11tok, *desctok;
double *riskfactor;
double maxfeepercent;
double *maxfeepercent;
u64 *msatoshi;
struct pay *pay = tal(cmd, struct pay);
struct bolt11 *b11;
@ -615,7 +631,7 @@ static void json_pay(struct command *cmd,
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
p_opt_tal("description", json_tok_tok, &desctok),
p_opt_def_tal("riskfactor", json_tok_double, &riskfactor, 1.0),
p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
p_opt_def_tal("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
p_opt_def_tal("retry_for", json_tok_number, &retryfor, 60),
p_opt_def_tal("maxdelay", json_tok_number, &maxdelay,
cmd->ld->config.locktime_max),
@ -662,7 +678,7 @@ static void json_pay(struct command *cmd,
}
pay->msatoshi = *msatoshi;
pay->riskfactor = *riskfactor * 1000;
pay->maxfeepercent = maxfeepercent;
pay->maxfeepercent = *maxfeepercent;
if (*maxdelay < pay->min_final_cltv_expiry) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,

Loading…
Cancel
Save