Skip to content

Commit

Permalink
libplugin: pass a pointer to plugin to send_outreq
Browse files Browse the repository at this point in the history
autoclean needs to send outreqs from a timer cb, hence with cmd == NULL.
  • Loading branch information
darosior committed Feb 2, 2020
1 parent 0e05923 commit aa0ff6b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion plugins/autoclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static struct command_result *do_clean(struct plugin *p)
json_out_finished(params);

/* FIXME: delexpiredinvoice should be in our plugin too! */
return send_outreq(NULL, "delexpiredinvoice", ignore, ignore, p,
return send_outreq(p, NULL, "delexpiredinvoice", ignore, ignore, p,
take(params));
}

Expand Down
18 changes: 9 additions & 9 deletions plugins/fundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static struct command_result *tx_abort(struct command *cmd,
/* We need to call txdiscard, and forward the actual cause for the
* error after we've cleaned up. We swallow any errors returned by
* this call, as we don't really care if it succeeds or not */
return send_outreq(cmd, "txdiscard",
return send_outreq(cmd->plugin, cmd, "txdiscard",
send_prior, send_prior,
fr, take(ret));
}
Expand Down Expand Up @@ -155,7 +155,7 @@ static struct command_result *send_tx(struct command *cmd,
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));
json_out_end(ret, '}');

