Browse Source

jsonrpc: add the obj token to the callback.

This (will) avoid the plugin having to walk back from the params object
as it currently does.

No code changes; I removed UNUSED and UNNEEDED labels from the other
parameters though (as *every* json_rpc callback needs to call param()
these days, they're *always* used).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
plugin-6
Rusty Russell 6 years ago
parent
commit
8015e7dcfb
  1. 4
      lightningd/chaintopology.c
  2. 4
      lightningd/connect_control.c
  3. 25
      lightningd/gossip_control.c
  4. 29
      lightningd/invoice.c
  5. 34
      lightningd/jsonrpc.c
  6. 4
      lightningd/jsonrpc.h
  7. 4
      lightningd/log.c
  8. 10
      lightningd/memdump.c
  9. 4
      lightningd/opening_control.c
  10. 4
      lightningd/options.c
  11. 14
      lightningd/pay.c
  12. 4
      lightningd/payalgo.c
  13. 32
      lightningd/peer_control.c
  14. 10
      lightningd/peer_htlcs.c
  15. 4
      lightningd/ping.c
  16. 1
      lightningd/plugin.c
  17. 6
      lightningd/test/run-param.c
  18. 25
      wallet/walletrpc.c

4
lightningd/chaintopology.c

@ -463,7 +463,9 @@ u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style)
}
static void json_feerates(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct chain_topology *topo = cmd->ld->topology;
struct json_stream *response;

4
lightningd/connect_control.c

@ -74,7 +74,9 @@ static void connect_cmd_succeed(struct command *cmd, const struct pubkey *id)
}
static void json_connect(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u32 *port;
jsmntok_t *idtok;

25
lightningd/gossip_control.c

@ -243,8 +243,10 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
command_success(cmd, response);
}
static void json_listnodes(struct command *cmd, const char *buffer,
const jsmntok_t *params)
static void json_listnodes(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *req;
struct pubkey *id;
@ -286,7 +288,10 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con
command_success(cmd, response);
}
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 *obj UNNEEDED,
const jsmntok_t *params)
{
struct lightningd *ld = cmd->ld;
struct pubkey *destination;
@ -393,8 +398,10 @@ static void json_listchannels_reply(struct subd *gossip UNUSED, const u8 *reply,
command_success(cmd, response);
}
static void json_listchannels(struct command *cmd, const char *buffer,
const jsmntok_t *params)
static void json_listchannels(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *req;
struct short_channel_id *id;
@ -443,7 +450,9 @@ static void json_scids_reply(struct subd *gossip UNUSED, const u8 *reply,
}
static void json_dev_query_scids(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *msg;
const jsmntok_t *scidstok;
@ -486,6 +495,7 @@ AUTODATA(json_command, &dev_query_scids_command);
static void json_dev_send_timestamp_filter(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *msg;
@ -555,6 +565,7 @@ static void json_channel_range_reply(struct subd *gossip UNUSED, const u8 *reply
static void json_dev_query_channel_range(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *msg;
@ -584,6 +595,7 @@ AUTODATA(json_command, &dev_query_channel_range_command);
static void json_dev_set_max_scids_encode_size(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *msg;
@ -609,6 +621,7 @@ AUTODATA(json_command, &dev_set_max_scids_encode_size);
static void json_dev_suppress_gossip(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
if (!param(cmd, buffer, params, NULL))

29
lightningd/invoice.c

@ -292,7 +292,9 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
}
static void json_invoice(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *fallbacks;
const jsmntok_t *preimagetok;
@ -415,7 +417,9 @@ static void json_add_invoices(struct json_stream *response,
}
static void json_listinvoices(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_escaped *label;
struct json_stream *response;
@ -441,7 +445,9 @@ static const struct json_command listinvoices_command = {
AUTODATA(json_command, &listinvoices_command);
static void json_delinvoice(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct invoice i;
const struct invoice_details *details;
@ -492,7 +498,9 @@ static const struct json_command delinvoice_command = {
};
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 *obj UNNEEDED,
const jsmntok_t *params)
{
u64 *maxexpirytime;
@ -516,6 +524,7 @@ AUTODATA(json_command, &delexpiredinvoice_command);
static void json_autocleaninvoice(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u64 *cycle;
@ -541,7 +550,9 @@ static const struct json_command autocleaninvoice_command = {
AUTODATA(json_command, &autocleaninvoice_command);
static void json_waitanyinvoice(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u64 *pay_index;
struct wallet *wallet = cmd->ld->wallet;
@ -575,7 +586,9 @@ AUTODATA(json_command, &waitanyinvoice_command);
* waiters, if the payment is still pending.
*/
static void json_waitinvoice(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct invoice i;
const struct invoice_details *details;
@ -648,7 +661,9 @@ static void json_add_fallback(struct json_stream *response,
}
static void json_decodepay(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct bolt11 *b11;
struct json_stream *response;

34
lightningd/jsonrpc.c

@ -134,7 +134,9 @@ static void destroy_jcon(struct json_connection *jcon)
}
static void json_help(struct command *cmd,
const char *buffer, const jsmntok_t *params);
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params);
static const struct json_command help_command = {
"help",
@ -151,7 +153,9 @@ static const struct json_command help_command = {
AUTODATA(json_command, &help_command);
static void json_stop(struct command *cmd,
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
@ -174,7 +178,9 @@ AUTODATA(json_command, &stop_command);
#if DEVELOPER
static void json_rhash(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNUSED,
const jsmntok_t *params)
{
struct json_stream *response;
struct sha256 *secret;
@ -222,7 +228,9 @@ static void slowcmd_start(struct slowcmd *sc)
}
static void json_slowcmd(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNUSED,
const jsmntok_t *params)
{
struct slowcmd *sc = tal(cmd, struct slowcmd);
@ -244,7 +252,9 @@ static const struct json_command dev_slowcmd_command = {
AUTODATA(json_command, &dev_slowcmd_command);
static void json_crash(struct command *cmd UNUSED,
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
if (!param(cmd, buffer, params, NULL))
return;
@ -277,7 +287,7 @@ static void json_add_help_command(struct command *cmd,
{
char *usage;
cmd->mode = CMD_USAGE;
json_command->dispatch(cmd, NULL, NULL);
json_command->dispatch(cmd, NULL, NULL, NULL);
usage = tal_fmt(cmd, "%s %s", json_command->name, cmd->usage);
json_object_start(response, NULL);
@ -302,7 +312,9 @@ static void json_add_help_command(struct command *cmd,
}
static void json_help(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
const jsmntok_t *cmdtok;
@ -570,7 +582,7 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
}
db_begin_transaction(jcon->ld->wallet->db);
c->json_cmd->dispatch(c, jcon->buffer, params);
c->json_cmd->dispatch(c, jcon->buffer, tok, params);
db_commit_transaction(jcon->ld->wallet->db);
/* If they didn't complete it, they must call command_still_pending.
@ -953,7 +965,9 @@ static bool json_tok_command(struct command *cmd, const char *name,
}
static void json_check(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
jsmntok_t *mod_params;
const jsmntok_t *name_tok;
@ -984,7 +998,7 @@ static void json_check(struct command *cmd,
* we're after and would be more clear. */
ok = true;
cmd->ok = &ok;
cmd->json_cmd->dispatch(cmd, buffer, mod_params);
cmd->json_cmd->dispatch(cmd, buffer, mod_params, mod_params);
if (!ok)
return;

4
lightningd/jsonrpc.h

@ -47,7 +47,9 @@ struct command {
struct json_command {
const char *name;
void (*dispatch)(struct command *,
const char *buffer, const jsmntok_t *params);
const char *buffer,
const jsmntok_t *obj,
const jsmntok_t *params);
const char *description;
bool deprecated;
const char *verbose;

4
lightningd/log.c

@ -716,7 +716,9 @@ bool json_tok_loglevel(struct command *cmd, const char *name,
}
static void json_getlog(struct command *cmd,
const char *buffer, const jsmntok_t * params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t * params)
{
struct json_stream *response;
enum log_level *minlevel;

10
lightningd/memdump.c

@ -62,8 +62,9 @@ static void add_memdump(struct json_stream *response,
}
static void json_memdump(struct command *cmd,
const char *buffer UNNEEDED,
const jsmntok_t *params UNNEEDED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
@ -283,8 +284,9 @@ void opening_memleak_done(struct command *cmd, struct subd *leaker)
}
static void json_memleak(struct command *cmd,
const char *buffer UNNEEDED,
const jsmntok_t *params UNNEEDED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
if (!param(cmd, buffer, params, NULL))
return;

4
lightningd/opening_control.c

@ -762,7 +762,9 @@ void opening_peer_no_active_channels(struct peer *peer)
* json_fund_channel - Entrypoint for funding a channel
*/
static void json_fund_channel(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *sattok;
struct funding_channel * fc = tal(cmd, struct funding_channel);

4
lightningd/options.c

@ -1046,7 +1046,9 @@ static void add_config(struct lightningd *ld,
}
static void json_listconfigs(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
size_t i;
struct json_stream *response = NULL;

14
lightningd/pay.c

@ -941,7 +941,9 @@ static void json_sendpay_on_resolve(const struct sendpay_result* r,
}
static void json_sendpay(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *routetok;
const jsmntok_t *t, *end;
@ -1025,7 +1027,9 @@ static void waitsendpay_timeout(struct command *cmd)
command_fail(cmd, PAY_IN_PROGRESS, "Timed out while waiting");
}
static void json_waitsendpay(struct command *cmd, const char *buffer,
static void json_waitsendpay(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct sha256 *rhash;
@ -1054,8 +1058,10 @@ static const struct json_command waitsendpay_command = {
};
AUTODATA(json_command, &waitsendpay_command);
static void json_listpayments(struct command *cmd, const char *buffer,
const jsmntok_t *params)
static void json_listpayments(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const struct wallet_payment **payments;
struct json_stream *response;

4
lightningd/payalgo.c

@ -592,7 +592,9 @@ static void json_pay_stop_retrying(struct pay *pay)
}
static void json_pay(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
double *riskfactor;
double *maxfeepercent;

32
lightningd/peer_control.c

@ -803,7 +803,9 @@ static void json_add_peer(struct lightningd *ld,
}
static void json_listpeers(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
enum log_level *ll;
struct pubkey *specific_id;
@ -890,7 +892,9 @@ command_find_channel(struct command *cmd,
}
static void json_close(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *idtok;
struct peer *peer;
@ -1032,7 +1036,9 @@ void load_channels_from_wallet(struct lightningd *ld)
}
static void json_disconnect(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *id;
struct peer *peer;
@ -1071,7 +1077,9 @@ static const struct json_command disconnect_command = {
AUTODATA(json_command, &disconnect_command);
static void json_getinfo(struct command *cmd,
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
struct peer *peer;
@ -1144,7 +1152,9 @@ AUTODATA(json_command, &getinfo_command);
#if DEVELOPER
static void json_sign_last_tx(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *peerid;
struct peer *peer;
@ -1191,7 +1201,9 @@ static const struct json_command dev_sign_last_tx = {
AUTODATA(json_command, &dev_sign_last_tx);
static void json_dev_fail(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *peerid;
struct peer *peer;
@ -1236,7 +1248,9 @@ static void dev_reenable_commit_finished(struct subd *channeld UNUSED,
}
static void json_dev_reenable_commit(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *peerid;
struct peer *peer;
@ -1325,7 +1339,9 @@ static void process_dev_forget_channel(struct bitcoind *bitcoind UNUSED,
command_success(forget->cmd, response);
}
static void json_dev_forget_channel(struct command *cmd, const char *buffer,
static void json_dev_forget_channel(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *peerid;

10
lightningd/peer_htlcs.c

@ -1791,7 +1791,9 @@ void htlcs_reconnect(struct lightningd *ld,
#if DEVELOPER
static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer,
static void json_dev_ignore_htlcs(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct pubkey *peerid;
@ -1846,8 +1848,10 @@ static void listforwardings_add_forwardings(struct json_stream *response, struct
tal_free(forwardings);
}
static void json_listforwards(struct command *cmd, const char *buffer,
const jsmntok_t *params)
static void json_listforwards(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;

4
lightningd/ping.c

@ -79,7 +79,9 @@ void ping_reply(struct subd *subd, const u8 *msg)
}
static void json_ping(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u8 *msg;
unsigned int *len, *pongbytes;

1
lightningd/plugin.c

@ -534,6 +534,7 @@ static void plugin_rpcmethod_cb(const struct plugin_request *req,
}
static void plugin_rpcmethod_dispatch(struct command *cmd, const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *toks = params, *methtok, *idtok;

6
lightningd/test/run-param.c

@ -507,7 +507,9 @@ static void json_tok_tests(void)
test_cb(json_tok_percent, double, "[ 'wow' ]", 0, false);
}
static void test_invoice(struct command *cmd, const char *buffer,
static void test_invoice(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
u64 *msatoshi_val;
@ -546,7 +548,7 @@ static void usage(void)
cmd->mode = CMD_USAGE;
cmd->json_cmd = &invoice_command;
cmd->json_cmd->dispatch(cmd, NULL, NULL);
cmd->json_cmd->dispatch(cmd, NULL, NULL, NULL);
assert(streq(cmd->usage,
"msatoshi label description "

25
wallet/walletrpc.c

@ -85,7 +85,9 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
* the HSM to generate the signatures.
*/
static void json_withdraw(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
const jsmntok_t *desttok, *sattok;
struct withdrawal *withdraw = tal(cmd, struct withdrawal);
@ -239,8 +241,10 @@ static bool json_tok_newaddr(struct command *cmd, const char *name,
return false;
}
static void json_newaddr(struct command *cmd, const char *buffer UNUSED,
const jsmntok_t *params UNUSED)
static void json_newaddr(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
struct ext_key ext;
@ -299,7 +303,9 @@ static const struct json_command newaddr_command = {
AUTODATA(json_command, &newaddr_command);
static void json_listaddrs(struct command *cmd,
const char *buffer, const jsmntok_t *params)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
struct ext_key ext;
@ -376,8 +382,10 @@ static const struct json_command listaddrs_command = {
};
AUTODATA(json_command, &listaddrs_command);
static void json_listfunds(struct command *cmd, const char *buffer UNUSED,
const jsmntok_t *params UNUSED)
static void json_listfunds(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
struct peer *p;
@ -503,8 +511,9 @@ static void process_utxo_result(struct bitcoind *bitcoind,
}
static void json_dev_rescan_outputs(struct command *cmd,
const char *buffer UNUSED,
const jsmntok_t *params UNUSED)
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct txo_rescan *rescan = tal(cmd, struct txo_rescan);

Loading…
Cancel
Save