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>
|
2021-06-18 17:21:41 +02:00
|
|
|
#include <common/bolt11.h>
|
2018-12-08 01:39:28 +01:00
|
|
|
#include <common/json.h>
|
2021-07-02 23:00:17 +02:00
|
|
|
#include <common/lease_rates.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-07-07 22:50:28 +02:00
|
|
|
struct bitcoin_txid;
|
2020-12-04 11:24:14 +01:00
|
|
|
struct bitcoin_outpoint;
|
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;
|
2021-11-04 22:06:01 +01:00
|
|
|
struct route_exclusion;
|
2019-01-15 04:54:27 +01:00
|
|
|
struct sha256;
|
2020-09-03 19:59:55 +02:00
|
|
|
struct wally_psbt;
|
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
|
|
|
|
2022-05-19 13:51:49 +02:00
|
|
|
/* Extract number from this (may be a string, or a number literal) */
|
|
|
|
struct command_result *param_u32(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
uint32_t **num);
|
|
|
|
|
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);
|
2021-05-22 07:00:22 +02:00
|
|
|
|
|
|
|
struct command_result *param_short_channel_id(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct short_channel_id **scid);
|
|
|
|
|
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);
|
|
|
|
|
2020-07-07 22:50:21 +02:00
|
|
|
struct command_result *param_feerate_val(struct command *cmd,
|
|
|
|
const char *name, const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
u32 **feerate_per_kw);
|
|
|
|
|
2020-07-07 22:50:28 +02:00
|
|
|
struct command_result *param_txid(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct bitcoin_txid **txid);
|
|
|
|
|
2020-07-07 22:50:26 +02:00
|
|
|
enum address_parse_result {
|
|
|
|
/* Not recognized as an onchain address */
|
|
|
|
ADDRESS_PARSE_UNRECOGNIZED,
|
|
|
|
/* Recognized as an onchain address, but targets wrong network */
|
|
|
|
ADDRESS_PARSE_WRONG_NETWORK,
|
|
|
|
/* Recognized and succeeds */
|
|
|
|
ADDRESS_PARSE_SUCCESS,
|
|
|
|
};
|
|
|
|
/* Return result of address parsing and fills in *scriptpubkey
|
|
|
|
* allocated off ctx if ADDRESS_PARSE_SUCCESS
|
|
|
|
*/
|
|
|
|
enum address_parse_result json_to_address_scriptpubkey(const tal_t *ctx,
|
|
|
|
const struct chainparams *chainparams,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok, const u8 **scriptpubkey);
|
2020-08-07 03:21:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
struct command_result *param_bitcoin_address(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
const u8 **scriptpubkey);
|
2020-09-03 19:59:55 +02:00
|
|
|
|
|
|
|
struct command_result *param_psbt(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct wally_psbt **psbt);
|
2020-12-04 11:24:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a list of `txid:output` outpoints.
|
|
|
|
*/
|
|
|
|
struct command_result *param_outpoint_arr(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct bitcoin_outpoint **outpoints);
|
2021-06-17 18:06:43 +02:00
|
|
|
|
|
|
|
struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct tlv_field **fields);
|
2021-06-18 17:21:41 +02:00
|
|
|
|
|
|
|
struct command_result *
|
|
|
|
param_routehint_array(struct command *cmd, const char *name, const char *buffer,
|
|
|
|
const jsmntok_t *tok, struct route_info ***ris);
|
|
|
|
|
2021-11-04 22:06:01 +01:00
|
|
|
struct command_result *param_route_exclusion(struct command *cmd,
|
|
|
|
const char *name, const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct route_exclusion **re);
|
|
|
|
|
|
|
|
struct command_result *
|
|
|
|
param_route_exclusion_array(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct route_exclusion ***res);
|
|
|
|
|
2021-07-02 23:00:17 +02:00
|
|
|
/**
|
|
|
|
* Parse a 'compact-lease' (serialized lease_rates) back into lease_rates
|
|
|
|
*/
|
|
|
|
struct command_result *param_lease_hex(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
struct lease_rates **rates);
|
2018-12-08 01:39:28 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|