return send_outreq(cmd, "txsend",
return send_outreq(cmd->plugin, cmd, "txsend",
finish, tx_abort,
fr, take(ret));
}
Expand Down Expand Up @@ -214,7 +214,7 @@ static struct command_result *tx_prepare_done(struct command *cmd,
json_out_add(ret, "txout", false, "%u", outnum);
json_out_end(ret, '}');

return send_outreq(cmd, "fundchannel_complete",
return send_outreq(cmd->plugin, cmd, "fundchannel_complete",
send_tx, tx_abort,
fr, take(ret));
}
Expand All @@ -234,7 +234,7 @@ static struct command_result *cancel_start(struct command *cmd,
json_out_addstr(ret, "id", node_id_to_hexstr(tmpctx, fr->id));
json_out_end(ret, '}');

return send_outreq(cmd, "fundchannel_cancel",
return send_outreq(cmd->plugin, cmd, "fundchannel_cancel",
send_prior, send_prior,
fr, take(ret));
}
Expand Down Expand Up @@ -274,7 +274,7 @@ static struct command_result *prepare_actual(struct command *cmd,

ret = txprepare(cmd, fr, fr->funding_addr);

return send_outreq(cmd, "txprepare",
return send_outreq(cmd->plugin, cmd, "txprepare",
tx_prepare_done, cancel_start,
fr, take(ret));
}
Expand All @@ -301,7 +301,7 @@ static struct command_result *fundchannel_start_done(struct command *cmd,
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));
json_out_end(ret, '}');

return send_outreq(cmd, "txdiscard",
return send_outreq(cmd->plugin, cmd, "txdiscard",
prepare_actual, cancel_start,
fr, take(ret));
}
Expand Down Expand Up @@ -330,7 +330,7 @@ static struct command_result *fundchannel_start(struct command *cmd,
json_out_end(ret, '}');
json_out_finished(ret);

return send_outreq(cmd, "fundchannel_start",
return send_outreq(cmd->plugin, cmd, "fundchannel_start",
fundchannel_start_done, tx_abort,
fr, take(ret));
}
Expand Down Expand Up @@ -397,7 +397,7 @@ static struct command_result *exec_dryrun(struct command *cmd,
* so we can get an accurate idea of the funding amount */
ret = txprepare(cmd, fr, placeholder_funding_addr);

return send_outreq(cmd, "txprepare",
return send_outreq(cmd->plugin, cmd, "txprepare",
post_dryrun, forward_error,
fr, take(ret));

Expand All @@ -413,7 +413,7 @@ static struct command_result *connect_to_peer(struct command *cmd,
json_out_end(ret, '}');
json_out_finished(ret);

return send_outreq(cmd, "connect",
return send_outreq(cmd->plugin, cmd, "connect",
exec_dryrun, forward_error,
fr, take(ret));
}
Expand Down
15 changes: 8 additions & 7 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
}

struct command_result *
send_outreq_(struct command *cmd,
send_outreq_(struct plugin *plugin,
struct command *cmd,
const char *method,
struct command_result *(*cb)(struct command *command,
const char *buf,
Expand All @@ -442,23 +443,23 @@ send_outreq_(struct command *cmd,
struct json_stream *js;
struct out_req *out;

out = tal(cmd, struct out_req);
out->id = cmd->plugin->next_outreq_id++;
out = tal(plugin, struct out_req);
out->id = plugin->next_outreq_id++;
out->cmd = cmd;
out->cb = cb;
out->errcb = errcb;
out->arg = arg;
uintmap_add(&cmd->plugin->out_reqs, out->id, out);
uintmap_add(&plugin->out_reqs, out->id, out);

js = new_json_stream(NULL, cmd, NULL);
js = new_json_stream(NULL, NULL, NULL);
json_object_start(js, NULL);
json_add_string(js, "jsonrpc", "2.0");
json_add_u64(js, "id", out->id);
json_add_string(js, "method", method);
json_out_add_splice(js->jout, "params", params);
json_object_compat_end(js);
json_stream_close(js, cmd);
ld_rpc_send(cmd->plugin, js);
json_stream_close(js, NULL);
ld_rpc_send(plugin, js);

if (taken(params))
tal_free(params);
Expand Down
7 changes: 4 additions & 3 deletions plugins/libplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ const char *rpc_delve(const tal_t *ctx,
* @params can be NULL, otherwise it's an array or object.
*/
struct command_result *
send_outreq_(struct command *cmd,
send_outreq_(struct plugin *plugin,
struct command *cmd,
const char *method,
struct command_result *(*cb)(struct command *command,
const char *buf,
Expand All @@ -183,8 +184,8 @@ send_outreq_(struct command *cmd,
void *arg,
const struct json_out *params TAKES);

#define send_outreq(cmd, method, cb, errcb, arg, params) \
send_outreq_((cmd), (method), \
#define send_outreq(plugin, cmd, method, cb, errcb, arg, params) \
send_outreq_((plugin), (cmd), (method), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \
Expand Down
16 changes: 8 additions & 8 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ execute_waitblockheight(struct command *cmd,
json_out_end(params, '}');
json_out_finished(params);

return send_outreq(cmd, "waitblockheight",
return send_outreq(cmd->plugin, cmd, "waitblockheight",
&waitblockheight_done,
&waitblockheight_error,
pc,
Expand Down Expand Up @@ -581,7 +581,7 @@ static struct command_result *sendpay_done(struct command *cmd,
const jsmntok_t *result,
struct pay_command *pc)
{
return send_outreq(cmd, "waitsendpay",
return send_outreq(cmd->plugin, cmd, "waitsendpay",
waitsendpay_done, waitsendpay_error, pc,
take(json_out_obj(NULL, "payment_hash",
pc->payment_hash)));
Expand Down Expand Up @@ -849,7 +849,7 @@ static struct command_result *getroute_done(struct command *cmd,
pc->payment_secret);
json_out_end(params, '}');

return send_outreq(cmd, "sendpay", sendpay_done, sendpay_error, pc,
return send_outreq(cmd->plugin, cmd, "sendpay", sendpay_done, sendpay_error, pc,
take(params));

}
Expand Down Expand Up @@ -945,7 +945,7 @@ static struct command_result *execute_getroute(struct command *cmd,
}
json_out_end(params, '}');

return send_outreq(cmd, "getroute", getroute_done, getroute_error, pc,
return send_outreq(cmd->plugin, cmd, "getroute", getroute_done, getroute_error, pc,
take(params));
}

Expand Down Expand Up @@ -989,7 +989,7 @@ static struct command_result *
execute_getstartblockheight(struct command *cmd,
struct pay_command *pc)
{
return send_outreq(cmd, "getinfo",
return send_outreq(cmd->plugin, cmd, "getinfo",
&getstartblockheight_done,
&getstartblockheight_error,
pc,
Expand Down Expand Up @@ -1113,7 +1113,7 @@ static struct command_result *shadow_route(struct command *cmd,
if (pseudorand(2) == 0)
return start_pay_attempt(cmd, pc, "Initial attempt");

return send_outreq(cmd, "listchannels",
return send_outreq(cmd->plugin, cmd, "listchannels",
add_shadow_route, forward_error, pc,
take(json_out_obj(NULL, "source", pc->shadow_dest)));
}
Expand Down Expand Up @@ -1357,7 +1357,7 @@ static struct command_result *json_pay(struct command *cmd,
#endif

/* Get capacities of local channels (no parameters) */
return send_outreq(cmd, "listpeers", listpeers_done, forward_error, pc,
return send_outreq(cmd->plugin, cmd, "listpeers", listpeers_done, forward_error, pc,
take(json_out_obj(NULL, NULL, NULL)));
}

Expand Down Expand Up @@ -1670,7 +1670,7 @@ static struct command_result *json_listpays(struct command *cmd,
NULL))
return command_param_failed();

return send_outreq(cmd, "listsendpays",
return send_outreq(cmd->plugin, cmd, "listsendpays",
listsendpays_done, forward_error,
cast_const(char *, b11str),
/* Neatly returns empty object if b11str is NULL */
Expand Down

0 comments on commit aa0ff6b

Please sign in to comment.