mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
param: remove old callback code
Cleaned up remaining code. Reduced comment noise. Reverted macro names back to the original. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Rusty Russell
parent
fa55e2cab0
commit
a3178b8177
@@ -615,9 +615,9 @@ static void json_dev_setfees(struct command *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("immediate", json_tok_number, &imm),
|
p_opt("immediate", json_tok_number, &imm),
|
||||||
p_opt_tal("normal", json_tok_number, &norm),
|
p_opt("normal", json_tok_number, &norm),
|
||||||
p_opt_tal("slow", json_tok_number, &slow),
|
p_opt("slow", json_tok_number, &slow),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ static void json_connect(struct command *cmd,
|
|||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_tok, (const jsmntok_t **) &idtok),
|
p_req("id", json_tok_tok, (const jsmntok_t **) &idtok),
|
||||||
p_opt_tal("host", json_tok_tok, &hosttok),
|
p_opt("host", json_tok_tok, &hosttok),
|
||||||
p_opt_tal("port", json_tok_number, &port),
|
p_opt("port", json_tok_number, &port),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ static void json_listnodes(struct command *cmd, const char *buffer,
|
|||||||
struct pubkey *id;
|
struct pubkey *id;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("id", json_tok_pubkey, &id),
|
p_opt("id", json_tok_pubkey, &id),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -287,13 +287,13 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
|||||||
struct siphash_seed seed;
|
struct siphash_seed seed;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &destination),
|
p_req("id", json_tok_pubkey, &destination),
|
||||||
p_req_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_req("msatoshi", json_tok_u64, &msatoshi),
|
||||||
p_req_tal("riskfactor", json_tok_double, &riskfactor),
|
p_req("riskfactor", json_tok_double, &riskfactor),
|
||||||
p_opt_def_tal("cltv", json_tok_number, &cltv, 9),
|
p_opt_def("cltv", json_tok_number, &cltv, 9),
|
||||||
p_opt_def_tal("fromid", json_tok_pubkey, &source, ld->id),
|
p_opt_def("fromid", json_tok_pubkey, &source, ld->id),
|
||||||
p_opt_tal("seed", json_tok_tok, &seedtok),
|
p_opt("seed", json_tok_tok, &seedtok),
|
||||||
p_opt_def_tal("fuzzpercent", json_tok_double, &fuzz, 75.0),
|
p_opt_def("fuzzpercent", json_tok_double, &fuzz, 75.0),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ static void json_listchannels(struct command *cmd, const char *buffer,
|
|||||||
u8 *req;
|
u8 *req;
|
||||||
struct short_channel_id *id;
|
struct short_channel_id *id;
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("short_channel_id", json_tok_short_channel_id, &id),
|
p_opt("short_channel_id", json_tok_short_channel_id, &id),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -436,8 +436,8 @@ static void json_dev_query_scids(struct command *cmd,
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
p_req_tal("scids", json_tok_tok, &scidstok),
|
p_req("scids", json_tok_tok, &scidstok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -484,9 +484,9 @@ static void json_dev_send_timestamp_filter(struct command *cmd,
|
|||||||
u32 *first, *range;
|
u32 *first, *range;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
p_req_tal("first", json_tok_number, &first),
|
p_req("first", json_tok_number, &first),
|
||||||
p_req_tal("range", json_tok_number, &range),
|
p_req("range", json_tok_number, &range),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -552,9 +552,9 @@ static void json_dev_query_channel_range(struct command *cmd,
|
|||||||
u32 *first, *num;
|
u32 *first, *num;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
p_req_tal("first", json_tok_number, &first),
|
p_req("first", json_tok_number, &first),
|
||||||
p_req_tal("num", json_tok_number, &num),
|
p_req("num", json_tok_number, &num),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -580,7 +580,7 @@ static void json_dev_set_max_scids_encode_size(struct command *cmd,
|
|||||||
u32 *max;
|
u32 *max;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("max", json_tok_number, &max),
|
p_req("max", json_tok_number, &max),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -168,12 +168,12 @@ static void json_invoice(struct command *cmd,
|
|||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("msatoshi", json_tok_tok, &msatoshi),
|
p_req("msatoshi", json_tok_tok, &msatoshi),
|
||||||
p_req_tal("label", json_tok_tok, &label),
|
p_req("label", json_tok_tok, &label),
|
||||||
p_req_tal("description", json_tok_tok, &desctok),
|
p_req("description", json_tok_tok, &desctok),
|
||||||
p_opt_def_tal("expiry", json_tok_u64, &expiry, 3600),
|
p_opt_def("expiry", json_tok_u64, &expiry, 3600),
|
||||||
p_opt_tal("fallbacks", json_tok_tok, &fallbacks),
|
p_opt("fallbacks", json_tok_tok, &fallbacks),
|
||||||
p_opt_tal("preimage", json_tok_tok, &preimagetok),
|
p_opt("preimage", json_tok_tok, &preimagetok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ static void json_listinvoices(struct command *cmd,
|
|||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("label", json_tok_tok, &labeltok),
|
p_opt("label", json_tok_tok, &labeltok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -415,8 +415,8 @@ static void json_delinvoice(struct command *cmd,
|
|||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("label", json_tok_tok, &labeltok),
|
p_req("label", json_tok_tok, &labeltok),
|
||||||
p_req_tal("status", json_tok_tok, &statustok),
|
p_req("status", json_tok_tok, &statustok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -475,7 +475,7 @@ static void json_delexpiredinvoice(struct command *cmd, const char *buffer,
|
|||||||
struct json_result *result;
|
struct json_result *result;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("maxexpirytime", json_tok_u64, &maxexpirytime,
|
p_opt_def("maxexpirytime", json_tok_u64, &maxexpirytime,
|
||||||
time_now().ts.tv_sec),
|
time_now().ts.tv_sec),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
@@ -503,8 +503,8 @@ static void json_autocleaninvoice(struct command *cmd,
|
|||||||
struct json_result *result;
|
struct json_result *result;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("cycle_seconds", json_tok_u64, &cycle, 3600),
|
p_opt_def("cycle_seconds", json_tok_u64, &cycle, 3600),
|
||||||
p_opt_def_tal("expired_by", json_tok_u64, &exby, 86400),
|
p_opt_def("expired_by", json_tok_u64, &exby, 86400),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -531,7 +531,7 @@ static void json_waitanyinvoice(struct command *cmd,
|
|||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("lastpay_index", json_tok_u64, &pay_index, 0),
|
p_opt_def("lastpay_index", json_tok_u64, &pay_index, 0),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -568,7 +568,7 @@ static void json_waitinvoice(struct command *cmd,
|
|||||||
struct json_escaped *label;
|
struct json_escaped *label;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("label", json_tok_tok, &labeltok),
|
p_req("label", json_tok_tok, &labeltok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -651,8 +651,8 @@ static void json_decodepay(struct command *cmd,
|
|||||||
char *str, *desc, *fail;
|
char *str, *desc, *fail;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("bolt11", json_tok_tok, &bolt11tok),
|
p_req("bolt11", json_tok_tok, &bolt11tok),
|
||||||
p_opt_tal("description", json_tok_tok, &desctok),
|
p_opt("description", json_tok_tok, &desctok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ static void json_rhash(struct command *cmd,
|
|||||||
struct sha256 *secret;
|
struct sha256 *secret;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("secret", json_tok_sha256, &secret),
|
p_req("secret", json_tok_sha256, &secret),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ static void json_help(struct command *cmd,
|
|||||||
const jsmntok_t *cmdtok;
|
const jsmntok_t *cmdtok;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("command", json_tok_tok, &cmdtok),
|
p_opt("command", json_tok_tok, &cmdtok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -666,7 +666,7 @@ static void json_getlog(struct command *cmd,
|
|||||||
struct log_book *lr = cmd->ld->log_book;
|
struct log_book *lr = cmd->ld->log_book;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("level", json_tok_loglevel, &minlevel,
|
p_opt_def("level", json_tok_loglevel, &minlevel,
|
||||||
LOG_INFORM),
|
LOG_INFORM),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -769,8 +769,8 @@ static void json_fund_channel(struct command *cmd,
|
|||||||
fc->uc = NULL;
|
fc->uc = NULL;
|
||||||
wtx_init(cmd, &fc->wtx);
|
wtx_init(cmd, &fc->wtx);
|
||||||
if (!param(fc->cmd, buffer, params,
|
if (!param(fc->cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
p_req_tal("satoshi", json_tok_tok, &sattok),
|
p_req("satoshi", json_tok_tok, &sattok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -1011,7 +1011,7 @@ static void json_listconfigs(struct command *cmd,
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("config", json_tok_tok, &configtok),
|
p_opt("config", json_tok_tok, &configtok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -11,19 +11,16 @@ struct param {
|
|||||||
const char *name;
|
const char *name;
|
||||||
bool is_set;
|
bool is_set;
|
||||||
bool required;
|
bool required;
|
||||||
param_cb cb;
|
|
||||||
param_cbx cbx;
|
param_cbx cbx;
|
||||||
void *arg;
|
void *arg;
|
||||||
size_t argsize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool param_add(struct param **params,
|
static bool param_add(struct param **params,
|
||||||
const char *name, bool required, param_cb cb,
|
const char *name, bool required,
|
||||||
param_cbx cbx, void *arg,
|
param_cbx cbx, void *arg)
|
||||||
size_t argsize)
|
|
||||||
{
|
{
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
if (!(name && (cb || cbx) && arg))
|
if (!(name && cbx && arg))
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
struct param *last;
|
struct param *last;
|
||||||
@@ -34,79 +31,18 @@ static bool param_add(struct param **params,
|
|||||||
last->is_set = false;
|
last->is_set = false;
|
||||||
last->name = name;
|
last->name = name;
|
||||||
last->required = required;
|
last->required = required;
|
||||||
last->cb = cb;
|
|
||||||
last->cbx = cbx;
|
last->cbx = cbx;
|
||||||
last->arg = arg;
|
last->arg = arg;
|
||||||
last->argsize = argsize;
|
|
||||||
/* Non-0 means we are supposed to allocate iff found */
|
|
||||||
if (last->argsize != 0)
|
|
||||||
*(void **)last->arg = NULL;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fail_format {
|
|
||||||
void *cb;
|
|
||||||
const char *format;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct fail_format fail_formats[] = {
|
|
||||||
{json_tok_wtx,
|
|
||||||
"'%s' should be 'all' or a positive integer greater than "
|
|
||||||
"545, not '%.*s'"},
|
|
||||||
{NULL, "'%s' of '%.*s' is invalid'"}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *find_fail_format(param_cb cb)
|
|
||||||
{
|
|
||||||
struct fail_format *fmt = fail_formats;
|
|
||||||
while (fmt->cb != NULL) {
|
|
||||||
if (fmt->cb == cb)
|
|
||||||
break;
|
|
||||||
fmt++;
|
|
||||||
}
|
|
||||||
return fmt->format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a json_result out of a jsmntok_t. */
|
|
||||||
static struct json_result *make_result(tal_t *ctx, const char *name, const char *buffer,
|
|
||||||
const jsmntok_t *tok)
|
|
||||||
{
|
|
||||||
struct json_result *data = new_json_result(ctx);
|
|
||||||
const char *val = tal_fmt(ctx, "%.*s", tok->end - tok->start,
|
|
||||||
buffer + tok->start);
|
|
||||||
json_object_start(data, NULL);
|
|
||||||
json_add_string(data, name, val);
|
|
||||||
json_object_end(data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool make_callback(struct command *cmd,
|
static bool make_callback(struct command *cmd,
|
||||||
struct param *def,
|
struct param *def,
|
||||||
const char *buffer, const jsmntok_t *tok)
|
const char *buffer, const jsmntok_t *tok)
|
||||||
{
|
{
|
||||||
void *arg;
|
|
||||||
def->is_set = true;
|
def->is_set = true;
|
||||||
|
|
||||||
if (def->cb) {
|
return def->cbx(cmd, def->name, buffer, tok, def->arg);
|
||||||
if (def->argsize) {
|
|
||||||
*(void **)def->arg
|
|
||||||
= arg
|
|
||||||
= tal_arr_label(cmd, char, def->argsize, "param");
|
|
||||||
} else
|
|
||||||
arg = def->arg;
|
|
||||||
|
|
||||||
if (!def->cb(buffer, tok, arg)) {
|
|
||||||
command_fail_detailed(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
make_result(cmd, def->name, buffer, tok),
|
|
||||||
find_fail_format(def->cb), def->name,
|
|
||||||
tok->end - tok->start,
|
|
||||||
buffer + tok->start);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return def->cbx(cmd, def->name, buffer, tok, def->arg);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct param *post_check(struct command *cmd, struct param *params)
|
static struct param *post_check(struct command *cmd, struct param *params)
|
||||||
@@ -317,12 +253,9 @@ bool param(struct command *cmd, const char *buffer,
|
|||||||
va_start(ap, tokens);
|
va_start(ap, tokens);
|
||||||
while ((name = va_arg(ap, const char *)) != NULL) {
|
while ((name = va_arg(ap, const char *)) != NULL) {
|
||||||
bool required = va_arg(ap, int);
|
bool required = va_arg(ap, int);
|
||||||
bool advanced = va_arg(ap, int);
|
param_cbx cbx = va_arg(ap, param_cbx);
|
||||||
param_cb cb = advanced ? NULL : va_arg(ap, param_cb);
|
|
||||||
param_cbx cbx = advanced ? va_arg(ap, param_cbx) : NULL;
|
|
||||||
void *arg = va_arg(ap, void *);
|
void *arg = va_arg(ap, void *);
|
||||||
size_t argsize = va_arg(ap, size_t);
|
if (!param_add(¶ms, name, required, cbx, arg)) {
|
||||||
if (!param_add(¶ms, name, required, cb, cbx, arg, argsize)) {
|
|
||||||
command_fail(cmd, PARAM_DEV_ERROR, "developer error");
|
command_fail(cmd, PARAM_DEV_ERROR, "developer error");
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
Typesafe callback system for unmarshalling and validating json parameters.
|
Typesafe callback system for unmarshalling and validating json parameters.
|
||||||
|
|
||||||
Typical usage:
|
Typical usage:
|
||||||
unsigned cltv;
|
unsigned *cltv;
|
||||||
u64 *msatoshi;
|
u64 *msatoshi;
|
||||||
const jsmntok_t *note;
|
const jsmntok_t *note;
|
||||||
u64 expiry;
|
u64 *expiry;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("cltv", json_tok_number, &cltv),
|
p_req("cltv", json_tok_number, &cltv),
|
||||||
@@ -19,131 +19,68 @@
|
|||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
At this point in the code you can be assured the json tokens were successfully
|
See json_invoice() for a good example. The common callbacks can be found in
|
||||||
parsed. If not, param() returned false, having already called command_fail()
|
lightningd/json.c. Use them as an example for writing your own custom
|
||||||
with a descriptive error message. The data section of the json result contains
|
callbacks.
|
||||||
the offending parameter and its value.
|
|
||||||
|
|
||||||
cltv is a required parameter. It must be present in the json input and will
|
|
||||||
be set appropriately.
|
|
||||||
|
|
||||||
msatoshi is optional. If not present it will be set to NULL.
|
|
||||||
|
|
||||||
note is also optional. It uses a special callback that simply sets note to the
|
|
||||||
appropriate value (or NULL) and lets the handler do the validating.
|
|
||||||
|
|
||||||
expiry is also optional and will be set to a default value if not present.
|
|
||||||
|
|
||||||
There are canned failure messages for common callbacks. An example:
|
|
||||||
|
|
||||||
'msatoshi' should be an unsigned 64 bit integer, not '123z'
|
|
||||||
|
|
||||||
Otherwise a generic message is provided.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* parse the json tokens. @params can be an array of values, or an object
|
* Parse the json tokens. @params can be an array of values or an object
|
||||||
* of named values.
|
* of named values.
|
||||||
*/
|
*/
|
||||||
bool param(struct command *cmd, const char *buffer,
|
bool param(struct command *cmd, const char *buffer,
|
||||||
const jsmntok_t params[], ...);
|
const jsmntok_t params[], ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The callback provided must follow this signature; e.g.,
|
* The callback signature. Callbacks must return true on success. On failure they
|
||||||
* bool json_tok_double(const char *buffer, const jsmntok_t *tok, double *arg)
|
* must call comand_fail and return false.
|
||||||
*/
|
|
||||||
typedef bool(*param_cb)(const char *buffer, const jsmntok_t *tok, void *arg);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Advanced callback. Returns NULL on success, error message on failure.
|
|
||||||
*/
|
*/
|
||||||
typedef bool(*param_cbx)(struct command *cmd,
|
typedef bool(*param_cbx)(struct command *cmd,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
void **arg);
|
void **arg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a handler to unmarshal a required json token into @arg. The handler must
|
* Add a required parameter.
|
||||||
* return true on success and false on failure. Upon failure, command_fail will be
|
|
||||||
* called with a descriptive error message.
|
|
||||||
*
|
|
||||||
* This operation is typesafe; i.e., a compilation error will occur if the types
|
|
||||||
* of @arg and the last parameter of @cb do not match (see the weird 0*sizeof).
|
|
||||||
*/
|
*/
|
||||||
#define p_req(name, cb, arg) \
|
#define p_req(name, cbx, arg) \
|
||||||
name"", \
|
name"", \
|
||||||
true, \
|
true, \
|
||||||
false, \
|
(cbx), \
|
||||||
(cb), \
|
(arg) + 0*sizeof((cbx)((struct command *)NULL, \
|
||||||
(arg) + 0*sizeof((cb)((const char *)NULL, \
|
(const char *)NULL, \
|
||||||
(const jsmntok_t *)NULL, \
|
(const char *)NULL, \
|
||||||
(arg)) == true), \
|
(const jsmntok_t *)NULL, \
|
||||||
(size_t)0
|
(arg)) == true)
|
||||||
|
|
||||||
#define p_req_tal(name, cbx, arg) \
|
|
||||||
name"", \
|
|
||||||
true, \
|
|
||||||
true, \
|
|
||||||
(cbx), \
|
|
||||||
(arg) + 0*sizeof((cbx)((struct command *)NULL,\
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const jsmntok_t *)NULL, \
|
|
||||||
(arg)) == true), \
|
|
||||||
(size_t)0
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Similar to above but for optional parameters.
|
* Add an optional parameter. *arg is set to NULL if it isn't found.
|
||||||
* @arg must be the address of a pointer. If found during parsing, it will be
|
|
||||||
* allocated, otherwise it will be set to NULL.
|
|
||||||
*/
|
*/
|
||||||
#define p_opt(name, cb, arg) \
|
#define p_opt(name, cbx, arg) \
|
||||||
name"", \
|
name"", \
|
||||||
false, \
|
false, \
|
||||||
false, \
|
(cbx), \
|
||||||
(cb), \
|
({ *arg = NULL; \
|
||||||
(arg) + 0*sizeof((cb)((const char *)NULL, \
|
(arg) + 0*sizeof((cbx)((struct command *)NULL, \
|
||||||
(const jsmntok_t *)NULL, \
|
(const char *)NULL, \
|
||||||
*(arg)) == true), \
|
(const char *)NULL, \
|
||||||
sizeof(**(arg))
|
(const jsmntok_t *)NULL, \
|
||||||
|
(arg)) == true); })
|
||||||
#define p_opt_tal(name, cbx, arg) \
|
|
||||||
name"", \
|
|
||||||
false, \
|
|
||||||
true, \
|
|
||||||
(cbx), \
|
|
||||||
(arg) + 0*sizeof((cbx)((struct command *)NULL,\
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const jsmntok_t *)NULL, \
|
|
||||||
(arg)) == true), \
|
|
||||||
sizeof(**(arg))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Similar to p_req but for optional parameters with defaults.
|
* Add an optional parameter. *arg is set to @def if it isn't found.
|
||||||
* @arg will be set to @def if it isn't found during parsing.
|
|
||||||
*/
|
*/
|
||||||
#define p_opt_def(name, cb, arg, def) \
|
#define p_opt_def(name, cbx, arg, def) \
|
||||||
name"", \
|
name"", \
|
||||||
false, \
|
false, \
|
||||||
false, \
|
(cbx), \
|
||||||
(cb), \
|
({ (*arg) = tal((cmd), typeof(**arg)); \
|
||||||
(arg) + 0*sizeof((cb)((const char *)NULL, \
|
(**arg) = (def); \
|
||||||
(const jsmntok_t *)NULL, \
|
(arg) + 0*sizeof((cbx)((struct command *)NULL, \
|
||||||
(arg)) == true), \
|
(const char *)NULL, \
|
||||||
((void)((*arg) = (def)), (size_t)0)
|
(const char *)NULL, \
|
||||||
|
(const jsmntok_t *)NULL, \
|
||||||
#define p_opt_def_tal(name, cbx, arg, def) \
|
(arg)) == true); })
|
||||||
name"", \
|
|
||||||
false, \
|
|
||||||
true, \
|
|
||||||
(cbx), \
|
|
||||||
(arg) + 0*sizeof((cbx)((struct command *)NULL,\
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const char *)NULL, \
|
|
||||||
(const jsmntok_t *)NULL, \
|
|
||||||
(arg)) == true), \
|
|
||||||
({ (*arg) = tal((cmd), typeof(**arg)); (**arg) = (def); (size_t)0;})
|
|
||||||
|
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_PARAM_H */
|
#endif /* LIGHTNING_LIGHTNINGD_PARAM_H */
|
||||||
|
|||||||
@@ -955,10 +955,10 @@ static void json_sendpay(struct command *cmd,
|
|||||||
const char *description;
|
const char *description;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("route", json_tok_tok, &routetok),
|
p_req("route", json_tok_tok, &routetok),
|
||||||
p_req_tal("payment_hash", json_tok_sha256, &rhash),
|
p_req("payment_hash", json_tok_sha256, &rhash),
|
||||||
p_opt_tal("description", json_tok_tok, &desctok),
|
p_opt("description", json_tok_tok, &desctok),
|
||||||
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1094,8 +1094,8 @@ static void json_waitsendpay(struct command *cmd, const char *buffer,
|
|||||||
unsigned int *timeout;
|
unsigned int *timeout;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("payment_hash", json_tok_sha256, &rhash),
|
p_req("payment_hash", json_tok_sha256, &rhash),
|
||||||
p_opt_tal("timeout", json_tok_number, &timeout),
|
p_opt("timeout", json_tok_number, &timeout),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1125,8 +1125,8 @@ static void json_listpayments(struct command *cmd, const char *buffer,
|
|||||||
struct sha256 *rhash = NULL;
|
struct sha256 *rhash = NULL;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("bolt11", json_tok_tok, &bolt11tok),
|
p_opt("bolt11", json_tok_tok, &bolt11tok),
|
||||||
p_opt_tal("payment_hash", json_tok_tok, &rhashtok),
|
p_opt("payment_hash", json_tok_tok, &rhashtok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -627,15 +627,15 @@ static void json_pay(struct command *cmd,
|
|||||||
unsigned int *exemptfee;
|
unsigned int *exemptfee;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("bolt11", json_tok_tok, &bolt11tok),
|
p_req("bolt11", json_tok_tok, &bolt11tok),
|
||||||
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||||
p_opt_tal("description", json_tok_tok, &desctok),
|
p_opt("description", json_tok_tok, &desctok),
|
||||||
p_opt_def_tal("riskfactor", json_tok_double, &riskfactor, 1.0),
|
p_opt_def("riskfactor", json_tok_double, &riskfactor, 1.0),
|
||||||
p_opt_def_tal("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
|
p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
|
||||||
p_opt_def_tal("retry_for", json_tok_number, &retryfor, 60),
|
p_opt_def("retry_for", json_tok_number, &retryfor, 60),
|
||||||
p_opt_def_tal("maxdelay", json_tok_number, &maxdelay,
|
p_opt_def("maxdelay", json_tok_number, &maxdelay,
|
||||||
cmd->ld->config.locktime_max),
|
cmd->ld->config.locktime_max),
|
||||||
p_opt_def_tal("exemptfee", json_tok_number, &exemptfee, 5000),
|
p_opt_def("exemptfee", json_tok_number, &exemptfee, 5000),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -749,8 +749,8 @@ static void json_listpeers(struct command *cmd,
|
|||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_tal("id", json_tok_pubkey, &specific_id),
|
p_opt("id", json_tok_pubkey, &specific_id),
|
||||||
p_opt_tal("level", json_tok_loglevel, &ll),
|
p_opt("level", json_tok_loglevel, &ll),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -836,9 +836,9 @@ static void json_close(struct command *cmd,
|
|||||||
bool *force;
|
bool *force;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_tok, &idtok),
|
p_req("id", json_tok_tok, &idtok),
|
||||||
p_opt_def_tal("force", json_tok_bool, &force, false),
|
p_opt_def("force", json_tok_bool, &force, false),
|
||||||
p_opt_def_tal("timeout", json_tok_number, &timeout, 30),
|
p_opt_def("timeout", json_tok_number, &timeout, 30),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -946,7 +946,7 @@ static void json_disconnect(struct command *cmd,
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -988,7 +988,7 @@ static void json_sign_last_tx(struct command *cmd,
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1032,7 +1032,7 @@ static void json_dev_fail(struct command *cmd,
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1078,7 +1078,7 @@ static void json_dev_reenable_commit(struct command *cmd,
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1171,9 +1171,9 @@ static void json_dev_forget_channel(struct command *cmd, const char *buffer,
|
|||||||
|
|
||||||
bool *force;
|
bool *force;
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
p_opt_tal("short_channel_id", json_tok_short_channel_id, &scid),
|
p_opt("short_channel_id", json_tok_short_channel_id, &scid),
|
||||||
p_opt_def_tal("force", json_tok_bool, &force, false),
|
p_opt_def("force", json_tok_bool, &force, false),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -1698,8 +1698,8 @@ static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer,
|
|||||||
bool *ignore;
|
bool *ignore;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
p_req_tal("ignore", json_tok_bool, &ignore),
|
p_req("ignore", json_tok_bool, &ignore),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ static void json_ping(struct command *cmd,
|
|||||||
struct pubkey *id;
|
struct pubkey *id;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &id),
|
p_req("id", json_tok_pubkey, &id),
|
||||||
p_opt_def_tal("len", json_tok_number, &len, 128),
|
p_opt_def("len", json_tok_number, &len, 128),
|
||||||
p_opt_def_tal("pongbytes", json_tok_number, &pongbytes, 128),
|
p_opt_def("pongbytes", json_tok_number, &pongbytes, 128),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ static void stest(const struct json *j, struct sanity *b)
|
|||||||
u64 *ival;
|
u64 *ival;
|
||||||
double *dval;
|
double *dval;
|
||||||
if (!param(cmd, j->buffer, j->toks,
|
if (!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("u64", json_tok_u64, &ival),
|
p_req("u64", json_tok_u64, &ival),
|
||||||
p_req_tal("double", json_tok_double, &dval), NULL)) {
|
p_req("double", json_tok_double, &dval), NULL)) {
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(b->failed == true);
|
assert(b->failed == true);
|
||||||
if (!strstr(fail_msg, b->fail_str)) {
|
if (!strstr(fail_msg, b->fail_str)) {
|
||||||
@@ -173,7 +173,7 @@ static void tok_tok(void)
|
|||||||
struct json *j = json_parse(cmd, "{ 'satoshi', '546' }");
|
struct json *j = json_parse(cmd, "{ 'satoshi', '546' }");
|
||||||
|
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("satoshi", json_tok_tok, &tok), NULL));
|
p_req("satoshi", json_tok_tok, &tok), NULL));
|
||||||
assert(tok);
|
assert(tok);
|
||||||
assert(json_to_number(j->buffer, tok, &n));
|
assert(json_to_number(j->buffer, tok, &n));
|
||||||
assert(n == 546);
|
assert(n == 546);
|
||||||
@@ -185,7 +185,7 @@ static void tok_tok(void)
|
|||||||
|
|
||||||
struct json *j = json_parse(cmd, "{}");
|
struct json *j = json_parse(cmd, "{}");
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_opt_tal("satoshi", json_tok_tok, &tok), NULL));
|
p_opt("satoshi", json_tok_tok, &tok), NULL));
|
||||||
|
|
||||||
/* make sure it *is* NULL */
|
/* make sure it *is* NULL */
|
||||||
assert(tok == NULL);
|
assert(tok == NULL);
|
||||||
@@ -202,8 +202,8 @@ static void dup_names(void)
|
|||||||
u64 *i;
|
u64 *i;
|
||||||
double *d;
|
double *d;
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("u64", json_tok_u64, &i),
|
p_req("u64", json_tok_u64, &i),
|
||||||
p_req_tal("double", json_tok_double, &d), NULL));
|
p_req("double", json_tok_double, &d), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void null_params(void)
|
static void null_params(void)
|
||||||
@@ -214,13 +214,13 @@ static void null_params(void)
|
|||||||
json_parse(cmd, "[ '10', '11', '12', '13', '14', '15', '16']");
|
json_parse(cmd, "[ '10', '11', '12', '13', '14', '15', '16']");
|
||||||
|
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("0", json_tok_u64, &intptrs[0]),
|
p_req("0", json_tok_u64, &intptrs[0]),
|
||||||
p_req_tal("1", json_tok_u64, &intptrs[1]),
|
p_req("1", json_tok_u64, &intptrs[1]),
|
||||||
p_req_tal("2", json_tok_u64, &intptrs[2]),
|
p_req("2", json_tok_u64, &intptrs[2]),
|
||||||
p_req_tal("3", json_tok_u64, &intptrs[3]),
|
p_req("3", json_tok_u64, &intptrs[3]),
|
||||||
p_opt_def_tal("4", json_tok_u64, &intptrs[4], 999),
|
p_opt_def("4", json_tok_u64, &intptrs[4], 999),
|
||||||
p_opt_tal("5", json_tok_u64, &intptrs[5]),
|
p_opt("5", json_tok_u64, &intptrs[5]),
|
||||||
p_opt_tal("6", json_tok_u64, &intptrs[6]),
|
p_opt("6", json_tok_u64, &intptrs[6]),
|
||||||
NULL));
|
NULL));
|
||||||
for (int i = 0; i < tal_count(intptrs); ++i) {
|
for (int i = 0; i < tal_count(intptrs); ++i) {
|
||||||
assert(intptrs[i]);
|
assert(intptrs[i]);
|
||||||
@@ -230,13 +230,13 @@ static void null_params(void)
|
|||||||
/* missing at end */
|
/* missing at end */
|
||||||
j = json_parse(cmd, "[ '10', '11', '12', '13', '14']");
|
j = json_parse(cmd, "[ '10', '11', '12', '13', '14']");
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("0", json_tok_u64, &intptrs[0]),
|
p_req("0", json_tok_u64, &intptrs[0]),
|
||||||
p_req_tal("1", json_tok_u64, &intptrs[1]),
|
p_req("1", json_tok_u64, &intptrs[1]),
|
||||||
p_req_tal("2", json_tok_u64, &intptrs[2]),
|
p_req("2", json_tok_u64, &intptrs[2]),
|
||||||
p_req_tal("3", json_tok_u64, &intptrs[3]),
|
p_req("3", json_tok_u64, &intptrs[3]),
|
||||||
p_opt_tal("4", json_tok_u64, &intptrs[4]),
|
p_opt("4", json_tok_u64, &intptrs[4]),
|
||||||
p_opt_tal("5", json_tok_u64, &intptrs[5]),
|
p_opt("5", json_tok_u64, &intptrs[5]),
|
||||||
p_opt_def_tal("6", json_tok_u64, &intptrs[6], 888),
|
p_opt_def("6", json_tok_u64, &intptrs[6], 888),
|
||||||
NULL));
|
NULL));
|
||||||
assert(*intptrs[0] == 10);
|
assert(*intptrs[0] == 10);
|
||||||
assert(*intptrs[1] == 11);
|
assert(*intptrs[1] == 11);
|
||||||
@@ -260,35 +260,35 @@ static void bad_programmer(void)
|
|||||||
|
|
||||||
/* check for repeated names */
|
/* check for repeated names */
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("repeat", json_tok_u64, &ival),
|
p_req("repeat", json_tok_u64, &ival),
|
||||||
p_req_tal("double", json_tok_double, &dval),
|
p_req("double", json_tok_double, &dval),
|
||||||
p_req_tal("repeat", json_tok_u64, &ival2), NULL));
|
p_req("repeat", json_tok_u64, &ival2), NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "developer error"));
|
assert(strstr(fail_msg, "developer error"));
|
||||||
|
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("repeat", json_tok_u64, &ival),
|
p_req("repeat", json_tok_u64, &ival),
|
||||||
p_req_tal("double", json_tok_double, &dval),
|
p_req("double", json_tok_double, &dval),
|
||||||
p_req_tal("repeat", json_tok_u64, &ival), NULL));
|
p_req("repeat", json_tok_u64, &ival), NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "developer error"));
|
assert(strstr(fail_msg, "developer error"));
|
||||||
|
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("u64", json_tok_u64, &ival),
|
p_req("u64", json_tok_u64, &ival),
|
||||||
p_req_tal("repeat", json_tok_double, &dval),
|
p_req("repeat", json_tok_double, &dval),
|
||||||
p_req_tal("repeat", json_tok_double, &dval), NULL));
|
p_req("repeat", json_tok_double, &dval), NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "developer error"));
|
assert(strstr(fail_msg, "developer error"));
|
||||||
|
|
||||||
/* check for repeated arguments */
|
/* check for repeated arguments */
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("u64", json_tok_u64, &ival),
|
p_req("u64", json_tok_u64, &ival),
|
||||||
p_req_tal("repeated-arg", json_tok_u64, &ival), NULL));
|
p_req("repeated-arg", json_tok_u64, &ival), NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "developer error"));
|
assert(strstr(fail_msg, "developer error"));
|
||||||
|
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req("u64", (param_cb) NULL, &ival), NULL));
|
p_req("u64", (param_cbx) NULL, NULL), NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "developer error"));
|
assert(strstr(fail_msg, "developer error"));
|
||||||
|
|
||||||
@@ -297,10 +297,10 @@ static void bad_programmer(void)
|
|||||||
unsigned int *msatoshi;
|
unsigned int *msatoshi;
|
||||||
double *riskfactor;
|
double *riskfactor;
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("u64", json_tok_u64, &ival),
|
p_req("u64", json_tok_u64, &ival),
|
||||||
p_req_tal("double", json_tok_double, &dval),
|
p_req("double", json_tok_double, &dval),
|
||||||
p_opt_def_tal("msatoshi", json_tok_number, &msatoshi, 100),
|
p_opt_def("msatoshi", json_tok_number, &msatoshi, 100),
|
||||||
p_req_tal("riskfactor", json_tok_double, &riskfactor), NULL));
|
p_req("riskfactor", json_tok_double, &riskfactor), NULL));
|
||||||
assert(*msatoshi);
|
assert(*msatoshi);
|
||||||
assert(*msatoshi == 100);
|
assert(*msatoshi == 100);
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
@@ -317,7 +317,6 @@ static void add_members(struct param **params,
|
|||||||
json_add_num(obj, name, i);
|
json_add_num(obj, name, i);
|
||||||
json_add_num(arr, NULL, i);
|
json_add_num(arr, NULL, i);
|
||||||
param_add(params, name, true,
|
param_add(params, name, true,
|
||||||
NULL,
|
|
||||||
typesafe_cb_preargs(bool, void **,
|
typesafe_cb_preargs(bool, void **,
|
||||||
json_tok_number,
|
json_tok_number,
|
||||||
&ints[i],
|
&ints[i],
|
||||||
@@ -325,7 +324,7 @@ static void add_members(struct param **params,
|
|||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
const jsmntok_t *),
|
const jsmntok_t *),
|
||||||
&ints[i], 0);
|
&ints[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,10 +373,10 @@ static void sendpay(void)
|
|||||||
unsigned *cltv;
|
unsigned *cltv;
|
||||||
|
|
||||||
if (!param(cmd, j->buffer, j->toks,
|
if (!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("route", json_tok_tok, &routetok),
|
p_req("route", json_tok_tok, &routetok),
|
||||||
p_req_tal("cltv", json_tok_number, &cltv),
|
p_req("cltv", json_tok_number, &cltv),
|
||||||
p_opt_tal("note", json_tok_tok, ¬e),
|
p_opt("note", json_tok_tok, ¬e),
|
||||||
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||||
NULL))
|
NULL))
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
@@ -397,10 +396,10 @@ static void sendpay_nulltok(void)
|
|||||||
unsigned *cltv;
|
unsigned *cltv;
|
||||||
|
|
||||||
if (!param(cmd, j->buffer, j->toks,
|
if (!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("route", json_tok_tok, &routetok),
|
p_req("route", json_tok_tok, &routetok),
|
||||||
p_req_tal("cltv", json_tok_number, &cltv),
|
p_req("cltv", json_tok_number, &cltv),
|
||||||
p_opt_tal("note", json_tok_tok, ¬e),
|
p_opt("note", json_tok_tok, ¬e),
|
||||||
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||||
NULL))
|
NULL))
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
@@ -474,11 +473,11 @@ static void advanced(void)
|
|||||||
const jsmntok_t *tok;
|
const jsmntok_t *tok;
|
||||||
|
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("description", json_tok_label_x, &label),
|
p_req("description", json_tok_label_x, &label),
|
||||||
p_req_tal("msat", json_tok_msat, &msat),
|
p_req("msat", json_tok_msat, &msat),
|
||||||
p_req_tal("tok", json_tok_tok, &tok),
|
p_req("tok", json_tok_tok, &tok),
|
||||||
p_opt_tal("msat_opt1", json_tok_msat, &msat_opt1),
|
p_opt("msat_opt1", json_tok_msat, &msat_opt1),
|
||||||
p_opt_tal("msat_opt2", json_tok_msat, &msat_opt2),
|
p_opt("msat_opt2", json_tok_msat, &msat_opt2),
|
||||||
NULL));
|
NULL));
|
||||||
assert(label != NULL);
|
assert(label != NULL);
|
||||||
assert(!strcmp(label->s, "lightning"));
|
assert(!strcmp(label->s, "lightning"));
|
||||||
@@ -492,8 +491,8 @@ static void advanced(void)
|
|||||||
struct json *j = json_parse(cmd, "[ 3 'foo' ]");
|
struct json *j = json_parse(cmd, "[ 3 'foo' ]");
|
||||||
struct json_escaped *label, *foo;
|
struct json_escaped *label, *foo;
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("label", json_tok_label_x, &label),
|
p_req("label", json_tok_label_x, &label),
|
||||||
p_opt_tal("foo", json_tok_label_x, &foo),
|
p_opt("foo", json_tok_label_x, &foo),
|
||||||
NULL));
|
NULL));
|
||||||
assert(!strcmp(label->s, "3"));
|
assert(!strcmp(label->s, "3"));
|
||||||
assert(!strcmp(foo->s, "foo"));
|
assert(!strcmp(foo->s, "foo"));
|
||||||
@@ -503,8 +502,8 @@ static void advanced(void)
|
|||||||
u64 *msat2;
|
u64 *msat2;
|
||||||
struct json *j = json_parse(cmd, "[ 3 ]");
|
struct json *j = json_parse(cmd, "[ 3 ]");
|
||||||
assert(param(cmd, j->buffer, j->toks,
|
assert(param(cmd, j->buffer, j->toks,
|
||||||
p_opt_def_tal("msat", json_tok_msat, &msat, 23),
|
p_opt_def("msat", json_tok_msat, &msat, 23),
|
||||||
p_opt_def_tal("msat2", json_tok_msat, &msat2, 53),
|
p_opt_def("msat2", json_tok_msat, &msat2, 53),
|
||||||
NULL));
|
NULL));
|
||||||
assert(*msat == 3);
|
assert(*msat == 3);
|
||||||
assert(msat2);
|
assert(msat2);
|
||||||
@@ -518,7 +517,7 @@ static void advanced_fail(void)
|
|||||||
struct json *j = json_parse(cmd, "[ 'anyx' ]");
|
struct json *j = json_parse(cmd, "[ 'anyx' ]");
|
||||||
u64 *msat;
|
u64 *msat;
|
||||||
assert(!param(cmd, j->buffer, j->toks,
|
assert(!param(cmd, j->buffer, j->toks,
|
||||||
p_req_tal("msat", json_tok_msat, &msat),
|
p_req("msat", json_tok_msat, &msat),
|
||||||
NULL));
|
NULL));
|
||||||
assert(check_fail());
|
assert(check_fail());
|
||||||
assert(strstr(fail_msg, "'msat' should be a positive"
|
assert(strstr(fail_msg, "'msat' should be a positive"
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ static void json_withdraw(struct command *cmd,
|
|||||||
wtx_init(cmd, &withdraw->wtx);
|
wtx_init(cmd, &withdraw->wtx);
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("destination", json_tok_tok, &desttok),
|
p_req("destination", json_tok_tok, &desttok),
|
||||||
p_req_tal("satoshi", json_tok_tok, &sattok),
|
p_req("satoshi", json_tok_tok, &sattok),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ static void json_newaddr(struct command *cmd, const char *buffer UNUSED,
|
|||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("addresstype", json_tok_newaddr, &is_p2wpkh, true),
|
p_opt_def("addresstype", json_tok_newaddr, &is_p2wpkh, true),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ static void json_listaddrs(struct command *cmd,
|
|||||||
u64 *bip32_max_index;
|
u64 *bip32_max_index;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_opt_def_tal("bip32_max_index", json_tok_u64, &bip32_max_index,
|
p_opt_def("bip32_max_index", json_tok_u64, &bip32_max_index,
|
||||||
db_get_intvar(cmd->ld->wallet->db,
|
db_get_intvar(cmd->ld->wallet->db,
|
||||||
"bip32_max_index", 0)),
|
"bip32_max_index", 0)),
|
||||||
NULL))
|
NULL))
|
||||||
|
|||||||
Reference in New Issue
Block a user