Browse Source

libplugin: pass a pointer to plugin to send_outreq

autoclean needs to send outreqs from a timer cb, hence with cmd == NULL.
travis-debug
darosior 5 years ago
committed by Rusty Russell
parent
commit
b31e3b1541
  1. 2
      plugins/autoclean.c
  2. 18
      plugins/fundchannel.c
  3. 15
      plugins/libplugin.c
  4. 7
      plugins/libplugin.h
  5. 16
      plugins/pay.c

2
plugins/autoclean.c

@ -32,7 +32,7 @@ static struct command_result *do_clean(struct plugin *p)
json_out_finished(params); json_out_finished(params);
/* FIXME: delexpiredinvoice should be in our plugin too! */ /* 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)); take(params));
} }

18
plugins/fundchannel.c

@ -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 /* We need to call txdiscard, and forward the actual cause for the
* error after we've cleaned up. We swallow any errors returned by * 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 */ * 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, send_prior, send_prior,
fr, take(ret)); fr, take(ret));
} }
@ -155,7 +155,7 @@ static struct command_result *send_tx(struct command *cmd,
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id)); type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));
json_out_end(ret, '}'); json_out_end(ret, '}');
return send_outreq(cmd, "txsend", return send_outreq(cmd->plugin, cmd, "txsend",
finish, tx_abort, finish, tx_abort,
fr, take(ret)); fr, take(ret));
} }
@ -214,7 +214,7 @@ static struct command_result *tx_prepare_done(struct command *cmd,
json_out_add(ret, "txout", false, "%u", outnum); json_out_add(ret, "txout", false, "%u", outnum);
json_out_end(ret, '}'); json_out_end(ret, '}');
return send_outreq(cmd, "fundchannel_complete", return send_outreq(cmd->plugin, cmd, "fundchannel_complete",
send_tx, tx_abort, send_tx, tx_abort,
fr, take(ret)); fr, take(ret));
} }
@ -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_addstr(ret, "id", node_id_to_hexstr(tmpctx, fr->id));
json_out_end(ret, '}'); json_out_end(ret, '}');
return send_outreq(cmd, "fundchannel_cancel", return send_outreq(cmd->plugin, cmd, "fundchannel_cancel",
send_prior, send_prior, send_prior, send_prior,
fr, take(ret)); fr, take(ret));
} }
@ -274,7 +274,7 @@ static struct command_result *prepare_actual(struct command *cmd,
ret = txprepare(cmd, fr, fr->funding_addr); ret = txprepare(cmd, fr, fr->funding_addr);
return send_outreq(cmd, "txprepare", return send_outreq(cmd->plugin, cmd, "txprepare",
tx_prepare_done, cancel_start, tx_prepare_done, cancel_start,
fr, take(ret)); fr, take(ret));
} }
@ -301,7 +301,7 @@ static struct command_result *fundchannel_start_done(struct command *cmd,
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id)); type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));
json_out_end(ret, '}'); json_out_end(ret, '}');
return send_outreq(cmd, "txdiscard", return send_outreq(cmd->plugin, cmd, "txdiscard",
prepare_actual, cancel_start, prepare_actual, cancel_start,
fr, take(ret)); fr, take(ret));
} }
@ -330,7 +330,7 @@ static struct command_result *fundchannel_start(struct command *cmd,
json_out_end(ret, '}'); json_out_end(ret, '}');
json_out_finished(ret); json_out_finished(ret);
return send_outreq(cmd, "fundchannel_start", return send_outreq(cmd->plugin, cmd, "fundchannel_start",
fundchannel_start_done, tx_abort, fundchannel_start_done, tx_abort,
fr, take(ret)); fr, take(ret));
} }
@ -397,7 +397,7 @@ static struct command_result *exec_dryrun(struct command *cmd,
* so we can get an accurate idea of the funding amount */ * so we can get an accurate idea of the funding amount */
ret = txprepare(cmd, fr, placeholder_funding_addr); ret = txprepare(cmd, fr, placeholder_funding_addr);
return send_outreq(cmd, "txprepare", return send_outreq(cmd->plugin, cmd, "txprepare",
post_dryrun, forward_error, post_dryrun, forward_error,
fr, take(ret)); fr, take(ret));
@ -413,7 +413,7 @@ static struct command_result *connect_to_peer(struct command *cmd,
json_out_end(ret, '}'); json_out_end(ret, '}');
json_out_finished(ret); json_out_finished(ret);
return send_outreq(cmd, "connect", return send_outreq(cmd->plugin, cmd, "connect",
exec_dryrun, forward_error, exec_dryrun, forward_error,
fr, take(ret)); fr, take(ret));
} }

15
plugins/libplugin.c

