From a3178b81772516a2d98efbd701baf4128f139b5f Mon Sep 17 00:00:00 2001 From: Mark Beckwith Date: Wed, 15 Aug 2018 10:16:02 -0500 Subject: [PATCH] param: remove old callback code Cleaned up remaining code. Reduced comment noise. Reverted macro names back to the original. Signed-off-by: Mark Beckwith --- lightningd/chaintopology.c | 6 +- lightningd/connect_control.c | 6 +- lightningd/gossip_control.c | 36 ++++----- lightningd/invoice.c | 32 ++++---- lightningd/jsonrpc.c | 4 +- lightningd/log.c | 2 +- lightningd/opening_control.c | 4 +- lightningd/options.c | 2 +- lightningd/param.c | 79 ++---------------- lightningd/param.h | 153 +++++++++++------------------------ lightningd/pay.c | 16 ++-- lightningd/payalgo.c | 16 ++-- lightningd/peer_control.c | 24 +++--- lightningd/peer_htlcs.c | 4 +- lightningd/ping.c | 6 +- lightningd/test/run-param.c | 111 +++++++++++++------------ wallet/walletrpc.c | 8 +- 17 files changed, 189 insertions(+), 320 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 506c2bf1a..07c396395 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -615,9 +615,9 @@ static void json_dev_setfees(struct command *cmd, } if (!param(cmd, buffer, params, - p_opt_tal("immediate", json_tok_number, &imm), - p_opt_tal("normal", json_tok_number, &norm), - p_opt_tal("slow", json_tok_number, &slow), + p_opt("immediate", json_tok_number, &imm), + p_opt("normal", json_tok_number, &norm), + p_opt("slow", json_tok_number, &slow), NULL)) return; diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 9f0aef981..2beb875ea 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -88,9 +88,9 @@ static void json_connect(struct command *cmd, struct peer *peer; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_tok, (const jsmntok_t **) &idtok), - p_opt_tal("host", json_tok_tok, &hosttok), - p_opt_tal("port", json_tok_number, &port), + p_req("id", json_tok_tok, (const jsmntok_t **) &idtok), + p_opt("host", json_tok_tok, &hosttok), + p_opt("port", json_tok_number, &port), NULL)) return; diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index ade73a96e..2b9495f0b 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -233,7 +233,7 @@ static void json_listnodes(struct command *cmd, const char *buffer, struct pubkey *id; if (!param(cmd, buffer, params, - p_opt_tal("id", json_tok_pubkey, &id), + p_opt("id", json_tok_pubkey, &id), NULL)) return; @@ -287,13 +287,13 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok struct siphash_seed seed; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &destination), - p_req_tal("msatoshi", json_tok_u64, &msatoshi), - p_req_tal("riskfactor", json_tok_double, &riskfactor), - p_opt_def_tal("cltv", json_tok_number, &cltv, 9), - p_opt_def_tal("fromid", json_tok_pubkey, &source, ld->id), - p_opt_tal("seed", json_tok_tok, &seedtok), - p_opt_def_tal("fuzzpercent", json_tok_double, &fuzz, 75.0), + p_req("id", json_tok_pubkey, &destination), + p_req("msatoshi", json_tok_u64, &msatoshi), + p_req("riskfactor", json_tok_double, &riskfactor), + p_opt_def("cltv", json_tok_number, &cltv, 9), + p_opt_def("fromid", json_tok_pubkey, &source, ld->id), + p_opt("seed", json_tok_tok, &seedtok), + p_opt_def("fuzzpercent", json_tok_double, &fuzz, 75.0), NULL)) return; @@ -383,7 +383,7 @@ static void json_listchannels(struct command *cmd, const char *buffer, u8 *req; struct short_channel_id *id; 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)) return; @@ -436,8 +436,8 @@ static void json_dev_query_scids(struct command *cmd, size_t i; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), - p_req_tal("scids", json_tok_tok, &scidstok), + p_req("id", json_tok_pubkey, &id), + p_req("scids", json_tok_tok, &scidstok), NULL)) return; @@ -484,9 +484,9 @@ static void json_dev_send_timestamp_filter(struct command *cmd, u32 *first, *range; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), - p_req_tal("first", json_tok_number, &first), - p_req_tal("range", json_tok_number, &range), + p_req("id", json_tok_pubkey, &id), + p_req("first", json_tok_number, &first), + p_req("range", json_tok_number, &range), NULL)) return; @@ -552,9 +552,9 @@ static void json_dev_query_channel_range(struct command *cmd, u32 *first, *num; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), - p_req_tal("first", json_tok_number, &first), - p_req_tal("num", json_tok_number, &num), + p_req("id", json_tok_pubkey, &id), + p_req("first", json_tok_number, &first), + p_req("num", json_tok_number, &num), NULL)) return; @@ -580,7 +580,7 @@ static void json_dev_set_max_scids_encode_size(struct command *cmd, u32 *max; if (!param(cmd, buffer, params, - p_req_tal("max", json_tok_number, &max), + p_req("max", json_tok_number, &max), NULL)) return; diff --git a/lightningd/invoice.c b/lightningd/invoice.c index ace192e58..88994474c 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -168,12 +168,12 @@ static void json_invoice(struct command *cmd, bool result; if (!param(cmd, buffer, params, - p_req_tal("msatoshi", json_tok_tok, &msatoshi), - p_req_tal("label", json_tok_tok, &label), - p_req_tal("description", json_tok_tok, &desctok), - p_opt_def_tal("expiry", json_tok_u64, &expiry, 3600), - p_opt_tal("fallbacks", json_tok_tok, &fallbacks), - p_opt_tal("preimage", json_tok_tok, &preimagetok), + p_req("msatoshi", json_tok_tok, &msatoshi), + p_req("label", json_tok_tok, &label), + p_req("description", json_tok_tok, &desctok), + p_opt_def("expiry", json_tok_u64, &expiry, 3600), + p_opt("fallbacks", json_tok_tok, &fallbacks), + p_opt("preimage", json_tok_tok, &preimagetok), NULL)) return; @@ -372,7 +372,7 @@ static void json_listinvoices(struct command *cmd, struct wallet *wallet = cmd->ld->wallet; if (!param(cmd, buffer, params, - p_opt_tal("label", json_tok_tok, &labeltok), + p_opt("label", json_tok_tok, &labeltok), NULL)) return; @@ -415,8 +415,8 @@ static void json_delinvoice(struct command *cmd, struct wallet *wallet = cmd->ld->wallet; if (!param(cmd, buffer, params, - p_req_tal("label", json_tok_tok, &labeltok), - p_req_tal("status", json_tok_tok, &statustok), + p_req("label", json_tok_tok, &labeltok), + p_req("status", json_tok_tok, &statustok), NULL)) return; @@ -475,7 +475,7 @@ static void json_delexpiredinvoice(struct command *cmd, const char *buffer, struct json_result *result; 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), NULL)) return; @@ -503,8 +503,8 @@ static void json_autocleaninvoice(struct command *cmd, struct json_result *result; if (!param(cmd, buffer, params, - p_opt_def_tal("cycle_seconds", json_tok_u64, &cycle, 3600), - p_opt_def_tal("expired_by", json_tok_u64, &exby, 86400), + p_opt_def("cycle_seconds", json_tok_u64, &cycle, 3600), + p_opt_def("expired_by", json_tok_u64, &exby, 86400), NULL)) return; @@ -531,7 +531,7 @@ static void json_waitanyinvoice(struct command *cmd, struct wallet *wallet = cmd->ld->wallet; 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)) return; @@ -568,7 +568,7 @@ static void json_waitinvoice(struct command *cmd, struct json_escaped *label; if (!param(cmd, buffer, params, - p_req_tal("label", json_tok_tok, &labeltok), + p_req("label", json_tok_tok, &labeltok), NULL)) return; @@ -651,8 +651,8 @@ static void json_decodepay(struct command *cmd, char *str, *desc, *fail; if (!param(cmd, buffer, params, - p_req_tal("bolt11", json_tok_tok, &bolt11tok), - p_opt_tal("description", json_tok_tok, &desctok), + p_req("bolt11", json_tok_tok, &bolt11tok), + p_opt("description", json_tok_tok, &desctok), NULL)) return; diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index d5b6dec65..152c2a518 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -99,7 +99,7 @@ static void json_rhash(struct command *cmd, struct sha256 *secret; if (!param(cmd, buffer, params, - p_req_tal("secret", json_tok_sha256, &secret), + p_req("secret", json_tok_sha256, &secret), NULL)) return; @@ -189,7 +189,7 @@ static void json_help(struct command *cmd, const jsmntok_t *cmdtok; if (!param(cmd, buffer, params, - p_opt_tal("command", json_tok_tok, &cmdtok), + p_opt("command", json_tok_tok, &cmdtok), NULL)) return; diff --git a/lightningd/log.c b/lightningd/log.c index a9353c153..0b55d91e6 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -666,7 +666,7 @@ static void json_getlog(struct command *cmd, struct log_book *lr = cmd->ld->log_book; if (!param(cmd, buffer, params, - p_opt_def_tal("level", json_tok_loglevel, &minlevel, + p_opt_def("level", json_tok_loglevel, &minlevel, LOG_INFORM), NULL)) return; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 063c36268..ac6c8ba70 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -769,8 +769,8 @@ static void json_fund_channel(struct command *cmd, fc->uc = NULL; wtx_init(cmd, &fc->wtx); if (!param(fc->cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), - p_req_tal("satoshi", json_tok_tok, &sattok), + p_req("id", json_tok_pubkey, &id), + p_req("satoshi", json_tok_tok, &sattok), NULL)) return; diff --git a/lightningd/options.c b/lightningd/options.c index 4f045bae3..055fb30bc 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -1011,7 +1011,7 @@ static void json_listconfigs(struct command *cmd, bool found = false; if (!param(cmd, buffer, params, - p_opt_tal("config", json_tok_tok, &configtok), + p_opt("config", json_tok_tok, &configtok), NULL)) return; diff --git a/lightningd/param.c b/lightningd/param.c index b371bc0ad..bb11317e9 100644 --- a/lightningd/param.c +++ b/lightningd/param.c @@ -11,19 +11,16 @@ struct param { const char *name; bool is_set; bool required; - param_cb cb; param_cbx cbx; void *arg; - size_t argsize; }; static bool param_add(struct param **params, - const char *name, bool required, param_cb cb, - param_cbx cbx, void *arg, - size_t argsize) + const char *name, bool required, + param_cbx cbx, void *arg) { #if DEVELOPER - if (!(name && (cb || cbx) && arg)) + if (!(name && cbx && arg)) return false; #endif struct param *last; @@ -34,79 +31,18 @@ static bool param_add(struct param **params, last->is_set = false; last->name = name; last->required = required; - last->cb = cb; last->cbx = cbx; 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; } -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, struct param *def, const char *buffer, const jsmntok_t *tok) { - void *arg; def->is_set = true; - if (def->cb) { - 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; + return def->cbx(cmd, def->name, buffer, tok, def->arg); } 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); while ((name = va_arg(ap, const char *)) != NULL) { bool required = va_arg(ap, int); - bool advanced = va_arg(ap, int); - param_cb cb = advanced ? NULL : va_arg(ap, param_cb); - param_cbx cbx = advanced ? va_arg(ap, param_cbx) : NULL; + param_cbx cbx = va_arg(ap, param_cbx); void *arg = va_arg(ap, void *); - size_t argsize = va_arg(ap, size_t); - if (!param_add(¶ms, name, required, cb, cbx, arg, argsize)) { + if (!param_add(¶ms, name, required, cbx, arg)) { command_fail(cmd, PARAM_DEV_ERROR, "developer error"); va_end(ap); return false; diff --git a/lightningd/param.h b/lightningd/param.h index 89ed4c12f..1aac100ff 100644 --- a/lightningd/param.h +++ b/lightningd/param.h @@ -6,10 +6,10 @@ Typesafe callback system for unmarshalling and validating json parameters. Typical usage: - unsigned cltv; + unsigned *cltv; u64 *msatoshi; const jsmntok_t *note; - u64 expiry; + u64 *expiry; if (!param(cmd, buffer, params, p_req("cltv", json_tok_number, &cltv), @@ -19,131 +19,68 @@ NULL)) return; - At this point in the code you can be assured the json tokens were successfully - parsed. If not, param() returned false, having already called command_fail() - with a descriptive error message. The data section of the json result contains - 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. + See json_invoice() for a good example. The common callbacks can be found in + lightningd/json.c. Use them as an example for writing your own custom + callbacks. */ /* - * 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. */ bool param(struct command *cmd, const char *buffer, const jsmntok_t params[], ...); /* - * The callback provided must follow this signature; e.g., - * bool json_tok_double(const char *buffer, const jsmntok_t *tok, double *arg) - */ -typedef bool(*param_cb)(const char *buffer, const jsmntok_t *tok, void *arg); - -/* - * Advanced callback. Returns NULL on success, error message on failure. + * The callback signature. Callbacks must return true on success. On failure they + * must call comand_fail and return false. */ typedef bool(*param_cbx)(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - void **arg); + const char *name, + const char *buffer, + const jsmntok_t *tok, + void **arg); /* - * Add a handler to unmarshal a required json token into @arg. The handler must - * 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). + * Add a required parameter. */ -#define p_req(name, cb, arg) \ - name"", \ - true, \ - false, \ - (cb), \ - (arg) + 0*sizeof((cb)((const char *)NULL, \ - (const jsmntok_t *)NULL, \ - (arg)) == true), \ - (size_t)0 - -#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 +#define p_req(name, cbx, arg) \ + name"", \ + true, \ + (cbx), \ + (arg) + 0*sizeof((cbx)((struct command *)NULL, \ + (const char *)NULL, \ + (const char *)NULL, \ + (const jsmntok_t *)NULL, \ + (arg)) == true) /* - * Similar to above but for optional parameters. - * @arg must be the address of a pointer. If found during parsing, it will be - * allocated, otherwise it will be set to NULL. + * Add an optional parameter. *arg is set to NULL if it isn't found. */ -#define p_opt(name, cb, arg) \ - name"", \ - false, \ - false, \ - (cb), \ - (arg) + 0*sizeof((cb)((const char *)NULL, \ - (const jsmntok_t *)NULL, \ - *(arg)) == true), \ - sizeof(**(arg)) - -#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)) +#define p_opt(name, cbx, arg) \ + name"", \ + false, \ + (cbx), \ + ({ *arg = NULL; \ + (arg) + 0*sizeof((cbx)((struct command *)NULL, \ + (const char *)NULL, \ + (const char *)NULL, \ + (const jsmntok_t *)NULL, \ + (arg)) == true); }) /* - * Similar to p_req but for optional parameters with defaults. - * @arg will be set to @def if it isn't found during parsing. + * Add an optional parameter. *arg is set to @def if it isn't found. */ -#define p_opt_def(name, cb, arg, def) \ - name"", \ - false, \ - false, \ - (cb), \ - (arg) + 0*sizeof((cb)((const char *)NULL, \ - (const jsmntok_t *)NULL, \ - (arg)) == true), \ - ((void)((*arg) = (def)), (size_t)0) - -#define p_opt_def_tal(name, cbx, arg, def) \ - 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;}) +#define p_opt_def(name, cbx, arg, def) \ + name"", \ + false, \ + (cbx), \ + ({ (*arg) = tal((cmd), typeof(**arg)); \ + (**arg) = (def); \ + (arg) + 0*sizeof((cbx)((struct command *)NULL, \ + (const char *)NULL, \ + (const char *)NULL, \ + (const jsmntok_t *)NULL, \ + (arg)) == true); }) #endif /* LIGHTNING_LIGHTNINGD_PARAM_H */ diff --git a/lightningd/pay.c b/lightningd/pay.c index 6cb19991e..b1fe2f5fd 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -955,10 +955,10 @@ static void json_sendpay(struct command *cmd, const char *description; if (!param(cmd, buffer, params, - p_req_tal("route", json_tok_tok, &routetok), - p_req_tal("payment_hash", json_tok_sha256, &rhash), - p_opt_tal("description", json_tok_tok, &desctok), - p_opt_tal("msatoshi", json_tok_u64, &msatoshi), + p_req("route", json_tok_tok, &routetok), + p_req("payment_hash", json_tok_sha256, &rhash), + p_opt("description", json_tok_tok, &desctok), + p_opt("msatoshi", json_tok_u64, &msatoshi), NULL)) return; @@ -1094,8 +1094,8 @@ static void json_waitsendpay(struct command *cmd, const char *buffer, unsigned int *timeout; if (!param(cmd, buffer, params, - p_req_tal("payment_hash", json_tok_sha256, &rhash), - p_opt_tal("timeout", json_tok_number, &timeout), + p_req("payment_hash", json_tok_sha256, &rhash), + p_opt("timeout", json_tok_number, &timeout), NULL)) return; @@ -1125,8 +1125,8 @@ static void json_listpayments(struct command *cmd, const char *buffer, struct sha256 *rhash = NULL; if (!param(cmd, buffer, params, - p_opt_tal("bolt11", json_tok_tok, &bolt11tok), - p_opt_tal("payment_hash", json_tok_tok, &rhashtok), + p_opt("bolt11", json_tok_tok, &bolt11tok), + p_opt("payment_hash", json_tok_tok, &rhashtok), NULL)) return; diff --git a/lightningd/payalgo.c b/lightningd/payalgo.c index bec0db98d..04f698262 100644 --- a/lightningd/payalgo.c +++ b/lightningd/payalgo.c @@ -627,15 +627,15 @@ static void json_pay(struct command *cmd, unsigned int *exemptfee; if (!param(cmd, buffer, params, - p_req_tal("bolt11", json_tok_tok, &bolt11tok), - p_opt_tal("msatoshi", json_tok_u64, &msatoshi), - p_opt_tal("description", json_tok_tok, &desctok), - p_opt_def_tal("riskfactor", json_tok_double, &riskfactor, 1.0), - p_opt_def_tal("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5), - p_opt_def_tal("retry_for", json_tok_number, &retryfor, 60), - p_opt_def_tal("maxdelay", json_tok_number, &maxdelay, + p_req("bolt11", json_tok_tok, &bolt11tok), + p_opt("msatoshi", json_tok_u64, &msatoshi), + p_opt("description", json_tok_tok, &desctok), + p_opt_def("riskfactor", json_tok_double, &riskfactor, 1.0), + p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5), + p_opt_def("retry_for", json_tok_number, &retryfor, 60), + p_opt_def("maxdelay", json_tok_number, &maxdelay, 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)) return; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 3aae66713..c8f0138df 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -749,8 +749,8 @@ static void json_listpeers(struct command *cmd, struct json_result *response = new_json_result(cmd); if (!param(cmd, buffer, params, - p_opt_tal("id", json_tok_pubkey, &specific_id), - p_opt_tal("level", json_tok_loglevel, &ll), + p_opt("id", json_tok_pubkey, &specific_id), + p_opt("level", json_tok_loglevel, &ll), NULL)) return; @@ -836,9 +836,9 @@ static void json_close(struct command *cmd, bool *force; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_tok, &idtok), - p_opt_def_tal("force", json_tok_bool, &force, false), - p_opt_def_tal("timeout", json_tok_number, &timeout, 30), + p_req("id", json_tok_tok, &idtok), + p_opt_def("force", json_tok_bool, &force, false), + p_opt_def("timeout", json_tok_number, &timeout, 30), NULL)) return; @@ -946,7 +946,7 @@ static void json_disconnect(struct command *cmd, struct channel *channel; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), + p_req("id", json_tok_pubkey, &id), NULL)) return; @@ -988,7 +988,7 @@ static void json_sign_last_tx(struct command *cmd, struct channel *channel; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &peerid), + p_req("id", json_tok_pubkey, &peerid), NULL)) return; @@ -1032,7 +1032,7 @@ static void json_dev_fail(struct command *cmd, struct channel *channel; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &peerid), + p_req("id", json_tok_pubkey, &peerid), NULL)) return; @@ -1078,7 +1078,7 @@ static void json_dev_reenable_commit(struct command *cmd, struct channel *channel; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &peerid), + p_req("id", json_tok_pubkey, &peerid), NULL)) return; @@ -1171,9 +1171,9 @@ static void json_dev_forget_channel(struct command *cmd, const char *buffer, bool *force; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &peerid), - p_opt_tal("short_channel_id", json_tok_short_channel_id, &scid), - p_opt_def_tal("force", json_tok_bool, &force, false), + p_req("id", json_tok_pubkey, &peerid), + p_opt("short_channel_id", json_tok_short_channel_id, &scid), + p_opt_def("force", json_tok_bool, &force, false), NULL)) return; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 1fbb6c913..8a437e989 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1698,8 +1698,8 @@ static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer, bool *ignore; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &peerid), - p_req_tal("ignore", json_tok_bool, &ignore), + p_req("id", json_tok_pubkey, &peerid), + p_req("ignore", json_tok_bool, &ignore), NULL)) return; diff --git a/lightningd/ping.c b/lightningd/ping.c index 4a822d3c2..3b7168a9b 100644 --- a/lightningd/ping.c +++ b/lightningd/ping.c @@ -43,9 +43,9 @@ static void json_ping(struct command *cmd, struct pubkey *id; if (!param(cmd, buffer, params, - p_req_tal("id", json_tok_pubkey, &id), - p_opt_def_tal("len", json_tok_number, &len, 128), - p_opt_def_tal("pongbytes", json_tok_number, &pongbytes, 128), + p_req("id", json_tok_pubkey, &id), + p_opt_def("len", json_tok_number, &len, 128), + p_opt_def("pongbytes", json_tok_number, &pongbytes, 128), NULL)) return; diff --git a/lightningd/test/run-param.c b/lightningd/test/run-param.c index 1dbafa56a..f6b0bb8be 100644 --- a/lightningd/test/run-param.c +++ b/lightningd/test/run-param.c @@ -135,8 +135,8 @@ static void stest(const struct json *j, struct sanity *b) u64 *ival; double *dval; if (!param(cmd, j->buffer, j->toks, - p_req_tal("u64", json_tok_u64, &ival), - p_req_tal("double", json_tok_double, &dval), NULL)) { + p_req("u64", json_tok_u64, &ival), + p_req("double", json_tok_double, &dval), NULL)) { assert(check_fail()); assert(b->failed == true); if (!strstr(fail_msg, b->fail_str)) { @@ -173,7 +173,7 @@ static void tok_tok(void) struct json *j = json_parse(cmd, "{ 'satoshi', '546' }"); 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(json_to_number(j->buffer, tok, &n)); assert(n == 546); @@ -185,7 +185,7 @@ static void tok_tok(void) struct json *j = json_parse(cmd, "{}"); 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 */ assert(tok == NULL); @@ -202,8 +202,8 @@ static void dup_names(void) u64 *i; double *d; assert(!param(cmd, j->buffer, j->toks, - p_req_tal("u64", json_tok_u64, &i), - p_req_tal("double", json_tok_double, &d), NULL)); + p_req("u64", json_tok_u64, &i), + p_req("double", json_tok_double, &d), NULL)); } static void null_params(void) @@ -214,13 +214,13 @@ static void null_params(void) json_parse(cmd, "[ '10', '11', '12', '13', '14', '15', '16']"); assert(param(cmd, j->buffer, j->toks, - p_req_tal("0", json_tok_u64, &intptrs[0]), - p_req_tal("1", json_tok_u64, &intptrs[1]), - p_req_tal("2", json_tok_u64, &intptrs[2]), - p_req_tal("3", json_tok_u64, &intptrs[3]), - p_opt_def_tal("4", json_tok_u64, &intptrs[4], 999), - p_opt_tal("5", json_tok_u64, &intptrs[5]), - p_opt_tal("6", json_tok_u64, &intptrs[6]), + p_req("0", json_tok_u64, &intptrs[0]), + p_req("1", json_tok_u64, &intptrs[1]), + p_req("2", json_tok_u64, &intptrs[2]), + p_req("3", json_tok_u64, &intptrs[3]), + p_opt_def("4", json_tok_u64, &intptrs[4], 999), + p_opt("5", json_tok_u64, &intptrs[5]), + p_opt("6", json_tok_u64, &intptrs[6]), NULL)); for (int i = 0; i < tal_count(intptrs); ++i) { assert(intptrs[i]); @@ -230,13 +230,13 @@ static void null_params(void) /* missing at end */ j = json_parse(cmd, "[ '10', '11', '12', '13', '14']"); assert(param(cmd, j->buffer, j->toks, - p_req_tal("0", json_tok_u64, &intptrs[0]), - p_req_tal("1", json_tok_u64, &intptrs[1]), - p_req_tal("2", json_tok_u64, &intptrs[2]), - p_req_tal("3", json_tok_u64, &intptrs[3]), - p_opt_tal("4", json_tok_u64, &intptrs[4]), - p_opt_tal("5", json_tok_u64, &intptrs[5]), - p_opt_def_tal("6", json_tok_u64, &intptrs[6], 888), + p_req("0", json_tok_u64, &intptrs[0]), + p_req("1", json_tok_u64, &intptrs[1]), + p_req("2", json_tok_u64, &intptrs[2]), + p_req("3", json_tok_u64, &intptrs[3]), + p_opt("4", json_tok_u64, &intptrs[4]), + p_opt("5", json_tok_u64, &intptrs[5]), + p_opt_def("6", json_tok_u64, &intptrs[6], 888), NULL)); assert(*intptrs[0] == 10); assert(*intptrs[1] == 11); @@ -260,35 +260,35 @@ static void bad_programmer(void) /* check for repeated names */ assert(!param(cmd, j->buffer, j->toks, - p_req_tal("repeat", json_tok_u64, &ival), - p_req_tal("double", json_tok_double, &dval), - p_req_tal("repeat", json_tok_u64, &ival2), NULL)); + p_req("repeat", json_tok_u64, &ival), + p_req("double", json_tok_double, &dval), + p_req("repeat", json_tok_u64, &ival2), NULL)); assert(check_fail()); assert(strstr(fail_msg, "developer error")); assert(!param(cmd, j->buffer, j->toks, - p_req_tal("repeat", json_tok_u64, &ival), - p_req_tal("double", json_tok_double, &dval), - p_req_tal("repeat", json_tok_u64, &ival), NULL)); + p_req("repeat", json_tok_u64, &ival), + p_req("double", json_tok_double, &dval), + p_req("repeat", json_tok_u64, &ival), NULL)); assert(check_fail()); assert(strstr(fail_msg, "developer error")); assert(!param(cmd, j->buffer, j->toks, - p_req_tal("u64", json_tok_u64, &ival), - p_req_tal("repeat", json_tok_double, &dval), - p_req_tal("repeat", json_tok_double, &dval), NULL)); + p_req("u64", json_tok_u64, &ival), + p_req("repeat", json_tok_double, &dval), + p_req("repeat", json_tok_double, &dval), NULL)); assert(check_fail()); assert(strstr(fail_msg, "developer error")); /* check for repeated arguments */ assert(!param(cmd, j->buffer, j->toks, - p_req_tal("u64", json_tok_u64, &ival), - p_req_tal("repeated-arg", json_tok_u64, &ival), NULL)); + p_req("u64", json_tok_u64, &ival), + p_req("repeated-arg", json_tok_u64, &ival), NULL)); assert(check_fail()); assert(strstr(fail_msg, "developer error")); 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(strstr(fail_msg, "developer error")); @@ -297,10 +297,10 @@ static void bad_programmer(void) unsigned int *msatoshi; double *riskfactor; assert(!param(cmd, j->buffer, j->toks, - p_req_tal("u64", json_tok_u64, &ival), - p_req_tal("double", json_tok_double, &dval), - p_opt_def_tal("msatoshi", json_tok_number, &msatoshi, 100), - p_req_tal("riskfactor", json_tok_double, &riskfactor), NULL)); + p_req("u64", json_tok_u64, &ival), + p_req("double", json_tok_double, &dval), + p_opt_def("msatoshi", json_tok_number, &msatoshi, 100), + p_req("riskfactor", json_tok_double, &riskfactor), NULL)); assert(*msatoshi); assert(*msatoshi == 100); assert(check_fail()); @@ -317,7 +317,6 @@ static void add_members(struct param **params, json_add_num(obj, name, i); json_add_num(arr, NULL, i); param_add(params, name, true, - NULL, typesafe_cb_preargs(bool, void **, json_tok_number, &ints[i], @@ -325,7 +324,7 @@ static void add_members(struct param **params, const char *, const char *, const jsmntok_t *), - &ints[i], 0); + &ints[i]); } } @@ -374,10 +373,10 @@ static void sendpay(void) unsigned *cltv; if (!param(cmd, j->buffer, j->toks, - p_req_tal("route", json_tok_tok, &routetok), - p_req_tal("cltv", json_tok_number, &cltv), - p_opt_tal("note", json_tok_tok, ¬e), - p_opt_tal("msatoshi", json_tok_u64, &msatoshi), + p_req("route", json_tok_tok, &routetok), + p_req("cltv", json_tok_number, &cltv), + p_opt("note", json_tok_tok, ¬e), + p_opt("msatoshi", json_tok_u64, &msatoshi), NULL)) assert(false); @@ -397,10 +396,10 @@ static void sendpay_nulltok(void) unsigned *cltv; if (!param(cmd, j->buffer, j->toks, - p_req_tal("route", json_tok_tok, &routetok), - p_req_tal("cltv", json_tok_number, &cltv), - p_opt_tal("note", json_tok_tok, ¬e), - p_opt_tal("msatoshi", json_tok_u64, &msatoshi), + p_req("route", json_tok_tok, &routetok), + p_req("cltv", json_tok_number, &cltv), + p_opt("note", json_tok_tok, ¬e), + p_opt("msatoshi", json_tok_u64, &msatoshi), NULL)) assert(false); @@ -474,11 +473,11 @@ static void advanced(void) const jsmntok_t *tok; assert(param(cmd, j->buffer, j->toks, - p_req_tal("description", json_tok_label_x, &label), - p_req_tal("msat", json_tok_msat, &msat), - p_req_tal("tok", json_tok_tok, &tok), - p_opt_tal("msat_opt1", json_tok_msat, &msat_opt1), - p_opt_tal("msat_opt2", json_tok_msat, &msat_opt2), + p_req("description", json_tok_label_x, &label), + p_req("msat", json_tok_msat, &msat), + p_req("tok", json_tok_tok, &tok), + p_opt("msat_opt1", json_tok_msat, &msat_opt1), + p_opt("msat_opt2", json_tok_msat, &msat_opt2), NULL)); assert(label != NULL); assert(!strcmp(label->s, "lightning")); @@ -492,8 +491,8 @@ static void advanced(void) struct json *j = json_parse(cmd, "[ 3 'foo' ]"); struct json_escaped *label, *foo; assert(param(cmd, j->buffer, j->toks, - p_req_tal("label", json_tok_label_x, &label), - p_opt_tal("foo", json_tok_label_x, &foo), + p_req("label", json_tok_label_x, &label), + p_opt("foo", json_tok_label_x, &foo), NULL)); assert(!strcmp(label->s, "3")); assert(!strcmp(foo->s, "foo")); @@ -503,8 +502,8 @@ static void advanced(void) u64 *msat2; struct json *j = json_parse(cmd, "[ 3 ]"); assert(param(cmd, j->buffer, j->toks, - p_opt_def_tal("msat", json_tok_msat, &msat, 23), - p_opt_def_tal("msat2", json_tok_msat, &msat2, 53), + p_opt_def("msat", json_tok_msat, &msat, 23), + p_opt_def("msat2", json_tok_msat, &msat2, 53), NULL)); assert(*msat == 3); assert(msat2); @@ -518,7 +517,7 @@ static void advanced_fail(void) struct json *j = json_parse(cmd, "[ 'anyx' ]"); u64 *msat; assert(!param(cmd, j->buffer, j->toks, - p_req_tal("msat", json_tok_msat, &msat), + p_req("msat", json_tok_msat, &msat), NULL)); assert(check_fail()); assert(strstr(fail_msg, "'msat' should be a positive" diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 715d48358..92da7c10f 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -99,8 +99,8 @@ static void json_withdraw(struct command *cmd, wtx_init(cmd, &withdraw->wtx); if (!param(cmd, buffer, params, - p_req_tal("destination", json_tok_tok, &desttok), - p_req_tal("satoshi", json_tok_tok, &sattok), + p_req("destination", json_tok_tok, &desttok), + p_req("satoshi", json_tok_tok, &sattok), NULL)) return; @@ -246,7 +246,7 @@ static void json_newaddr(struct command *cmd, const char *buffer UNUSED, char *out; 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)) return; @@ -302,7 +302,7 @@ static void json_listaddrs(struct command *cmd, u64 *bip32_max_index; 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, "bip32_max_index", 0)), NULL))