Browse Source

param: make json_tok_ handlers all return command_result, rename to param_

Handers of a specific form are both designed to be used as callbacks
for param(), and also dispose of the command if something goes wrong.

Make them return the 'struct command_result *' from command_failed(),
or NULL.  

Renaming them just makes sense: json_tok_XXX is used for non-command-freeing
parsers too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
plugin-7
Rusty Russell 6 years ago
parent
commit
bc41ab2cb9
  1. 185
      common/json_tok.c
  2. 75
      common/json_tok.h
  3. 98
      common/param.c
  4. 26
      common/param.h
  5. 172
      common/test/run-param.c
  6. 16
      lightningd/chaintopology.c
  7. 7
      lightningd/chaintopology.h
  8. 6
      lightningd/connect_control.c
  9. 36
      lightningd/gossip_control.c
  10. 32
      lightningd/invoice.c
  11. 91
      lightningd/json.c
  12. 38
      lightningd/json.h
  13. 45
      lightningd/jsonrpc.c
  14. 25
      lightningd/log.c
  15. 8
      lightningd/log.h
  16. 12
      lightningd/opening_control.c
  17. 2
      lightningd/options.c
  18. 24
      lightningd/pay.c
  19. 16
      lightningd/payalgo.c
  20. 26
      lightningd/peer_control.c
  21. 4
      lightningd/peer_htlcs.c
  22. 6
      lightningd/ping.c
  23. 132
      lightningd/test/run-invoice-select-inchan.c
  24. 39
      lightningd/test/run-jsonrpc.c
  25. 64
      wallet/test/run-wallet.c
  26. 37
      wallet/walletrpc.c

185
common/json_tok.c

