Skip to content

Commit

Permalink
offers: monitor blockheight.
Browse files Browse the repository at this point in the history
We need this to create the payment_constraints for an invoice blinded path.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Nov 9, 2022
1 parent 4bc1057 commit 7446059
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions plugins/offers.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <plugins/offers_offer.h>

struct pubkey id;
u32 blockheight;
u16 cltv_final;
bool offers_enabled;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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);
}

0 comments on commit 7446059

Please sign in to comment.