@ -426,7 +426,8 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
} }
struct command_result * struct command_result *
send_outreq_(struct command *cmd, send_outreq_(struct plugin *plugin,
struct command *cmd,
const char *method, const char *method,
struct command_result *(*cb)(struct command *command, struct command_result *(*cb)(struct command *command,
const char *buf, const char *buf,
@ -442,23 +443,23 @@ send_outreq_(struct command *cmd,
struct json_stream *js; struct json_stream *js;
struct out_req *out; struct out_req *out;
out = tal(cmd, struct out_req); out = tal(plugin, struct out_req);
out->id = cmd->plugin->next_outreq_id++; out->id = plugin->next_outreq_id++;
out->cmd = cmd; out->cmd = cmd;
out->cb = cb; out->cb = cb;
out->errcb = errcb; out->errcb = errcb;
out->arg = arg; 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_object_start(js, NULL);
json_add_string(js, "jsonrpc", "2.0"); json_add_string(js, "jsonrpc", "2.0");
json_add_u64(js, "id", out->id); json_add_u64(js, "id", out->id);
json_add_string(js, "method", method); json_add_string(js, "method", method);
json_out_add_splice(js->jout, "params", params); json_out_add_splice(js->jout, "params", params);
json_object_compat_end(js); json_object_compat_end(js);
json_stream_close(js, cmd); json_stream_close(js, NULL);
ld_rpc_send(cmd->plugin, js); ld_rpc_send(plugin, js);
if (taken(params)) if (taken(params))
tal_free(params); tal_free(params);

7
plugins/libplugin.h

@ -170,7 +170,8 @@ const char *rpc_delve(const tal_t *ctx,
* @params can be NULL, otherwise it's an array or object. * @params can be NULL, otherwise it's an array or object.
*/ */
struct command_result * struct command_result *
send_outreq_(struct command *cmd, send_outreq_(struct plugin *plugin,
struct command *cmd,
const char *method, const char *method,
struct command_result *(*cb)(struct command *command, struct command_result *(*cb)(struct command *command,
const char *buf, const char *buf,
@ -183,8 +184,8 @@ send_outreq_(struct command *cmd,
void *arg, void *arg,
const struct json_out *params TAKES); const struct json_out *params TAKES);
#define send_outreq(cmd, method, cb, errcb, arg, params) \ #define send_outreq(plugin, cmd, method, cb, errcb, arg, params) \
send_outreq_((cmd), (method), \ send_outreq_((plugin), (cmd), (method), \
typesafe_cb_preargs(struct command_result *, void *, \ typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \ (cb), (arg), \
struct command *command, \ struct command *command, \

16
plugins/pay.c

@ -376,7 +376,7 @@ execute_waitblockheight(struct command *cmd,
json_out_end(params, '}'); json_out_end(params, '}');
json_out_finished(params); json_out_finished(params);
return send_outreq(cmd, "waitblockheight", return send_outreq(cmd->plugin, cmd, "waitblockheight",
&waitblockheight_done, &waitblockheight_done,
&waitblockheight_error, &waitblockheight_error,
pc, pc,
@ -581,7 +581,7 @@ static struct command_result *sendpay_done(struct command *cmd,
const jsmntok_t *result, const jsmntok_t *result,
struct pay_command *pc) struct pay_command *pc)
{ {
return send_outreq(cmd, "waitsendpay", return send_outreq(cmd->plugin, cmd, "waitsendpay",
waitsendpay_done, waitsendpay_error, pc, waitsendpay_done, waitsendpay_error, pc,
take(json_out_obj(NULL, "payment_hash", take(json_out_obj(NULL, "payment_hash",
pc->payment_hash))); pc->payment_hash)));
@ -849,7 +849,7 @@ static struct command_result *getroute_done(struct command *cmd,
pc->payment_secret); pc->payment_secret);
json_out_end(params, '}'); 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)); take(params));
} }
@ -945,7 +945,7 @@ static struct command_result *execute_getroute(struct command *cmd,
} }
json_out_end(params, '}'); 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)); take(params));
} }
@ -989,7 +989,7 @@ static struct command_result *
execute_getstartblockheight(struct command *cmd, execute_getstartblockheight(struct command *cmd,
struct pay_command *pc) struct pay_command *pc)
{ {
return send_outreq(cmd, "getinfo", return send_outreq(cmd->plugin, cmd, "getinfo",
&getstartblockheight_done, &getstartblockheight_done,
&getstartblockheight_error, &getstartblockheight_error,
pc, pc,
@ -1113,7 +1113,7 @@ static struct command_result *shadow_route(struct command *cmd,
if (pseudorand(2) == 0) if (pseudorand(2) == 0)
return start_pay_attempt(cmd, pc, "Initial attempt"); 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, add_shadow_route, forward_error, pc,
take(json_out_obj(NULL, "source", pc->shadow_dest))); take(json_out_obj(NULL, "source", pc->shadow_dest)));
} }
@ -1357,7 +1357,7 @@ static struct command_result *json_pay(struct command *cmd,
#endif #endif
/* Get capacities of local channels (no parameters) */ /* 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))); take(json_out_obj(NULL, NULL, NULL)));
} }
@ -1670,7 +1670,7 @@ static struct command_result *json_listpays(struct command *cmd,
NULL)) NULL))
return command_param_failed(); return command_param_failed();
return send_outreq(cmd, "listsendpays", return send_outreq(cmd->plugin, cmd, "listsendpays",
listsendpays_done, forward_error, listsendpays_done, forward_error,
cast_const(char *, b11str), cast_const(char *, b11str),
/* Neatly returns empty object if b11str is NULL */ /* Neatly returns empty object if b11str is NULL */

Loading…
Cancel
Save