@ -6,170 +6,165 @@
#include <common/jsonrpc_errors.h> #include <common/jsonrpc_errors.h>
#include <common/param.h> #include <common/param.h>
bool json_tok_array(struct command *cmd, const char *name, struct command_result *param_array(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
const jsmntok_t **arr) const jsmntok_t **arr)
{ {
if (tok->type == JSMN_ARRAY) if (tok->type == JSMN_ARRAY) {
return (*arr = tok); *arr = tok;
return NULL;
}
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be an array, not '%.*s'", "'%s' should be an array, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_bool(struct command *cmd, const char *name, struct command_result *param_bool(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
bool **b) bool **b)
{ {
*b = tal(cmd, bool); *b = tal(cmd, bool);
if (json_to_bool(buffer, tok, *b)) if (json_to_bool(buffer, tok, *b))
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'true' or 'false', not '%.*s'", "'%s' should be 'true' or 'false', not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_double(struct command *cmd, const char *name, struct command_result *param_double(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
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; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return 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;
} }
bool json_tok_escaped_string(struct command *cmd, const char *name, struct command_result *param_escaped_string(struct command *cmd,
const char * buffer, const jsmntok_t *tok, const char *name,
const char **str) const char * buffer,
const jsmntok_t *tok,
const char **str)
{ {
struct json_escaped *esc = json_to_escaped_string(cmd, buffer, tok); struct json_escaped *esc = json_to_escaped_string(cmd, buffer, tok);
if (esc) { if (esc) {
*str = json_escaped_unescape(cmd, esc); *str = json_escaped_unescape(cmd, esc);
if (*str) if (*str)
return true; return NULL;
} }
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a string, not '%.*s'" "'%s' should be a string, not '%.*s'"
" (note, we don't allow \\u)", " (note, we don't allow \\u)",
name, name,
tok->end - tok->start, buffer + tok->start); tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_string(struct command *cmd, const char *name, struct command_result *param_string(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok, const char * buffer, const jsmntok_t *tok,
const char **str) const char **str)
{ {
*str = tal_strndup(cmd, buffer + tok->start, *str = tal_strndup(cmd, buffer + tok->start,
tok->end - tok->start); tok->end - tok->start);
return true; return NULL;
} }
bool json_tok_label(struct command *cmd, const char *name, struct command_result *param_label(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok, const char * buffer, const jsmntok_t *tok,
struct json_escaped **label) struct json_escaped **label)
{ {
/* We accept both strings and number literals here. */ /* We accept both strings and number literals here. */
*label = json_escaped_string_(cmd, buffer + tok->start, tok->end - tok->start); *label = json_escaped_string_(cmd, buffer + tok->start, tok->end - tok->start);
if (*label && (tok->type == JSMN_STRING || json_tok_is_num(buffer, tok))) if (*label && (tok->type == JSMN_STRING || json_tok_is_num(buffer, tok)))
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a string or number, not '%.*s'", "'%s' should be a string or number, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_number(struct command *cmd, const char *name, struct command_result *param_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; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return 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;
} }
bool json_tok_sha256(struct command *cmd, const char *name, struct command_result *param_sha256(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
struct sha256 **hash) struct sha256 **hash)
{ {
*hash = tal(cmd, struct sha256); *hash = tal(cmd, struct sha256);
if (hex_decode(buffer + tok->start, if (hex_decode(buffer + tok->start,
tok->end - tok->start, tok->end - tok->start,
*hash, sizeof(**hash))) *hash, sizeof(**hash)))
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a 32 byte hex value, not '%.*s'", "'%s' should be a 32 byte hex value, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_msat(struct command *cmd, const char *name, struct command_result *param_msat(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok, const char *buffer, const jsmntok_t * tok,
u64 **msatoshi_val) u64 **msatoshi_val)
{ {
if (json_tok_streq(buffer, tok, "any")) { if (json_tok_streq(buffer, tok, "any")) {
*msatoshi_val = NULL; *msatoshi_val = NULL;
return true; return NULL;
} }
*msatoshi_val = tal(cmd, u64); *msatoshi_val = tal(cmd, u64);
if (json_to_u64(buffer, tok, *msatoshi_val) && *msatoshi_val != 0) if (json_to_u64(buffer, tok, *msatoshi_val) && *msatoshi_val != 0)
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a positive number or 'any', not '%.*s'", "'%s' should be a positive number or 'any', not '%.*s'",
name, name,
tok->end - tok->start, tok->end - tok->start,
buffer + tok->start); buffer + tok->start);
return false;
} }
bool json_tok_percent(struct command *cmd, const char *name, struct command_result *param_percent(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
double **num) double **num)
{ {
*num = tal(cmd, double); *num = tal(cmd, double);
if (json_to_double(buffer, tok, *num) && **num >= 0.0) if (json_to_double(buffer, tok, *num) && **num >= 0.0)
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a positive double, not '%.*s'", "'%s' should be a positive double, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
bool json_tok_u64(struct command *cmd, const char *name, struct command_result *param_u64(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
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; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return 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;
} }
bool json_tok_tok(struct command *cmd, const char *name, struct command_result *param_tok(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok, const char *buffer, const jsmntok_t * tok,
const jsmntok_t **out) const jsmntok_t **out)
{ {
return (*out = tok); *out = tok;
return NULL;
} }

75
common/json_tok.h

@ -5,61 +5,64 @@
#include <common/json.h> #include <common/json.h>
struct command; struct command;
struct command_result;
/* Extract json array token */ /* Extract json array token */
bool json_tok_array(struct command *cmd, const char *name, struct command_result *param_array(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
const jsmntok_t **arr); const jsmntok_t **arr);
/* Extract boolean this (must be a true or false) */ /* Extract boolean this (must be a true or false) */
bool json_tok_bool(struct command *cmd, const char *name, struct command_result *param_bool(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
bool **b); bool **b);
/* Extract double from this (must be a number literal) */ /* Extract double from this (must be a number literal) */
bool json_tok_double(struct command *cmd, const char *name, struct command_result *param_double(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
double **num); double **num);
/* Extract an escaped string (and unescape it) */ /* Extract an escaped string (and unescape it) */
bool json_tok_escaped_string(struct command *cmd, const char *name, struct command_result *param_escaped_string(struct command *cmd,
const char * buffer, const jsmntok_t *tok, const char *name,
const char **str); const char *buffer,
const jsmntok_t *tok,
const char **str);
/* Extract a string */ /* Extract a string */
bool json_tok_string(struct command *cmd, const char *name, struct command_result *param_string(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok, const char * buffer, const jsmntok_t *tok,
const char **str); const char **str);
/* Extract a label. It is either an escaped string or a number. */ /* Extract a label. It is either an escaped string or a number. */
bool json_tok_label(struct command *cmd, const char *name, struct command_result *param_label(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok, const char * buffer, const jsmntok_t *tok,
struct json_escaped **label); struct json_escaped **label);
/* Extract number from this (may be a string, or a number literal) */ /* Extract number from this (may be a string, or a number literal) */
bool json_tok_number(struct command *cmd, const char *name, struct command_result *param_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);
/* Extract sha256 hash */ /* Extract sha256 hash */
bool json_tok_sha256(struct command *cmd, const char *name, struct command_result *param_sha256(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
struct sha256 **hash); struct sha256 **hash);
/* Extract positive integer, or NULL if tok is 'any'. */ /* Extract positive integer, or NULL if tok is 'any'. */
bool json_tok_msat(struct command *cmd, const char *name, struct command_result *param_msat(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok, const char *buffer, const jsmntok_t * tok,
u64 **msatoshi_val); u64 **msatoshi_val);
/* Extract double in range [0.0, 100.0] */ /* Extract double in range [0.0, 100.0] */
bool json_tok_percent(struct command *cmd, const char *name, struct command_result *param_percent(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
double **num); double **num);
/* Extract number from this (may be a string, or a number literal) */ /* Extract number from this (may be a string, or a number literal) */
bool json_tok_u64(struct command *cmd, const char *name, struct command_result *param_u64(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
uint64_t **num); uint64_t **num);
/* /*
* Set the address of @out to @tok. Used as a callback by handlers that * Set the address of @out to @tok. Used as a callback by handlers that
@ -68,8 +71,8 @@ bool json_tok_u64(struct command *cmd, const char *name,
* Usage of this is discouraged. Writing a local static bespoke handler is * Usage of this is discouraged. Writing a local static bespoke handler is
* preferred. * preferred.
*/ */
bool json_tok_tok(struct command *cmd, const char *name, struct command_result *param_tok(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t * tok, const char *buffer, const jsmntok_t * tok,
const jsmntok_t **out); const jsmntok_t **out);
#endif /* LIGHTNING_COMMON_JSON_TOK_H */ #endif /* LIGHTNING_COMMON_JSON_TOK_H */

98
common/param.c

@ -31,16 +31,18 @@ static bool param_add(struct param **params,
return true; return true;
} }
static bool make_callback(struct command *cmd, static struct command_result *make_callback(struct command *cmd,
struct param *def, struct param *def,
const char *buffer, const jsmntok_t *tok) const char *buffer,
const jsmntok_t *tok)
{ {
def->is_set = true; def->is_set = true;
return def->cbx(cmd, def->name, buffer, tok, def->arg); return def->cbx(cmd, def->name, buffer, tok, def->arg);
} }
static bool post_check(struct command *cmd, struct param *params) static struct command_result *post_check(struct command *cmd,
struct param *params)
{ {
struct param *first = params; struct param *first = params;
struct param *last = first + tal_count(params); struct param *last = first + tal_count(params);
@ -48,42 +50,43 @@ static bool post_check(struct command *cmd, struct param *params)
/* Make sure required params were provided. */ /* Make sure required params were provided. */
while (first != last && first->required) { while (first != last && first->required) {
if (!first->is_set) { if (!first->is_set) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"missing required parameter: '%s'", "missing required parameter: '%s'",
first->name); first->name);
return false;
} }
first++; first++;
} }
return true; return NULL;
} }
static bool parse_by_position(struct command *cmd, static struct command_result *parse_by_position(struct command *cmd,
struct param *params, struct param *params,
const char *buffer, const char *buffer,
const jsmntok_t tokens[], const jsmntok_t tokens[],
bool allow_extra) bool allow_extra)
{ {
struct command_result *res;
const jsmntok_t *tok = tokens + 1; const jsmntok_t *tok = tokens + 1;
const jsmntok_t *end = json_next(tokens); const jsmntok_t *end = json_next(tokens);
struct param *first = params; struct param *first = params;
struct param *last = first + tal_count(params); struct param *last = first + tal_count(params);
while (first != last && tok != end) { while (first != last && tok != end) {
if (!json_tok_is_null(buffer, tok)) if (!json_tok_is_null(buffer, tok)) {
if (!make_callback(cmd, first, buffer, tok)) res = make_callback(cmd, first, buffer, tok);
return NULL; if (res)
return res;
}
tok = json_next(tok); tok = json_next(tok);
first++; first++;
} }
/* check for unexpected trailing params */ /* check for unexpected trailing params */
if (!allow_extra && tok != end) { if (!allow_extra && tok != end) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"too many parameters:" "too many parameters:"
" got %u, expected %zu", " got %u, expected %zu",
tokens->size, tal_count(params)); tokens->size, tal_count(params));
return false;
} }
return post_check(cmd, params); return post_check(cmd, params);
@ -104,11 +107,11 @@ static struct param *find_param(struct param *params, const char *start,
return NULL; return NULL;
} }
static bool parse_by_name(struct command *cmd, static struct command_result *parse_by_name(struct command *cmd,
struct param *params, struct param *params,
const char *buffer, const char *buffer,
const jsmntok_t tokens[], const jsmntok_t tokens[],
bool allow_extra) bool allow_extra)
{ {
const jsmntok_t *first = tokens + 1; const jsmntok_t *first = tokens + 1;
const jsmntok_t *last = json_next(tokens); const jsmntok_t *last = json_next(tokens);
@ -118,21 +121,23 @@ static bool parse_by_name(struct command *cmd,
first->end - first->start); first->end - first->start);
if (!p) { if (!p) {
if (!allow_extra) { if (!allow_extra) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"unknown parameter: '%.*s'", "unknown parameter: '%.*s'",
first->end - first->start, first->end - first->start,
buffer + first->start); buffer + first->start);
return false;
} }
} else { } else {
struct command_result *res;
if (p->is_set) { if (p->is_set) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"duplicate json names: '%s'", p->name); "duplicate json names: '%s'",
return false; p->name);
} }
if (!make_callback(cmd, p, buffer, first + 1)) res = make_callback(cmd, p, buffer, first + 1);
return false; if (res)
return res;
} }
first = json_next(first + 1); first = json_next(first + 1);
} }
@ -237,15 +242,15 @@ static char *param_usage(const tal_t *ctx,
return usage; return usage;
} }
static bool param_arr(struct command *cmd, const char *buffer, static struct command_result *param_arr(struct command *cmd, const char *buffer,
const jsmntok_t tokens[], const jsmntok_t tokens[],
struct param *params, struct param *params,
bool allow_extra) bool allow_extra)
{ {
#if DEVELOPER #if DEVELOPER
if (!check_params(params)) { if (!check_params(params)) {
command_fail(cmd, PARAM_DEV_ERROR, "developer error: check_params"); return command_fail(cmd, PARAM_DEV_ERROR,
return false; "developer error: check_params");
} }
#endif #endif
if (tokens->type == JSMN_ARRAY) if (tokens->type == JSMN_ARRAY)
@ -253,9 +258,8 @@ static bool param_arr(struct command *cmd, const char *buffer,
else if (tokens->type == JSMN_OBJECT) else if (tokens->type == JSMN_OBJECT)
return parse_by_name(cmd, params, buffer, tokens, allow_extra); return parse_by_name(cmd, params, buffer, tokens, allow_extra);
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Expected array or object for params"); "Expected array or object for params");
return false;
} }
bool param(struct command *cmd, const char *buffer, bool param(struct command *cmd, const char *buffer,
@ -291,6 +295,6 @@ bool param(struct command *cmd, const char *buffer,
/* Always return false if we're simply checking command parameters; /* Always return false if we're simply checking command parameters;
* normally this returns true if all parameters are valid. */ * normally this returns true if all parameters are valid. */
return param_arr(cmd, buffer, tokens, params, allow_extra) return param_arr(cmd, buffer, tokens, params, allow_extra) == NULL
&& !command_check_only(cmd); && !command_check_only(cmd);
} }

26
common/param.h

@ -35,6 +35,10 @@
*/ */
struct command; struct command;
/* A dummy type returned by command_ functions, to ensure you return them
* immediately */
struct command_result;
/* /*
* Parse the json tokens. @params can be an array of values or an object * Parse the json tokens. @params can be an array of values or an object
* of named values. * of named values.
@ -43,14 +47,16 @@ bool param(struct command *cmd, const char *buffer,
const jsmntok_t params[], ...) LAST_ARG_NULL; const jsmntok_t params[], ...) LAST_ARG_NULL;
/* /*
* The callback signature. Callbacks must return true on success. On failure they * The callback signature.
* must call comand_fail and return false. *
* Callbacks must return NULL on success. On failure they
* must return command_fail(...).
*/ */
typedef bool(*param_cbx)(struct command *cmd, typedef struct command_result *(*param_cbx)(struct command *cmd,
const char *name, const char *name,
const char *buffer, const char *buffer,
const jsmntok_t *tok, const jsmntok_t *tok,
void **arg); void **arg);
/* /*
* Add a required parameter. * Add a required parameter.
@ -63,7 +69,7 @@ typedef bool(*param_cbx)(struct command *cmd,
(const char *)NULL, \ (const char *)NULL, \
(const char *)NULL, \ (const char *)NULL, \
(const jsmntok_t *)NULL, \ (const jsmntok_t *)NULL, \
(arg)) == true) (arg)) == (struct command_result *)NULL)
/* /*
* Add an optional parameter. *arg is set to NULL if it isn't found. * Add an optional parameter. *arg is set to NULL if it isn't found.
@ -77,7 +83,7 @@ typedef bool(*param_cbx)(struct command *cmd,
(const char *)NULL, \ (const char *)NULL, \
(const char *)NULL, \ (const char *)NULL, \
(const jsmntok_t *)NULL, \ (const jsmntok_t *)NULL, \
(arg)) == true); }) (arg)) == (struct command_result *)NULL); })
/* /*
* Add an optional parameter. *arg is set to @def if it isn't found. * Add an optional parameter. *arg is set to @def if it isn't found.
@ -92,7 +98,7 @@ typedef bool(*param_cbx)(struct command *cmd,
(const char *)NULL, \ (const char *)NULL, \
(const char *)NULL, \ (const char *)NULL, \
(const jsmntok_t *)NULL, \ (const jsmntok_t *)NULL, \
(arg)) == true); }) (arg)) == (struct command_result *)NULL); })
/* Special flag for 'check' which allows any parameters. */ /* Special flag for 'check' which allows any parameters. */
#define p_opt_any() "", false, NULL, NULL #define p_opt_any() "", false, NULL, NULL

172
common/test/run-param.c

@ -22,6 +22,10 @@ static bool check_fail(void) {
struct command *cmd; struct command *cmd;
struct command_result {
};
static struct command_result cmd_failed;
struct command_result *command_fail(struct command *cmd, struct command_result *command_fail(struct command *cmd,
int code, const char *fmt, ...) int code, const char *fmt, ...)
{ {
@ -30,7 +34,7 @@ struct command_result *command_fail(struct command *cmd,
va_start(ap, fmt); va_start(ap, fmt);
fail_msg = tal_vfmt(cmd, fmt, ap); fail_msg = tal_vfmt(cmd, fmt, ap);
va_end(ap); va_end(ap);
return NULL; return &cmd_failed;
} }
/* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS START */
@ -144,8 +148,8 @@ static void stest(const struct json *j, struct sanity *b)
u64 *ival; u64 *ival;
double *dval; double *dval;
if (!param(cmd, j->buffer, j->toks, if (!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", param_u64, &ival),
p_req("double", json_tok_double, &dval), NULL)) { p_req("double", param_double, &dval), NULL)) {
assert(check_fail()); assert(check_fail());
assert(b->failed == true); assert(b->failed == true);
if (!strstr(fail_msg, b->fail_str)) { if (!strstr(fail_msg, b->fail_str)) {
@ -182,7 +186,7 @@ static void tok_tok(void)
struct json *j = json_parse(cmd, "{ 'satoshi', '546' }"); struct json *j = json_parse(cmd, "{ 'satoshi', '546' }");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("satoshi", json_tok_tok, &tok), NULL)); p_req("satoshi", param_tok, &tok), NULL));
assert(tok); assert(tok);
assert(json_to_number(j->buffer, tok, &n)); assert(json_to_number(j->buffer, tok, &n));
assert(n == 546); assert(n == 546);
@ -194,7 +198,7 @@ static void tok_tok(void)
struct json *j = json_parse(cmd, "{}"); struct json *j = json_parse(cmd, "{}");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_opt("satoshi", json_tok_tok, &tok), NULL)); p_opt("satoshi", param_tok, &tok), NULL));
/* make sure it *is* NULL */ /* make sure it *is* NULL */
assert(tok == NULL); assert(tok == NULL);
@ -211,8 +215,8 @@ static void dup_names(void)
u64 *i; u64 *i;
double *d; double *d;
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &i), p_req("u64", param_u64, &i),
p_req("double", json_tok_double, &d), NULL)); p_req("double", param_double, &d), NULL));
} }
static void null_params(void) static void null_params(void)
@ -223,13 +227,13 @@ static void null_params(void)
json_parse(cmd, "[ '10', '11', '12', '13', '14', '15', '16']"); json_parse(cmd, "[ '10', '11', '12', '13', '14', '15', '16']");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("0", json_tok_u64, &intptrs[0]), p_req("0", param_u64, &intptrs[0]),
p_req("1", json_tok_u64, &intptrs[1]), p_req("1", param_u64, &intptrs[1]),
p_req("2", json_tok_u64, &intptrs[2]), p_req("2", param_u64, &intptrs[2]),
p_req("3", json_tok_u64, &intptrs[3]), p_req("3", param_u64, &intptrs[3]),
p_opt_def("4", json_tok_u64, &intptrs[4], 999), p_opt_def("4", param_u64, &intptrs[4], 999),
p_opt("5", json_tok_u64, &intptrs[5]), p_opt("5", param_u64, &intptrs[5]),
p_opt("6", json_tok_u64, &intptrs[6]), p_opt("6", param_u64, &intptrs[6]),
NULL)); NULL));
for (int i = 0; i < tal_count(intptrs); ++i) { for (int i = 0; i < tal_count(intptrs); ++i) {
assert(intptrs[i]); assert(intptrs[i]);
@ -239,13 +243,13 @@ static void null_params(void)
/* missing at end */ /* missing at end */
j = json_parse(cmd, "[ '10', '11', '12', '13', '14']"); j = json_parse(cmd, "[ '10', '11', '12', '13', '14']");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("0", json_tok_u64, &intptrs[0]), p_req("0", param_u64, &intptrs[0]),
p_req("1", json_tok_u64, &intptrs[1]), p_req("1", param_u64, &intptrs[1]),
p_req("2", json_tok_u64, &intptrs[2]), p_req("2", param_u64, &intptrs[2]),
p_req("3", json_tok_u64, &intptrs[3]), p_req("3", param_u64, &intptrs[3]),
p_opt("4", json_tok_u64, &intptrs[4]), p_opt("4", param_u64, &intptrs[4]),
p_opt("5", json_tok_u64, &intptrs[5]), p_opt("5", param_u64, &intptrs[5]),
p_opt_def("6", json_tok_u64, &intptrs[6], 888), p_opt_def("6", param_u64, &intptrs[6], 888),
NULL)); NULL));
assert(*intptrs[0] == 10); assert(*intptrs[0] == 10);
assert(*intptrs[1] == 11); assert(*intptrs[1] == 11);
@ -279,30 +283,30 @@ static void bad_programmer(void)
/* check for repeated names */ /* check for repeated names */
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("repeat", json_tok_u64, &ival), p_req("repeat", param_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", param_double, &dval),
p_req("repeat", json_tok_u64, &ival2), NULL)); p_req("repeat", param_u64, &ival2), NULL));
assert(check_fail()); assert(check_fail());
assert(strstr(fail_msg, "developer error")); assert(strstr(fail_msg, "developer error"));
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("repeat", json_tok_u64, &ival), p_req("repeat", param_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", param_double, &dval),
p_req("repeat", json_tok_u64, &ival), NULL)); p_req("repeat", param_u64, &ival), NULL));
assert(check_fail()); assert(check_fail());
assert(strstr(fail_msg, "developer error")); assert(strstr(fail_msg, "developer error"));
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", param_u64, &ival),
p_req("repeat", json_tok_double, &dval), p_req("repeat", param_double, &dval),
p_req("repeat", json_tok_double, &dval), NULL)); p_req("repeat", param_double, &dval), NULL));
assert(check_fail()); assert(check_fail());
assert(strstr(fail_msg, "developer error")); assert(strstr(fail_msg, "developer error"));
/* check for repeated arguments */ /* check for repeated arguments */
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", param_u64, &ival),
p_req("repeated-arg", json_tok_u64, &ival), NULL)); p_req("repeated-arg", param_u64, &ival), NULL));
assert(check_fail()); assert(check_fail());
assert(strstr(fail_msg, "developer error")); assert(strstr(fail_msg, "developer error"));
@ -316,10 +320,10 @@ static void bad_programmer(void)
unsigned int *msatoshi; unsigned int *msatoshi;
double *riskfactor; double *riskfactor;
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", param_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", param_double, &dval),
p_opt_def("msatoshi", json_tok_number, &msatoshi, 100), p_opt_def("msatoshi", param_number, &msatoshi, 100),
p_req("riskfactor", json_tok_double, &riskfactor), NULL)); p_req("riskfactor", param_double, &riskfactor), NULL));
assert(*msatoshi); assert(*msatoshi);
assert(*msatoshi == 100); assert(*msatoshi == 100);
assert(check_fail()); assert(check_fail());
@ -340,8 +344,8 @@ static void add_members(struct param **params,
tal_append_fmt(obj, "\"%i\" : %i", i, i); tal_append_fmt(obj, "\"%i\" : %i", i, i);
tal_append_fmt(arr, "%i", i); tal_append_fmt(arr, "%i", i);
param_add(params, name, true, param_add(params, name, true,
typesafe_cb_preargs(bool, void **, typesafe_cb_preargs(struct command_result *, void **,
json_tok_number, param_number,
&ints[i], &ints[i],
struct command *, struct command *,
const char *, const char *,
@ -368,7 +372,7 @@ static void five_hundred_params(void)
/* first test object version */ /* first test object version */
struct json *j = json_parse(params, obj); struct json *j = json_parse(params, obj);
assert(param_arr(cmd, j->buffer, j->toks, params, false)); assert(param_arr(cmd, j->buffer, j->toks, params, false) == NULL);
for (int i = 0; i < tal_count(ints); ++i) { for (int i = 0; i < tal_count(ints); ++i) {
assert(ints[i]); assert(ints[i]);
assert(*ints[i] == i); assert(*ints[i] == i);
@ -377,7 +381,7 @@ static void five_hundred_params(void)
/* now test array */ /* now test array */
j = json_parse(params, arr); j = json_parse(params, arr);
assert(param_arr(cmd, j->buffer, j->toks, params, false)); assert(param_arr(cmd, j->buffer, j->toks, params, false) == NULL);
for (int i = 0; i < tal_count(ints); ++i) { for (int i = 0; i < tal_count(ints); ++i) {
assert(*ints[i] == i); assert(*ints[i] == i);
} }
@ -394,10 +398,10 @@ static void sendpay(void)
unsigned *cltv; unsigned *cltv;
if (!param(cmd, j->buffer, j->toks, if (!param(cmd, j->buffer, j->toks,
p_req("route", json_tok_tok, &routetok), p_req("route", param_tok, &routetok),
p_req("cltv", json_tok_number, &cltv), p_req("cltv", param_number, &cltv),
p_opt("note", json_tok_tok, &note), p_opt("note", param_tok, &note),
p_opt("msatoshi", json_tok_u64, &msatoshi), p_opt("msatoshi", param_u64, &msatoshi),
NULL)) NULL))
assert(false); assert(false);
@ -417,10 +421,10 @@ static void sendpay_nulltok(void)
unsigned *cltv; unsigned *cltv;
if (!param(cmd, j->buffer, j->toks, if (!param(cmd, j->buffer, j->toks,
p_req("route", json_tok_tok, &routetok), p_req("route", param_tok, &routetok),
p_req("cltv", json_tok_number, &cltv), p_req("cltv", param_number, &cltv),
p_opt("note", json_tok_tok, &note), p_opt("note", param_tok, &note),
p_opt("msatoshi", json_tok_u64, &msatoshi), p_opt("msatoshi", param_u64, &msatoshi),
NULL)) NULL))
assert(false); assert(false);
@ -439,11 +443,11 @@ static void advanced(void)
const jsmntok_t *tok; const jsmntok_t *tok;
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("description", json_tok_label, &label), p_req("description", param_label, &label),
p_req("msat", json_tok_msat, &msat), p_req("msat", param_msat, &msat),
p_req("tok", json_tok_tok, &tok), p_req("tok", param_tok, &tok),
p_opt("msat_opt1", json_tok_msat, &msat_opt1), p_opt("msat_opt1", param_msat, &msat_opt1),
p_opt("msat_opt2", json_tok_msat, &msat_opt2), p_opt("msat_opt2", param_msat, &msat_opt2),
NULL)); NULL));
assert(label != NULL); assert(label != NULL);
assert(streq(label->s, "lightning")); assert(streq(label->s, "lightning"));
@ -457,8 +461,8 @@ static void advanced(void)
struct json *j = json_parse(cmd, "[ 3 'foo' ]"); struct json *j = json_parse(cmd, "[ 3 'foo' ]");
struct json_escaped *label, *foo; struct json_escaped *label, *foo;
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("label", json_tok_label, &label), p_req("label", param_label, &label),
p_opt("foo", json_tok_label, &foo), p_opt("foo", param_label, &foo),
NULL)); NULL));
assert(streq(label->s, "3")); assert(streq(label->s, "3"));
assert(streq(foo->s, "foo")); assert(streq(foo->s, "foo"));
@ -468,8 +472,8 @@ static void advanced(void)
u64 *msat2; u64 *msat2;
struct json *j = json_parse(cmd, "[ 3 ]"); struct json *j = json_parse(cmd, "[ 3 ]");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_opt_def("msat", json_tok_msat, &msat, 23), p_opt_def("msat", param_msat, &msat, 23),
p_opt_def("msat2", json_tok_msat, &msat2, 53), p_opt_def("msat2", param_msat, &msat2, 53),
NULL)); NULL));
assert(*msat == 3); assert(*msat == 3);
assert(msat2); assert(msat2);
@ -483,7 +487,7 @@ static void advanced_fail(void)
struct json *j = json_parse(cmd, "[ 'anyx' ]"); struct json *j = json_parse(cmd, "[ 'anyx' ]");
u64 *msat; u64 *msat;
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("msat", json_tok_msat, &msat), p_req("msat", param_msat, &msat),
NULL)); NULL));
assert(check_fail()); assert(check_fail());
assert(strstr(fail_msg, "'msat' should be a positive" assert(strstr(fail_msg, "'msat' should be a positive"
@ -495,31 +499,31 @@ static void advanced_fail(void)
{ \ { \
struct json *j = json_parse(cmd, json_); \ struct json *j = json_parse(cmd, json_); \
T *v; \ T *v; \
bool ret = cb(cmd, "name", j->buffer, j->toks + 1, &v); \ struct command_result *ret = cb(cmd, "name", j->buffer, j->toks + 1, &v); \
assert(ret == pass); \ assert((ret == NULL) == pass); \
if (ret) { \ if (ret == NULL) { \
assert(v); \ assert(v); \
assert(*v == value); \ assert(*v == value); \
} \ } \
} }
static void json_tok_tests(void) static void param_tests(void)
{ {
test_cb(json_tok_bool, bool, "[ true ]", true, true); test_cb(param_bool, bool, "[ true ]", true, true);
test_cb(json_tok_bool, bool, "[ false ]", false, true); test_cb(param_bool, bool, "[ false ]", false, true);
test_cb(json_tok_bool, bool, "[ tru ]", false, false); test_cb(param_bool, bool, "[ tru ]", false, false);
test_cb(json_tok_bool, bool, "[ 1 ]", false, false); test_cb(param_bool, bool, "[ 1 ]", false, false);
test_cb(json_tok_percent, double, "[ -0.01 ]", 0, false); test_cb(param_percent, double, "[ -0.01 ]", 0, false);
test_cb(json_tok_percent, double, "[ 0.00 ]", 0, true); test_cb(param_percent, double, "[ 0.00 ]", 0, true);
test_cb(json_tok_percent, double, "[ 1 ]", 1, true); test_cb(param_percent, double, "[ 1 ]", 1, true);
test_cb(json_tok_percent, double, "[ 1.1 ]", 1.1, true); test_cb(param_percent, double, "[ 1.1 ]", 1.1, true);
test_cb(json_tok_percent, double, "[ 1.01 ]", 1.01, true); test_cb(param_percent, double, "[ 1.01 ]", 1.01, true);
test_cb(json_tok_percent, double, "[ 99.99 ]", 99.99, true); test_cb(param_percent, double, "[ 99.99 ]", 99.99, true);
test_cb(json_tok_percent, double, "[ 100.0 ]", 100, true); test_cb(param_percent, double, "[ 100.0 ]", 100, true);
test_cb(json_tok_percent, double, "[ 100.001 ]", 100.001, true); test_cb(param_percent, double, "[ 100.001 ]", 100.001, true);
test_cb(json_tok_percent, double, "[ 1000 ]", 1000, true); test_cb(param_percent, double, "[ 1000 ]", 1000, true);
test_cb(json_tok_percent, double, "[ 'wow' ]", 0, false); test_cb(param_percent, double, "[ 'wow' ]", 0, false);
} }
static void test_invoice(struct command *cmd, static void test_invoice(struct command *cmd,
@ -536,12 +540,12 @@ static void test_invoice(struct command *cmd,
assert(cmd->mode == CMD_USAGE); assert(cmd->mode == CMD_USAGE);
if(!param(cmd, buffer, params, if(!param(cmd, buffer, params,
p_req("msatoshi", json_tok_msat, &msatoshi_val), p_req("msatoshi", param_msat, &msatoshi_val),
p_req("label", json_tok_label, &label_val), p_req("label", param_label, &label_val),
p_req("description", json_tok_escaped_string, &desc_val), p_req("description", param_escaped_string, &desc_val),
p_opt("expiry", json_tok_u64, &expiry), p_opt("expiry", param_u64, &expiry),
p_opt("fallbacks", json_tok_array, &fallbacks), p_opt("fallbacks", param_array, &fallbacks),
p_opt("preimage", json_tok_tok, &preimagetok), NULL)) p_opt("preimage", param_tok, &preimagetok), NULL))
return; return;
/* should not be here since we are in the mode of CMD_USAGE /* should not be here since we are in the mode of CMD_USAGE
@ -583,7 +587,7 @@ int main(void)
sendpay_nulltok(); sendpay_nulltok();
advanced(); advanced();
advanced_fail(); advanced_fail();
json_tok_tests(); param_tests();
usage(); usage();
tal_free(tmpctx); tal_free(tmpctx);

16
lightningd/chaintopology.c

@ -286,16 +286,16 @@ const char *feerate_name(enum feerate feerate)
abort(); abort();
} }
bool json_feerate_estimate(struct command *cmd, struct command_result *param_feerate_estimate(struct command *cmd,
u32 **feerate_per_kw, enum feerate feerate) u32 **feerate_per_kw,
enum feerate feerate)
{ {
*feerate_per_kw = tal(cmd, u32); *feerate_per_kw = tal(cmd, u32);
**feerate_per_kw = try_get_feerate(cmd->ld->topology, feerate); **feerate_per_kw = try_get_feerate(cmd->ld->topology, feerate);
if (!**feerate_per_kw) { if (!**feerate_per_kw)
command_fail(cmd, LIGHTNINGD, "Cannot estimate fees"); return command_fail(cmd, LIGHTNINGD, "Cannot estimate fees");
return false;
} return NULL;
return true;
} }
/* Mutual recursion via timer. */ /* Mutual recursion via timer. */
@ -475,7 +475,7 @@ static void json_feerates(struct command *cmd,
enum feerate_style *style; enum feerate_style *style;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("style", json_tok_feerate_style, &style), p_req("style", param_feerate_style, &style),
NULL)) NULL))
return; return;

7
lightningd/chaintopology.h

@ -150,9 +150,10 @@ u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style);
const char *feerate_name(enum feerate feerate); const char *feerate_name(enum feerate feerate);
/* Set feerate_per_kw to this estimate, or fail cmd */ /* Set feerate_per_kw to this estimate & return NULL, or fail cmd */
bool json_feerate_estimate(struct command *cmd, struct command_result *param_feerate_estimate(struct command *cmd,
u32 **feerate_per_kw, enum feerate feerate); u32 **feerate_per_kw,
enum feerate feerate);
/* Broadcast a single tx, and rebroadcast as reqd (copies tx). /* Broadcast a single tx, and rebroadcast as reqd (copies tx).
* If failed is non-NULL, call that and don't rebroadcast. */ * If failed is non-NULL, call that and don't rebroadcast. */

6
lightningd/connect_control.c

@ -92,9 +92,9 @@ static void json_connect(struct command *cmd,
struct peer *peer; struct peer *peer;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_tok, (const jsmntok_t **) &idtok), p_req("id", param_tok, (const jsmntok_t **) &idtok),
p_opt("host", json_tok_string, &name), p_opt("host", param_string, &name),
p_opt("port", json_tok_number, &port), p_opt("port", param_number, &port),
NULL)) NULL))
return; return;

