diff --git a/common/json_tok.c b/common/json_tok.c index 6868b2752..e163f23fc 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -199,3 +200,17 @@ struct command_result *param_sat_or_all(struct command *cmd, const char *name, } return param_sat(cmd, name, buffer, tok, sat); } + +struct command_result *param_node_id(struct command *cmd, const char *name, + const char *buffer, const jsmntok_t *tok, + struct node_id **id) +{ + *id = tal(cmd, struct node_id); + if (json_to_node_id(buffer, tok, *id)) + return NULL; + + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "'%s' should be a node id, not '%.*s'", + name, json_tok_full_len(tok), + json_tok_full(buffer, tok)); +} diff --git a/common/json_tok.h b/common/json_tok.h index 6a15c30ef..8ff5322bf 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -4,6 +4,7 @@ #include "config.h" #include #include +#include struct amount_msat; struct amount_sat; @@ -80,6 +81,14 @@ struct command_result *param_sat_or_all(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct amount_sat **sat); + +/* Extract node_id from this string. Makes sure *id is valid. */ +struct command_result *param_node_id(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct node_id **id); + /* * Set the address of @out to @tok. Used as a callback by handlers that * want to unmarshal @tok themselves. diff --git a/common/test/run-param.c b/common/test/run-param.c index 3bbf05139..2aa533626 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -42,6 +42,10 @@ struct command_result *command_fail(struct command *cmd, /* Generated stub for fromwire_fail */ const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_fail called!\n"); abort(); } +/* Generated stub for json_to_node_id */ +bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, + struct node_id *id UNNEEDED) +{ fprintf(stderr, "json_to_node_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* We do this lightningd-style: */ diff --git a/lightningd/json.c b/lightningd/json.c index f811c6e3e..7ec0b1399 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -77,23 +77,6 @@ void json_add_txid(struct json_stream *result, const char *fieldname, json_add_string(result, fieldname, hex); } -struct command_result *param_node_id(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - struct node_id **id) -{ - *id = tal(cmd, struct node_id); - if (json_to_node_id(buffer, tok, *id)) - return NULL; - - return command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "'%s' should be a node id, not '%.*s'", - name, json_tok_full_len(tok), - json_tok_full(buffer, tok)); -} - - struct command_result *param_pubkey(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct pubkey **pubkey) diff --git a/lightningd/json.h b/lightningd/json.h index 1eaaf92d6..6ede9b5fc 100644 --- a/lightningd/json.h +++ b/lightningd/json.h @@ -64,12 +64,6 @@ struct command_result *param_pubkey(struct command *cmd, const char *name, struct command_result *param_txid(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct bitcoin_txid **txid); -/* Makes sure *id is valid. */ -struct command_result *param_node_id(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - struct node_id **id); struct command_result *param_short_channel_id(struct command *cmd, const char *name, diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 018e027f8..d78959a69 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -30,10 +30,6 @@ const char *feerate_name(enum feerate feerate UNNEEDED) /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } -/* Generated stub for json_to_node_id */ -bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, - struct node_id *id UNNEEDED) -{ fprintf(stderr, "json_to_node_id called!\n"); abort(); } /* Generated stub for json_to_pubkey */ bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct pubkey *pubkey UNNEEDED)