libplugin: add command_finish_rawstr() for when we're simply repeating an entore response.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2026-02-16 17:24:33 +10:30
parent edbad6cdca
commit 9bcac63414
2 changed files with 31 additions and 4 deletions

View File

@@ -473,11 +473,9 @@ struct json_stream *jsonrpc_stream_fail_data(struct command *cmd,
return js;
}
static struct command_result *command_complete(struct command *cmd,
struct json_stream *result)
static struct command_result *command_complete_nojson(struct command *cmd,
struct json_stream *result)
{
/* Global object */
json_object_end(result);
json_stream_close(result, cmd);
ld_send(cmd->plugin, result);
tal_free(cmd);
@@ -485,6 +483,14 @@ static struct command_result *command_complete(struct command *cmd,
return &complete;
}
static struct command_result *command_complete(struct command *cmd,
struct json_stream *result)
{
/* Global object */
json_object_end(result);
return command_complete_nojson(cmd, result);
}
struct command_result *command_finished(struct command *cmd,
struct json_stream *response)
{
@@ -506,6 +512,20 @@ struct command_result *command_finished(struct command *cmd,
return command_complete(cmd, response);
}
struct command_result *command_finish_rawstr(struct command *cmd,
const char *json,
size_t json_len)
{
struct json_stream *js = new_json_stream(cmd, cmd, NULL);
char *raw;
assert(cmd->type == COMMAND_TYPE_NORMAL
|| cmd->type == COMMAND_TYPE_HOOK);
raw = json_out_direct(js->jout, json_len);
memcpy(raw, json, json_len);
return command_complete_nojson(cmd, js);
}
struct command_result *WARN_UNUSED_RESULT
command_still_pending(struct command *cmd)
{

View File

@@ -363,6 +363,13 @@ WARN_UNUSED_RESULT
struct command_result *command_still_pending(struct command *cmd)
NON_NULL_ARGS(1);
/* Forward this raw JSON string as the command response */
WARN_UNUSED_RESULT
struct command_result *command_finish_rawstr(struct command *cmd,
const char *json,
size_t json_len)
NO_NULL_ARGS;
/* Helper to create a zero or single-value JSON object; if @str is NULL,
* object is empty. */
struct json_out *json_out_obj(const tal_t *ctx,