36
lightningd/gossip_control.c

@ -253,7 +253,7 @@ static void json_listnodes(struct command *cmd,
struct pubkey *id; struct pubkey *id;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("id", json_tok_pubkey, &id), p_opt("id", param_pubkey, &id),
NULL)) NULL))
return; return;
@ -310,13 +310,13 @@ static void json_getroute(struct command *cmd,
struct siphash_seed seed; struct siphash_seed seed;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &destination), p_req("id", param_pubkey, &destination),
p_req("msatoshi", json_tok_u64, &msatoshi), p_req("msatoshi", param_u64, &msatoshi),
p_req("riskfactor", json_tok_double, &riskfactor), p_req("riskfactor", param_double, &riskfactor),
p_opt_def("cltv", json_tok_number, &cltv, 9), p_opt_def("cltv", param_number, &cltv, 9),
p_opt_def("fromid", json_tok_pubkey, &source, ld->id), p_opt_def("fromid", param_pubkey, &source, ld->id),
p_opt("seed", json_tok_tok, &seedtok), p_opt("seed", param_tok, &seedtok),
p_opt_def("fuzzpercent", json_tok_percent, &fuzz, 75.0), p_opt_def("fuzzpercent", param_percent, &fuzz, 75.0),
NULL)) NULL))
return; return;
@ -407,7 +407,7 @@ static void json_listchannels(struct command *cmd,
u8 *req; u8 *req;
struct short_channel_id *id; struct short_channel_id *id;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("short_channel_id", json_tok_short_channel_id, &id), p_opt("short_channel_id", param_short_channel_id, &id),
NULL)) NULL))
return; return;
@ -463,8 +463,8 @@ static void json_dev_query_scids(struct command *cmd,
size_t i; size_t i;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_req("scids", json_tok_array, &scidstok), p_req("scids", param_array, &scidstok),
NULL)) NULL))
return; return;
@ -504,9 +504,9 @@ static void json_dev_send_timestamp_filter(struct command *cmd,
u32 *first, *range; u32 *first, *range;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_req("first", json_tok_number, &first), p_req("first", param_number, &first),
p_req("range", json_tok_number, &range), p_req("range", param_number, &range),
NULL)) NULL))
return; return;
@ -574,9 +574,9 @@ static void json_dev_query_channel_range(struct command *cmd,
u32 *first, *num; u32 *first, *num;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_req("first", json_tok_number, &first), p_req("first", param_number, &first),
p_req("num", json_tok_number, &num), p_req("num", param_number, &num),
NULL)) NULL))
return; return;
@ -603,7 +603,7 @@ static void json_dev_set_max_scids_encode_size(struct command *cmd,
u32 *max; u32 *max;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("max", json_tok_number, &max), p_req("max", param_number, &max),
NULL)) NULL))
return; return;

