lightningd: derive JSONRPC ids from incoming id (append /cln:<method>#NNN).

Usually the calls are spontanous, so it's just "cln:<method>#NNN", but
json_invoice() calls listincoming, and json_checkmessage calls
listnodes, so those become "cli:invoice-<pid>/cln:listincoming#NNN".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-09-13 06:49:11 +09:30
parent 8fcf880e0f
commit a9557d5194
9 changed files with 40 additions and 20 deletions

View File

@@ -1314,7 +1314,8 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n)
}
struct jsonrpc_request *jsonrpc_request_start_(
const tal_t *ctx, const char *method, struct log *log,
const tal_t *ctx, const char *method,
const char *id_prefix, struct log *log,
bool add_header,
void (*notify_cb)(const char *buffer,
const jsmntok_t *methodtok,
@@ -1327,7 +1328,11 @@ struct jsonrpc_request *jsonrpc_request_start_(
{
struct jsonrpc_request *r = tal(ctx, struct jsonrpc_request);
static u64 next_request_id = 0;
r->id = tal_fmt(r, "cln:%s#%"PRIu64, method, next_request_id);
if (id_prefix)
r->id = tal_fmt(r, "%s/cln:%s#%"PRIu64,
id_prefix, method, next_request_id);
else
r->id = tal_fmt(r, "cln:%s#%"PRIu64, method, next_request_id);
next_request_id++;
r->notify_cb = notify_cb;
r->response_cb = response_cb;