mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
params: removed the param_opt_tok macro
There doesn't seeem to be a need for this anymore (unless I'm missing something). I added the sendpay_nulltok() unit test to confirm. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
1b50ea2abd
commit
7d9ad89010
2 changed files with 28 additions and 15 deletions
|
@ -15,7 +15,7 @@ struct param;
|
|||
|
||||
if (!param_parse(cmd, buffer, tokens,
|
||||
param_req("cltv", json_tok_number, &cltv),
|
||||
param_opt_tok("note", ¬e),
|
||||
param_opt("note", json_tok_tok, ¬e),
|
||||
param_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||
NULL))
|
||||
return;
|
||||
|
@ -67,7 +67,9 @@ typedef bool(*param_cb)(const char *buffer, const jsmntok_t *tok, void *arg);
|
|||
const jsmntok_t *), \
|
||||
(arg), 0
|
||||
/*
|
||||
* Same as above but for optional parameters.
|
||||
* 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.
|
||||
*/
|
||||
#define param_opt(name, cb, arg) \
|
||||
name"", \
|
||||
|
@ -77,15 +79,4 @@ typedef bool(*param_cb)(const char *buffer, const jsmntok_t *tok, void *arg);
|
|||
const jsmntok_t *), \
|
||||
(arg), sizeof(**arg)
|
||||
|
||||
/*
|
||||
* For when you want an optional raw token.
|
||||
*
|
||||
* Note: weird sizeof() does type check that arg really is a (const) jsmntok_t **.
|
||||
*/
|
||||
#define param_opt_tok(name, arg) \
|
||||
name"", \
|
||||
json_tok_tok, \
|
||||
(arg) + 0*sizeof(*(arg) == (jsmntok_t *)NULL), \
|
||||
sizeof(const jsmntok_t *)
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PARAMS_H */
|
||||
|
|
|
@ -175,7 +175,7 @@ static void tok_tok(void)
|
|||
|
||||
struct json *j = json_parse(cmd, "{}");
|
||||
assert(param_parse(cmd, j->buffer, j->toks,
|
||||
param_opt_tok("satoshi", &tok), NULL));
|
||||
param_opt("satoshi", json_tok_tok, &tok), NULL));
|
||||
|
||||
/* make sure it *is* NULL */
|
||||
assert(tok == NULL);
|
||||
|
@ -417,16 +417,37 @@ static void sendpay(void)
|
|||
if (!param_parse(cmd, j->buffer, j->toks,
|
||||
param_req("route", json_tok_tok, &routetok),
|
||||
param_req("cltv", json_tok_number, &cltv),
|
||||
param_opt_tok("note", ¬e),
|
||||
param_opt("note", json_tok_tok, ¬e),
|
||||
param_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||
NULL))
|
||||
assert(false);
|
||||
|
||||
assert(note);
|
||||
assert(!strncmp("hello there", j->buffer + note->start, note->end - note->start));
|
||||
assert(msatoshi);
|
||||
assert(*msatoshi == 547);
|
||||
}
|
||||
|
||||
static void sendpay_nulltok(void)
|
||||
{
|
||||
struct json *j = json_parse(cmd, "[ 'A', '123']");
|
||||
|
||||
const jsmntok_t *routetok, *note = (void *) 65535;
|
||||
u64 *msatoshi;
|
||||
unsigned cltv;
|
||||
|
||||
if (!param_parse(cmd, j->buffer, j->toks,
|
||||
param_req("route", json_tok_tok, &routetok),
|
||||
param_req("cltv", json_tok_number, &cltv),
|
||||
param_opt("note", json_tok_tok, ¬e),
|
||||
param_opt("msatoshi", json_tok_u64, &msatoshi),
|
||||
NULL))
|
||||
assert(false);
|
||||
|
||||
assert(note == NULL);
|
||||
assert(msatoshi == NULL);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setup_locale();
|
||||
|
@ -444,6 +465,7 @@ int main(void)
|
|||
dup_names();
|
||||
five_hundred_params();
|
||||
sendpay();
|
||||
sendpay_nulltok();
|
||||
tal_free(tmpctx);
|
||||
printf("run-params ok\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue