mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
lightningd/: Hooks now support a consistent interface for 'no operation'.
Changelog-Changed: The hooks `db_write`, `invoice_payment`, and `rpc_command` now accept `{ "result": "continue" }` to mean "do default action", in addition to `true` (`db_write`), `{}` (`invoice_payment`), and `{"continue": true}` (`rpc_command`). The older "default" indicators are now deprecated and are now recognized only if `--deprecated-apis` is set.
This commit is contained in:
committed by
ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
f9b3b96a63
commit
6e34aa233a
@@ -667,9 +667,9 @@ static void
|
||||
rpc_command_hook_callback(struct rpc_command_hook_payload *p,
|
||||
const char *buffer, const jsmntok_t *resulttok)
|
||||
{
|
||||
const jsmntok_t *tok, *params, *custom_return, *tok_continue;
|
||||
const jsmntok_t *tok, *params, *custom_return;
|
||||
const jsmntok_t *innerresulttok;
|
||||
struct json_stream *response;
|
||||
bool exec;
|
||||
|
||||
params = json_get_member(p->buffer, p->request, "params");
|
||||
|
||||
@@ -678,11 +678,37 @@ rpc_command_hook_callback(struct rpc_command_hook_payload *p,
|
||||
if (buffer == NULL)
|
||||
return was_pending(command_exec(p->cmd->jcon, p->cmd, p->buffer,
|
||||
p->request, params));
|
||||
else {
|
||||
|
||||
#ifdef COMPAT_V080
|
||||
if (deprecated_apis) {
|
||||
const jsmntok_t *tok_continue;
|
||||
bool exec;
|
||||
tok_continue = json_get_member(buffer, resulttok, "continue");
|
||||
if (tok_continue && json_to_bool(buffer, tok_continue, &exec) && exec)
|
||||
if (tok_continue && json_to_bool(buffer, tok_continue, &exec) && exec) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
log_unusual(p->cmd->ld->log,
|
||||
"Plugin returned 'continue' : true "
|
||||
"to rpc_command hook. "
|
||||
"This is now deprecated and "
|
||||
"you should return with "
|
||||
"{'result': 'continue'} instead.");
|
||||
}
|
||||
return was_pending(command_exec(p->cmd->jcon, p->cmd, p->buffer,
|
||||
p->request, params));
|
||||
}
|
||||
}
|
||||
#endif /* defined(COMPAT_V080) */
|
||||
|
||||
innerresulttok = json_get_member(buffer, resulttok, "result");
|
||||
if (innerresulttok) {
|
||||
if (json_tok_streq(buffer, innerresulttok, "continue")) {
|
||||
return was_pending(command_exec(p->cmd->jcon, p->cmd, p->buffer,
|
||||
p->request, params));
|
||||
}
|
||||
return was_pending(command_fail(p->cmd, JSONRPC2_INVALID_REQUEST,
|
||||
"Bad 'result' to 'rpc_command' hook."));
|
||||
}
|
||||
|
||||
/* If the registered plugin did not respond with continue,
|
||||
|
||||
Reference in New Issue
Block a user