diff --git a/plugins/offers.c b/plugins/offers.c index 8130feae5..f781cfd4b 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -18,6 +18,7 @@ #include struct pubkey id; +u32 blockheight; u16 cltv_final; bool offers_enabled; @@ -132,6 +133,23 @@ static const struct plugin_hook hooks[] = { }, }; +static struct command_result *block_added_notify(struct command *cmd, + const char *buf, + const jsmntok_t *params) +{ + json_scan(cmd, buf, params, "{block:{height:%}}", + JSON_SCAN(json_to_u32, &blockheight)); + return notification_handled(cmd); +} + +static const struct plugin_notification notifications[] = { + { + "block_added", + block_added_notify, + }, +}; + + struct decodable { const char *type; struct bolt11 *b11; @@ -922,12 +940,10 @@ static const char *init(struct plugin *p, const char *buf UNUSED, const jsmntok_t *config UNUSED) { - struct pubkey k; - rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)), - "{id:%}", JSON_SCAN(json_to_pubkey, &k)); - id.pubkey = k.pubkey; + "{id:%}", JSON_SCAN(json_to_pubkey, &id), + "{blockheight:%}", JSON_SCAN(json_to_u32, &blockheight)); rpc_scan(p, "listconfigs", take(json_out_obj(NULL, NULL, NULL)), @@ -968,7 +984,9 @@ int main(int argc, char *argv[]) /* We deal in UTC; mktime() uses local time */ setenv("TZ", "", 1); - plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands, - ARRAY_SIZE(commands), NULL, 0, hooks, ARRAY_SIZE(hooks), + plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, + commands, ARRAY_SIZE(commands), + notifications, ARRAY_SIZE(notifications), + hooks, ARRAY_SIZE(hooks), NULL, 0, NULL); }