common/json_tok: expose param_txid.

Move it out of lightningd/ so plugins can use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-07-08 06:20:28 +09:30 committed by Christian Decker
parent 731e037b36
commit 869fa082d4
6 changed files with 26 additions and 23 deletions

View file

@ -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));
}

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,