32
lightningd/invoice.c

@ -309,12 +309,12 @@ static void json_invoice(struct command *cmd,
info->cmd = cmd; info->cmd = cmd;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("msatoshi", json_tok_msat, &msatoshi_val), p_req("msatoshi", param_msat, &msatoshi_val),
p_req("label", json_tok_label, &info->label), p_req("label", param_label, &info->label),
p_req("description", json_tok_escaped_string, &desc_val), p_req("description", param_escaped_string, &desc_val),
p_opt_def("expiry", json_tok_u64, &expiry, 3600), p_opt_def("expiry", param_u64, &expiry, 3600),
p_opt("fallbacks", json_tok_array, &fallbacks), p_opt("fallbacks", param_array, &fallbacks),
p_opt("preimage", json_tok_tok, &preimagetok), p_opt("preimage", param_tok, &preimagetok),
NULL)) NULL))
return; return;
@ -425,7 +425,7 @@ static void json_listinvoices(struct command *cmd,
struct json_stream *response; struct json_stream *response;
struct wallet *wallet = cmd->ld->wallet; struct wallet *wallet = cmd->ld->wallet;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("label", json_tok_label, &label), p_opt("label", param_label, &label),
NULL)) NULL))
return; return;
response = json_stream_success(cmd); response = json_stream_success(cmd);
@ -457,8 +457,8 @@ static void json_delinvoice(struct command *cmd,
struct wallet *wallet = cmd->ld->wallet; struct wallet *wallet = cmd->ld->wallet;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("label", json_tok_label, &label), p_req("label", param_label, &label),
p_req("status", json_tok_string, &status), p_req("status", param_string, &status),
NULL)) NULL))
return; return;
@ -506,7 +506,7 @@ static void json_delexpiredinvoice(struct command *cmd,
u64 *maxexpirytime; u64 *maxexpirytime;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("maxexpirytime", json_tok_u64, &maxexpirytime, p_opt_def("maxexpirytime", param_u64, &maxexpirytime,
time_now().ts.tv_sec), time_now().ts.tv_sec),
NULL)) NULL))
return; return;
@ -531,8 +531,8 @@ static void json_autocleaninvoice(struct command *cmd,
u64 *exby; u64 *exby;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("cycle_seconds", json_tok_u64, &cycle, 3600), p_opt_def("cycle_seconds", param_u64, &cycle, 3600),
p_opt_def("expired_by", json_tok_u64, &exby, 86400), p_opt_def("expired_by", param_u64, &exby, 86400),
NULL)) NULL))
return; return;
@ -558,7 +558,7 @@ static void json_waitanyinvoice(struct command *cmd,
struct wallet *wallet = cmd->ld->wallet; struct wallet *wallet = cmd->ld->wallet;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("lastpay_index", json_tok_u64, &pay_index, 0), p_opt_def("lastpay_index", param_u64, &pay_index, 0),
NULL)) NULL))
return; return;
@ -596,7 +596,7 @@ static void json_waitinvoice(struct command *cmd,
struct json_escaped *label; struct json_escaped *label;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("label", json_tok_label, &label), p_req("label", param_label, &label),
NULL)) NULL))
return; return;
@ -671,8 +671,8 @@ static void json_decodepay(struct command *cmd,
char *fail; char *fail;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("bolt11", json_tok_string, &str), p_req("bolt11", param_string, &str),
p_opt("description", json_tok_string, &desc), p_opt("description", param_string, &desc),
NULL)) NULL))
return; return;

