mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
json: add a param parser for a txid
This commit is contained in:
committed by
Rusty Russell
parent
c40250ad0b
commit
a4a193840f
@@ -68,3 +68,10 @@ bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||
tok->end - tok->start, scid,
|
||||
may_be_deprecated_form));
|
||||
}
|
||||
|
||||
bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
||||
struct bitcoin_txid *txid)
|
||||
{
|
||||
return bitcoin_txid_from_hex(buffer + tok->start,
|
||||
tok->end - tok->start, txid);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef LIGHTNING_COMMON_JSON_HELPERS_H
|
||||
#define LIGHTNING_COMMON_JSON_HELPERS_H
|
||||
#include "config.h"
|
||||
#include <bitcoin/tx.h>
|
||||
#include <common/json.h>
|
||||
|
||||
struct amount_msat;
|
||||
@@ -35,4 +36,7 @@ bool json_to_sat(const char *buffer, const jsmntok_t *tok,
|
||||
bool json_to_msat(const char *buffer, const jsmntok_t *tok,
|
||||
struct amount_msat *msat);
|
||||
|
||||
/* Extract a bitcoin txid from this */
|
||||
bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
||||
struct bitcoin_txid *txid);
|
||||
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */
|
||||
|
||||
@@ -108,6 +108,21 @@ 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));
|
||||
}
|
||||
|
||||
void json_add_short_channel_id(struct json_stream *response,
|
||||
const char *fieldname,
|
||||
const struct short_channel_id *scid)
|
||||
|
||||
@@ -54,6 +54,9 @@ 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);
|
||||
/* Makes sure *id is valid. */
|
||||
struct command_result *param_node_id(struct command *cmd,
|
||||
const char *name,
|
||||
|
||||
@@ -34,6 +34,10 @@ bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok
|
||||
struct short_channel_id *scid UNNEEDED,
|
||||
bool may_be_deprecated_form 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 char *fmt UNNEEDED, ...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user