2018-12-08 01:39:28 +01:00
|
|
|
/* Helpers for use with param parsing. */
|
|
|
|
#ifndef LIGHTNING_COMMON_JSON_TOK_H
|
|
|
|
#define LIGHTNING_COMMON_JSON_TOK_H
|
|
|
|
#include "config.h"
|
2019-01-15 04:54:27 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-12-08 01:39:28 +01:00
|
|
|
#include <common/json.h>
|
2019-08-28 05:23:14 +02:00
|
|
|
#include <common/node_id.h>
|
2019-11-24 19:09:19 +01:00
|
|
|
#include <common/sphinx.h>
|
2019-09-30 18:31:27 +02:00
|
|
|
#include <wire/wire.h>
|
2018-12-08 01:39:28 +01:00
|
|
|
|
2019-02-21 01:45:57 +01:00
|
|
|
struct amount_msat;
|
|
|
|
struct amount_sat;
|
2020-05-15 12:30:25 +02:00
|
|
|
struct channel_id;
|
2018-12-08 01:39:28 +01:00
|
|
|
struct command;
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result;
|
2019-06-12 02:38:54 +02:00
|
|
|
struct json_escape;
|
2019-01-15 04:54:27 +01:00
|
|
|
struct sha256;
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract json array token */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_array(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
const jsmntok_t **arr);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract boolean this (must be a true or false) */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_bool(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
bool **b);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
2020-01-29 12:30:00 +01:00
|
|
|
/*
|
|
|
|
* Extract a non-negative (either 0 or positive) floating-point number from this
|
|
|
|
* (must be a number literal), multiply it by 1 million and return it as an
|
|
|
|
* integer.
|
|
|
|
*/
|
|
|
|
struct command_result *param_millionths(struct command *cmd, const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok, uint64_t **num);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract an escaped string (and unescape it) */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_escaped_string(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
const char **str);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract a string */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_string(struct command *cmd, const char *name,
|
|
|
|
const char * buffer, const jsmntok_t *tok,
|
|
|
|
const char **str);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract a label. It is either an escaped string or a number. */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_label(struct command *cmd, const char *name,
|
|
|
|
const char * buffer, const jsmntok_t *tok,
|
2019-06-12 02:38:54 +02:00
|
|
|
struct json_escape **label);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract number from this (may be a string, or a number literal) */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_number(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
unsigned int **num);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract sha256 hash */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_sha256(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct sha256 **hash);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
|
|
|
/* Extract number from this (may be a string, or a number literal) */
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_u64(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
uint64_t **num);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
2019-05-22 01:48:30 +02:00
|
|
|
/* Extract msatoshi amount from this string */
|
2019-02-21 01:45:57 +01:00
|
|
|
struct command_result *param_msat(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct amount_msat **msat);
|
|
|
|
|
2019-05-22 01:48:30 +02:00
|
|
|
/* Extract satoshi amount from this string */
|
2019-02-21 01:45:57 +01:00
|
|
|
struct command_result *param_sat(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct amount_sat **sat);
|
|
|
|
|
2019-08-15 19:41:23 +02:00
|
|
|
/* Extract satoshi amount from this string. */
|
|
|
|
/* If the string is "all", set amonut as AMOUNT_SAT(-1ULL). */
|
|
|
|
struct command_result *param_sat_or_all(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct amount_sat **sat);
|
|
|
|
|
2019-08-28 05:23:14 +02:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2019-09-30 18:31:27 +02:00
|
|
|
struct command_result *param_channel_id(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct channel_id **cid);
|
2018-12-08 01:39:28 +01:00
|
|
|
/*
|
|
|
|
* Set the address of @out to @tok. Used as a callback by handlers that
|
|
|
|
* want to unmarshal @tok themselves.
|
2018-12-10 19:59:04 +01:00
|
|
|
*
|
|
|
|
* Usage of this is discouraged. Writing a local static bespoke handler is
|
|
|
|
* preferred.
|
2018-12-08 01:39:28 +01:00
|
|
|
*/
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_tok(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t * tok,
|
|
|
|
const jsmntok_t **out);
|
2018-12-08 01:39:28 +01:00
|
|
|
|
2019-07-16 03:41:51 +02:00
|
|
|
/* Ignore the token. Not usually used. */
|
|
|
|
struct command_result *param_ignore(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
const void *unused);
|
2019-09-30 18:31:27 +02:00
|
|
|
|
2019-11-07 17:56:06 +01:00
|
|
|
/* Extract a secret from this string */
|
|
|
|
struct command_result *param_secret(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct secret **secret);
|
|
|
|
|
|
|
|
/* Extract a binary value from the param and unhexlify it. */
|
|
|
|
struct command_result *param_bin_from_hex(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
u8 **bin);
|
|
|
|
|
2019-11-24 19:09:19 +01:00
|
|
|
struct command_result *param_hops_array(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct sphinx_hop **hops);
|
|
|
|
|
2019-11-25 13:42:23 +01:00
|
|
|
struct command_result *param_secrets_array(struct command *cmd,
|
|
|
|
const char *name, const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct secret **secrets);
|
|
|
|
|
2018-12-08 01:39:28 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|