Browse Source

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>
keysend
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
869fa082d4
  1. 15
      common/json_tok.c
  2. 7
      common/json_tok.h
  3. 4
      common/test/run-param.c
  4. 15
      lightningd/json.c
  5. 4
      lightningd/json.h
  6. 4
      lightningd/test/run-jsonrpc.c

15
common/json_tok.c

@ -490,3 +490,18 @@ json_to_address_scriptpubkey(const tal_t *ctx,
return ADDRESS_PARSE_UNRECOGNIZED; 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));
}

7
common/json_tok.h

@ -10,6 +10,7 @@
struct amount_msat; struct amount_msat;
struct amount_sat; struct amount_sat;
struct bitcoin_txid;
struct channel_id; struct channel_id;
struct command; struct command;
struct command_result; struct command_result;
@ -136,6 +137,12 @@ struct command_result *param_feerate_val(struct command *cmd,
const jsmntok_t *tok, const jsmntok_t *tok,
u32 **feerate_per_kw); 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 { enum address_parse_result {
/* Not recognized as an onchain address */ /* Not recognized as an onchain address */
ADDRESS_PARSE_UNRECOGNIZED, ADDRESS_PARSE_UNRECOGNIZED,

4
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, bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct pubkey *pubkey UNNEEDED)
{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); } { 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 */ /* Generated stub for segwit_addr_decode */
int segwit_addr_decode( int segwit_addr_decode(
int* ver UNNEEDED, int* ver UNNEEDED,

15
lightningd/json.c

@ -37,21 +37,6 @@ struct command_result *param_pubkey(struct command *cmd, const char *name,
json_tok_full(buffer, tok)); 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, struct command_result *param_short_channel_id(struct command *cmd,
const char *name, const char *name,
const char *buffer, const char *buffer,

4
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, const char *buffer, const jsmntok_t *tok,
struct pubkey **pubkey); 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, struct command_result *param_short_channel_id(struct command *cmd,
const char *name, const char *name,
const char *buffer, const char *buffer,

4
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, bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id *scid UNNEEDED) struct short_channel_id *scid UNNEEDED)
{ fprintf(stderr, "json_to_short_channel_id called!\n"); abort(); } { 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_ */ /* Generated stub for log_ */
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED,
const struct node_id *node_id UNNEEDED, const struct node_id *node_id UNNEEDED,

Loading…
Cancel
Save