91
lightningd/json.c

@ -104,18 +104,18 @@ bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
tok->end - tok->start, pubkey); tok->end - tok->start, pubkey);
} }
bool json_tok_pubkey(struct command *cmd, const char *name, struct command_result *param_pubkey(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
struct pubkey **pubkey) struct pubkey **pubkey)
{ {
*pubkey = tal(cmd, struct pubkey); *pubkey = tal(cmd, struct pubkey);
if (json_to_pubkey(buffer, tok, *pubkey)) if (json_to_pubkey(buffer, tok, *pubkey))
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a pubkey, not '%.*s'", "'%s' should be a pubkey, not '%.*s'",
name, json_tok_full_len(tok), json_tok_full(buffer, tok)); name, json_tok_full_len(tok),
return false; json_tok_full(buffer, tok));
} }
void json_add_short_channel_id(struct json_stream *response, void json_add_short_channel_id(struct json_stream *response,
@ -133,18 +133,20 @@ bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
tok->end - tok->start, scid)); tok->end - tok->start, scid));
} }
bool json_tok_short_channel_id(struct command *cmd, const char *name, struct command_result *param_short_channel_id(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
struct short_channel_id **scid) const char *buffer,
const jsmntok_t *tok,
struct short_channel_id **scid)
{ {
*scid = tal(cmd, struct short_channel_id); *scid = tal(cmd, struct short_channel_id);
if (json_to_short_channel_id(buffer, tok, *scid)) if (json_to_short_channel_id(buffer, tok, *scid))
return true; return NULL;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a short channel id, not '%.*s'", "'%s' should be a short channel id, not '%.*s'",
name, json_tok_full_len(tok), json_tok_full(buffer, tok)); name, json_tok_full_len(tok),
return false; json_tok_full(buffer, tok));
} }
const char *json_feerate_style_name(enum feerate_style style) const char *json_feerate_style_name(enum feerate_style style)
@ -158,33 +160,34 @@ const char *json_feerate_style_name(enum feerate_style style)
abort(); abort();
} }
bool json_tok_feerate_style(struct command *cmd, const char *name, struct command_result *param_feerate_style(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
enum feerate_style **style) const char *buffer,
const jsmntok_t *tok,
enum feerate_style **style)
{ {
*style = tal(cmd, enum feerate_style); *style = tal(cmd, enum feerate_style);
if (json_tok_streq(buffer, tok, if (json_tok_streq(buffer, tok,
json_feerate_style_name(FEERATE_PER_KSIPA))) { json_feerate_style_name(FEERATE_PER_KSIPA))) {
**style = FEERATE_PER_KSIPA; **style = FEERATE_PER_KSIPA;
return true; return NULL;
} else if (json_tok_streq(buffer, tok, } else if (json_tok_streq(buffer, tok,
json_feerate_style_name(FEERATE_PER_KBYTE))) { json_feerate_style_name(FEERATE_PER_KBYTE))) {
**style = FEERATE_PER_KBYTE; **style = FEERATE_PER_KBYTE;
return true; return NULL;
} }
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be '%s' or '%s', not '%.*s'", "'%s' should be '%s' or '%s', not '%.*s'",
name, name,
json_feerate_style_name(FEERATE_PER_KSIPA), json_feerate_style_name(FEERATE_PER_KSIPA),
json_feerate_style_name(FEERATE_PER_KBYTE), json_feerate_style_name(FEERATE_PER_KBYTE),
json_tok_full_len(tok), json_tok_full(buffer, tok)); json_tok_full_len(tok), json_tok_full(buffer, tok));
return false;
} }
bool json_tok_feerate(struct command *cmd, const char *name, struct command_result *param_feerate(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
u32 **feerate) u32 **feerate)
{ {
jsmntok_t base = *tok, suffix = *tok; jsmntok_t base = *tok, suffix = *tok;
enum feerate_style style; enum feerate_style style;
@ -192,7 +195,7 @@ bool json_tok_feerate(struct command *cmd, const char *name,
for (size_t i = 0; i < NUM_FEERATES; i++) { for (size_t i = 0; i < NUM_FEERATES; i++) {
if (json_tok_streq(buffer, tok, feerate_name(i))) if (json_tok_streq(buffer, tok, feerate_name(i)))
return json_feerate_estimate(cmd, feerate, i); return param_feerate_estimate(cmd, feerate, i);
} }
/* We have to split the number and suffix. */ /* We have to split the number and suffix. */
@ -203,10 +206,10 @@ bool json_tok_feerate(struct command *cmd, const char *name,
} }
if (!json_to_number(buffer, &base, &num)) { if (!json_to_number(buffer, &base, &num)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' prefix should be an integer, not '%.*s'", "'%s' prefix should be an integer, not '%.*s'",
name, base.end - base.start, buffer + base.start); name, base.end - base.start,
return false; buffer + base.start);
} }
if (json_tok_streq(buffer, &suffix, "") if (json_tok_streq(buffer, &suffix, "")
@ -217,18 +220,18 @@ bool json_tok_feerate(struct command *cmd, const char *name,
json_feerate_style_name(FEERATE_PER_KSIPA))) { json_feerate_style_name(FEERATE_PER_KSIPA))) {
style = FEERATE_PER_KSIPA; style = FEERATE_PER_KSIPA;
} else { } else {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' suffix should be '%s' or '%s', not '%.*s'", "'%s' suffix should be '%s' or '%s', not '%.*s'",
name, name,
json_feerate_style_name(FEERATE_PER_KSIPA), json_feerate_style_name(FEERATE_PER_KSIPA),
json_feerate_style_name(FEERATE_PER_KBYTE), json_feerate_style_name(FEERATE_PER_KBYTE),
suffix.end - suffix.start, buffer + suffix.start); suffix.end - suffix.start,
return false; buffer + suffix.start);
} }
*feerate = tal(cmd, u32); *feerate = tal(cmd, u32);
**feerate = feerate_from_style(num, style); **feerate = feerate_from_style(num, style);
return true; return NULL;
} }
bool bool

38
lightningd/json.h

