Browse Source

common: hoist param_bitcoin_address where plugins can use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bump-pyln-proto
Rusty Russell 4 years ago
parent
commit
5e0b03fba9
  1. 26
      common/json_tok.c
  2. 7
      common/json_tok.h
  3. 26
      lightningd/json.c
  4. 7
      lightningd/json.h

26
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();
}

7
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 */

26
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();
}

7
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 */

Loading…
Cancel
Save