mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
common: hoist param_bitcoin_address where plugins can use it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -505,3 +505,29 @@ struct command_result *param_txid(struct command *cmd,
|
|||||||
name, json_tok_full_len(tok),
|
name, json_tok_full_len(tok),
|
||||||
json_tok_full(buffer, 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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -158,4 +158,11 @@ enum address_parse_result json_to_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);
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
||||||
|
|||||||
@@ -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,
|
return hex_decode(buffer + tok->start, tok->end - tok->start,
|
||||||
cid, sizeof(*cid));
|
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();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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,
|
bool json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||||
struct channel_id *cid);
|
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 */
|
#endif /* LIGHTNING_LIGHTNINGD_JSON_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user