mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
Modern param style for chaintopology.c, ...
connect_control.c, dev_ping.c, gossip_control.c, invoice.c. This converts about 50% of all calls of `json_get_params` to `param`. After trying (and failing) to squash and rebase #1682 I just made a new branch from a patch file and closed #1682. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
232b330284
commit
b876c601a6
@ -5,7 +5,6 @@
|
|||||||
#include "bitcoind.h"
|
#include "bitcoind.h"
|
||||||
#include "chaintopology.h"
|
#include "chaintopology.h"
|
||||||
#include "jsonrpc.h"
|
#include "jsonrpc.h"
|
||||||
#include "jsonrpc_errors.h"
|
|
||||||
#include "lightningd.h"
|
#include "lightningd.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
@ -20,6 +19,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <lightningd/channel_control.h>
|
#include <lightningd/channel_control.h>
|
||||||
#include <lightningd/gossip_control.h>
|
#include <lightningd/gossip_control.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
|
|
||||||
/* Mutual recursion via timer. */
|
/* Mutual recursion via timer. */
|
||||||
static void try_extend_tip(struct chain_topology *topo);
|
static void try_extend_tip(struct chain_topology *topo);
|
||||||
@ -589,18 +589,9 @@ u32 get_feerate(const struct chain_topology *topo, enum feerate feerate)
|
|||||||
static void json_dev_setfees(struct command *cmd,
|
static void json_dev_setfees(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *ratetok[NUM_FEERATES];
|
|
||||||
struct chain_topology *topo = cmd->ld->topology;
|
struct chain_topology *topo = cmd->ld->topology;
|
||||||
struct json_result *response;
|
struct json_result *response;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
|
||||||
"?immediate", &ratetok[FEERATE_IMMEDIATE],
|
|
||||||
"?normal", &ratetok[FEERATE_NORMAL],
|
|
||||||
"?slow", &ratetok[FEERATE_SLOW],
|
|
||||||
NULL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!topo->dev_override_fee_rate) {
|
if (!topo->dev_override_fee_rate) {
|
||||||
u32 fees[NUM_FEERATES];
|
u32 fees[NUM_FEERATES];
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(fees); i++)
|
for (size_t i = 0; i < ARRAY_SIZE(fees); i++)
|
||||||
@ -608,18 +599,20 @@ static void json_dev_setfees(struct command *cmd,
|
|||||||
topo->dev_override_fee_rate = tal_dup_arr(topo, u32, fees,
|
topo->dev_override_fee_rate = tal_dup_arr(topo, u32, fees,
|
||||||
ARRAY_SIZE(fees), 0);
|
ARRAY_SIZE(fees), 0);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < NUM_FEERATES; i++) {
|
|
||||||
if (!ratetok[i])
|
if (!param(cmd, buffer, params,
|
||||||
continue;
|
p_opt_def("immediate", json_tok_number,
|
||||||
if (!json_tok_number(buffer, ratetok[i],
|
&topo->dev_override_fee_rate[FEERATE_IMMEDIATE],
|
||||||
&topo->dev_override_fee_rate[i])) {
|
topo->dev_override_fee_rate[FEERATE_IMMEDIATE]),
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
p_opt_def("normal", json_tok_number,
|
||||||
"Invalid feerate %.*s",
|
&topo->dev_override_fee_rate[FEERATE_NORMAL],
|
||||||
ratetok[i]->end - ratetok[i]->start,
|
topo->dev_override_fee_rate[FEERATE_NORMAL]),
|
||||||
buffer + ratetok[i]->start);
|
p_opt_def("slow", json_tok_number,
|
||||||
return;
|
&topo->dev_override_fee_rate[FEERATE_SLOW],
|
||||||
}
|
topo->dev_override_fee_rate[FEERATE_SLOW]),
|
||||||
}
|
NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
log_debug(topo->log,
|
log_debug(topo->log,
|
||||||
"dev-setfees: fees now %u/%u/%u",
|
"dev-setfees: fees now %u/%u/%u",
|
||||||
topo->dev_override_fee_rate[FEERATE_IMMEDIATE],
|
topo->dev_override_fee_rate[FEERATE_IMMEDIATE],
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <lightningd/jsonrpc_errors.h>
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
#include <lightningd/subd.h>
|
#include <lightningd/subd.h>
|
||||||
|
|
||||||
struct connect {
|
struct connect {
|
||||||
@ -80,7 +81,8 @@ void gossip_connect_result(struct lightningd *ld, const u8 *msg)
|
|||||||
static void json_connect(struct command *cmd,
|
static void json_connect(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *hosttok, *porttok, *idtok;
|
const jsmntok_t *hosttok, *porttok;
|
||||||
|
jsmntok_t *idtok;
|
||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
char *id_str;
|
char *id_str;
|
||||||
char *atptr;
|
char *atptr;
|
||||||
@ -90,13 +92,12 @@ static void json_connect(struct command *cmd,
|
|||||||
u8 *msg;
|
u8 *msg;
|
||||||
const char *err_msg;
|
const char *err_msg;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_tok, (const jsmntok_t **) &idtok),
|
||||||
"?host", &hosttok,
|
p_opt_tok("host", &hosttok),
|
||||||
"?port", &porttok,
|
p_opt_tok("port", &porttok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for id@addrport form */
|
/* Check for id@addrport form */
|
||||||
id_str = tal_strndup(cmd, buffer + idtok->start,
|
id_str = tal_strndup(cmd, buffer + idtok->start,
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <lightningd/jsonrpc_errors.h>
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
#include <lightningd/peer_control.h>
|
#include <lightningd/peer_control.h>
|
||||||
#include <lightningd/subd.h>
|
#include <lightningd/subd.h>
|
||||||
|
|
||||||
@ -42,28 +43,16 @@ static void json_dev_ping(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
jsmntok_t *idtok, *lentok, *pongbytestok;
|
|
||||||
unsigned int len, pongbytes;
|
unsigned int len, pongbytes;
|
||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
struct subd *owner;
|
struct subd *owner;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_pubkey, &id),
|
||||||
"len", &lentok,
|
p_req("len", json_tok_number, &len),
|
||||||
"pongbytes", &pongbytestok,
|
p_req("pongbytes", json_tok_number, &pongbytes),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: These checks are horrible, use a peer flag to say it's
|
|
||||||
* ready to forward! */
|
|
||||||
if (!json_tok_number(buffer, lentok, &len)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
lentok->end - lentok->start,
|
|
||||||
buffer + lentok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* BOLT #1:
|
/* BOLT #1:
|
||||||
*
|
*
|
||||||
@ -85,14 +74,6 @@ static void json_dev_ping(struct command *cmd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_tok_number(buffer, pongbytestok, &pongbytes)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
pongbytestok->end - pongbytestok->start,
|
|
||||||
buffer + pongbytestok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Note that > 65531 is valid: it means "no pong reply" */
|
/* Note that > 65531 is valid: it means "no pong reply" */
|
||||||
if (pongbytes > 65535) {
|
if (pongbytes > 65535) {
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
@ -100,14 +81,6 @@ static void json_dev_ping(struct command *cmd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid pubkey",
|
|
||||||
idtok->end - idtok->start,
|
|
||||||
buffer + idtok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First, see if it's in channeld. */
|
/* First, see if it's in channeld. */
|
||||||
peer = peer_by_id(cmd->ld, &id);
|
peer = peer_by_id(cmd->ld, &id);
|
||||||
if (peer) {
|
if (peer) {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <lightningd/jsonrpc.h>
|
#include <lightningd/jsonrpc.h>
|
||||||
#include <lightningd/jsonrpc_errors.h>
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
#include <sodium/randombytes.h>
|
#include <sodium/randombytes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wire/gen_peer_wire.h>
|
#include <wire/gen_peer_wire.h>
|
||||||
@ -332,22 +333,12 @@ static void json_listnodes(struct command *cmd, const char *buffer,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *req;
|
u8 *req;
|
||||||
jsmntok_t *idtok = NULL;
|
struct pubkey *id;
|
||||||
struct pubkey *id = NULL;
|
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"?id", &idtok,
|
p_opt("id", json_tok_pubkey, &id),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (idtok) {
|
|
||||||
id = tal_arr(cmd, struct pubkey, 1);
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req = towire_gossip_getnodes_request(cmd, id);
|
req = towire_gossip_getnodes_request(cmd, id);
|
||||||
subd_req(cmd, cmd->ld->gossip, req, -1, 0, json_getnodes_reply, cmd);
|
subd_req(cmd, cmd->ld->gossip, req, -1, 0, json_getnodes_reply, cmd);
|
||||||
@ -384,72 +375,31 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con
|
|||||||
static void json_getroute(struct command *cmd, const char *buffer, const jsmntok_t *params)
|
static void json_getroute(struct command *cmd, const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
struct lightningd *ld = cmd->ld;
|
struct lightningd *ld = cmd->ld;
|
||||||
struct pubkey source = ld->id, destination;
|
struct pubkey destination;
|
||||||
jsmntok_t *idtok, *msatoshitok, *riskfactortok, *cltvtok, *fromidtok;
|
struct pubkey source;
|
||||||
jsmntok_t *fuzztok;
|
|
||||||
jsmntok_t *seedtok;
|
jsmntok_t *seedtok;
|
||||||
u64 msatoshi;
|
u64 msatoshi;
|
||||||
unsigned cltv = 9;
|
unsigned cltv;
|
||||||
double riskfactor;
|
double riskfactor;
|
||||||
/* Higher fuzz means that some high-fee paths can be discounted
|
/* Higher fuzz means that some high-fee paths can be discounted
|
||||||
* for an even larger value, increasing the scope for route
|
* for an even larger value, increasing the scope for route
|
||||||
* randomization (the higher-fee paths become more likely to
|
* randomization (the higher-fee paths become more likely to
|
||||||
* be selected) at the cost of increasing the probability of
|
* be selected) at the cost of increasing the probability of
|
||||||
* selecting the higher-fee paths. */
|
* selecting the higher-fee paths. */
|
||||||
double fuzz = 75.0;
|
double fuzz;
|
||||||
struct siphash_seed seed;
|
struct siphash_seed seed;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_pubkey, &destination),
|
||||||
"msatoshi", &msatoshitok,
|
p_req("msatoshi", json_tok_u64, &msatoshi),
|
||||||
"riskfactor", &riskfactortok,
|
p_req("riskfactor", json_tok_double, &riskfactor),
|
||||||
"?cltv", &cltvtok,
|
p_opt_def("cltv", json_tok_number, &cltv, 9),
|
||||||
"?fromid", &fromidtok,
|
p_opt_def("fromid", json_tok_pubkey, &source, ld->id),
|
||||||
"?fuzzpercent", &fuzztok,
|
p_opt_def("fuzzpercent", json_tok_double, &fuzz, 75.0),
|
||||||
"?seed", &seedtok,
|
p_opt_tok("seed", &seedtok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, &destination)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cltvtok && !json_tok_number(buffer, cltvtok, &cltv)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid cltv");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_u64(buffer, msatoshitok, &msatoshi)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
msatoshitok->end - msatoshitok->start,
|
|
||||||
buffer + msatoshitok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_double(buffer, riskfactortok, &riskfactor)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid double",
|
|
||||||
riskfactortok->end - riskfactortok->start,
|
|
||||||
buffer + riskfactortok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fromidtok && !json_tok_pubkey(buffer, fromidtok, &source)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid from id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fuzztok &&
|
|
||||||
!json_tok_double(buffer, fuzztok, &fuzz)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid double",
|
|
||||||
fuzztok->end - fuzztok->start,
|
|
||||||
buffer + fuzztok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(0.0 <= fuzz && fuzz <= 100.0)) {
|
if (!(0.0 <= fuzz && fuzz <= 100.0)) {
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"fuzz must be in range 0.0 <= %f <= 100.0",
|
"fuzz must be in range 0.0 <= %f <= 100.0",
|
||||||
@ -531,23 +481,11 @@ static void json_listchannels(struct command *cmd, const char *buffer,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *req;
|
u8 *req;
|
||||||
jsmntok_t *idtok;
|
struct short_channel_id *id;
|
||||||
struct short_channel_id *id = NULL;
|
if (!param(cmd, buffer, params,
|
||||||
|
p_opt("short_channel_id", json_tok_short_channel_id, &id),
|
||||||
if (!json_get_params(cmd, buffer, params,
|
NULL))
|
||||||
"?short_channel_id", &idtok,
|
|
||||||
NULL)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (idtok) {
|
|
||||||
id = tal_arr(cmd, struct short_channel_id, 1);
|
|
||||||
if (!json_tok_short_channel_id(buffer, idtok, id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"Invalid short_channel_id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req = towire_gossip_getchannels_request(cmd, id);
|
req = towire_gossip_getchannels_request(cmd, id);
|
||||||
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
||||||
@ -591,26 +529,17 @@ static void json_dev_query_scids(struct command *cmd,
|
|||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
jsmntok_t *idtok, *scidstok;
|
const jsmntok_t *scidstok;
|
||||||
const jsmntok_t *t, *end;
|
const jsmntok_t *t, *end;
|
||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
struct short_channel_id *scids;
|
struct short_channel_id *scids;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_pubkey, &id),
|
||||||
"scids", &scidstok,
|
p_req("scids", json_tok_tok, &scidstok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid id",
|
|
||||||
idtok->end - idtok->start,
|
|
||||||
buffer + idtok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scidstok->type != JSMN_ARRAY) {
|
if (scidstok->type != JSMN_ARRAY) {
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
@ -651,32 +580,15 @@ static void json_dev_send_timestamp_filter(struct command *cmd,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
jsmntok_t *idtok, *firsttok, *rangetok;
|
|
||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
u32 first, range;
|
u32 first, range;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_pubkey, &id),
|
||||||
"first", &firsttok,
|
p_req("first", json_tok_number, &first),
|
||||||
"range", &rangetok,
|
p_req("range", json_tok_number, &range),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid id",
|
|
||||||
idtok->end - idtok->start,
|
|
||||||
buffer + idtok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_number(buffer, firsttok, &first)
|
|
||||||
|| !json_tok_number(buffer, rangetok, &range)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"bad first or range numbers");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_debug(cmd->ld->log, "Setting timestamp range %u+%u", first, range);
|
log_debug(cmd->ld->log, "Setting timestamp range %u+%u", first, range);
|
||||||
/* Tell gossipd, since this is a gossip query. */
|
/* Tell gossipd, since this is a gossip query. */
|
||||||
@ -736,32 +648,15 @@ static void json_dev_query_channel_range(struct command *cmd,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
jsmntok_t *idtok, *firsttok, *numtok;
|
|
||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
u32 first, num;
|
u32 first, num;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"id", &idtok,
|
p_req("id", json_tok_pubkey, &id),
|
||||||
"first", &firsttok,
|
p_req("first", json_tok_number, &first),
|
||||||
"num", &numtok,
|
p_req("num", json_tok_number, &num),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid id",
|
|
||||||
idtok->end - idtok->start,
|
|
||||||
buffer + idtok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_number(buffer, firsttok, &first)
|
|
||||||
|| !json_tok_number(buffer, numtok, &num)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"first and num must be numbers");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tell gossipd, since this is a gossip query. */
|
/* Tell gossipd, since this is a gossip query. */
|
||||||
msg = towire_gossip_query_channel_range(cmd, &id, first, num);
|
msg = towire_gossip_query_channel_range(cmd, &id, first, num);
|
||||||
@ -782,20 +677,12 @@ static void json_dev_set_max_scids_encode_size(struct command *cmd,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
jsmntok_t *maxtok;
|
|
||||||
u32 max;
|
u32 max;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"max", &maxtok,
|
p_req("max", json_tok_number, &max),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_tok_number(buffer, maxtok, &max)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"max must be a number");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = towire_gossip_dev_set_max_scids_encode_size(NULL, max);
|
msg = towire_gossip_dev_set_max_scids_encode_size(NULL, max);
|
||||||
subd_send_msg(cmd->ld->gossip, take(msg));
|
subd_send_msg(cmd->ld->gossip, take(msg));
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <lightningd/jsonrpc_errors.h>
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
#include <lightningd/options.h>
|
#include <lightningd/options.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
#include <sodium/randombytes.h>
|
#include <sodium/randombytes.h>
|
||||||
#include <wire/wire_sync.h>
|
#include <wire/wire_sync.h>
|
||||||
|
|
||||||
@ -158,8 +159,8 @@ static void json_invoice(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct invoice invoice;
|
struct invoice invoice;
|
||||||
struct invoice_details details;
|
struct invoice_details details;
|
||||||
jsmntok_t *msatoshi, *label, *desctok, *exp, *fallback, *fallbacks;
|
const jsmntok_t *msatoshi, *label, *desctok, *fallback, *fallbacks;
|
||||||
jsmntok_t *preimagetok;
|
const jsmntok_t *preimagetok;
|
||||||
u64 *msatoshi_val;
|
u64 *msatoshi_val;
|
||||||
const struct json_escaped *label_val, *desc;
|
const struct json_escaped *label_val, *desc;
|
||||||
const char *desc_val;
|
const char *desc_val;
|
||||||
@ -168,20 +169,19 @@ static void json_invoice(struct command *cmd,
|
|||||||
struct bolt11 *b11;
|
struct bolt11 *b11;
|
||||||
char *b11enc;
|
char *b11enc;
|
||||||
const u8 **fallback_scripts = NULL;
|
const u8 **fallback_scripts = NULL;
|
||||||
u64 expiry = 3600;
|
u64 expiry;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"msatoshi", &msatoshi,
|
p_req("msatoshi", json_tok_tok, &msatoshi),
|
||||||
"label", &label,
|
p_req("label", json_tok_tok, &label),
|
||||||
"description", &desctok,
|
p_req("description", json_tok_tok, &desctok),
|
||||||
"?expiry", &exp,
|
p_opt_def("expiry", json_tok_u64, &expiry, 3600),
|
||||||
"?fallback", &fallback,
|
p_opt_tok("fallback", &fallback),
|
||||||
"?fallbacks", &fallbacks,
|
p_opt_tok("fallbacks", &fallbacks),
|
||||||
"?preimage", &preimagetok,
|
p_opt_tok("preimage", &preimagetok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Get arguments. */
|
/* Get arguments. */
|
||||||
/* msatoshi */
|
/* msatoshi */
|
||||||
@ -244,14 +244,6 @@ static void json_invoice(struct command *cmd,
|
|||||||
strlen(desc_val));
|
strlen(desc_val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* expiry */
|
|
||||||
if (exp && !json_tok_u64(buffer, exp, &expiry)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"Expiry '%.*s' invalid seconds",
|
|
||||||
exp->end - exp->start,
|
|
||||||
buffer + exp->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fallback addresses */
|
/* fallback addresses */
|
||||||
if (fallback) {
|
if (fallback) {
|
||||||
@ -405,16 +397,15 @@ static void json_listinvoice_internal(struct command *cmd,
|
|||||||
const jsmntok_t *params,
|
const jsmntok_t *params,
|
||||||
bool modern)
|
bool modern)
|
||||||
{
|
{
|
||||||
jsmntok_t *labeltok = NULL;
|
jsmntok_t *labeltok;
|
||||||
struct json_escaped *label;
|
struct json_escaped *label;
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"?label", &labeltok,
|
p_opt_tok("label", &labeltok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (labeltok) {
|
if (labeltok) {
|
||||||
label = json_tok_label(cmd, buffer, labeltok);
|
label = json_tok_label(cmd, buffer, labeltok);
|
||||||
@ -473,18 +464,17 @@ static void json_delinvoice(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct invoice i;
|
struct invoice i;
|
||||||
struct invoice_details details;
|
struct invoice_details details;
|
||||||
jsmntok_t *labeltok, *statustok;
|
const jsmntok_t *labeltok, *statustok;
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
const char *status, *actual_status;
|
const char *status, *actual_status;
|
||||||
struct json_escaped *label;
|
struct json_escaped *label;
|
||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"label", &labeltok,
|
p_req("label", json_tok_tok, &labeltok),
|
||||||
"status", &statustok,
|
p_req("status", json_tok_tok, &statustok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
label = json_tok_label(cmd, buffer, labeltok);
|
label = json_tok_label(cmd, buffer, labeltok);
|
||||||
if (!label) {
|
if (!label) {
|
||||||
@ -536,25 +526,14 @@ AUTODATA(json_command, &delinvoice_command);
|
|||||||
static void json_delexpiredinvoice(struct command *cmd, const char *buffer,
|
static void json_delexpiredinvoice(struct command *cmd, const char *buffer,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *maxexpirytimetok;
|
u64 maxexpirytime;
|
||||||
u64 maxexpirytime = time_now().ts.tv_sec;
|
|
||||||
struct json_result *result;
|
struct json_result *result;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"?maxexpirytime", &maxexpirytimetok,
|
p_opt_def("maxexpirytime", json_tok_u64, &maxexpirytime,
|
||||||
NULL)) {
|
time_now().ts.tv_sec),
|
||||||
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (maxexpirytimetok) {
|
|
||||||
if (!json_tok_u64(buffer, maxexpirytimetok, &maxexpirytime)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
maxexpirytimetok->end - maxexpirytimetok->start,
|
|
||||||
buffer + maxexpirytimetok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wallet_invoice_delete_expired(cmd->ld->wallet, maxexpirytime);
|
wallet_invoice_delete_expired(cmd->ld->wallet, maxexpirytime);
|
||||||
|
|
||||||
@ -574,37 +553,15 @@ static void json_autocleaninvoice(struct command *cmd,
|
|||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *cycletok;
|
u64 cycle;
|
||||||
jsmntok_t *exbytok;
|
u64 exby;
|
||||||
u64 cycle = 3600;
|
|
||||||
u64 exby = 86400;
|
|
||||||
struct json_result *result;
|
struct json_result *result;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"?cycle_seconds", &cycletok,
|
p_opt_def("cycle_seconds", json_tok_u64, &cycle, 3600),
|
||||||
"?expired_by", &exbytok,
|
p_opt_def("expired_by", json_tok_u64, &exby, 86400),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (cycletok) {
|
|
||||||
if (!json_tok_u64(buffer, cycletok, &cycle)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
cycletok->end - cycletok->start,
|
|
||||||
buffer + cycletok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (exbytok) {
|
|
||||||
if (!json_tok_u64(buffer, exbytok, &exby)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
exbytok->end - exbytok->start,
|
|
||||||
buffer + exbytok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wallet_invoice_autoclean(cmd->ld->wallet, cycle, exby);
|
wallet_invoice_autoclean(cmd->ld->wallet, cycle, exby);
|
||||||
|
|
||||||
@ -625,27 +582,13 @@ AUTODATA(json_command, &autocleaninvoice_command);
|
|||||||
static void json_waitanyinvoice(struct command *cmd,
|
static void json_waitanyinvoice(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *pay_indextok;
|
|
||||||
u64 pay_index;
|
u64 pay_index;
|
||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"?lastpay_index", &pay_indextok,
|
p_opt_def("lastpay_index", json_tok_u64, &pay_index, 0),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!pay_indextok) {
|
|
||||||
pay_index = 0;
|
|
||||||
} else {
|
|
||||||
if (!json_tok_u64(buffer, pay_indextok, &pay_index)) {
|
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%.*s' is not a valid number",
|
|
||||||
pay_indextok->end - pay_indextok->start,
|
|
||||||
buffer + pay_indextok->start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set command as pending. We do not know if
|
/* Set command as pending. We do not know if
|
||||||
* wallet_invoice_waitany will return immediately
|
* wallet_invoice_waitany will return immediately
|
||||||
@ -676,12 +619,13 @@ static void json_waitinvoice(struct command *cmd,
|
|||||||
struct invoice i;
|
struct invoice i;
|
||||||
struct invoice_details details;
|
struct invoice_details details;
|
||||||
struct wallet *wallet = cmd->ld->wallet;
|
struct wallet *wallet = cmd->ld->wallet;
|
||||||
jsmntok_t *labeltok;
|
const jsmntok_t *labeltok;
|
||||||
struct json_escaped *label;
|
struct json_escaped *label;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params, "label", &labeltok, NULL)) {
|
if (!param(cmd, buffer, params,
|
||||||
|
p_req("label", json_tok_tok, &labeltok),
|
||||||
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Search for invoice */
|
/* Search for invoice */
|
||||||
label = json_tok_label(cmd, buffer, labeltok);
|
label = json_tok_label(cmd, buffer, labeltok);
|
||||||
@ -756,17 +700,16 @@ static void json_add_fallback(struct json_result *response,
|
|||||||
static void json_decodepay(struct command *cmd,
|
static void json_decodepay(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *bolt11tok, *desctok;
|
const jsmntok_t *bolt11tok, *desctok;
|
||||||
struct bolt11 *b11;
|
struct bolt11 *b11;
|
||||||
struct json_result *response;
|
struct json_result *response;
|
||||||
char *str, *desc, *fail;
|
char *str, *desc, *fail;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
"bolt11", &bolt11tok,
|
p_req("bolt11", json_tok_tok, &bolt11tok),
|
||||||
"?description", &desctok,
|
p_opt_tok("description", &desctok),
|
||||||
NULL)) {
|
NULL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
str = tal_strndup(cmd, buffer + bolt11tok->start,
|
str = tal_strndup(cmd, buffer + bolt11tok->start,
|
||||||
bolt11tok->end - bolt11tok->start);
|
bolt11tok->end - bolt11tok->start);
|
||||||
|
Loading…
Reference in New Issue
Block a user