libplugin: allow NULL calllbacks for jsonrpc_set_datastore.

You often don't care about the reply, so this is quite convenient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-09-08 10:39:13 +09:30 committed by Christian Decker
parent fb433a70f8
commit b3b5b74069
2 changed files with 18 additions and 1 deletions

View file

@ -617,6 +617,16 @@ bool rpc_scan_datastore_hex(struct plugin *plugin,
return ret;
}
static struct command_result *datastore_fail(struct command *command,
const char *buf,
const jsmntok_t *result,
void *unused)
{
plugin_err(command->plugin, "datastore failed: %.*s",
json_tok_full_len(result),
json_tok_full(buf, result));
}
struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
struct command *cmd,
const char *path,
@ -635,6 +645,11 @@ struct command_result *jsonrpc_set_datastore_(struct plugin *plugin,
{
struct out_req *req;
if (!cb)
cb = ignore_cb;
if (!errcb)
errcb = datastore_fail;
req = jsonrpc_request_start(plugin, cmd, "datastore", cb, errcb, arg);
json_add_keypath(req->js->jout, "key", path);

View file

@ -161,7 +161,9 @@ struct json_stream *jsonrpc_stream_fail_data(struct command *cmd,
int code,
const char *err);
/* Helper to jsonrpc_request_start() and send_outreq() to update datastore. */
/* 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,
const char *path,