libplugin: make jsonrpc_set_datastore_binary() take an explicit length.

This means it doesn't have to be a tal ptr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-08-14 10:57:52 +09:30
parent ed77edf4c6
commit a25c1d45ad
3 changed files with 9 additions and 8 deletions

View File

@@ -665,7 +665,7 @@ static struct command_result *commit_peer_backup(struct command *cmd,
"chanbackup/peers/%s",
fmt_node_id(tmpctx,
&pb->peer)),
pb->data,
pb->data, tal_bytelen(pb->data),
"create-or-replace",
NULL, NULL, NULL);
}
@@ -899,6 +899,7 @@ static struct command_result *handle_your_peer_storage(struct command *cmd,
return jsonrpc_set_datastore_binary(cmd,
"chanbackup/latestscb",
decoded_bkp,
tal_bytelen(decoded_bkp),
"create-or-replace",
datastore_success,
datastore_failed,

View File

@@ -912,7 +912,7 @@ void rpc_enable_batching(struct plugin *plugin)
struct command_result *jsonrpc_set_datastore_(struct command *cmd,
const char *path,
const void *value,
bool value_is_string,
int len_or_str,
const char *mode,
struct command_result *(*cb)(struct command *command,
const char *method,
@@ -936,10 +936,10 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd,
req = jsonrpc_request_start(cmd, "datastore", cb, errcb, arg);
json_add_keypath(req->js->jout, "key", path);
if (value_is_string)
if (len_or_str == -1)
json_add_string(req->js, "string", value);
else
json_add_hex_talarr(req->js, "hex", value);
json_add_hex(req->js, "hex", value, len_or_str);
json_add_string(req->js, "mode", mode);
return send_outreq(req);
}

View File

@@ -272,7 +272,7 @@ struct json_stream *jsonrpc_stream_fail_data(struct command *cmd,
struct command_result *jsonrpc_set_datastore_(struct command *cmd,
const char *path,
const void *value,
bool value_is_string,
int len_or_str,
const char *mode,
struct command_result *(*cb)(struct command *command,
const char *method,
@@ -288,7 +288,7 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd,
NON_NULL_ARGS(1, 2, 3, 5);
#define jsonrpc_set_datastore_string(cmd, path, str, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((cmd), (path), (str), true, (mode), \
jsonrpc_set_datastore_((cmd), (path), (str), -1, (mode), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \
@@ -303,8 +303,8 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd,
const jsmntok_t *result), \
(arg))
#define jsonrpc_set_datastore_binary(cmd, path, tal_ptr, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((cmd), (path), (tal_ptr), false, (mode), \
#define jsonrpc_set_datastore_binary(cmd, path, ptr, len, mode, cb, errcb, arg) \
jsonrpc_set_datastore_((cmd), (path), (ptr), (len), (mode), \
typesafe_cb_preargs(struct command_result *, void *, \
(cb), (arg), \
struct command *command, \