diff --git a/common/json_tok.c b/common/json_tok.c index a50b0d3d5..dcf22534c 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -505,3 +505,29 @@ struct command_result *param_txid(struct command *cmd, name, json_tok_full_len(tok), json_tok_full(buffer, tok)); } + +struct command_result *param_bitcoin_address(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + const u8 **scriptpubkey) +{ + /* Parse address. */ + switch (json_to_address_scriptpubkey(cmd, + chainparams, + buffer, tok, + scriptpubkey)) { + case ADDRESS_PARSE_UNRECOGNIZED: + return command_fail(cmd, LIGHTNINGD, + "Could not parse destination address, " + "%s should be a valid address", + name ? name : "address field"); + case ADDRESS_PARSE_WRONG_NETWORK: + return command_fail(cmd, LIGHTNINGD, + "Destination address is not on network %s", + chainparams->network_name); + case ADDRESS_PARSE_SUCCESS: + return NULL; + } + abort(); +} diff --git a/common/json_tok.h b/common/json_tok.h index 4e8a7ceac..e814dc615 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -158,4 +158,11 @@ enum address_parse_result json_to_address_scriptpubkey(const tal_t *ctx, const struct chainparams *chainparams, const char *buffer, const jsmntok_t *tok, const u8 **scriptpubkey); + + +struct command_result *param_bitcoin_address(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + const u8 **scriptpubkey); #endif /* LIGHTNING_COMMON_JSON_TOK_H */ diff --git a/lightningd/json.c b/lightningd/json.c index fbbb18041..8b0082b2d 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -107,29 +107,3 @@ json_tok_channel_id(const char *buffer, const jsmntok_t *tok, return hex_decode(buffer + tok->start, tok->end - tok->start, cid, sizeof(*cid)); } - -struct command_result *param_bitcoin_address(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - const u8 **scriptpubkey) -{ - /* Parse address. */ - switch (json_to_address_scriptpubkey(cmd, - chainparams, - buffer, tok, - scriptpubkey)) { - case ADDRESS_PARSE_UNRECOGNIZED: - return command_fail(cmd, LIGHTNINGD, - "Could not parse destination address, " - "%s should be a valid address", - name ? name : "address field"); - case ADDRESS_PARSE_WRONG_NETWORK: - return command_fail(cmd, LIGHTNINGD, - "Destination address is not on network %s", - chainparams->network_name); - case ADDRESS_PARSE_SUCCESS: - return NULL; - } - abort(); -} diff --git a/lightningd/json.h b/lightningd/json.h index 28a797ee3..e065570a0 100644 --- a/lightningd/json.h +++ b/lightningd/json.h @@ -51,11 +51,4 @@ struct command_result *param_feerate(struct command *cmd, const char *name, bool json_tok_channel_id(const char *buffer, const jsmntok_t *tok, struct channel_id *cid); - -struct command_result *param_bitcoin_address(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - const u8 **scriptpubkey); - #endif /* LIGHTNING_LIGHTNINGD_JSON_H */