libplugin: replace rpc_delve with rpc_scan.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-01-06 16:11:20 +10:30
committed by Christian Decker
parent b61da8c5a9
commit 09b18bf64f
6 changed files with 44 additions and 61 deletions

View File

@@ -490,18 +490,19 @@ static struct json_out *start_json_request(const tal_t *ctx,
return jout;
}
/* Synchronous routine to send command and extract single field from response */
const char *rpc_delve(const tal_t *ctx,
struct plugin *plugin,
const char *method,
const struct json_out *params TAKES,
const char *guide)
/* Synchronous routine to send command and extract fields from response */
void rpc_scan(struct plugin *plugin,
const char *method,
const struct json_out *params TAKES,
const char *guide,
...)
{
bool error;
const jsmntok_t *contents, *t;
const jsmntok_t *contents;
int reqlen;
const char *ret;
const char *p;
struct json_out *jout;
va_list ap;
jout = start_json_request(tmpctx, 0, method, params);
finish_and_send_json(plugin->rpc_conn->fd, jout);
@@ -511,14 +512,15 @@ const char *rpc_delve(const tal_t *ctx,
plugin_err(plugin, "Got error reply to %s: '%.*s'",
method, reqlen, membuf_elems(&plugin->rpc_conn->mb));
t = json_delve(membuf_elems(&plugin->rpc_conn->mb), contents, guide);
if (!t)
plugin_err(plugin, "Could not find %s in reply to %s: '%.*s'",
guide, method, reqlen, membuf_elems(&plugin->rpc_conn->mb));
p = membuf_consume(&plugin->rpc_conn->mb, reqlen);
ret = json_strdup(ctx, membuf_elems(&plugin->rpc_conn->mb), t);
membuf_consume(&plugin->rpc_conn->mb, reqlen);
return ret;
va_start(ap, guide);
error = !json_scanv(p, contents, guide, ap);
va_end(ap);
if (error)
plugin_err(plugin, "Could not parse %s in reply to %s: '%.*s'",
guide, method, reqlen, membuf_elems(&plugin->rpc_conn->mb));
}
static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)