mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
json: move param node_id parser to common
Going to need this for a plugin that's external
This commit is contained in:
parent
8d28e52515
commit
19e65068a9
@ -4,6 +4,7 @@
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_helpers.h>
|
||||
#include <common/json_tok.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/param.h>
|
||||
@ -199,3 +200,17 @@ struct command_result *param_sat_or_all(struct command *cmd, const char *name,
|
||||
}
|
||||
return param_sat(cmd, name, buffer, tok, sat);
|
||||
}
|
||||
|
||||
struct command_result *param_node_id(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct node_id **id)
|
||||
{
|
||||
*id = tal(cmd, struct node_id);
|
||||
if (json_to_node_id(buffer, tok, *id))
|
||||
return NULL;
|
||||
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a node id, not '%.*s'",
|
||||
name, json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/json.h>
|
||||
#include <common/node_id.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct amount_sat;
|
||||
@ -80,6 +81,14 @@ struct command_result *param_sat_or_all(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct amount_sat **sat);
|
||||
|
||||
|
||||
/* Extract node_id from this string. Makes sure *id is valid. */
|
||||
struct command_result *param_node_id(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct node_id **id);
|
||||
|
||||
/*
|
||||
* Set the address of @out to @tok. Used as a callback by handlers that
|
||||
* want to unmarshal @tok themselves.
|
||||
|
@ -42,6 +42,10 @@ struct command_result *command_fail(struct command *cmd,
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
/* Generated stub for json_to_node_id */
|
||||
bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct node_id *id UNNEEDED)
|
||||
{ fprintf(stderr, "json_to_node_id called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
/* We do this lightningd-style: */
|
||||
|
@ -77,23 +77,6 @@ void json_add_txid(struct json_stream *result, const char *fieldname,
|
||||
json_add_string(result, fieldname, hex);
|
||||
}
|
||||
|
||||
struct command_result *param_node_id(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct node_id **id)
|
||||
{
|
||||
*id = tal(cmd, struct node_id);
|
||||
if (json_to_node_id(buffer, tok, *id))
|
||||
return NULL;
|
||||
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a node id, not '%.*s'",
|
||||
name, json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
||||
|
||||
struct command_result *param_pubkey(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct pubkey **pubkey)
|
||||
|
@ -64,12 +64,6 @@ struct command_result *param_pubkey(struct command *cmd, const char *name,
|
||||
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,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct node_id **id);
|
||||
|
||||
struct command_result *param_short_channel_id(struct command *cmd,
|
||||
const char *name,
|
||||
|
@ -30,10 +30,6 @@ const char *feerate_name(enum feerate feerate UNNEEDED)
|
||||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for json_to_node_id */
|
||||
bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct node_id *id UNNEEDED)
|
||||
{ fprintf(stderr, "json_to_node_id called!\n"); abort(); }
|
||||
/* Generated stub for json_to_pubkey */
|
||||
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct pubkey *pubkey UNNEEDED)
|
||||
|
Loading…
Reference in New Issue
Block a user