-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test.c hooks and notifications with libplugin.c
Signed-off-by: Saibato <saibato.naga@pm.me>
- Loading branch information
Showing
5 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <bitcoin/chainparams.c> | ||
#include <ccan/array_size/array_size.h> | ||
#include <ccan/json_out/json_out.h> | ||
#include <plugins/libplugin.h> | ||
|
||
/* test hook and notification plugins */ | ||
|
||
static void init(struct plugin_conn *rpc, | ||
const char *buf UNUSED, const jsmntok_t *config UNUSED) | ||
{ | ||
} | ||
|
||
static struct command_result *json_hook(struct command *cmd, | ||
const char *buf, | ||
const jsmntok_t *params) | ||
{ | ||
struct json_out *ret; | ||
|
||
plugin_log(LOG_DBG, "hook: '%s'", buf); | ||
|
||
ret = json_out_new(NULL); | ||
json_out_start(ret, NULL, '{'); | ||
json_out_addstr(ret, "result", "continue"); | ||
json_out_end(ret, '}'); | ||
|
||
return command_success(cmd, ret); | ||
} | ||
|
||
static void json_notificate(struct command *cmd, | ||
const char *buf, | ||
const jsmntok_t *params) | ||
{ | ||
plugin_log(LOG_DBG, "notification: '%s'", buf); | ||
return; | ||
} | ||
|
||
const struct plugin_notification command_notification[] = { { | ||
"connect", | ||
json_notificate | ||
}, | ||
}; | ||
|
||
|
||
const struct plugin_hook command_hook[] = { { | ||
"peer_connected", | ||
json_hook | ||
}, | ||
}; | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
setup_locale(); | ||
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, 0, | ||
command_notification, ARRAY_SIZE(command_notification), | ||
command_hook, ARRAY_SIZE(command_hook) | ||
, NULL); | ||
} |