libplugin: clean up API.

When we used to allow cmd to be NULL, we had to hand the plugin
everywhere.  We no longer do.

1. Various jsonrpc_ functions no longer need the plugin arg.
2. send_outreq no longer needs a plugin arg.
3. The init function takes a command, not a plugin.
4. Remove command_deprecated_in_nocmd_ok.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-11-06 21:30:36 +10:30
parent 00d851c792
commit c5099b1647
35 changed files with 393 additions and 455 deletions

View File

@ -759,11 +759,11 @@ static struct command_result *json_getroutes(struct command *cmd,
if (have_layer(info->layers, "auto.localchans")) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listpeerchannels",
listpeerchannels_done,
forward_error, info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
} else
info->local_layer = NULL;
@ -1152,9 +1152,10 @@ static void askrene_markmem(struct plugin *plugin, struct htable *memtable)
reserve_memleak_mark(askrene, memtable);
}
static const char *init(struct plugin *plugin,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
struct plugin *plugin = init_cmd->plugin;
struct askrene *askrene = tal(plugin, struct askrene);
askrene->plugin = plugin;
list_head_init(&askrene->layers);
@ -1165,7 +1166,7 @@ static const char *init(struct plugin *plugin,
plugin_err(plugin, "Could not load gossmap %s: %s",
GOSSIP_STORE_FILENAME, strerror(errno));
askrene->capacities = get_capacities(askrene, askrene->plugin, askrene->gossmap);
rpc_scan(plugin, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_node_id, &askrene->my_id));
plugin_set_data(plugin, askrene);

View File

@ -259,7 +259,7 @@ static struct command_result *clean_finished(struct clean_info *cinfo)
plugin_log(plugin, LOG_DBG, "cleaned %zu from %s",
num_cleaned, subsystem_to_str(&sv));
*total_cleaned(&sv) += num_cleaned;
jsonrpc_set_datastore_string(plugin, cinfo->cmd,
jsonrpc_set_datastore_string(cinfo->cmd,
datastore_path(tmpctx, &sv, "num"),
tal_fmt(tmpctx, "%"PRIu64,
*total_cleaned(&sv)),
@ -509,10 +509,10 @@ static struct command_result *list_done(struct command *cmd,
}
subsystem->cinfo->cleanup_reqs_remaining++;
req = jsonrpc_request_start(plugin, cmd, ops->del_command,
req = jsonrpc_request_start(cmd, ops->del_command,
del_done, del_failed, variant);
ops->add_del_fields(req, buf, t);
send_outreq(plugin, req);
send_outreq(req);
}
subsystem->offset += max_entries_per_call;
@ -555,7 +555,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
filter = tal_fmt(tmpctx, "{\"%s\":[{%s}]}",
ops->arr_name, ops->list_filter);
req = jsonrpc_request_with_filter_start(plugin, cinfo->cmd,
req = jsonrpc_request_with_filter_start(cinfo->cmd,
tal_fmt(tmpctx,
"list%s",
ops->system_name),
@ -567,7 +567,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
json_add_string(req->js, "index", "created");
json_add_u64(req->js, "start", ps->offset);
json_add_u64(req->js, "limit", max_entries_per_call);
send_outreq(plugin, req);
send_outreq(req);
cinfo->cleanup_reqs_remaining++;
}
@ -628,13 +628,13 @@ static struct command_result *start_clean(struct clean_info *cinfo)
}
ps->offset = 0;
req = jsonrpc_request_start(plugin, cinfo->cmd,
req = jsonrpc_request_start(cinfo->cmd,
"wait",
wait_done, wait_failed, ps);
json_add_string(req->js, "subsystem", ops->system_name);
json_add_string(req->js, "indexname", "created");
json_add_u64(req->js, "nextvalue", 0);
send_outreq(plugin, req);
send_outreq(req);
cinfo->cleanup_reqs_remaining++;
}
@ -742,29 +742,29 @@ static void memleak_mark_timer_cinfo(struct plugin *plugin,
memleak_scan_obj(memtable, timer_cinfo);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
struct subsystem_and_variant sv;
plugin = p;
plugin = init_cmd->plugin;
/* Plugin owns global */
tal_steal(plugin, timer_cinfo);
plugin_set_memleak_handler(plugin, memleak_mark_timer_cinfo);
cleantimer = global_timer(p, time_from_sec(cycle_seconds), do_clean_timer, NULL);
cleantimer = global_timer(plugin, time_from_sec(cycle_seconds), do_clean_timer, NULL);
/* We don't care if this fails (it usually does, since entries
* don't exist! */
sv = first_sv();
do {
rpc_scan_datastore_str(tmpctx, plugin,
rpc_scan_datastore_str(tmpctx, init_cmd,
datastore_path(tmpctx, &sv, "num"),
JSON_SCAN(json_to_u64, total_cleaned(&sv)));
} while (next_sv(&sv));
/* Optimization FTW! */
rpc_enable_batching(p);
rpc_enable_batching(plugin);
return NULL;
}

View File

@ -1100,10 +1100,10 @@ static void memleak_mark_bitcoind(struct plugin *p, struct htable *memtable)
memleak_scan_obj(memtable, bitcoind);
}
static const char *init(struct plugin *p, const char *buffer UNUSED,
static const char *init(struct command *init_cmd, const char *buffer UNUSED,
const jsmntok_t *config UNUSED)
{
wait_and_check_bitcoind(p);
wait_and_check_bitcoind(init_cmd->plugin);
/* Usually we fake up fees in regtest */
if (streq(chainparams->network_name, "regtest"))
@ -1111,8 +1111,8 @@ static const char *init(struct plugin *p, const char *buffer UNUSED,
else
bitcoind->fake_fees = false;
plugin_set_memleak_handler(p, memleak_mark_bitcoind);
plugin_log(p, LOG_INFORM,
plugin_set_memleak_handler(init_cmd->plugin, memleak_mark_bitcoind);
plugin_log(init_cmd->plugin, LOG_INFORM,
"bitcoin-cli initialized and connected to bitcoind.");
return NULL;

View File

@ -123,11 +123,11 @@ static struct command_result *json_channel_apy(struct command *cmd,
return command_param_failed();
/* First get the current blockheight */
req = jsonrpc_request_start(cmd->plugin, cmd, "getinfo",
req = jsonrpc_request_start(cmd, "getinfo",
&getblockheight_done,
forward_error,
apyreq);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *param_csv_format(struct command *cmd, const char *name,
@ -1122,13 +1122,13 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
if (tal_count(new_accts) > 0) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listpeerchannels",
listpeerchannels_multi_done,
log_error,
new_accts);
/* FIXME(vicenzopalazzo) require the channel by channel_id to avoid parsing not useful json */
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
plugin_log(cmd->plugin, LOG_DBG, "Snapshot balances updated");
@ -1288,20 +1288,20 @@ static struct command_result *lookup_invoice_desc(struct command *cmd,
/* Otherwise will go away when event is cleaned up */
tal_steal(cmd, payment_hash);
if (!amount_msat_is_zero(credit))
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listinvoices",
listinvoices_done,
log_error,
payment_hash);
else
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listsendpays",
listsendpays_done,
log_error,
payment_hash);
json_add_sha256(req->js, "payment_hash", payment_hash);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
struct event_info {
@ -1564,13 +1564,13 @@ parse_and_log_chain_move(struct command *cmd,
is_channel_account(acct) ?
acct : orig_acct);
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listpeerchannels",
listpeerchannels_done,
log_error,
info);
/* FIXME: use the peer_id to reduce work here */
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* Maybe mark acct as onchain resolved */
@ -1977,8 +1977,10 @@ static const struct plugin_command commands[] = {
},
};
static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
static const char *init(struct command *init_cmd, const char *b, const jsmntok_t *t)
{
struct plugin *p = init_cmd->plugin;
/* Switch to bookkeeper-dir, if specified */
if (datadir && chdir(datadir) != 0) {
if (mkdir(datadir, 0700) != 0 && errno != EEXIST)

View File

@ -261,7 +261,7 @@ static struct command_result *json_emergencyrecover(struct command *cmd,
"Incompatible SCB file version on disk, contact the admin!");
}
req = jsonrpc_request_start(cmd->plugin, cmd, "recoverchannel",
req = jsonrpc_request_start(cmd, "recoverchannel",
after_recover_rpc,
&forward_error, NULL);
@ -273,7 +273,7 @@ static struct command_result *json_emergencyrecover(struct command *cmd,
}
json_array_end(req->js);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static void update_scb(struct plugin *p, struct scb_chan **channels)
@ -353,8 +353,7 @@ static struct command_result *peer_after_listdatastore(struct command *cmd,
plugin_log(cmd->plugin, LOG_DBG,
"sending their backup from our datastore");
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"sendcustommsg",
peer_after_send_their_peer_strg,
peer_after_send_their_peer_strg_err,
@ -364,7 +363,7 @@ static struct command_result *peer_after_listdatastore(struct command *cmd,
json_add_hex(req->js, "msg", payload,
tal_bytelen(payload));
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *peer_after_send_scb(struct command *cmd,
@ -374,8 +373,7 @@ static struct command_result *peer_after_send_scb(struct command *cmd,
{
plugin_log(cmd->plugin, LOG_DBG, "Peer storage sent!");
return jsonrpc_get_datastore_binary(cmd->plugin,
cmd,
return jsonrpc_get_datastore_binary(cmd,
tal_fmt(cmd,
"chanbackup/peers/%s",
fmt_node_id(tmpctx,
@ -464,8 +462,7 @@ static struct command_result *after_listpeers(struct command *cmd,
nodeid = json_get_member(buf, peer, "id");
json_to_node_id(buf, nodeid, &node_id);
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"sendcustommsg",
after_send_scb_single,
after_send_scb_single_fail,
@ -475,7 +472,7 @@ static struct command_result *after_listpeers(struct command *cmd,
json_add_hex(req->js, "msg", serialise_scb,
tal_bytelen(serialise_scb));
info->idx++;
send_outreq(cmd->plugin, req);
send_outreq(req);
}
}
@ -498,13 +495,12 @@ static struct command_result *after_staticbackup(struct command *cmd,
update_scb(cmd->plugin, scb_chan);
struct info *info = tal(cmd, struct info);
info->idx = 0;
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"listpeers",
after_listpeers,
&forward_error,
info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_state_changed(struct command *cmd,
@ -520,14 +516,13 @@ static struct command_result *json_state_changed(struct command *cmd,
json_tok_streq(buf, statetok, "CHANNELD_AWAITING_LOCKIN") ||
json_tok_streq(buf, statetok, "DUALOPEND_AWAITING_LOCKIN")) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"staticbackup",
after_staticbackup,
&forward_error,
NULL);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
return notification_handled(cmd);
@ -569,8 +564,7 @@ static struct command_result *peer_connected(struct command *cmd,
return command_hook_success(cmd);
}
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"sendcustommsg",
peer_after_send_scb,
peer_after_send_scb_failed,
@ -580,7 +574,7 @@ static struct command_result *peer_connected(struct command *cmd,
json_add_hex(req->js, "msg", serialise_scb,
tal_bytelen(serialise_scb));
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *failed_peer_restore(struct command *cmd,
@ -635,8 +629,7 @@ static struct command_result *handle_your_peer_storage(struct command *cmd,
}
if (fromwire_peer_storage(cmd, payload, &payload_deserialise)) {
return jsonrpc_set_datastore_binary(cmd->plugin,
cmd,
return jsonrpc_set_datastore_binary(cmd,
tal_fmt(cmd,
"chanbackup/peers/%s",
fmt_node_id(tmpctx,
@ -681,8 +674,7 @@ static struct command_result *handle_your_peer_storage(struct command *cmd,
"Peer altered our data");
return jsonrpc_set_datastore_binary(cmd->plugin,
cmd,
return jsonrpc_set_datastore_binary(cmd,
"chanbackup/latestscb",
decoded_bkp,
"create-or-replace",
@ -727,7 +719,7 @@ static struct command_result *after_latestscb(struct command *cmd,
"Incompatible version, Contact the admin!");
}
req = jsonrpc_request_start(cmd->plugin, cmd, "recoverchannel",
req = jsonrpc_request_start(cmd, "recoverchannel",
after_recover_rpc,
&forward_error, NULL);
@ -739,7 +731,7 @@ static struct command_result *after_latestscb(struct command *cmd,
}
json_array_end(req->js);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
@ -750,8 +742,7 @@ static struct command_result *json_restorefrompeer(struct command *cmd,
if (!param(cmd, buf, params, NULL))
return command_param_failed();
return jsonrpc_get_datastore_binary(cmd->plugin,
cmd,
return jsonrpc_get_datastore_binary(cmd,
"chanbackup/latestscb",
after_latestscb,
NULL);
@ -774,7 +765,7 @@ static struct command_result *json_getemergencyrecoverdata(struct command *cmd,
return command_finished(cmd, response);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
@ -784,29 +775,29 @@ static const char *init(struct plugin *p,
u8 *features;
/* Figure out if they specified --experimental-peer-storage */
rpc_scan(p, "getinfo",
rpc_scan(init_cmd, "getinfo",
take(json_out_obj(NULL, NULL, NULL)),
"{our_features:{init:%}}",
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
peer_backup = feature_offered(features, OPT_WANT_PEER_BACKUP_STORAGE);
rpc_scan(p, "staticbackup",
rpc_scan(init_cmd, "staticbackup",
take(json_out_obj(NULL, NULL, NULL)),
"{scb:%}", JSON_SCAN(json_to_scb_chan, &scb_chan));
rpc_scan(p, "makesecret",
rpc_scan(init_cmd, "makesecret",
take(json_out_obj(NULL, "hex",
tal_hexstr(tmpctx,
info_hex,
tal_bytelen(info_hex)))),
"{secret:%}", JSON_SCAN(json_to_secret, &secret));
plugin_log(p, LOG_DBG, "Chanbackup Initialised!");
plugin_log(init_cmd->plugin, LOG_DBG, "Chanbackup Initialised!");
/* flush the tmp file, if exists */
unlink_noerr("scb.tmp");
maybe_create_new_scb(p, scb_chan);
maybe_create_new_scb(init_cmd->plugin, scb_chan);
return NULL;
}

View File

@ -145,13 +145,13 @@ static struct command_result *send_response(struct command *cmd,
towire(&cmd_msg, reply->buf + reply->off, msglen);
reply->off += msglen;
req = jsonrpc_request_start(plugin, cmd, "sendcustommsg",
req = jsonrpc_request_start(cmd, "sendcustommsg",
send_response, send_response,
reply);
json_add_node_id(req->js, "node_id", &reply->incoming->peer);
json_add_hex_talarr(req->js, "msg", cmd_msg);
tal_free(cmd_msg);
send_outreq(plugin, req);
send_outreq(req);
return command_still_pending(cmd);
}
@ -279,7 +279,7 @@ static struct command_result *execute_command(struct command *cmd,
struct out_req *req;
/* We handle success and failure the same */
req = jsonrpc_request_whole_object_start(plugin, cmd,
req = jsonrpc_request_whole_object_start(cmd,
json_strdup(tmpctx, cinfo->buf, cinfo->method),
cinfo->cmdid_prefix,
cmd_done, cinfo->incoming);
@ -318,7 +318,7 @@ static struct command_result *execute_command(struct command *cmd,
json_tok_full(cinfo->buf, cinfo->filter),
json_tok_full_len(cinfo->filter));
}
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *checkrune_done(struct command *cmd,
@ -420,7 +420,7 @@ static struct command_result *try_command(struct command *cmd,
destroy_commando(incoming, &incoming_commands);
tal_del_destructor2(incoming, destroy_commando, &incoming_commands);
req = jsonrpc_request_start(plugin, cmd, "checkrune",
req = jsonrpc_request_start(cmd, "checkrune",
checkrune_done, checkrune_failed,
cinfo);
json_add_node_id(req->js, "nodeid", &incoming->peer);
@ -428,7 +428,7 @@ static struct command_result *try_command(struct command *cmd,
json_add_tok(req->js, "method", method, cinfo->buf);
if (params)
json_add_tok(req->js, "params", params, cinfo->buf);
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *handle_incmd(struct command *cmd,
@ -630,12 +630,12 @@ static struct command_result *send_more_cmd(struct command *cmd,
return command_still_pending(cmd);
}
req = jsonrpc_request_start(plugin, cmd, "sendcustommsg",
req = jsonrpc_request_start(cmd, "sendcustommsg",
send_more_cmd, forward_error, outgoing);
json_add_node_id(req->js, "node_id", &outgoing->peer);
json_add_hex_talarr(req->js, "msg", outgoing->msgs[outgoing->msg_off++]);
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *json_commando(struct command *cmd,
@ -728,11 +728,11 @@ static struct command_result *forward_command(struct command *cmd,
/* params could be an array, so use low-level helper */
struct out_req *req;
req = jsonrpc_request_whole_object_start(plugin, cmd, method,
req = jsonrpc_request_whole_object_start(cmd, method,
json_id_prefix(tmpctx, cmd),
forward_reply, NULL);
json_add_tok(req->js, "params", params, buffer);
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *json_commando_rune(struct command *cmd,
@ -787,13 +787,13 @@ static void memleak_mark_globals(struct plugin *p, struct htable *memtable)
memleak_scan_obj(memtable, incoming_commands);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
outgoing_commands = tal_arr(p, struct commando *, 0);
incoming_commands = tal_arr(p, struct commando *, 0);
plugin = p;
plugin_set_memleak_handler(p, memleak_mark_globals);
plugin = init_cmd->plugin;
outgoing_commands = tal_arr(plugin, struct commando *, 0);
incoming_commands = tal_arr(plugin, struct commando *, 0);
plugin_set_memleak_handler(plugin, memleak_mark_globals);
return NULL;
}

View File

@ -53,10 +53,10 @@ static struct command_result *connect_direct(struct command *cmd,
plugin_log(cmd->plugin, LOG_DBG, "connecting directly to %s",
fmt_pubkey(tmpctx, &ci->dst));
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"connect", connect_ok, command_failed, ci);
json_add_pubkey(req->js, "id", &ci->dst);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static bool can_carry_onionmsg(const struct gossmap *map,
@ -231,9 +231,9 @@ struct command_result *establish_onion_path_(struct command *cmd,
ci->gossmap = gossmap;
/* We use listpeers here: we don't actually care about channels, just connections! */
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeers",
req = jsonrpc_request_start(cmd, "listpeers",
listpeers_done,
command_failed,
ci);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}

View File

@ -1045,7 +1045,7 @@ struct command_result *json_fetchinvoice(struct command *cmd,
0);
/* Make the invoice request (fills in payer_key and payer_info) */
req = jsonrpc_request_start(cmd->plugin, cmd, "createinvoicerequest",
req = jsonrpc_request_start(cmd, "createinvoicerequest",
&invreq_done,
&forward_error,
sent);
@ -1055,7 +1055,7 @@ struct command_result *json_fetchinvoice(struct command *cmd,
json_add_bool(req->js, "savetodb", false);
if (rec_label)
json_add_string(req->js, "recurrence_label", rec_label);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* FIXME: Using a hook here is not ideal: technically it doesn't mean
@ -1094,12 +1094,12 @@ struct command_result *invoice_payment(struct command *cmd,
continue;
/* It was paid! Success. Return as per waitinvoice. */
req = jsonrpc_request_start(cmd->plugin, i->cmd, "waitinvoice",
req = jsonrpc_request_start(i->cmd, "waitinvoice",
&forward_result,
&forward_error,
i);
json_add_escaped_string(req->js, "label", i->inv_label);
discard_result(send_outreq(cmd->plugin, req));
discard_result(send_outreq(req));
break;
}
return command_hook_success(cmd);
@ -1157,14 +1157,14 @@ static struct command_result *sign_invoice(struct command *cmd,
struct out_req *req;
/* Get invoice signature and put in db so we can receive payment */
req = jsonrpc_request_start(cmd->plugin, cmd, "createinvoice",
req = jsonrpc_request_start(cmd, "createinvoice",
&createinvoice_done,
&forward_error,
sent);
json_add_string(req->js, "invstring", invoice_encode(tmpctx, sent->inv));
json_add_preimage(req->js, "preimage", &sent->inv_preimage);
json_add_escaped_string(req->js, "label", sent->inv_label);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *param_invreq(struct command *cmd,

View File

@ -101,12 +101,12 @@ static struct command_result *unreserve_psbt(struct command *cmd,
/* This can outlive the underlying cmd, so use an aux! */
aux = aux_command(cmd);
req = jsonrpc_request_start(open->p, aux,
req = jsonrpc_request_start(aux,
"unreserveinputs",
unreserve_done, unreserve_done,
open);
json_add_psbt(req->js, "psbt", open->psbt);
send_outreq(open->p, req);
send_outreq(req);
/* We will free this in callback, but remove from list *now*
* to avoid calling twice! */
@ -215,7 +215,7 @@ remember_channel_utxos(struct command *cmd,
fmt_channel_id(cmd,
&open->channel_id));
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"datastore",
&datastore_add_success,
&datastore_add_fail,
@ -237,7 +237,7 @@ remember_channel_utxos(struct command *cmd,
/* We either update the existing or add a new one, nbd */
json_add_string(req->js, "mode", "create-or-replace");
json_add_hex(req->js, "hex", utxos_bin, tal_bytelen(utxos_bin));
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -319,7 +319,7 @@ json_openchannel2_sign_call(struct command *cmd,
"openchannel_sign PSBT is %s",
fmt_wally_psbt(tmpctx, psbt));
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"signpsbt",
&signpsbt_done,
&forward_error,
@ -342,7 +342,7 @@ json_openchannel2_sign_call(struct command *cmd,
fmt_channel_id(tmpctx,
&open->channel_id), count,
count == 1 ? "" : "s");
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -534,7 +534,7 @@ build_utxopsbt_request(struct command *cmd,
{
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"utxopsbt",
&psbt_funded,
&psbt_fund_failed,
@ -723,7 +723,7 @@ listfunds_success(struct command *cmd,
/* We don't re-reserve any UTXOS :) */
json_add_num(req->js, "reserve", 0);
} else {
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"fundpsbt",
&psbt_funded,
&psbt_fund_failed,
@ -745,7 +745,7 @@ listfunds_success(struct command *cmd,
json_add_bool(req->js, "excess_as_change", true);
json_add_num(req->js, "locktime", info->locktime);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -892,13 +892,13 @@ json_openchannel2_call(struct command *cmd,
}
/* Figure out what our funds are */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listfunds",
&listfunds_success,
&listfunds_failed,
info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -917,12 +917,12 @@ datastore_list_fail(struct command *cmd,
/* Figure out what our funds are... same flow
* as with openchannel2 callback. */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listfunds",
&listfunds_success,
&listfunds_failed,
info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -986,12 +986,12 @@ datastore_list_success(struct command *cmd,
tal_arr_expand(&info->prev_outs, outpoint);
}
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listfunds",
&listfunds_success,
&listfunds_failed,
info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* Peer has asked us to RBF */
@ -1061,7 +1061,7 @@ json_rbf_channel_call(struct command *cmd,
}
/* Fetch out previous utxos from the datastore */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listdatastore",
&datastore_list_success,
&datastore_list_fail,
@ -1070,7 +1070,7 @@ json_rbf_channel_call(struct command *cmd,
fmt_channel_id(cmd,
&info->cid));
json_add_string(req->js, "key", chan_key);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_disconnect(struct command *cmd,
@ -1109,7 +1109,7 @@ delete_channel_from_datastore(struct command *cmd,
* If we were clever, we'd have some way of tracking
* channels that we actually might have data for
* but this is much easier */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"deldatastore",
&datastore_del_success,
&datastore_del_fail,
@ -1117,7 +1117,7 @@ delete_channel_from_datastore(struct command *cmd,
json_add_string(req->js, "key",
tal_fmt(cmd, "funder/%s",
fmt_channel_id(cmd, cid)));
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_channel_state_changed(struct command *cmd,
@ -1417,7 +1417,7 @@ json_funderupdate(struct command *cmd,
current_policy = tal_steal(NULL, policy);
/* Update lightningd, also */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"setleaserates",
&leaserates_set,
&forward_error,
@ -1432,7 +1432,7 @@ json_funderupdate(struct command *cmd,
json_add_lease_rates(req->js, &rates);
}
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static const struct plugin_command commands[] = {
@ -1442,7 +1442,7 @@ static const struct plugin_command commands[] = {
},
};
static void tell_lightningd_lease_rates(struct plugin *p,
static void tell_lightningd_lease_rates(struct command *init_cmd,
struct lease_rates *rates)
{
struct json_out *jout;
@ -1470,7 +1470,7 @@ static void tell_lightningd_lease_rates(struct plugin *p,
json_out_end(jout, '}');
json_out_finished(jout);
rpc_scan(p, "setleaserates", take(jout),
rpc_scan(init_cmd, "setleaserates", take(jout),
/* Unused */
"{lease_fee_base_msat:%}",
JSON_SCAN(json_to_msat, &mval));
@ -1483,7 +1483,7 @@ static void memleak_mark(struct plugin *p, struct htable *memtable)
memleak_scan_obj(memtable, current_policy);
}
static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
static const char *init(struct command *init_cmd, const char *b, const jsmntok_t *t)
{
const char *err;
struct amount_msat msat;
@ -1492,19 +1492,19 @@ static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
err = funder_check_policy(current_policy);
if (err)
plugin_err(p, "Invalid parameter combination: %s", err);
plugin_err(init_cmd->plugin, "Invalid parameter combination: %s", err);
if (current_policy->rates)
tell_lightningd_lease_rates(p, current_policy->rates);
tell_lightningd_lease_rates(init_cmd, current_policy->rates);
rpc_scan(p, "listconfigs",
rpc_scan(init_cmd, "listconfigs",
take(json_out_obj(NULL, NULL, NULL)),
"{configs:"
"{min-emergency-msat:{value_msat:%}}}",
JSON_SCAN(json_to_msat, &msat));
emergency_reserve = amount_msat_to_sat_round_down(msat);
plugin_set_memleak_handler(p, memleak_mark);
plugin_set_memleak_handler(init_cmd->plugin, memleak_mark);
return NULL;
}

View File

@ -154,13 +154,13 @@ static bool jsonarr_accumulate_u64(const char *buffer,
return true;
}
static const char *init(struct plugin *p, const char *buf UNUSED,
static const char *init(struct command *init_cmd, const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)), "{id:%}",
rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)), "{id:%}",
JSON_SCAN(json_to_node_id, &my_id));
global_hints = notleak_with_children(channel_hint_set_new(p));
global_hints = notleak_with_children(channel_hint_set_new(init_cmd->plugin));
accepted_extra_tlvs = notleak(tal_arr(NULL, u64, 0));
/* BOLT #4:
@ -173,7 +173,7 @@ static const char *init(struct plugin *p, const char *buf UNUSED,
maxdelay_default = 2016;
/* accept-htlc-tlv-types deprecated in v23.08, but still grab it! */
/* max-locktime-blocks deprecated in v24.05, but still grab it! */
rpc_scan(p, "listconfigs", take(json_out_obj(NULL, NULL, NULL)),
rpc_scan(init_cmd, "listconfigs", take(json_out_obj(NULL, NULL, NULL)),
"{configs:{"
"max-locktime-blocks?:{value_int:%},"
"accept-htlc-tlv-types?:{value_str:%},"
@ -311,19 +311,19 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
/* We do pre-approval immediately (note: even if command_check_only!) */
if (command_check_only(cmd)) {
req = jsonrpc_request_start(p->plugin, cmd, "check",
req = jsonrpc_request_start(cmd, "check",
preapprovekeysend_succeed,
forward_error, p);
json_add_string(req->js, "command_to_check", "preapprovekeysend");
} else {
req = jsonrpc_request_start(p->plugin, cmd, "preapprovekeysend",
req = jsonrpc_request_start(cmd, "preapprovekeysend",
preapprovekeysend_succeed,
forward_error, p);
}
json_add_node_id(req->js, "destination", p->route_destination);
json_add_sha256(req->js, "payment_hash", p->payment_hash);
json_add_amount_msat(req->js, "amount_msat", p->our_amount);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static const struct plugin_command commands[] = {
@ -571,7 +571,7 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
* label could collide (unlikely since we use the nanosecond time). If
* the call to `invoice` fails we will just continue, and `lightningd`
* will be nice and reject the payment. */
req = jsonrpc_request_start(cmd->plugin, cmd, "invoice",
req = jsonrpc_request_start(cmd, "invoice",
&htlc_accepted_invoice_created,
&htlc_accepted_invoice_failed,
ki);
@ -592,7 +592,7 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
}
json_add_preimage(req->js, "preimage", &ki->payment_preimage);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static const struct plugin_hook hooks[] = {

View File

@ -318,11 +318,11 @@ payment_getblockheight_success(struct command *cmd,
/* Now we just need to ask `lightningd` what height it has
* synced up to, and we remember that as chainlag. */
req = jsonrpc_request_start(p->plugin, cmd, "waitblockheight",
req = jsonrpc_request_start(cmd, "waitblockheight",
&payment_waitblockheight_cb,
&payment_rpc_failure, p);
json_add_u32(req->js, "blockheight", 0);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
#define INVALID_BLOCKHEIGHT UINT32_MAX
@ -364,11 +364,11 @@ payment_start_at_blockheight(struct payment *p, u32 blockheight)
* height, allowing us to send while still syncing.
*/
struct out_req *req;
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "getchaininfo",
req = jsonrpc_request_start(payment_cmd(p), "getchaininfo",
&payment_getblockheight_success,
&payment_rpc_failure, p);
json_add_u32(req->js, "last_height", 0);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
void payment_start(struct payment *p)
@ -1021,10 +1021,10 @@ static struct command_result *payment_getlocalmods(struct payment *p)
if (p->mods)
return payment_getroute(p);
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "listpeerchannels",
req = jsonrpc_request_start(payment_cmd(p), "listpeerchannels",
&payment_listpeerchannels_success,
&payment_rpc_failure, p);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
static struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx,
@ -1639,11 +1639,11 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer,
"Extracted channel_update %s from onionreply %s",
tal_hex(tmpctx, update),
tal_hex(tmpctx, p->result->raw_message));
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "addgossip",
req = jsonrpc_request_start(payment_cmd(p), "addgossip",
payment_addgossip_success,
payment_addgossip_failure, p);
json_add_hex_talarr(req->js, "message", update);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
return payment_addgossip_success(cmd, NULL, NULL, p);
@ -1655,13 +1655,13 @@ static struct command_result *payment_sendonion_success(struct command *cmd,
struct payment *p)
{
struct out_req *req;
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "waitsendpay",
req = jsonrpc_request_start(payment_cmd(p), "waitsendpay",
payment_waitsendpay_finished,
payment_waitsendpay_finished, p);
json_add_sha256(req->js, "payment_hash", p->payment_hash);
json_add_num(req->js, "partid", p->partid);
json_add_u64(req->js, "groupid", p->groupid);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
static struct command_result *payment_createonion_success(struct command *cmd,
@ -1683,7 +1683,7 @@ static struct command_result *payment_createonion_success(struct command *cmd,
p->createonion_response = json_to_createonion_response(p, buffer, toks);
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "sendonion",
req = jsonrpc_request_start(payment_cmd(p), "sendonion",
payment_sendonion_success,
payment_rpc_failure, p);
json_add_hex_talarr(req->js, "onion", p->createonion_response->onion);
@ -1726,7 +1726,7 @@ static struct command_result *payment_createonion_success(struct command *cmd,
if (p->local_invreq_id)
json_add_sha256(req->js, "localinvreqid", p->local_invreq_id);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
/* Temporary serialization method for the tlv_payload.data until we rework the
@ -1913,7 +1913,7 @@ static struct command_result *payment_sendonion(struct payment *p)
{
struct out_req *req;
u8 *payload, *tlv;
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "createonion",
req = jsonrpc_request_start(payment_cmd(p), "createonion",
payment_createonion_success,
payment_rpc_failure, p);
@ -1942,7 +1942,7 @@ static struct command_result *payment_sendonion(struct payment *p)
json_add_secret(req->js, "sessionkey",
p->createonion_request->session_key);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
/* Mutual recursion. */
@ -2563,10 +2563,10 @@ static struct command_result *local_channel_hints_cb(void *d UNUSED, struct paym
if (p->parent != NULL || p->step != PAYMENT_STEP_INITIALIZED)
return payment_continue(p);
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "listpeerchannels",
req = jsonrpc_request_start(payment_cmd(p), "listpeerchannels",
local_channel_hints_listpeerchannels,
local_channel_hints_listpeerchannels, p);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(local_channel_hints, void *, NULL, local_channel_hints_cb);
@ -3184,11 +3184,11 @@ static struct command_result *shadow_route_extend(struct shadow_route_data *d,
struct payment *p)
{
struct out_req *req;
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "listchannels",
req = jsonrpc_request_start(payment_cmd(p), "listchannels",
shadow_route_listchannels,
payment_rpc_failure, p);
json_add_node_id(req->js, "source", &d->destination);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
static struct command_result *shadow_route_listchannels(struct command *cmd,
@ -3451,12 +3451,12 @@ static struct command_result *direct_pay_cb(struct direct_pay_data *d, struct pa
if (p->step != PAYMENT_STEP_INITIALIZED)
return payment_continue(p);
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "listpeerchannels",
req = jsonrpc_request_start(payment_cmd(p), "listpeerchannels",
direct_pay_listpeerchannels,
direct_pay_listpeerchannels,
p);
json_add_node_id(req->js, "id", p->route_destination);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
static struct direct_pay_data *direct_pay_init(struct payment *p)
@ -3755,11 +3755,11 @@ static struct command_result *payee_incoming_limit_step_cb(void *d UNUSED, struc
/* Get information on the destination. */
struct out_req *req;
req = jsonrpc_request_start(p->plugin, payment_cmd(p), "listchannels",
req = jsonrpc_request_start(payment_cmd(p), "listchannels",
&payee_incoming_limit_count,
&payment_rpc_failure, p);
json_add_node_id(req->js, "source", p->route_destination);
return send_outreq(p->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(payee_incoming_limit, void *, NULL,

View File

@ -120,7 +120,7 @@ struct plugin {
struct plugin_option *opts;
/* Anything special to do at init ? */
const char *(*init)(struct plugin *p,
const char *(*init)(struct command *init_cmd,
const char *buf, const jsmntok_t *);
/* Has the manifest been sent already ? */
bool manifested;
@ -169,22 +169,6 @@ struct json_filter **command_filter_ptr(struct command *cmd)
return &cmd->filter;
}
static void complain_deprecated_nocmd(const char *feature,
bool allowing,
struct plugin *plugin)
{
if (!allowing) {
/* Mild log message for disallowing */
plugin_log(plugin, LOG_DBG,
"Note: disallowing deprecated %s",
feature);
} else {
plugin_log(plugin, LOG_BROKEN,
"DEPRECATED API USED: %s",
feature);
}
}
/* New command, without a filter */
static struct command *new_command(const tal_t *ctx,
struct plugin *plugin,
@ -202,18 +186,6 @@ static struct command *new_command(const tal_t *ctx,
return cmd;
}
bool command_deprecated_in_nocmd_ok(struct plugin *plugin,
const char *name,
const char *depr_start,
const char *depr_end)
{
return deprecated_ok(plugin->deprecated_ok,
name,
depr_start, depr_end,
plugin->beglist,
complain_deprecated_nocmd, plugin);
}
static void complain_deprecated(const char *feature,
bool allowing,
struct command *cmd)
@ -330,7 +302,7 @@ static void destroy_out_req(struct out_req *out_req, struct plugin *plugin)
/* FIXME: Move lightningd/jsonrpc to common/ ? */
struct out_req *
jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
jsonrpc_request_start_(struct command *cmd,
const char *method,
const char *id_prefix,
const char *filter,
@ -348,13 +320,13 @@ jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
assert(cmd);
out = tal(cmd, struct out_req);
out->id = append_json_id(out, plugin, method, id_prefix);
out->id = append_json_id(out, cmd->plugin, method, id_prefix);
out->cmd = cmd;
out->cb = cb;
out->errcb = errcb;
out->arg = arg;
strmap_add(&plugin->out_reqs, out->id, out);
tal_add_destructor2(out, destroy_out_req, plugin);
strmap_add(&cmd->plugin->out_reqs, out->id, out);
tal_add_destructor2(out, destroy_out_req, cmd->plugin);
/* If command goes away, don't call callbacks! */
tal_add_destructor2(out->cmd, disable_request_cb, out);
@ -753,12 +725,14 @@ static const jsmntok_t *sync_req(const tal_t *ctx,
return contents;
}
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx, struct plugin *plugin,
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
struct command *init_cmd,
const char *method,
const struct json_out *params TAKES,
const char **resp)
{
return sync_req(ctx, plugin, method, params, resp);
assert(streq(init_cmd->methodname, "init"));
return sync_req(ctx, init_cmd->plugin, method, params, resp);
}
/* Returns contents of scanning guide on 'result' */
@ -777,7 +751,7 @@ static const char *rpc_scan_core(const tal_t *ctx,
}
/* Synchronous routine to send command and extract fields from response */
void rpc_scan(struct plugin *plugin,
void rpc_scan(struct command *init_cmd,
const char *method,
const struct json_out *params TAKES,
const char *guide,
@ -786,12 +760,13 @@ void rpc_scan(struct plugin *plugin,
const char *err;
va_list ap;
assert(streq(init_cmd->methodname, "init"));
va_start(ap, guide);
err = rpc_scan_core(tmpctx, plugin, method, params, guide, ap);
err = rpc_scan_core(tmpctx, init_cmd->plugin, method, params, guide, ap);
va_end(ap);
if (err)
plugin_err(plugin, "Could not parse %s in reply to %s: %s",
plugin_err(init_cmd->plugin, "Could not parse %s in reply to %s: %s",
guide, method, err);
}
@ -806,7 +781,7 @@ static void json_add_keypath(struct json_out *jout, const char *fieldname, const
}
static const char *rpc_scan_datastore(const tal_t *ctx,
struct plugin *plugin,
struct command *init_cmd,
const char *path,
const char *hex_or_string,
va_list ap)
@ -814,6 +789,7 @@ static const char *rpc_scan_datastore(const tal_t *ctx,
const char *guide;
struct json_out *params;
assert(streq(init_cmd->methodname, "init"));
params = json_out_new(NULL);
json_out_start(params, NULL, '{');
json_add_keypath(params, "key", path);
@ -821,12 +797,12 @@ static const char *rpc_scan_datastore(const tal_t *ctx,
json_out_finished(params);
guide = tal_fmt(tmpctx, "{datastore:[0:{%s:%%}]}", hex_or_string);
return rpc_scan_core(ctx, plugin, "listdatastore", take(params),
return rpc_scan_core(ctx, init_cmd->plugin, "listdatastore", take(params),
guide, ap);
}
const char *rpc_scan_datastore_str(const tal_t *ctx,
struct plugin *plugin,
struct command *init_cmd,
const char *path,
...)
{
@ -834,14 +810,14 @@ const char *rpc_scan_datastore_str(const tal_t *ctx,
va_list ap;
va_start(ap, path);
ret = rpc_scan_datastore(ctx, plugin, path, "string", ap);
ret = rpc_scan_datastore(ctx, init_cmd, path, "string", ap);
va_end(ap);
return ret;
}
/* This variant scans the hex encoding, not the string */
const char *rpc_scan_datastore_hex(const tal_t *ctx,
struct plugin *plugin,
struct command *init_cmd,
const char *path,
...)
{
@ -849,7 +825,7 @@ const char *rpc_scan_datastore_hex(const tal_t *ctx,
va_list ap;
va_start(ap, path);
ret = rpc_scan_datastore(ctx, plugin, path, "hex", ap);
ret = rpc_scan_datastore(ctx, init_cmd, path, "hex", ap);
va_end(ap);
return ret;
}
@ -879,8 +855,7 @@ static struct command_result *datastore_fail(struct command *command,
json_tok_full(buf, result));
}
struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
struct command *cmd,
struct command_result *jsonrpc_set_datastore_(struct command *cmd,
const char *path,
const void *value,
bool value_is_string,
@ -902,7 +877,7 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
if (!errcb)
errcb = datastore_fail;
req = jsonrpc_request_start(plugin, cmd, "datastore", cb, errcb, arg);
req = jsonrpc_request_start(cmd, "datastore", cb, errcb, arg);
json_add_keypath(req->js->jout, "key", path);
if (value_is_string)
@ -910,7 +885,7 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
else
json_add_hex_talarr(req->js, "hex", value);
json_add_string(req->js, "mode", mode);
return send_outreq(plugin, req);
return send_outreq(req);
}
struct get_ds_info {
@ -962,8 +937,7 @@ static struct command_result *listdatastore_done(struct command *cmd,
return dsi->binary_cb(cmd, val, dsi->arg);
}
struct command_result *jsonrpc_get_datastore_(struct plugin *plugin,
struct command *cmd,
struct command_result *jsonrpc_get_datastore_(struct command *cmd,
const char *path,
struct command_result *(*string_cb)(struct command *command,
const char *val,
@ -981,12 +955,12 @@ struct command_result *jsonrpc_get_datastore_(struct plugin *plugin,
dsi->arg = arg;
/* listdatastore doesn't fail (except API misuse) */
req = jsonrpc_request_start(plugin, cmd, "listdatastore",
req = jsonrpc_request_start(cmd, "listdatastore",
listdatastore_done, datastore_fail, dsi);
tal_steal(req, dsi);
json_add_keypath(req->js->jout, "key", path);
return send_outreq(plugin, req);
return send_outreq(req);
}
static void destroy_cmd_mark_freed(struct command *cmd, bool *cmd_freed)
@ -1058,7 +1032,7 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
}
struct command_result *
send_outreq(struct plugin *plugin, const struct out_req *req)
send_outreq(const struct out_req *req)
{
/* The "param" object. */
if (req->errcb)
@ -1066,10 +1040,8 @@ send_outreq(struct plugin *plugin, const struct out_req *req)
json_object_end(req->js);
json_stream_close(req->js, req->cmd);
ld_rpc_send(plugin, req->js);
if (req->cmd != NULL)
notleak_with_children(req->cmd);
ld_rpc_send(req->cmd->plugin, req->js);
notleak_with_children(req->cmd);
return &pending;
}
@ -1157,7 +1129,7 @@ struct out_req *add_to_batch(struct command *cmd,
{
batch->num_remaining++;
return jsonrpc_request_start(cmd->plugin, cmd, cmdname,
return jsonrpc_request_start(cmd, cmdname,
batch_one_success,
batch_one_failed,
batch);
@ -1527,7 +1499,7 @@ static struct command_result *handle_init(struct command *cmd,
}
if (p->init) {
const char *disable = p->init(p, buf, configtok);
const char *disable = p->init(cmd, buf, configtok);
if (disable)
return command_success(cmd, json_out_obj(cmd, "disable",
disable));
@ -1535,7 +1507,7 @@ static struct command_result *handle_init(struct command *cmd,
if (with_rpc) {
p->beglist = NULL;
rpc_scan(p, "listconfigs",
rpc_scan(cmd, "listconfigs",
take(json_out_obj(NULL, "config", "i-promise-to-fix-broken-api-user")),
"{configs:{i-promise-to-fix-broken-api-user?:%}}",
JSON_SCAN_TAL(p, json_to_apilist, &p->beglist));
@ -2267,7 +2239,7 @@ static struct io_plan *stdout_conn_init(struct io_conn *conn,
static struct plugin *new_plugin(const tal_t *ctx,
const char *argv0,
bool developer,
const char *(*init)(struct plugin *p,
const char *(*init)(struct command *init_cmd,
const char *buf,
const jsmntok_t *),
const enum plugin_restartability restartability,
@ -2361,7 +2333,7 @@ static struct plugin *new_plugin(const tal_t *ctx,
}
void plugin_main(char *argv[],
const char *(*init)(struct plugin *p,
const char *(*init)(struct command *init_cmd,
const char *buf, const jsmntok_t *),
void *data,
const enum plugin_restartability restartability,

View File

@ -110,8 +110,7 @@ struct plugin_hook {
const struct feature_set *plugin_feature_set(const struct plugin *p);
/* Helper to create a JSONRPC2 request stream. Send it with `send_outreq`. */
struct out_req *jsonrpc_request_start_(struct plugin *plugin,
struct command *cmd,
struct out_req *jsonrpc_request_start_(struct command *cmd,
const char *method,
const char *id_prefix,
const char *filter,
@ -124,12 +123,12 @@ struct out_req *jsonrpc_request_start_(struct plugin *plugin,
const jsmntok_t *result,
void *arg),
void *arg)
NON_NULL_ARGS(1, 2, 3, 4, 6);
NON_NULL_ARGS(1, 2, 3, 5);
/* This variant has callbacks received whole obj, not "result" or
* "error" members. */
#define jsonrpc_request_start(plugin, cmd, method, cb, errcb, arg) \
jsonrpc_request_start_((plugin), (cmd), (method), \
#define jsonrpc_request_start(cmd, method, cb, errcb, arg) \
jsonrpc_request_start_((cmd), (method), \
json_id_prefix(tmpctx, (cmd)), NULL, \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
@ -143,8 +142,8 @@ struct out_req *jsonrpc_request_start_(struct plugin *plugin,
const jsmntok_t *result), \
(arg))
#define jsonrpc_request_with_filter_start(plugin, cmd, method, filter, cb, errcb, arg) \
jsonrpc_request_start_((plugin), (cmd), (method), \
#define jsonrpc_request_with_filter_start(cmd, method, filter, cb, errcb, arg) \
jsonrpc_request_start_((cmd), (method), \
json_id_prefix(tmpctx, (cmd)), (filter), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
@ -160,8 +159,8 @@ struct out_req *jsonrpc_request_start_(struct plugin *plugin,
/* This variant has callbacks received whole obj, not "result" or
* "error" members. It also doesn't start params{}. */
#define jsonrpc_request_whole_object_start(plugin, cmd, method, id_prefix, cb, arg) \
jsonrpc_request_start_((plugin), (cmd), (method), (id_prefix), NULL, \
#define jsonrpc_request_whole_object_start(cmd, method, id_prefix, cb, arg) \
jsonrpc_request_start_((cmd), (method), (id_prefix), NULL, \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \
@ -237,8 +236,7 @@ struct json_stream *jsonrpc_stream_fail_data(struct command *cmd,
/* Helper to jsonrpc_request_start() and send_outreq() to update datastore.
* NULL cb means ignore, NULL errcb means plugin_error.
*/
struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
struct command *cmd,
struct command_result *jsonrpc_set_datastore_(struct command *cmd,
const char *path,
const void *value,
bool value_is_string,
@ -252,10 +250,10 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
const jsmntok_t *result,
void *arg),
void *arg)
NON_NULL_ARGS(1, 2, 3, 4, 6);
NON_NULL_ARGS(1, 2, 3, 5);
#define jsonrpc_set_datastore_string(plugin, cmd, path, str, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((plugin), (cmd), (path), (str), true, (mode), \
#define jsonrpc_set_datastore_string(cmd, path, str, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((cmd), (path), (str), true, (mode), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \
@ -268,8 +266,8 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
const jsmntok_t *result), \
(arg))
#define jsonrpc_set_datastore_binary(plugin, cmd, path, tal_ptr, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((plugin), (cmd), (path), (tal_ptr), false, (mode), \
#define jsonrpc_set_datastore_binary(cmd, path, tal_ptr, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((cmd), (path), (tal_ptr), false, (mode), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \
@ -285,8 +283,7 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
/* Helper to jsonrpc_request_start() and send_outreq() to read datastore.
* If the value not found, cb gets NULL @val.
*/
struct command_result *jsonrpc_get_datastore_(struct plugin *plugin,
struct command *cmd,
struct command_result *jsonrpc_get_datastore_(struct command *cmd,
const char *path,
struct command_result *(*string_cb)(struct command *command,
const char *val,
@ -295,10 +292,10 @@ struct command_result *jsonrpc_get_datastore_(struct plugin *plugin,
const u8 *val,
void *arg),
void *arg)
NON_NULL_ARGS(1, 2, 3);
NON_NULL_ARGS(1, 2);
#define jsonrpc_get_datastore_string(plugin, cmd, path, cb, arg) \
jsonrpc_get_datastore_((plugin), (cmd), (path), \
#define jsonrpc_get_datastore_string(cmd, path, cb, arg) \
jsonrpc_get_datastore_((cmd), (path), \
typesafe_cb_preargs(struct command_result *, \
void *, \
(cb), (arg), \
@ -307,8 +304,8 @@ struct command_result *jsonrpc_get_datastore_(struct plugin *plugin,
NULL, \
(arg))
#define jsonrpc_get_datastore_binary(plugin, cmd, path, cb, arg) \
jsonrpc_get_datastore_((plugin), (cmd), (path), \
#define jsonrpc_get_datastore_binary(cmd, path, cb, arg) \
jsonrpc_get_datastore_((cmd), (path), \
NULL, \
typesafe_cb_preargs(struct command_result *, \
void *, \
@ -345,12 +342,6 @@ bool command_deprecated_in_named_ok(struct command *cmd,
const char *depr_start,
const char *depr_end);
/* For commando, which doesn't have a "cmd" incoming */
bool command_deprecated_in_nocmd_ok(struct plugin *plugin,
const char *name,
const char *depr_start,
const char *depr_end);
/* Call this on fatal error. */
void NORETURN PRINTF_FMT(2,3) plugin_err(struct plugin *p, const char *fmt, ...);
@ -409,7 +400,7 @@ bool command_deprecated_ok_flag(const struct command *cmd)
/* Synchronous helper to send command and extract fields from
* response; can only be used in init callback. */
void rpc_scan(struct plugin *plugin,
void rpc_scan(struct command *init_cmd,
const char *method,
const struct json_out *params TAKES,
const char *guide,
@ -420,12 +411,12 @@ void rpc_scan(struct plugin *plugin,
* /-separated. Final arg is JSON_SCAN or JSON_SCAN_TAL.
*/
const char *rpc_scan_datastore_str(const tal_t *ctx,
struct plugin *plugin,
struct command *init_cmd,
const char *path,
...);
/* This variant scans the hex encoding, not the string */
const char *rpc_scan_datastore_hex(const tal_t *ctx,
struct plugin *plugin,
struct command *init_cmd,
const char *path,
...);
@ -433,8 +424,7 @@ const char *rpc_scan_datastore_hex(const tal_t *ctx,
void rpc_enable_batching(struct plugin *plugin);
/* Send an async rpc request to lightningd. */
struct command_result *send_outreq(struct plugin *plugin,
const struct out_req *req);
struct command_result *send_outreq(const struct out_req *req);
/* Callback to just forward error and close request; @cmd cannot be NULL */
struct command_result *forward_error(struct command *cmd,
@ -600,7 +590,7 @@ bool flag_jsonfmt(struct plugin *plugin, struct json_stream *js, const char *fie
/* The main plugin runner: append with 0 or more plugin_option(), then NULL. */
void NORETURN LAST_ARG_NULL plugin_main(char *argv[],
const char *(*init)(struct plugin *p,
const char *(*init)(struct command *init_cmd,
const char *buf,
const jsmntok_t *),
void *data TAKES,
@ -660,7 +650,8 @@ void plugin_set_memleak_handler(struct plugin *plugin,
/* Synchronously call a JSON-RPC method and return its contents and
* the parser token. */
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx, struct plugin *plugin,
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
struct command *init_cmd,
const char *method,
const struct json_out *params TAKES,
const char **resp);

View File

@ -104,7 +104,7 @@ inject_onionmessage_(struct command *cmd,
{
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "injectonionmessage",
req = jsonrpc_request_start(cmd, "injectonionmessage",
cb, errcb, arg);
json_add_pubkey(req->js, "path_key", &omsg->first_path_key);
json_array_start(req->js, "hops");
@ -115,7 +115,7 @@ inject_onionmessage_(struct command *cmd,
json_object_end(req->js);
}
json_array_end(req->js);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* Holds the details while we wait for establish_onion_path to connect */
@ -326,9 +326,9 @@ struct command_result *find_best_peer_(struct command *cmd,
data->cb = cb;
data->arg = arg;
data->needed_feature = needed_feature;
req = jsonrpc_request_start(cmd->plugin, cmd, "listincoming",
req = jsonrpc_request_start(cmd, "listincoming",
listincoming_done, forward_error, data);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static const struct plugin_hook hooks[] = {
@ -1377,30 +1377,30 @@ static struct command_result *json_decode(struct command *cmd,
if (decodable->emergency_recover) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "makesecret",
req = jsonrpc_request_start(cmd, "makesecret",
after_makesecret, &forward_error,
decodable);
json_add_string(req->js, "string", "scb secret");
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
return command_finished(cmd, response);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
rpc_scan(p, "getinfo",
rpc_scan(init_cmd, "getinfo",
take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_pubkey, &id));
rpc_scan(p, "getchaininfo",
rpc_scan(init_cmd, "getchaininfo",
take(json_out_obj(NULL, "last_height", NULL)),
"{headercount:%}", JSON_SCAN(json_to_u32, &blockheight));
rpc_scan(p, "listconfigs",
rpc_scan(init_cmd, "listconfigs",
take(json_out_obj(NULL, NULL, NULL)),
"{configs:"
"{cltv-final:{value_int:%},"
@ -1408,17 +1408,17 @@ static const char *init(struct plugin *p,
JSON_SCAN(json_to_u16, &cltv_final),
JSON_SCAN(json_to_bool, &offers_enabled));
rpc_scan(p, "makesecret",
rpc_scan(init_cmd, "makesecret",
take(json_out_obj(NULL, "string", BOLT12_ID_BASE_STRING)),
"{secret:%}",
JSON_SCAN(json_to_secret, &invoicesecret_base));
rpc_scan(p, "makesecret",
rpc_scan(init_cmd, "makesecret",
take(json_out_obj(NULL, "string", "offer-blinded-path")),
"{secret:%}",
JSON_SCAN(json_to_secret, &offerblinding_base));
rpc_scan(p, "makesecret",
rpc_scan(init_cmd, "makesecret",
take(json_out_obj(NULL, "string", NODE_ALIAS_BASE_STRING)),
"{secret:%}",
JSON_SCAN(json_to_secret, &nodealias_base));

View File

@ -190,11 +190,11 @@ static struct command_result *listinvreqs_done(struct command *cmd,
fmt_amount_msat(tmpctx, amt),
fmt_sha256(tmpctx, &inv->invreq_id));
req = jsonrpc_request_start(cmd->plugin, cmd, "pay",
req = jsonrpc_request_start(cmd, "pay",
pay_done, pay_error, inv);
json_add_string(req->js, "bolt11", invoice_encode(tmpctx, inv->inv));
json_add_sha256(req->js, "localinvreqid", &inv->invreq_id);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *listinvreqs_error(struct command *cmd,
@ -359,9 +359,9 @@ struct command_result *handle_invoice(struct command *cmd,
}
/* Now find the invoice_request. */
req = jsonrpc_request_start(cmd->plugin, cmd, "listinvoicerequests",
req = jsonrpc_request_start(cmd, "listinvoicerequests",
listinvreqs_done, listinvreqs_error, inv);
json_add_sha256(req->js, "invreq_id", &inv->invreq_id);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}

View File

@ -223,7 +223,7 @@ static struct command_result *create_invoicereq(struct command *cmd,
* if we don't have public channels! */
/* Now, write invoice to db (returns the signed version) */
req = jsonrpc_request_start(cmd->plugin, cmd, "createinvoice",
req = jsonrpc_request_start(cmd, "createinvoice",
createinvoice_done, createinvoice_error, ir);
json_add_string(req->js, "invstring", invoice_encode(tmpctx, ir->inv));
@ -231,7 +231,7 @@ static struct command_result *create_invoicereq(struct command *cmd,
json_add_label(req->js, &ir->offer_id, ir->inv->invreq_payer_id,
ir->inv->invreq_recurrence_counter
? *ir->inv->invreq_recurrence_counter : 0);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* FIXME: This is naive:
@ -545,7 +545,7 @@ static struct command_result *check_previous_invoice(struct command *cmd,
if (*ir->invreq->invreq_recurrence_counter == 0)
return check_period(cmd, ir, *ir->inv->invoice_created_at);
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listinvoices",
prev_invoice_done,
error,
@ -554,7 +554,7 @@ static struct command_result *check_previous_invoice(struct command *cmd,
&ir->offer_id,
ir->invreq->invreq_payer_id,
*ir->invreq->invreq_recurrence_counter - 1);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* BOLT-offers #12:
@ -750,13 +750,13 @@ static struct command_result *convert_currency(struct command *cmd,
for (size_t i = 0; i < iso4217->minor_unit; i++)
double_amount /= 10;
req = jsonrpc_request_start(cmd->plugin, cmd, "currencyconvert",
req = jsonrpc_request_start(cmd, "currencyconvert",
currency_done, error, ir);
json_add_stringn(req->js, "currency",
(const char *)ir->invreq->offer_currency,
tal_bytelen(ir->invreq->offer_currency));
json_add_primitive_fmt(req->js, "amount", "%f", double_amount);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *listoffers_done(struct command *cmd,
@ -1063,8 +1063,8 @@ struct command_result *handle_invoice_request(struct command *cmd,
invreq_offer_id(ir->invreq, &ir->offer_id);
/* Now, look up offer */
req = jsonrpc_request_start(cmd->plugin, cmd, "listoffers",
req = jsonrpc_request_start(cmd, "listoffers",
listoffers_done, error, ir);
json_add_sha256(req->js, "offer_id", &ir->offer_id);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}

View File

@ -265,7 +265,7 @@ static struct command_result *create_offer(struct command *cmd,
struct out_req *req;
/* We simply pass this through. */
req = jsonrpc_request_start(cmd->plugin, cmd, "createoffer",
req = jsonrpc_request_start(cmd, "createoffer",
check_result, forward_error,
offinfo);
json_add_string(req->js, "bolt12",
@ -274,7 +274,7 @@ static struct command_result *create_offer(struct command *cmd,
json_add_string(req->js, "label", offinfo->label);
json_add_bool(req->js, "single_use", *offinfo->single_use);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *found_best_peer(struct command *cmd,
@ -567,14 +567,14 @@ struct command_result *json_offer(struct command *cmd,
if (offer->offer_currency) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "currencyconvert",
req = jsonrpc_request_start(cmd, "currencyconvert",
currency_done, forward_error,
offinfo);
json_add_u32(req->js, "amount", 1);
json_add_stringn(req->js, "currency",
(const char *)offer->offer_currency,
tal_bytelen(offer->offer_currency));
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
return maybe_add_path(cmd, offinfo);
@ -587,7 +587,7 @@ static struct command_result *call_createinvoicerequest(struct command *cmd,
{
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "createinvoicerequest",
req = jsonrpc_request_start(cmd, "createinvoicerequest",
check_result, forward_error,
invreq);
json_add_string(req->js, "bolt12", invrequest_encode(tmpctx, invreq));
@ -595,7 +595,7 @@ static struct command_result *call_createinvoicerequest(struct command *cmd,
json_add_bool(req->js, "single_use", single_use);
if (label)
json_add_string(req->js, "recurrence_label", label);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
struct invrequest_data {

View File

@ -552,7 +552,7 @@ static struct command_result *json_listpays(struct command *cmd,
NULL))
return command_param_failed();
req = jsonrpc_request_start(cmd->plugin, cmd, "listsendpays",
req = jsonrpc_request_start(cmd, "listsendpays",
listsendpays_done, forward_error,
cast_const(char *, invstring));
if (invstring)
@ -563,7 +563,7 @@ static struct command_result *json_listpays(struct command *cmd,
if (status_str)
json_add_string(req->js, "status", status_str);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static void memleak_mark_payments(struct plugin *p, struct htable *memtable)
@ -571,10 +571,10 @@ static void memleak_mark_payments(struct plugin *p, struct htable *memtable)
memleak_scan_list_head(memtable, &payments);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_node_id, &my_id));
/* BOLT #4:
@ -586,17 +586,17 @@ static const char *init(struct plugin *p,
/* FIXME: Typo in spec for CLTV in descripton! But it breaks our spelling check, so we omit it above */
maxdelay_default = 2016;
global_hints = notleak_with_children(channel_hint_set_new(p));
global_hints = notleak_with_children(channel_hint_set_new(init_cmd->plugin));
/* max-locktime-blocks deprecated in v24.05, but still grab it! */
rpc_scan(p, "listconfigs", take(json_out_obj(NULL, NULL, NULL)),
"{configs:"
"{max-locktime-blocks?:{value_int:%},"
"experimental-offers:{set:%}}}",
JSON_SCAN(json_to_number, &maxdelay_default),
JSON_SCAN(json_to_bool, &exp_offers));
/* max-locktime-blocks deprecated in v24.05, but still grab it! */
rpc_scan(init_cmd, "listconfigs", take(json_out_obj(NULL, NULL, NULL)),
"{configs:"
"{max-locktime-blocks?:{value_int:%},"
"experimental-offers:{set:%}}}",
JSON_SCAN(json_to_number, &maxdelay_default),
JSON_SCAN(json_to_bool, &exp_offers));
plugin_set_memleak_handler(p, memleak_mark_payments);
plugin_set_memleak_handler(init_cmd->plugin, memleak_mark_payments);
return NULL;
}
@ -835,7 +835,7 @@ static struct command_result *selfpay(struct command *cmd, struct payment *p)
/* This "struct payment" simply gets freed once command is done. */
tal_steal(cmd, p);
req = jsonrpc_request_start(cmd->plugin, cmd, "sendpay",
req = jsonrpc_request_start(cmd, "sendpay",
selfpay_success,
forward_error, p);
/* Empty route means "to-self" */
@ -855,7 +855,7 @@ static struct command_result *selfpay(struct command *cmd, struct payment *p)
json_add_hex_talarr(req->js, "payment_metadata", p->payment_metadata);
if (p->description)
json_add_string(req->js, "description", p->description);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* We are interested in any prior attempts to pay this payment_hash /
@ -1033,12 +1033,12 @@ start_payment(struct command *cmd, struct payment *p)
/* We're keeping this around now */
tal_steal(cmd->plugin, p);
req = jsonrpc_request_start(cmd->plugin, cmd, "listsendpays",
req = jsonrpc_request_start(cmd, "listsendpays",
payment_listsendpays_previous,
payment_listsendpays_previous, p);
json_add_sha256(req->js, "payment_hash", p->payment_hash);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static bool scidtok_eq(const char *buf,
@ -1176,10 +1176,10 @@ decrypt_done(struct command *cmd,
p->blindedpath->first_node_id.is_pubkey = false;
p->blindedpath->first_node_id.scidd.scid = *enctlv->short_channel_id;
req = jsonrpc_request_with_filter_start(cmd->plugin, cmd, "listpeerchannels",
req = jsonrpc_request_with_filter_start(cmd, "listpeerchannels",
"{\"channels\":[{\"peer_id\":true,\"short_channel_id\":true,\"alias\":{\"local\":true}}]}",
listpeerchannels_done, forward_error, p);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
} else {
return command_fail(cmd, PAY_UNPARSEABLE_ONION,
"Invalid TLV for blinded path (no next!): %s",
@ -1202,13 +1202,13 @@ preapproveinvoice_succeed(struct command *cmd,
if (p->blindedpath && node_id_eq(p->route_destination, &my_id)) {
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "decryptencrypteddata",
req = jsonrpc_request_start(cmd, "decryptencrypteddata",
decrypt_done, forward_error, p);
json_add_hex_talarr(req->js, "encrypted_data",
p->blindedpath->path[0]->encrypted_recipient_data);
json_add_pubkey(req->js, "path_key", &p->blindedpath->first_path_key);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
return start_payment(cmd, p);
@ -1465,17 +1465,17 @@ static struct command_result *json_pay(struct command *cmd,
/* Now preapprove, then start payment. */
if (command_check_only(cmd)) {
req = jsonrpc_request_start(p->plugin, cmd, "check",
req = jsonrpc_request_start(cmd, "check",
&preapproveinvoice_succeed,
&forward_error, p);
json_add_string(req->js, "command_to_check", "preapproveinvoice");
} else {
req = jsonrpc_request_start(p->plugin, cmd, "preapproveinvoice",
req = jsonrpc_request_start(cmd, "preapproveinvoice",
&preapproveinvoice_succeed,
&forward_error, p);
}
json_add_string(req->js, "bolt11", p->invstring);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *handle_channel_hint_update(struct command *cmd,

View File

@ -281,29 +281,29 @@ static struct command_result *json_reckless(struct command *cmd,
return reckless_call(cmd, command, target, target2);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
plugin = p;
rpc_scan(p, "listconfigs",
plugin = init_cmd->plugin;
rpc_scan(init_cmd, "listconfigs",
take(json_out_obj(NULL, NULL, NULL)),
"{configs:{"
"conf?:{value_str:%},"
"lightning-dir:{value_str:%},"
"network:{value_str:%}"
"}}",
JSON_SCAN_TAL(p, json_strdup, &lconfig.config),
JSON_SCAN_TAL(p, json_strdup, &lconfig.lightningdir),
JSON_SCAN_TAL(p, json_strdup, &lconfig.network));
JSON_SCAN_TAL(plugin, json_strdup, &lconfig.config),
JSON_SCAN_TAL(plugin, json_strdup, &lconfig.lightningdir),
JSON_SCAN_TAL(plugin, json_strdup, &lconfig.network));
/* These lightning config parameters need to stick around for each
* reckless call. */
if (lconfig.config)
notleak(lconfig.config);
notleak(lconfig.lightningdir);
notleak(lconfig.network);
plugin_log(p, LOG_DBG, "plugin initialized!");
plugin_log(p, LOG_DBG, "lightning-dir: %s", lconfig.lightningdir);
plugin_log(plugin, LOG_DBG, "plugin initialized!");
plugin_log(plugin, LOG_DBG, "lightning-dir: %s", lconfig.lightningdir);
return NULL;
}

View File

@ -95,11 +95,11 @@ static struct command_result *find_peer_storage (struct command *cmd)
peer_storage_timer = NULL;
struct out_req *req;
req = jsonrpc_request_start(plugin, cmd, "restorefrompeer",
req = jsonrpc_request_start(cmd, "restorefrompeer",
after_restorefrompeer,
&forward_error, NULL);
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *do_find_peer_storage(struct command *cmd, void *unused)
@ -128,8 +128,7 @@ static struct command_result *do_check_gossip(struct command *cmd, void *unused)
gossmap_node_get_id(global_gossmap, neighbour, &peer_id);
struct out_req *req;
req = jsonrpc_request_start(plugin,
cmd,
req = jsonrpc_request_start(cmd,
"connect",
connect_success,
connect_fail,
@ -139,7 +138,7 @@ static struct command_result *do_check_gossip(struct command *cmd, void *unused)
plugin_log(plugin, LOG_DBG, "Connecting to: %s",
fmt_node_id(tmpctx, &peer_id));
send_outreq(plugin, req);
send_outreq(req);
}
@ -160,29 +159,27 @@ static void entering_recovery_mode(struct command *cmd)
if (!already_has_peers) {
for (size_t i = 0; i < ARRAY_SIZE(nodes_for_gossip); i++) {
struct out_req *req;
req = jsonrpc_request_start(plugin,
cmd,
req = jsonrpc_request_start(cmd,
"connect",
connect_success,
connect_fail,
NULL);
plugin_log (plugin, LOG_DBG, "Connecting to %s", nodes_for_gossip[i]);
json_add_string(req->js, "id", nodes_for_gossip[i]);
send_outreq(plugin, req);
send_outreq(req);
}
}
struct out_req *req_emer_recovery;
/* Let's try to recover whatever we have in the emergencyrecover file. */
req_emer_recovery = jsonrpc_request_start(plugin,
cmd,
req_emer_recovery = jsonrpc_request_start(cmd,
"emergencyrecover",
after_emergency_recover,
&forward_error,
NULL);
send_outreq(plugin, req_emer_recovery);
send_outreq(req_emer_recovery);
find_exes_timer = global_timer(
plugin, time_from_sec(CHECK_GOSSIP_INTERVAL), do_check_gossip, cmd);
return;
@ -225,11 +222,11 @@ static struct command_result *after_listpeerchannels(struct command *cmd,
static struct command_result *check_lost_peer(struct command *cmd)
{
struct out_req *req;
req = jsonrpc_request_start(plugin, cmd, "listpeerchannels",
req = jsonrpc_request_start(cmd, "listpeerchannels",
after_listpeerchannels,
&forward_error, NULL);
return send_outreq(plugin, req);
return send_outreq(req);
}
static struct command_result *do_check_lost_peer(struct command *cmd, void *unused)
@ -245,12 +242,12 @@ static struct command_result *do_check_lost_peer(struct command *cmd, void *unus
return check_lost_peer(cmd);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
plugin = p;
plugin_log(p, LOG_DBG, "Recover Plugin Initialised!");
plugin = init_cmd->plugin;
plugin_log(plugin, LOG_DBG, "Recover Plugin Initialised!");
recovery = false;
lost_state_timer = global_timer(plugin, time_from_sec(STARTUP_TIME),
do_check_lost_peer, NULL);
@ -258,7 +255,7 @@ static const char *init(struct plugin *p,
size_t num_cupdates_rejected;
/* Find number of peers */
rpc_scan(p, "getinfo",
rpc_scan(init_cmd, "getinfo",
take(json_out_obj(NULL, NULL, NULL)),
"{id:%,num_peers:%}",
JSON_SCAN(json_to_node_id, &local_id),
@ -269,15 +266,15 @@ static const char *init(struct plugin *p,
&num_cupdates_rejected));
if (!global_gossmap)
plugin_err(p, "Could not load gossmap %s: %s",
plugin_err(plugin, "Could not load gossmap %s: %s",
GOSSIP_STORE_FILENAME, strerror(errno));
if (num_cupdates_rejected)
plugin_log(p, LOG_DBG,
plugin_log(plugin, LOG_DBG,
"gossmap ignored %zu channel updates",
num_cupdates_rejected);
plugin_log(p, LOG_DBG, "Gossmap loaded!");
plugin_log(plugin, LOG_DBG, "Gossmap loaded!");
already_has_peers = num_peers > 1 ? 1: 0;

View File

@ -35,16 +35,17 @@ static void memleak_mark(struct plugin *p, struct htable *memtable)
memleak_scan_htable(memtable, &pay_plugin->pending_routes->raw);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
struct plugin *p = init_cmd->plugin;
size_t num_channel_updates_rejected = 0;
tal_steal(p, pay_plugin);
pay_plugin->plugin = p;
pay_plugin->last_time = 0;
rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_node_id, &pay_plugin->my_id));
/* BOLT #4:
@ -56,7 +57,7 @@ static const char *init(struct plugin *p,
/* FIXME: Typo in spec for CLTV in descripton! But it breaks our spelling check, so we omit it above */
pay_plugin->maxdelay_default = 2016;
/* max-locktime-blocks deprecated in v24.05, but still grab it! */
rpc_scan(p, "listconfigs",
rpc_scan(init_cmd, "listconfigs",
take(json_out_obj(NULL, NULL, NULL)),
"{configs:"
"{max-locktime-blocks?:{value_int:%},"

View File

@ -216,13 +216,13 @@ static struct command_result *previoussuccess_cb(struct payment *payment)
assert(cmd);
struct out_req *req = jsonrpc_request_start(
cmd->plugin, cmd, "listsendpays", previoussuccess_done,
cmd, "listsendpays", previoussuccess_done,
payment_rpc_failure, payment);
json_add_sha256(req->js, "payment_hash",
&payment->payment_info.payment_hash);
json_add_string(req->js, "status", "complete");
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(previoussuccess, previoussuccess_cb);
@ -312,11 +312,11 @@ static struct command_result *selfpay_cb(struct payment *payment)
/*partid=*/0, pinfo->payment_hash,
pinfo->amount, pinfo->amount);
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "sendpay",
req = jsonrpc_request_start(cmd, "sendpay",
selfpay_success, selfpay_failure, route);
route->hops = tal_arr(route, struct route_hop, 0);
json_add_route(req->js, route, payment);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(selfpay, selfpay_cb);
@ -452,9 +452,9 @@ static struct command_result *getmychannels_cb(struct payment *payment)
"getmychannels_pay_mod: cannot get a valid cmd.");
struct out_req *req = jsonrpc_request_start(
cmd->plugin, cmd, "listpeerchannels", getmychannels_done,
cmd, "listpeerchannels", getmychannels_done,
payment_rpc_failure, payment);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(getmychannels, getmychannels_cb);
@ -622,10 +622,10 @@ static struct command_result *routehints_cb(struct payment *payment)
struct command *cmd = payment_command(payment);
assert(cmd);
struct out_req *req = jsonrpc_request_start(
cmd->plugin, cmd, "waitblockheight", routehints_done,
cmd, "waitblockheight", routehints_done,
payment_rpc_failure, payment);
json_add_num(req->js, "blockheight", 0);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(routehints, routehints_cb);
@ -879,10 +879,10 @@ static struct command_result *end_cb(struct payment *payment)
struct command *cmd = payment_command(payment);
assert(cmd);
struct out_req *req =
jsonrpc_request_start(cmd->plugin, cmd, "waitblockheight", end_done,
jsonrpc_request_start(cmd, "waitblockheight", end_done,
payment_rpc_failure, payment);
json_add_num(req->js, "blockheight", 0);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(end, end_cb);
@ -1068,12 +1068,12 @@ static struct command_result *pendingsendpays_cb(struct payment *payment)
assert(cmd);
struct out_req *req = jsonrpc_request_start(
cmd->plugin, cmd, "listsendpays", pendingsendpays_done,
cmd, "listsendpays", pendingsendpays_done,
payment_rpc_failure, payment);
json_add_sha256(req->js, "payment_hash",
&payment->payment_info.payment_hash);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
REGISTER_PAYMENT_MODIFIER(pendingsendpays, pendingsendpays_cb);

View File

@ -152,10 +152,10 @@ static struct command_result *update_gossip(struct routefail *r)
goto skip_update_gossip;
struct out_req *req =
jsonrpc_request_start(r->cmd->plugin, r->cmd, "addgossip",
jsonrpc_request_start(r->cmd, "addgossip",
update_gossip_done, update_gossip_failure, r);
json_add_hex_talarr(req->js, "message", update);
return send_outreq(r->cmd->plugin, req);
return send_outreq(req);
skip_update_gossip:
return handle_failure(r);

View File

@ -329,7 +329,7 @@ struct command_result *route_sendpay_request(struct command *cmd,
struct payment *payment)
{
struct out_req *req =
jsonrpc_request_start(pay_plugin->plugin, cmd, "sendpay",
jsonrpc_request_start(cmd, "sendpay",
sendpay_done, sendpay_failed, route);
json_add_route(req->js, route, payment);
@ -337,7 +337,7 @@ struct command_result *route_sendpay_request(struct command *cmd,
route_map_add(payment->routetracker->sent_routes, route);
if(taken(route))
tal_steal(payment->routetracker->sent_routes, route);
return send_outreq(pay_plugin->plugin, req);
return send_outreq(req);
}
struct command_result *notification_sendpay_failure(struct command *cmd,

View File

@ -75,7 +75,7 @@ json_fundchannel(struct command *cmd,
"Must pass in 'compact_lease' if requesting"
" funds from peer");
req = jsonrpc_request_start(cmd->plugin, cmd, "multifundchannel",
req = jsonrpc_request_start(cmd, "multifundchannel",
&fundchannel_get_result, &forward_error,
NULL);
@ -111,7 +111,7 @@ json_fundchannel(struct command *cmd,
if (utxos)
json_add_tok(req->js, "utxos", utxos, buf);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static bool json_to_tok(const char *buffer, const jsmntok_t *tok, const jsmntok_t **ret)

View File

@ -8,9 +8,9 @@
* spending from the onchain wallet. */
static
const char *spender_init(struct plugin *p, const char *b, const jsmntok_t *t)
const char *spender_init(struct command *init_cmd, const char *b, const jsmntok_t *t)
{
openchannel_init(p, b, t);
openchannel_init(init_cmd->plugin, b, t);
/* whatever_init(p, b, t); */
return NULL;
}

View File

@ -168,8 +168,7 @@ static struct command_result *unreserve_call(struct command *cmd,
void *cb, void *cbdata)
{
struct wally_psbt *pruned_psbt;
struct out_req *req = jsonrpc_request_start(cmd->plugin,
cmd,
struct out_req *req = jsonrpc_request_start(cmd,
"unreserveinputs",
cb, cb, cbdata);
@ -188,7 +187,7 @@ static struct command_result *unreserve_call(struct command *cmd,
json_add_psbt(req->js, "psbt", take(pruned_psbt));
json_add_u32(req->js, "reserve", 2016);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* Cleans up a txid by doing `txdiscard` on it. */
@ -206,14 +205,13 @@ mfc_cleanup_oc(struct command *cmd,
struct multifundchannel_cleanup *cleanup,
struct multifundchannel_destination *dest)
{
struct out_req *req = jsonrpc_request_start(cmd->plugin,
cmd,
struct out_req *req = jsonrpc_request_start(cmd,
"openchannel_abort",
&mfc_cleanup_done,
&mfc_cleanup_done,
cleanup);
json_add_channel_id(req->js, "channel_id", &dest->channel_id);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
/* Cleans up a `fundchannel_start` by doing `fundchannel_cancel` on
@ -224,15 +222,14 @@ mfc_cleanup_fc(struct command *cmd,
struct multifundchannel_cleanup *cleanup,
struct multifundchannel_destination *dest)
{
struct out_req *req = jsonrpc_request_start(cmd->plugin,
cmd,
struct out_req *req = jsonrpc_request_start(cmd,
"fundchannel_cancel",
&mfc_cleanup_done,
&mfc_cleanup_done,
cleanup);
json_add_node_id(req->js, "id", &dest->id);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
/* Core cleanup function. */
@ -647,7 +644,7 @@ after_signpsbt(struct command *cmd,
plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": sendpsbt.", mfc->id);
req = jsonrpc_request_start(mfc->cmd->plugin, mfc->cmd,
req = jsonrpc_request_start(mfc->cmd,
"sendpsbt",
&after_sendpsbt,
&mfc_forward_error,
@ -656,7 +653,7 @@ after_signpsbt(struct command *cmd,
/* We already reserved inputs by 2 weeks, we don't need
* another 72 blocks. */
json_add_u32(req->js, "reserve", 0);
return send_outreq(mfc->cmd->plugin, req);
return send_outreq(req);
}
struct command_result *
@ -669,7 +666,7 @@ perform_signpsbt(struct multifundchannel_command *mfc)
plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": signpsbt.", mfc->id);
req = jsonrpc_request_start(mfc->cmd->plugin, mfc->cmd,
req = jsonrpc_request_start(mfc->cmd,
"signpsbt",
&after_signpsbt,
&mfc_forward_error,
@ -684,7 +681,7 @@ perform_signpsbt(struct multifundchannel_command *mfc)
json_add_num(req->js, NULL, i);
}
json_array_end(req->js);
return send_outreq(mfc->cmd->plugin, req);
return send_outreq(req);
}
/*~
@ -795,8 +792,7 @@ fundchannel_complete_dest(struct multifundchannel_destination *dest)
mfc->id, dest->index,
fmt_node_id(tmpctx, &dest->id));
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"fundchannel_complete",
&fundchannel_complete_ok,
&fundchannel_complete_err,
@ -804,7 +800,7 @@ fundchannel_complete_dest(struct multifundchannel_destination *dest)
json_add_node_id(req->js, "id", &dest->id);
json_add_psbt(req->js, "psbt", mfc->psbt);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
struct command_result *
@ -1108,8 +1104,7 @@ fundchannel_start_dest(struct multifundchannel_destination *dest)
mfc->id, dest->index,
fmt_node_id(tmpctx, &dest->id));
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"fundchannel_start",
&fundchannel_start_ok,
&fundchannel_start_err,
@ -1144,7 +1139,7 @@ fundchannel_start_dest(struct multifundchannel_destination *dest)
req->js, "reserve",
fmt_amount_sat(tmpctx, *dest->reserve));
send_outreq(cmd->plugin, req);
send_outreq(req);
}
static struct command_result *
@ -1325,8 +1320,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate)
"mfc %"PRIu64": utxopsbt.",
mfc->id);
req = jsonrpc_request_start(mfc->cmd->plugin,
mfc->cmd,
req = jsonrpc_request_start(mfc->cmd,
"utxopsbt",
&after_fundpsbt,
&mfc_forward_error,
@ -1339,8 +1333,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate)
"mfc %"PRIu64": fundpsbt.",
mfc->id);
req = jsonrpc_request_start(mfc->cmd->plugin,
mfc->cmd,
req = jsonrpc_request_start(mfc->cmd,
"fundpsbt",
&after_fundpsbt,
&mfc_forward_error,
@ -1424,7 +1417,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate)
/* Handle adding a change output if required. */
json_add_bool(req->js, "excess_as_change", true);
return send_outreq(mfc->cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -1460,8 +1453,7 @@ getfeerate(struct multifundchannel_command *mfc)
* fees for the channel open. This requires that we know
* the feerate ahead of time, so that we can figure the
* expected lease fees, and add that to the funding amount. */
req = jsonrpc_request_start(mfc->cmd->plugin,
mfc->cmd,
req = jsonrpc_request_start(mfc->cmd,
"parsefeerate",
&after_getfeerate,
&mfc_forward_error,
@ -1471,7 +1463,7 @@ getfeerate(struct multifundchannel_command *mfc)
json_add_string(req->js, "feerate",
mfc->feerate_str ? mfc->feerate_str: "opening");
return send_outreq(mfc->cmd->plugin, req);
return send_outreq(req);
}
/*---------------------------------------------------------------------------*/
@ -1610,7 +1602,7 @@ connect_dest(struct multifundchannel_destination *dest)
"mfc %"PRIu64", dest %u: connect %s.",
mfc->id, dest->index, id);
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"connect",
&connect_ok,
&connect_err,
@ -1622,7 +1614,7 @@ connect_dest(struct multifundchannel_destination *dest)
dest->addrhint));
else
json_add_node_id(req->js, "id", &dest->id);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
/*-----------------------------------------------------------------------------

View File

@ -248,13 +248,12 @@ mw_perform_cleanup(struct multiwithdraw_command *mw,
cleanup->mw = mw;
cleanup->error_json = tal_strdup(cleanup, error_json);
req = jsonrpc_request_start(mw->cmd->plugin,
mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"unreserveinputs",
&mw_after_cleanup, &mw_after_cleanup,
cleanup);
json_add_psbt(req->js, "psbt", mw->psbt);
return send_outreq(mw->cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
mw_after_cleanup(struct command *cmd UNUSED,
@ -344,8 +343,7 @@ static struct command_result *start_mw(struct multiwithdraw_command *mw)
plugin_log(mw->cmd->plugin, LOG_DBG,
"multiwithdraw %"PRIu64": utxopsbt.",
mw->id);
req = jsonrpc_request_start(mw->cmd->plugin,
mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"utxopsbt",
&mw_after_fundpsbt,
&mw_forward_error,
@ -356,8 +354,7 @@ static struct command_result *start_mw(struct multiwithdraw_command *mw)
plugin_log(mw->cmd->plugin, LOG_DBG,
"multiwithdraw %"PRIu64": fundpsbt.",
mw->id);
req = jsonrpc_request_start(mw->cmd->plugin,
mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"fundpsbt",
&mw_after_fundpsbt,
&mw_forward_error,
@ -379,7 +376,7 @@ static struct command_result *start_mw(struct multiwithdraw_command *mw)
json_add_string(req->js, "feerate", mw->feerate);
json_add_u64(req->js, "startweight", startweight);
return send_outreq(mw->cmd->plugin, req);
return send_outreq(req);
}
/*-----------------------------------------------------------------------------
@ -500,11 +497,11 @@ mw_get_change_addr(struct multiwithdraw_command *mw)
"multiwithdraw %"PRIu64": change output newaddr.",
mw->id);
req = jsonrpc_request_start(mw->cmd->plugin, mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"newaddr",
&mw_after_newaddr, &mw_forward_error, mw);
json_add_string(req->js, "addresstype", chainparams->is_elements ? "bech32" : "p2tr");
return send_outreq(mw->cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -627,13 +624,13 @@ mw_sign_and_send(struct multiwithdraw_command *mw)
plugin_log(mw->cmd->plugin, LOG_DBG,
"multiwithdraw %"PRIu64": signpsbt.", mw->id);
req = jsonrpc_request_start(mw->cmd->plugin, mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"signpsbt",
&mw_after_signpsbt,
&mw_forward_error,
mw);
json_add_psbt(req->js, "psbt", mw->psbt);
return send_outreq(mw->cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *
@ -668,8 +665,7 @@ mw_after_signpsbt(struct command *cmd,
plugin_log(mw->cmd->plugin, LOG_DBG,
"multiwithdraw: %"PRIu64": sendpsbt.", mw->id);
req = jsonrpc_request_start(mw->cmd->plugin,
mw->cmd,
req = jsonrpc_request_start(mw->cmd,
"sendpsbt",
&forward_result,
/* Properly speaking, if `sendpsbt` fails,
@ -683,5 +679,5 @@ mw_after_signpsbt(struct command *cmd,
&mw_forward_error,
mw);
json_add_psbt(req->js, "psbt", mw->psbt);
return send_outreq(mw->cmd->plugin, req);
return send_outreq(req);
}

View File

@ -444,8 +444,7 @@ openchannel_signed_dest(struct multifundchannel_destination *dest)
fmt_channel_id(tmpctx, &dest->channel_id),
fmt_wally_psbt(tmpctx, dest->psbt));
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"openchannel_signed",
&openchannel_signed_ok,
&openchannel_signed_err,
@ -453,7 +452,7 @@ openchannel_signed_dest(struct multifundchannel_destination *dest)
json_add_channel_id(req->js, "channel_id", &dest->channel_id);
json_add_psbt(req->js, "signed_psbt", dest->psbt);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
struct command_result *
@ -786,8 +785,7 @@ openchannel_update_dest(struct multifundchannel_destination *dest)
fmt_node_id(tmpctx, &dest->id),
fmt_wally_psbt(tmpctx, dest->psbt));
req = jsonrpc_request_start(cmd->plugin,
cmd,
req = jsonrpc_request_start(cmd,
"openchannel_update",
&openchannel_update_ok,
&openchannel_update_err,
@ -795,7 +793,7 @@ openchannel_update_dest(struct multifundchannel_destination *dest)
json_add_channel_id(req->js, "channel_id", &dest->channel_id);
json_add_psbt(req->js, "psbt", dest->psbt);
send_outreq(cmd->plugin, req);
send_outreq(req);
}
struct command_result *
@ -972,7 +970,7 @@ openchannel_init_dest(struct multifundchannel_destination *dest)
mfc->id, dest->index,
fmt_node_id(tmpctx, &dest->id));
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"openchannel_init",
&openchannel_init_ok,
&openchannel_init_err,
@ -1026,7 +1024,7 @@ openchannel_init_dest(struct multifundchannel_destination *dest)
json_add_channel_type_arr(req->js,
"channel_type", dest->channel_type);
}
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
void openchannel_init(struct plugin *p, const char *b, const jsmntok_t *t)

View File

@ -735,10 +735,10 @@ static struct command_result *default_refresh(struct command *cmd,
struct db_query *dbq)
{
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, td->cmdname,
req = jsonrpc_request_start(cmd, td->cmdname,
default_list_done, forward_error,
dbq);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static bool extract_scid(int gosstore_fd, size_t off, u16 type,
@ -870,12 +870,12 @@ static struct command_result *channels_refresh(struct command *cmd,
/* FIXME: sqlite 3.24.0 (2018-06-04) added UPSERT, but
* we don't require it. */
delete_channel_from_db(cmd, scid);
req = jsonrpc_request_start(cmd->plugin, cmd, "listchannels",
req = jsonrpc_request_start(cmd, "listchannels",
listchannels_one_done,
forward_error,
dbq);
json_add_short_channel_id(req->js, "short_channel_id", scid);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
} else if (type == WIRE_GOSSIP_STORE_DELETE_CHAN) {
/* This can fail if entry not fully written yet. */
if (!extract_scid(gosstore_fd, off, type, &scid)) {
@ -1007,12 +1007,12 @@ static struct command_result *nodes_refresh(struct command *cmd,
/* FIXME: sqlite 3.24.0 (2018-06-04) added UPSERT, but
* we don't require it. */
delete_node_from_db(cmd, &id);
req = jsonrpc_request_start(cmd->plugin, cmd, "listnodes",
req = jsonrpc_request_start(cmd, "listnodes",
listnodes_one_done,
forward_error,
dbq);
json_add_node_id(req->js, "id", &id);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
/* FIXME: Add WIRE_GOSSIP_STORE_DELETE_NODE marker! */
}
@ -1537,9 +1537,10 @@ static void memleak_mark_tablemap(struct plugin *p, struct htable *memtable)
memleak_scan_strmap(memtable, &tablemap);
}
static const char *init(struct plugin *plugin,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
struct plugin *plugin = init_cmd->plugin;
db = sqlite_setup(plugin);
init_tablemap(plugin);
init_indices(plugin);

View File

@ -249,8 +249,7 @@ int json_tok_full_len(const jsmntok_t *t UNNEEDED)
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for jsonrpc_request_start_ */
struct out_req *jsonrpc_request_start_(struct plugin *plugin UNNEEDED,
struct command *cmd UNNEEDED,
struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED,
const char *method UNNEEDED,
const char *id_prefix UNNEEDED,
const char *filter UNNEEDED,
@ -308,8 +307,7 @@ void plugin_notify_message(struct command *cmd UNNEEDED,
bool random_select(double weight UNNEEDED, double *tot_weight UNNEEDED)
{ fprintf(stderr, "random_select called!\n"); abort(); }
/* Generated stub for send_outreq */
struct command_result *send_outreq(struct plugin *plugin UNNEEDED,
const struct out_req *req UNNEEDED)
struct command_result *send_outreq(const struct out_req *req UNNEEDED)
{ fprintf(stderr, "send_outreq called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)

View File

@ -246,8 +246,7 @@ int json_tok_full_len(const jsmntok_t *t UNNEEDED)
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for jsonrpc_request_start_ */
struct out_req *jsonrpc_request_start_(struct plugin *plugin UNNEEDED,
struct command *cmd UNNEEDED,
struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED,
const char *method UNNEEDED,
const char *id_prefix UNNEEDED,
const char *filter UNNEEDED,
@ -305,8 +304,7 @@ void plugin_notify_message(struct command *cmd UNNEEDED,
bool random_select(double weight UNNEEDED, double *tot_weight UNNEEDED)
{ fprintf(stderr, "random_select called!\n"); abort(); }
/* Generated stub for send_outreq */
struct command_result *send_outreq(struct plugin *plugin UNNEEDED,
const struct out_req *req UNNEEDED)
struct command_result *send_outreq(const struct out_req *req UNNEEDED)
{ fprintf(stderr, "send_outreq called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)

View File

@ -204,10 +204,10 @@ static struct command_result *json_getroute(struct command *cmd,
return command_param_failed();
/* Add local info */
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
req = jsonrpc_request_start(cmd, "listpeerchannels",
listpeerchannels_getroute_done,
listpeerchannels_err, info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
HTABLE_DEFINE_TYPE(struct node_id, node_id_keyof, node_id_hash, node_id_eq,
@ -476,9 +476,9 @@ static struct command_result *json_listchannels(struct command *cmd,
// FIXME: Once this deprecation is removed, `listpeerchannels_done` can
// be embedded in the current function.
if (command_deprecated_out_ok(cmd, "include_private", "v24.02", "v24.08")) {
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
req = jsonrpc_request_start(cmd, "listpeerchannels",
listpeerchannels_done, forward_error, opts);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
// If deprecations are not necessary, call listpeerchannels_done directly,
@ -696,11 +696,10 @@ static struct command_result *json_listincoming(struct command *cmd,
return command_param_failed();
/* Add local info */
req = jsonrpc_request_start(cmd->plugin,
cmd, "listpeerchannels",
req = jsonrpc_request_start(cmd, "listpeerchannels",
listpeerchannels_listincoming_done,
listpeerchannels_err, NULL);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static void memleak_mark(struct plugin *p, struct htable *memtable)
@ -708,13 +707,13 @@ static void memleak_mark(struct plugin *p, struct htable *memtable)
memleak_scan_obj(memtable, global_gossmap);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
size_t num_cupdates_rejected;
plugin = p;
rpc_scan(p, "getinfo",
plugin = init_cmd->plugin;
rpc_scan(init_cmd, "getinfo",
take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_node_id, &local_id));
@ -729,7 +728,7 @@ static const char *init(struct plugin *p,
plugin_log(plugin, LOG_DBG,
"gossmap ignored %zu channel updates",
num_cupdates_rejected);
plugin_set_memleak_handler(p, memleak_mark);
plugin_set_memleak_handler(plugin, memleak_mark);
return NULL;
}

View File

@ -168,11 +168,11 @@ static struct command_result *signpsbt_done(struct command *cmd,
fmt_wally_psbt(tmpctx, utx->psbt));
}
req = jsonrpc_request_start(cmd->plugin, cmd, "sendpsbt",
req = jsonrpc_request_start(cmd, "sendpsbt",
sendpsbt_done, forward_error,
utx);
json_add_psbt(req->js, "psbt", utx->psbt);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *finish_txprepare(struct command *cmd,
@ -218,11 +218,11 @@ static struct command_result *finish_txprepare(struct command *cmd,
/* Won't live beyond this cmd. */
tal_steal(cmd, utx);
req = jsonrpc_request_start(cmd->plugin, cmd, "signpsbt",
req = jsonrpc_request_start(cmd, "signpsbt",
signpsbt_done, forward_error,
utx);
json_add_psbt(req->js, "psbt", utx->psbt);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
list_add(&unreleased_txs, &utx->list);
@ -308,7 +308,7 @@ static struct command_result *txprepare_continue(struct command *cmd,
/* These calls are deliberately very similar, but utxopsbt wants utxos,
* and fundpsbt wants minconf */
if (utxos) {
req = jsonrpc_request_start(cmd->plugin, cmd, "utxopsbt",
req = jsonrpc_request_start(cmd, "utxopsbt",
psbt_created, forward_error,
txp);
json_array_start(req->js, "utxos");
@ -318,7 +318,7 @@ static struct command_result *txprepare_continue(struct command *cmd,
json_array_end(req->js);
json_add_bool(req->js, "reservedok", reservedok);
} else {
req = jsonrpc_request_start(cmd->plugin, cmd, "fundpsbt",
req = jsonrpc_request_start(cmd, "fundpsbt",
psbt_created, forward_error,
txp);
if (minconf)
@ -334,7 +334,7 @@ static struct command_result *txprepare_continue(struct command *cmd,
json_add_bool(req->js, "excess_as_change", true);
json_add_string(req->js, "feerate", feerate);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_txprepare(struct command *cmd,
@ -413,11 +413,11 @@ static struct command_result *json_txdiscard(struct command *cmd,
/* Whatever happens, we free it once this command is done. */
tal_steal(cmd, utx);
req = jsonrpc_request_start(cmd->plugin, cmd, "unreserveinputs",
req = jsonrpc_request_start(cmd, "unreserveinputs",
unreserve_done, forward_error,
utx);
json_add_psbt(req->js, "psbt", utx->psbt);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_txsend(struct command *cmd,
@ -437,11 +437,11 @@ static struct command_result *json_txsend(struct command *cmd,
/* If things go wrong, free it. */
tal_steal(cmd, utx);
req = jsonrpc_request_start(cmd->plugin, cmd, "signpsbt",
req = jsonrpc_request_start(cmd, "signpsbt",
signpsbt_done, forward_error,
utx);
json_add_psbt(req->js, "psbt", utx->psbt);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_withdraw(struct command *cmd,
@ -597,12 +597,12 @@ static struct command_result *newaddr_sweep_done(struct command *cmd,
+ bitcoin_tx_output_weight(tal_bytelen(info->txp->outputs[0].script));
/* Find all the utxos we want to spend on this tx */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listfunds",
listfunds_done,
forward_error,
info);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *json_upgradewallet(struct command *cmd,
@ -621,13 +621,13 @@ static struct command_result *json_upgradewallet(struct command *cmd,
info->reservedok = *reservedok;
/* Get an address to send everything to */
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"newaddr",
newaddr_sweep_done,
forward_error,
info);
json_add_string(req->js, "addresstype", "all");
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static const struct plugin_command commands[] = {
@ -658,10 +658,10 @@ static void mark_unreleased_txs(struct plugin *plugin, struct htable *memtable)
memleak_scan_list_head(memtable, &unreleased_txs);
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
plugin_set_memleak_handler(p, mark_unreleased_txs);
plugin_set_memleak_handler(init_cmd->plugin, mark_unreleased_txs);
return NULL;
}

View File

@ -35,7 +35,7 @@ static struct command_result *get_ds_bin_done(struct command *cmd,
plugin_log(cmd->plugin, LOG_INFORM, "get_ds_bin_done: %s",
val ? tal_hex(tmpctx, val) : "NOT FOUND");
return jsonrpc_get_datastore_string(cmd->plugin, cmd,
return jsonrpc_get_datastore_string(cmd,
"test_libplugin/name",
get_ds_done, arg);
}
@ -54,7 +54,7 @@ static struct command_result *json_helloworld(struct command *cmd,
plugin_notify_message(cmd, LOG_INFORM, "Notification from %s", "json_helloworld");
if (!name)
return jsonrpc_get_datastore_binary(cmd->plugin, cmd,
return jsonrpc_get_datastore_binary(cmd,
"test_libplugin/name",
get_ds_bin_done,
"hello");
@ -147,9 +147,9 @@ static struct command_result *json_testrpc(struct command *cmd,
if (!param(cmd, buf, params, NULL))
return command_param_failed();
req = jsonrpc_request_start(cmd->plugin, cmd, "getinfo", testrpc_cb,
req = jsonrpc_request_start(cmd, "getinfo", testrpc_cb,
testrpc_cb, NULL);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static struct command_result *listdatastore_ok(struct command *cmd,
@ -178,13 +178,13 @@ static struct command_result *json_checkthis(struct command *cmd,
NULL))
return command_param_failed();
req = jsonrpc_request_start(cmd->plugin, cmd,
req = jsonrpc_request_start(cmd,
"listdatastore",
listdatastore_ok,
forward_error, NULL);
if (key)
json_add_tok(req->js, "key", key, buf);
return send_outreq(cmd->plugin, req);
return send_outreq(req);
}
static char *set_dynamic(struct plugin *plugin,
@ -205,12 +205,13 @@ static char *set_dynamic(struct plugin *plugin,
return NULL;
}
static const char *init(struct plugin *p,
static const char *init(struct command *init_cmd,
const char *buf UNUSED,
const jsmntok_t *config UNUSED)
{
const char *name, *err_str, *err_hex;
const u8 *binname;
struct plugin *p = init_cmd->plugin;
struct test_libplugin *tlp = get_test_libplugin(p);
plugin_log(p, LOG_DBG, "test_libplugin initialised!");
@ -222,12 +223,12 @@ static const char *init(struct plugin *p,
return "Disabled via selfdisable option";
/* Test rpc_scan_datastore funcs */
err_str = rpc_scan_datastore_str(tmpctx, p, "test_libplugin/name",
err_str = rpc_scan_datastore_str(tmpctx, init_cmd, "test_libplugin/name",
JSON_SCAN_TAL(tmpctx, json_strdup,
&name));
if (err_str)
name = NULL;
err_hex = rpc_scan_datastore_hex(tmpctx, p, "test_libplugin/name",
err_hex = rpc_scan_datastore_hex(tmpctx, init_cmd, "test_libplugin/name",
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex,
&binname));
if (err_hex)