mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
param: make json_tok_label non-static
Needed to do this so I could remove the implementation in the run-param test. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Rusty Russell
parent
4f81cd3852
commit
8590dbedfb
@@ -102,26 +102,6 @@ static bool hsm_sign_b11(const u5 *u5bytes,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool json_tok_label(struct command *cmd, const char *name,
|
||||
const char * buffer, const jsmntok_t *tok,
|
||||
struct json_escaped **label)
|
||||
{
|
||||
|
||||
if ((*label = json_tok_escaped_string(cmd, buffer, tok)))
|
||||
return true;
|
||||
|
||||
/* Allow literal numbers */
|
||||
if (json_tok_is_num(buffer, tok) &&
|
||||
((*label = json_escaped_string_(cmd, buffer + tok->start,
|
||||
tok->end - tok->start))))
|
||||
return true;
|
||||
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a string or number, not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool parse_fallback(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *fallback,
|
||||
const u8 **fallback_script)
|
||||
|
||||
@@ -129,6 +129,25 @@ bool json_tok_double(struct command *cmd, const char *name,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_tok_label(struct command *cmd, const char *name,
|
||||
const char * buffer, const jsmntok_t *tok,
|
||||
struct json_escaped **label)
|
||||
{
|
||||
if ((*label = json_tok_escaped_string(cmd, buffer, tok)))
|
||||
return true;
|
||||
|
||||
/* Allow literal numbers */
|
||||
if (json_tok_is_num(buffer, tok) &&
|
||||
((*label = json_escaped_string_(cmd, buffer + tok->start,
|
||||
tok->end - tok->start))))
|
||||
return true;
|
||||
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a string or number, not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_tok_number(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
unsigned int **num)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
struct bitcoin_txid;
|
||||
struct channel_id;
|
||||
struct command;
|
||||
struct json_escaped;
|
||||
struct json_result;
|
||||
struct pubkey;
|
||||
struct route_hop;
|
||||
@@ -53,6 +54,11 @@ bool json_tok_double(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
double **num);
|
||||
|
||||
/* Extract a label. It is either an escaped string or a number. */
|
||||
bool json_tok_label(struct command *cmd, const char *name,
|
||||
const char * buffer, const jsmntok_t *tok,
|
||||
struct json_escaped **label);
|
||||
|
||||
/* Extract number from this (may be a string, or a number literal) */
|
||||
bool json_tok_number(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
|
||||
@@ -413,38 +413,6 @@ static void sendpay_nulltok(void)
|
||||
assert(msatoshi == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* New version of json_tok_label conforming to advanced style. This can eventually
|
||||
* replace the existing json_tok_label.
|
||||
*/
|
||||
static bool json_tok_label_x(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct json_escaped **label)
|
||||
{
|
||||
if ((*label = json_tok_escaped_string(cmd, buffer, tok)))
|
||||
return true;
|
||||
|
||||
/* Allow literal numbers */
|
||||
if (tok->type != JSMN_PRIMITIVE)
|
||||
goto fail;
|
||||
|
||||
for (int i = tok->start; i < tok->end; i++)
|
||||
if (!cisdigit(buffer[i]))
|
||||
goto fail;
|
||||
|
||||
if ((*label = json_escaped_string_(cmd, buffer + tok->start,
|
||||
tok->end - tok->start)))
|
||||
return true;
|
||||
|
||||
fail:
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a string or number, not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void advanced(void)
|
||||
{
|
||||
{
|
||||
@@ -456,7 +424,7 @@ static void advanced(void)
|
||||
const jsmntok_t *tok;
|
||||
|
||||
assert(param(cmd, j->buffer, j->toks,
|
||||
p_req("description", json_tok_label_x, &label),
|
||||
p_req("description", json_tok_label, &label),
|
||||
p_req("msat", json_tok_msat, &msat),
|
||||
p_req("tok", json_tok_tok, &tok),
|
||||
p_opt("msat_opt1", json_tok_msat, &msat_opt1),
|
||||
@@ -474,8 +442,8 @@ static void advanced(void)
|
||||
struct json *j = json_parse(cmd, "[ 3 'foo' ]");
|
||||
struct json_escaped *label, *foo;
|
||||
assert(param(cmd, j->buffer, j->toks,
|
||||
p_req("label", json_tok_label_x, &label),
|
||||
p_opt("foo", json_tok_label_x, &foo),
|
||||
p_req("label", json_tok_label, &label),
|
||||
p_opt("foo", json_tok_label, &foo),
|
||||
NULL));
|
||||
assert(!strcmp(label->s, "3"));
|
||||
assert(!strcmp(foo->s, "foo"));
|
||||
|
||||
Reference in New Issue
Block a user