@ -51,17 +51,19 @@ void json_add_txid(struct json_stream *result, const char *fieldname,
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);
bool json_tok_pubkey(struct command *cmd, const char *name, struct command_result *param_pubkey(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
struct pubkey **pubkey); struct pubkey **pubkey);
/* Extract a short_channel_id from this */ /* Extract a short_channel_id from this */
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok, bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid); struct short_channel_id *scid);
bool json_tok_short_channel_id(struct command *cmd, const char *name, struct command_result *param_short_channel_id(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
struct short_channel_id **scid); const char *buffer,
const jsmntok_t *tok,
struct short_channel_id **scid);
enum feerate_style { enum feerate_style {
FEERATE_PER_KSIPA, FEERATE_PER_KSIPA,
@ -69,16 +71,18 @@ enum feerate_style {
}; };
/* Extract a feerate style. */ /* Extract a feerate style. */
bool json_tok_feerate_style(struct command *cmd, const char *name, struct command_result *param_feerate_style(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
enum feerate_style **style); const char *buffer,
const jsmntok_t *tok,
enum feerate_style **style);
const char *json_feerate_style_name(enum feerate_style style); const char *json_feerate_style_name(enum feerate_style style);
/* Extract a feerate with optional style suffix. */ /* Extract a feerate with optional style suffix. */
bool json_tok_feerate(struct command *cmd, const char *name, struct command_result *param_feerate(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok, const char *buffer, const jsmntok_t *tok,
u32 **feerate); u32 **feerate);
/* '"fieldname" : "1234:5:6"' */ /* '"fieldname" : "1234:5:6"' */
void json_add_short_channel_id(struct json_stream *response, void json_add_short_channel_id(struct json_stream *response,
@ -144,12 +148,12 @@ enum address_parse_result {
* allocated off ctx if ADDRESS_PARSE_SUCCESS * allocated off ctx if ADDRESS_PARSE_SUCCESS
*/ */
enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx, enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx,
const struct chainparams *chainparams, const struct chainparams *chainparams,
const char *buffer, const char *buffer,
const jsmntok_t *tok, const u8 **scriptpubkey); const jsmntok_t *tok, const u8 **scriptpubkey);
/* Parse the satoshi token in wallet_tx. */ /* Parse the satoshi token in wallet_tx. */
bool json_tok_wtx(struct wallet_tx * tx, const char * buffer, struct command_result *param_wtx(struct wallet_tx * tx, const char * buffer,
const jsmntok_t * sattok, u64 max); const jsmntok_t * sattok, u64 max);
#endif /* LIGHTNING_LIGHTNINGD_JSON_H */ #endif /* LIGHTNING_LIGHTNINGD_JSON_H */

45
lightningd/jsonrpc.c

@ -200,7 +200,7 @@ static void json_rhash(struct command *cmd,
struct sha256 *secret; struct sha256 *secret;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("secret", json_tok_sha256, &secret), p_req("secret", param_sha256, &secret),
NULL)) NULL))
return; return;
@ -250,7 +250,7 @@ static void json_slowcmd(struct command *cmd,
sc->cmd = cmd; sc->cmd = cmd;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("msec", json_tok_number, &sc->msec, 1000), p_opt_def("msec", param_number, &sc->msec, 1000),
NULL)) NULL))
return; return;
@ -335,7 +335,7 @@ static void json_help(struct command *cmd,
struct json_command **commands = cmd->ld->jsonrpc->commands; struct json_command **commands = cmd->ld->jsonrpc->commands;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("command", json_tok_tok, &cmdtok), p_opt("command", param_tok, &cmdtok),
NULL)) NULL))
return; return;
@ -963,36 +963,37 @@ json_tok_address_scriptpubkey(const tal_t *cxt,
return ADDRESS_PARSE_UNRECOGNIZED; return ADDRESS_PARSE_UNRECOGNIZED;
} }
bool json_tok_wtx(struct wallet_tx * tx, const char * buffer, struct command_result *param_wtx(struct wallet_tx * tx, const char * buffer,
const jsmntok_t *sattok, u64 max) const jsmntok_t *sattok, u64 max)
{ {
if (json_tok_streq(buffer, sattok, "all")) { if (json_tok_streq(buffer, sattok, "all")) {
tx->all_funds = true; tx->all_funds = true;
tx->amount = max; tx->amount = max;
} else if (!json_to_u64(buffer, sattok, &tx->amount)) { } else if (!json_to_u64(buffer, sattok, &tx->amount)) {
command_fail(tx->cmd, JSONRPC2_INVALID_PARAMS, return command_fail(tx->cmd, JSONRPC2_INVALID_PARAMS,
"Invalid satoshis"); "Invalid satoshis");
return false;
} else if (tx->amount > max) { } else if (tx->amount > max) {
command_fail(tx->cmd, FUND_MAX_EXCEEDED, return command_fail(tx->cmd, FUND_MAX_EXCEEDED,
"Amount exceeded %"PRIu64, max); "Amount exceeded %"PRIu64, max);
return false;
} }
return true; return NULL;
} }
static bool json_tok_command(struct command *cmd, const char *name, static struct command_result *param_command(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
const jsmntok_t **out) const char *buffer,
const jsmntok_t *tok,
const jsmntok_t **out)
{ {
cmd->json_cmd = find_cmd(cmd->jcon->ld->jsonrpc, buffer, tok); cmd->json_cmd = find_cmd(cmd->jcon->ld->jsonrpc, buffer, tok);
if (cmd->json_cmd) if (cmd->json_cmd) {
return (*out = tok); *out = tok;
return NULL;
}
command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Unknown command '%.*s'", "Unknown command '%.*s'",
tok->end - tok->start, buffer + tok->start); tok->end - tok->start, buffer + tok->start);
return false;
} }
/* We add this destructor as a canary to detect cmd failing. */ /* We add this destructor as a canary to detect cmd failing. */
@ -1018,7 +1019,7 @@ static void json_check(struct command *cmd,
} }
if (!param(cmd, buffer, mod_params, if (!param(cmd, buffer, mod_params,
p_req("command_to_check", json_tok_command, &name_tok), p_req("command_to_check", param_command, &name_tok),
p_opt_any(), p_opt_any(),
NULL)) NULL))
return; return;

25
lightningd/log.c

@ -702,9 +702,11 @@ void json_add_log(struct json_stream *response,
json_array_end(info.response); json_array_end(info.response);
} }
bool json_tok_loglevel(struct command *cmd, const char *name, struct command_result *param_loglevel(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
enum log_level **level) const char *buffer,
const jsmntok_t *tok,
enum log_level **level)
{ {
*level = tal(cmd, enum log_level); *level = tal(cmd, enum log_level);
if (json_tok_streq(buffer, tok, "io")) if (json_tok_streq(buffer, tok, "io"))
@ -716,14 +718,14 @@ bool json_tok_loglevel(struct command *cmd, const char *name,
else if (json_tok_streq(buffer, tok, "unusual")) else if (json_tok_streq(buffer, tok, "unusual"))
**level = LOG_UNUSUAL; **level = LOG_UNUSUAL;
else { else {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'io', 'debug', 'info', or " "'%s' should be 'io', 'debug', 'info', or "
"'unusual', not '%.*s'", "'unusual', not '%.*s'",
name, name,
json_tok_full_len(tok), json_tok_full(buffer, tok)); json_tok_full_len(tok),
return false; json_tok_full(buffer, tok));
} }
return true; return NULL;
} }
static void json_getlog(struct command *cmd, static void json_getlog(struct command *cmd,
@ -736,8 +738,7 @@ static void json_getlog(struct command *cmd,
struct log_book *lr = cmd->ld->log_book; struct log_book *lr = cmd->ld->log_book;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("level", json_tok_loglevel, &minlevel, p_opt_def("level", param_loglevel, &minlevel, LOG_INFORM),
LOG_INFORM),
NULL)) NULL))
return; return;

8
lightningd/log.h

@ -103,8 +103,10 @@ void log_backtrace_exit(void);
void json_add_log(struct json_stream *result, void json_add_log(struct json_stream *result,
const struct log_book *lr, enum log_level minlevel); const struct log_book *lr, enum log_level minlevel);
bool json_tok_loglevel(struct command *cmd, const char *name, struct command_result *param_loglevel(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
enum log_level **level); const char *buffer,
const jsmntok_t *tok,
enum log_level **level);
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */ #endif /* LIGHTNING_LIGHTNINGD_LOG_H */

12
lightningd/opening_control.c

@ -767,6 +767,7 @@ static void json_fund_channel(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct command_result *res;
const jsmntok_t *sattok; const jsmntok_t *sattok;
struct funding_channel * fc = tal(cmd, struct funding_channel); struct funding_channel * fc = tal(cmd, struct funding_channel);
struct pubkey *id; struct pubkey *id;
@ -781,14 +782,15 @@ static void json_fund_channel(struct command *cmd,
fc->uc = NULL; fc->uc = NULL;
wtx_init(cmd, &fc->wtx); wtx_init(cmd, &fc->wtx);
if (!param(fc->cmd, buffer, params, if (!param(fc->cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_req("satoshi", json_tok_tok, &sattok), p_req("satoshi", param_tok, &sattok),
p_opt("feerate", json_tok_feerate, &feerate_per_kw), p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", json_tok_bool, &announce_channel, true), p_opt_def("announce", param_bool, &announce_channel, true),
NULL)) NULL))
return; return;
if (!json_tok_wtx(&fc->wtx, buffer, sattok, max_funding_satoshi)) res = param_wtx(&fc->wtx, buffer, sattok, max_funding_satoshi);
if (res)
return; return;
if (!feerate_per_kw) { if (!feerate_per_kw) {

2
lightningd/options.c

@ -1056,7 +1056,7 @@ static void json_listconfigs(struct command *cmd,
const jsmntok_t *configtok; const jsmntok_t *configtok;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("config", json_tok_tok, &configtok), p_opt("config", param_tok, &configtok),
NULL)) NULL))
return; return;

24
lightningd/pay.c

@ -955,10 +955,10 @@ static void json_sendpay(struct command *cmd,
const char *description; const char *description;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("route", json_tok_array, &routetok), p_req("route", param_array, &routetok),
p_req("payment_hash", json_tok_sha256, &rhash), p_req("payment_hash", param_sha256, &rhash),
p_opt("description", json_tok_escaped_string, &description), p_opt("description", param_escaped_string, &description),
p_opt("msatoshi", json_tok_u64, &msatoshi), p_opt("msatoshi", param_u64, &msatoshi),
NULL)) NULL))
return; return;
@ -973,10 +973,10 @@ static void json_sendpay(struct command *cmd,
unsigned *delay; unsigned *delay;
if (!param(cmd, buffer, t, if (!param(cmd, buffer, t,
p_req("msatoshi", json_tok_u64, &amount), p_req("msatoshi", param_u64, &amount),
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_req("delay", json_tok_number, &delay), p_req("delay", param_number, &delay),
p_req("channel", json_tok_short_channel_id, &channel), p_req("channel", param_short_channel_id, &channel),
NULL)) NULL))
return; return;
@ -1037,8 +1037,8 @@ static void json_waitsendpay(struct command *cmd,
unsigned int *timeout; unsigned int *timeout;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("payment_hash", json_tok_sha256, &rhash), p_req("payment_hash", param_sha256, &rhash),
p_opt("timeout", json_tok_number, &timeout), p_opt("timeout", param_number, &timeout),
NULL)) NULL))
return; return;
@ -1070,8 +1070,8 @@ static void json_listpayments(struct command *cmd,
const char *b11str; const char *b11str;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("bolt11", json_tok_string, &b11str), p_opt("bolt11", param_string, &b11str),
p_opt("payment_hash", json_tok_sha256, &rhash), p_opt("payment_hash", param_sha256, &rhash),
NULL)) NULL))
return; return;

