From 869fa082d4ad158a05a6cc278779c9203168b912 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 8 Jul 2020 06:20:28 +0930 Subject: [PATCH] common/json_tok: expose param_txid. Move it out of lightningd/ so plugins can use it. Signed-off-by: Rusty Russell --- common/json_tok.c | 15 +++++++++++++++ common/json_tok.h | 7 +++++++ common/test/run-param.c | 4 ++++ lightningd/json.c | 15 --------------- lightningd/json.h | 4 ---- lightningd/test/run-jsonrpc.c | 4 ---- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/common/json_tok.c b/common/json_tok.c index 9ebe56b46..a50b0d3d5 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -490,3 +490,18 @@ json_to_address_scriptpubkey(const tal_t *ctx, return ADDRESS_PARSE_UNRECOGNIZED; } + +struct command_result *param_txid(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct bitcoin_txid **txid) +{ + *txid = tal(cmd, struct bitcoin_txid); + if (json_to_txid(buffer, tok, *txid)) + return NULL; + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "'%s' should be txid, 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 958bc796b..4e8a7ceac 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -10,6 +10,7 @@ struct amount_msat; struct amount_sat; +struct bitcoin_txid; struct channel_id; struct command; struct command_result; @@ -136,6 +137,12 @@ struct command_result *param_feerate_val(struct command *cmd, const jsmntok_t *tok, u32 **feerate_per_kw); +struct command_result *param_txid(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct bitcoin_txid **txid); + enum address_parse_result { /* Not recognized as an onchain address */ ADDRESS_PARSE_UNRECOGNIZED, diff --git a/common/test/run-param.c b/common/test/run-param.c index 34bd94046..b59ea83a3 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -50,6 +50,10 @@ bool json_to_node_id(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) { fprintf(stderr, "json_to_pubkey called!\n"); abort(); } +/* Generated stub for json_to_txid */ +bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, + struct bitcoin_txid *txid UNNEEDED) +{ fprintf(stderr, "json_to_txid called!\n"); abort(); } /* Generated stub for segwit_addr_decode */ int segwit_addr_decode( int* ver UNNEEDED, diff --git a/lightningd/json.c b/lightningd/json.c index 4d032307c..fbbb18041 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -37,21 +37,6 @@ struct command_result *param_pubkey(struct command *cmd, const char *name, json_tok_full(buffer, tok)); } -struct command_result *param_txid(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - struct bitcoin_txid **txid) -{ - *txid = tal(cmd, struct bitcoin_txid); - if (json_to_txid(buffer, tok, *txid)) - return NULL; - return command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "'%s' should be txid, not '%.*s'", - name, json_tok_full_len(tok), - json_tok_full(buffer, tok)); -} - struct command_result *param_short_channel_id(struct command *cmd, const char *name, const char *buffer, diff --git a/lightningd/json.h b/lightningd/json.h index 998f6202f..28a797ee3 100644 --- a/lightningd/json.h +++ b/lightningd/json.h @@ -29,10 +29,6 @@ struct command_result *param_pubkey(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct pubkey **pubkey); -struct command_result *param_txid(struct command *cmd, const char *name, - const char *buffer, const jsmntok_t *tok, - struct bitcoin_txid **txid); - struct command_result *param_short_channel_id(struct command *cmd, const char *name, const char *buffer, diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index e1acfd305..cdfea9955 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -43,10 +43,6 @@ bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct short_channel_id *scid UNNEEDED) { fprintf(stderr, "json_to_short_channel_id called!\n"); abort(); } -/* Generated stub for json_to_txid */ -bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, - struct bitcoin_txid *txid UNNEEDED) -{ fprintf(stderr, "json_to_txid called!\n"); abort(); } /* Generated stub for log_ */ void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const struct node_id *node_id UNNEEDED,