mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
param: consistent callback format
The `json_tok_X` functions now consistently check the success case first and call `command_fail` at the end. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Rusty Russell
parent
9c28f997d3
commit
a79e64c0a0
@@ -120,28 +120,28 @@ bool json_tok_double(struct command *cmd, const char *name,
|
|||||||
double **num)
|
double **num)
|
||||||
{
|
{
|
||||||
*num = tal(cmd, double);
|
*num = tal(cmd, double);
|
||||||
if (!json_to_double(buffer, tok, *num)) {
|
if (json_to_double(buffer, tok, *num))
|
||||||
|
return true;
|
||||||
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"'%s' should be a double, not '%.*s'",
|
"'%s' should be a double, not '%.*s'",
|
||||||
name, tok->end - tok->start, buffer + tok->start);
|
name, tok->end - tok->start, buffer + tok->start);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool json_tok_number(struct command *cmd, const char *name,
|
bool json_tok_number(struct command *cmd, const char *name,
|
||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
unsigned int **num)
|
unsigned int **num)
|
||||||
{
|
{
|
||||||
*num = tal(cmd, unsigned int);
|
*num = tal(cmd, unsigned int);
|
||||||
if (!json_to_number(buffer, tok, *num)) {
|
if (json_to_number(buffer, tok, *num))
|
||||||
|
return true;
|
||||||
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"'%s' should be an integer, not '%.*s'",
|
"'%s' should be an integer, not '%.*s'",
|
||||||
name, tok->end - tok->start, buffer + tok->start);
|
name, tok->end - tok->start, buffer + tok->start);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool json_tok_sha256(struct command *cmd, const char *name,
|
bool json_tok_sha256(struct command *cmd, const char *name,
|
||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
@@ -164,14 +164,14 @@ bool json_tok_u64(struct command *cmd, const char *name,
|
|||||||
uint64_t **num)
|
uint64_t **num)
|
||||||
{
|
{
|
||||||
*num = tal(cmd, uint64_t);
|
*num = tal(cmd, uint64_t);
|
||||||
if (!json_to_u64(buffer, tok, *num)) {
|
if (json_to_u64(buffer, tok, *num))
|
||||||
|
return true;
|
||||||
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"'%s' should be an unsigned 64 bit integer, not '%.*s'",
|
"'%s' should be an unsigned 64 bit integer, not '%.*s'",
|
||||||
name, tok->end - tok->start, buffer + tok->start);
|
name, tok->end - tok->start, buffer + tok->start);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
|
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||||
struct pubkey *pubkey)
|
struct pubkey *pubkey)
|
||||||
|
|||||||
Reference in New Issue
Block a user