16
lightningd/payalgo.c

@ -609,15 +609,15 @@ static void json_pay(struct command *cmd,
unsigned int *exemptfee; unsigned int *exemptfee;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("bolt11", json_tok_string, &b11str), p_req("bolt11", param_string, &b11str),
p_opt("msatoshi", json_tok_u64, &msatoshi), p_opt("msatoshi", param_u64, &msatoshi),
p_opt("description", json_tok_string, &desc), p_opt("description", param_string, &desc),
p_opt_def("riskfactor", json_tok_double, &riskfactor, 1.0), p_opt_def("riskfactor", param_double, &riskfactor, 1.0),
p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5), p_opt_def("maxfeepercent", param_percent, &maxfeepercent, 0.5),
p_opt_def("retry_for", json_tok_number, &retryfor, 60), p_opt_def("retry_for", param_number, &retryfor, 60),
p_opt_def("maxdelay", json_tok_number, &maxdelay, p_opt_def("maxdelay", param_number, &maxdelay,
cmd->ld->config.locktime_max), cmd->ld->config.locktime_max),
p_opt_def("exemptfee", json_tok_number, &exemptfee, 5000), p_opt_def("exemptfee", param_number, &exemptfee, 5000),
NULL)) NULL))
return; return;

26
lightningd/peer_control.c

@ -814,8 +814,8 @@ static void json_listpeers(struct command *cmd,
struct json_stream *response; struct json_stream *response;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("id", json_tok_pubkey, &specific_id), p_opt("id", param_pubkey, &specific_id),
p_opt("level", json_tok_loglevel, &ll), p_opt("level", param_loglevel, &ll),
NULL)) NULL))
return; return;
@ -903,9 +903,9 @@ static void json_close(struct command *cmd,
bool *force; bool *force;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_tok, &idtok), p_req("id", param_tok, &idtok),
p_opt_def("force", json_tok_bool, &force, false), p_opt_def("force", param_bool, &force, false),
p_opt_def("timeout", json_tok_number, &timeout, 30), p_opt_def("timeout", param_number, &timeout, 30),
NULL)) NULL))
return; return;
@ -1046,8 +1046,8 @@ static void json_disconnect(struct command *cmd,
bool *force; bool *force;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_opt_def("force", json_tok_bool, &force, false), p_opt_def("force", param_bool, &force, false),
NULL)) NULL))
return; return;
@ -1171,7 +1171,7 @@ static void json_sign_last_tx(struct command *cmd,
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &peerid), p_req("id", param_pubkey, &peerid),
NULL)) NULL))
return; return;
@ -1218,7 +1218,7 @@ static void json_dev_fail(struct command *cmd,
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &peerid), p_req("id", param_pubkey, &peerid),
NULL)) NULL))
return; return;
@ -1266,7 +1266,7 @@ static void json_dev_reenable_commit(struct command *cmd,
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &peerid), p_req("id", param_pubkey, &peerid),
NULL)) NULL))
return; return;
@ -1361,9 +1361,9 @@ static void json_dev_forget_channel(struct command *cmd,
bool *force; bool *force;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &peerid), p_req("id", param_pubkey, &peerid),
p_opt("short_channel_id", json_tok_short_channel_id, &scid), p_opt("short_channel_id", param_short_channel_id, &scid),
p_opt_def("force", json_tok_bool, &force, false), p_opt_def("force", param_bool, &force, false),
NULL)) NULL))
return; return;

4
lightningd/peer_htlcs.c

@ -1802,8 +1802,8 @@ static void json_dev_ignore_htlcs(struct command *cmd,
bool *ignore; bool *ignore;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &peerid), p_req("id", param_pubkey, &peerid),
p_req("ignore", json_tok_bool, &ignore), p_req("ignore", param_bool, &ignore),
NULL)) NULL))
return; return;

6
lightningd/ping.c

@ -89,9 +89,9 @@ static void json_ping(struct command *cmd,
struct pubkey *id; struct pubkey *id;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", param_pubkey, &id),
p_opt_def("len", json_tok_number, &len, 128), p_opt_def("len", param_number, &len, 128),
p_opt_def("pongbytes", json_tok_number, &pongbytes, 128), p_opt_def("pongbytes", param_number, &pongbytes, 128),
NULL)) NULL))
return; return;

132
lightningd/test/run-invoice-select-inchan.c

@ -183,74 +183,14 @@ struct json_stream *json_stream_success(struct command *cmd UNNEEDED)
{ fprintf(stderr, "json_stream_success called!\n"); abort(); } { fprintf(stderr, "json_stream_success called!\n"); abort(); }
/* Generated stub for json_tok_address_scriptpubkey */ /* Generated stub for json_tok_address_scriptpubkey */
enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx UNNEEDED, enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx UNNEEDED,
const struct chainparams *chainparams UNNEEDED, const struct chainparams *chainparams UNNEEDED,
const char *buffer UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED, const u8 **scriptpubkey UNNEEDED) const jsmntok_t *tok UNNEEDED, const u8 **scriptpubkey UNNEEDED)
{ fprintf(stderr, "json_tok_address_scriptpubkey called!\n"); abort(); } { fprintf(stderr, "json_tok_address_scriptpubkey called!\n"); abort(); }
/* Generated stub for json_tok_array */
bool json_tok_array(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const jsmntok_t **arr UNNEEDED)
{ fprintf(stderr, "json_tok_array called!\n"); abort(); }
/* Generated stub for json_tok_bool */
bool json_tok_bool(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
bool **b UNNEEDED)
{ fprintf(stderr, "json_tok_bool called!\n"); abort(); }
/* Generated stub for json_tok_channel_id */ /* Generated stub for json_tok_channel_id */
bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct channel_id *cid UNNEEDED) struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "json_tok_channel_id called!\n"); abort(); } { fprintf(stderr, "json_tok_channel_id called!\n"); abort(); }
/* Generated stub for json_tok_escaped_string */
bool json_tok_escaped_string(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "json_tok_escaped_string called!\n"); abort(); }
/* Generated stub for json_tok_label */
bool json_tok_label(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct json_escaped **label UNNEEDED)
{ fprintf(stderr, "json_tok_label called!\n"); abort(); }
/* Generated stub for json_tok_loglevel */
bool json_tok_loglevel(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
enum log_level **level UNNEEDED)
{ fprintf(stderr, "json_tok_loglevel called!\n"); abort(); }
/* Generated stub for json_tok_msat */
bool json_tok_msat(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
u64 **msatoshi_val UNNEEDED)
{ fprintf(stderr, "json_tok_msat called!\n"); abort(); }
/* Generated stub for json_tok_number */
bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "json_tok_number called!\n"); abort(); }
/* Generated stub for json_tok_pubkey */
bool json_tok_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "json_tok_pubkey called!\n"); abort(); }
/* Generated stub for json_tok_short_channel_id */
bool json_tok_short_channel_id(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "json_tok_short_channel_id called!\n"); abort(); }
/* Generated stub for json_tok_string */
bool json_tok_string(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "json_tok_string called!\n"); abort(); }
/* Generated stub for json_tok_tok */
bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "json_tok_tok called!\n"); abort(); }
/* Generated stub for json_tok_u64 */
bool json_tok_u64(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
uint64_t **num UNNEEDED)
{ fprintf(stderr, "json_tok_u64 called!\n"); abort(); }
/* Generated stub for json_to_pubkey */ /* Generated stub for json_to_pubkey */
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct pubkey *pubkey UNNEEDED)
@ -305,6 +245,72 @@ void opening_peer_no_active_channels(struct peer *peer UNNEEDED)
bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t params[] UNNEEDED, ...) const jsmntok_t params[] UNNEEDED, ...)
{ fprintf(stderr, "param called!\n"); abort(); } { fprintf(stderr, "param called!\n"); abort(); }
/* Generated stub for param_array */
struct command_result *param_array(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const jsmntok_t **arr UNNEEDED)
{ fprintf(stderr, "param_array called!\n"); abort(); }
/* Generated stub for param_bool */
struct command_result *param_bool(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
bool **b UNNEEDED)
{ fprintf(stderr, "param_bool called!\n"); abort(); }
/* Generated stub for param_escaped_string */
struct command_result *param_escaped_string(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "param_escaped_string called!\n"); abort(); }
/* Generated stub for param_label */
struct command_result *param_label(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct json_escaped **label UNNEEDED)
{ fprintf(stderr, "param_label called!\n"); abort(); }
/* Generated stub for param_loglevel */
struct command_result *param_loglevel(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
enum log_level **level UNNEEDED)
{ fprintf(stderr, "param_loglevel called!\n"); abort(); }
/* Generated stub for param_msat */
struct command_result *param_msat(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
u64 **msatoshi_val UNNEEDED)
{ fprintf(stderr, "param_msat called!\n"); abort(); }
/* Generated stub for param_number */
struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "param_number called!\n"); abort(); }
/* Generated stub for param_pubkey */
struct command_result *param_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "param_pubkey called!\n"); abort(); }
/* Generated stub for param_short_channel_id */
struct command_result *param_short_channel_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "param_short_channel_id called!\n"); abort(); }
/* Generated stub for param_string */
struct command_result *param_string(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "param_string called!\n"); abort(); }
/* Generated stub for param_tok */
struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "param_tok called!\n"); abort(); }
/* Generated stub for param_u64 */
struct command_result *param_u64(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
uint64_t **num UNNEEDED)
{ fprintf(stderr, "param_u64 called!\n"); abort(); }
/* Generated stub for peer_memleak_done */ /* Generated stub for peer_memleak_done */
void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDED) void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDED)
{ fprintf(stderr, "peer_memleak_done called!\n"); abort(); } { fprintf(stderr, "peer_memleak_done called!\n"); abort(); }

39
lightningd/test/run-jsonrpc.c

@ -21,25 +21,6 @@ const char *feerate_name(enum feerate feerate UNNEEDED)
/* Generated stub for fmt_wireaddr_without_port */ /* Generated stub for fmt_wireaddr_without_port */
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
/* Generated stub for json_feerate_estimate */
bool json_feerate_estimate(struct command *cmd UNNEEDED,
u32 **feerate_per_kw UNNEEDED, enum feerate feerate UNNEEDED)
{ fprintf(stderr, "json_feerate_estimate called!\n"); abort(); }
/* Generated stub for json_tok_number */
bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "json_tok_number called!\n"); abort(); }
/* Generated stub for json_tok_sha256 */
bool json_tok_sha256(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct sha256 **hash UNNEEDED)
{ fprintf(stderr, "json_tok_sha256 called!\n"); abort(); }
/* Generated stub for json_tok_tok */
bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "json_tok_tok called!\n"); abort(); }
/* Generated stub for log_ */ /* Generated stub for log_ */
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
@ -64,6 +45,26 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t params[] UNNEEDED, ...) const jsmntok_t params[] UNNEEDED, ...)
{ fprintf(stderr, "param called!\n"); abort(); } { fprintf(stderr, "param called!\n"); abort(); }
/* Generated stub for param_feerate_estimate */
struct command_result *param_feerate_estimate(struct command *cmd UNNEEDED,
u32 **feerate_per_kw UNNEEDED,
enum feerate feerate UNNEEDED)
{ fprintf(stderr, "param_feerate_estimate called!\n"); abort(); }
/* Generated stub for param_number */
struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "param_number called!\n"); abort(); }
/* Generated stub for param_sha256 */
struct command_result *param_sha256(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct sha256 **hash UNNEEDED)
{ fprintf(stderr, "param_sha256 called!\n"); abort(); }
/* Generated stub for param_tok */
struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "param_tok called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */
bool deprecated_apis; bool deprecated_apis;

64
wallet/test/run-wallet.c

@ -257,11 +257,6 @@ void json_object_start(struct json_stream *ks UNNEEDED, const char *fieldname UN
/* Generated stub for json_stream_success */ /* Generated stub for json_stream_success */
struct json_stream *json_stream_success(struct command *cmd UNNEEDED) struct json_stream *json_stream_success(struct command *cmd UNNEEDED)
{ fprintf(stderr, "json_stream_success called!\n"); abort(); } { fprintf(stderr, "json_stream_success called!\n"); abort(); }
/* Generated stub for json_tok_bool */
bool json_tok_bool(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
bool **b UNNEEDED)
{ fprintf(stderr, "json_tok_bool called!\n"); abort(); }
/* Generated stub for json_tok_channel_id */ /* Generated stub for json_tok_channel_id */
bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct channel_id *cid UNNEEDED) struct channel_id *cid UNNEEDED)
@ -272,31 +267,6 @@ const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEED
/* Generated stub for json_tok_full_len */ /* Generated stub for json_tok_full_len */
int json_tok_full_len(const jsmntok_t *t UNNEEDED) int json_tok_full_len(const jsmntok_t *t UNNEEDED)
{ fprintf(stderr, "json_tok_full_len called!\n"); abort(); } { fprintf(stderr, "json_tok_full_len called!\n"); abort(); }
/* Generated stub for json_tok_loglevel */
bool json_tok_loglevel(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
enum log_level **level UNNEEDED)
{ fprintf(stderr, "json_tok_loglevel called!\n"); abort(); }
/* Generated stub for json_tok_number */
bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "json_tok_number called!\n"); abort(); }
/* Generated stub for json_tok_pubkey */
bool json_tok_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "json_tok_pubkey called!\n"); abort(); }
/* Generated stub for json_tok_short_channel_id */
bool json_tok_short_channel_id(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "json_tok_short_channel_id called!\n"); abort(); }
/* Generated stub for json_tok_tok */
bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "json_tok_tok called!\n"); abort(); }
/* Generated stub for json_to_pubkey */ /* Generated stub for json_to_pubkey */
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct pubkey *pubkey UNNEEDED)
@ -349,6 +319,40 @@ void outpointfilter_remove(struct outpointfilter *of UNNEEDED,
bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t params[] UNNEEDED, ...) const jsmntok_t params[] UNNEEDED, ...)
{ fprintf(stderr, "param called!\n"); abort(); } { fprintf(stderr, "param called!\n"); abort(); }
/* Generated stub for param_bool */
struct command_result *param_bool(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
bool **b UNNEEDED)
{ fprintf(stderr, "param_bool called!\n"); abort(); }
/* Generated stub for param_loglevel */
struct command_result *param_loglevel(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
enum log_level **level UNNEEDED)
{ fprintf(stderr, "param_loglevel called!\n"); abort(); }
/* Generated stub for param_number */
struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED)
{ fprintf(stderr, "param_number called!\n"); abort(); }
/* Generated stub for param_pubkey */
struct command_result *param_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "param_pubkey called!\n"); abort(); }
/* Generated stub for param_short_channel_id */
struct command_result *param_short_channel_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "param_short_channel_id called!\n"); abort(); }
/* Generated stub for param_tok */
struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "param_tok called!\n"); abort(); }
/* Generated stub for parse_onionpacket */ /* Generated stub for parse_onionpacket */
struct onionpacket *parse_onionpacket( struct onionpacket *parse_onionpacket(
const tal_t *ctx UNNEEDED, const tal_t *ctx UNNEEDED,

37
wallet/walletrpc.c

@ -95,22 +95,26 @@ static void json_withdraw(struct command *cmd,
u32 *feerate_per_kw; u32 *feerate_per_kw;
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
enum address_parse_result addr_parse; enum address_parse_result addr_parse;
struct command_result *res;
withdraw->cmd = cmd; withdraw->cmd = cmd;
wtx_init(cmd, &withdraw->wtx); wtx_init(cmd, &withdraw->wtx);
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("destination", json_tok_tok, &desttok), p_req("destination", param_tok, &desttok),
p_req("satoshi", json_tok_tok, &sattok), p_req("satoshi", param_tok, &sattok),
p_opt("feerate", json_tok_feerate, &feerate_per_kw), p_opt("feerate", param_feerate, &feerate_per_kw),
NULL)) NULL))
return; return;
if (!json_tok_wtx(&withdraw->wtx, buffer, sattok, -1ULL)) res = param_wtx(&withdraw->wtx, buffer, sattok, -1ULL);
if (res)
return; return;
if (!feerate_per_kw) { if (!feerate_per_kw) {
if (!json_feerate_estimate(cmd, &feerate_per_kw, FEERATE_NORMAL)) res = param_feerate_estimate(cmd, &feerate_per_kw,
FEERATE_NORMAL);
if (res)
return; return;
} }
@ -223,23 +227,24 @@ encode_pubkey_to_addr(const tal_t *ctx,
} }
/* Extract a bool indicating "p2sh-segwit" or "bech32" */ /* Extract a bool indicating "p2sh-segwit" or "bech32" */
static bool json_tok_newaddr(struct command *cmd, const char *name, static struct command_result *param_newaddr(struct command *cmd,
const char *buffer, const jsmntok_t *tok, const char *name,
bool **is_p2wpkh) const char *buffer,
const jsmntok_t *tok,
bool **is_p2wpkh)
{ {
*is_p2wpkh = tal(cmd, bool); *is_p2wpkh = tal(cmd, bool);
if (json_tok_streq(buffer, tok, "p2sh-segwit")) { if (json_tok_streq(buffer, tok, "p2sh-segwit")) {
**is_p2wpkh = false; **is_p2wpkh = false;
return true; return NULL;
} }
if (json_tok_streq(buffer, tok, "bech32")) { if (json_tok_streq(buffer, tok, "bech32")) {
**is_p2wpkh = true; **is_p2wpkh = true;
return true; return NULL;
} }
command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'", "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'",
name, tok->end - tok->start, buffer + tok->start); name, tok->end - tok->start, buffer + tok->start);
return false;
} }
static void json_newaddr(struct command *cmd, static void json_newaddr(struct command *cmd,
@ -255,7 +260,7 @@ static void json_newaddr(struct command *cmd,
char *out; char *out;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("addresstype", json_tok_newaddr, &is_p2wpkh, true), p_opt_def("addresstype", param_newaddr, &is_p2wpkh, true),
NULL)) NULL))
return; return;
@ -314,7 +319,7 @@ static void json_listaddrs(struct command *cmd,
u64 *bip32_max_index; u64 *bip32_max_index;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_def("bip32_max_index", json_tok_u64, &bip32_max_index, p_opt_def("bip32_max_index", param_u64, &bip32_max_index,
db_get_intvar(cmd->ld->wallet->db, db_get_intvar(cmd->ld->wallet->db,
"bip32_max_index", 0)), "bip32_max_index", 0)),
NULL)) NULL))

Loading…
Cancel
Save