Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,8 @@
"ListOffers.offers[].label": 6,
"ListOffers.offers[].offer_id": 1,
"ListOffers.offers[].single_use": 3,
"ListOffers.offers[].used": 5
"ListOffers.offers[].used": 5,
"ListOffers.offers[].used_count": 9
},
"ListoffersRequest": {
"ListOffers.active_only": 2,
Expand Down Expand Up @@ -11483,6 +11484,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"ListOffers.offers[].used_count": {
"added": "v26.09",
"deprecated": null
},
"ListPays": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 37 additions & 5 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24414,7 +24414,8 @@
"single_use",
"force_paths",
"bolt12",
"used"
"used",
"used_count"
],
"properties": {
"offer_id": {
Expand Down Expand Up @@ -24461,6 +24462,12 @@
"True if an associated invoice has been paid."
]
},
"used_count": {
"type": "u64",
"description": [
"The number of times this offer has been paid."
]
},
"label": {
"type": "string",
"description": [
Expand Down Expand Up @@ -24498,24 +24505,27 @@
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000",
"used": false,
"description": "Fish sale!",
"used": false
"used_count": 0
},
{
"offer_id": "offeridl22000002200000220000022000002200000220000022000002200000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000",
"used": false,
"description": "Coffee",
"used": false
"used_count": 0
},
{
"offer_id": "offeridl23000002300000230000023000002300000230000023000002300000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": false,
"description": "Movie ticket",
"used": false
"used_count": 0
}
]
}
Expand All @@ -24535,7 +24545,29 @@
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": false
"used": false,
"used_count": 0
}
]
}
},
{
"request": {
"id": "example:listoffers#3",
"method": "listoffers",
"params": [
"offeridl23000002300000230000023000002300000230000023000002300000"
]
},
"response": {
"offers": [
{
"offer_id": "offeridl23000002300000230000023000002300000230000023000002300000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": true,
"used_count": 1
}
]
}
Expand Down
662 changes: 331 additions & 331 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ def listoffers_offers2py(m):
"offer_id": hexlify(m.offer_id), # PrimitiveField in generate_composite
"single_use": m.single_use, # PrimitiveField in generate_composite
"used": m.used, # PrimitiveField in generate_composite
"used_count": m.used_count, # PrimitiveField in generate_composite
})


Expand Down
42 changes: 37 additions & 5 deletions doc/schemas/listoffers.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"single_use",
"force_paths",
"bolt12",
"used"
"used",
"used_count"
],
"properties": {
"offer_id": {
Expand Down Expand Up @@ -91,6 +92,12 @@
"True if an associated invoice has been paid."
]
},
"used_count": {
"type": "u64",
"description": [
"The number of times this offer has been paid."
]
},
"label": {
"type": "string",
"description": [
Expand Down Expand Up @@ -128,24 +135,27 @@
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000210002100021000",
"used": false,
"description": "Fish sale!",
"used": false
"used_count": 0
},
{
"offer_id": "offeridl22000002200000220000022000002200000220000022000002200000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000220002200022000",
"used": false,
"description": "Coffee",
"used": false
"used_count": 0
},
{
"offer_id": "offeridl23000002300000230000023000002300000230000023000002300000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": false,
"description": "Movie ticket",
"used": false
"used_count": 0
}
]
}
Expand All @@ -165,7 +175,29 @@
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": false
"used": false,
"used_count": 0
}
]
}
},
{
"request": {
"id": "example:listoffers#3",
"method": "listoffers",
"params": [
"offeridl23000002300000230000023000002300000230000023000002300000"
]
},
"response": {
"offers": [
{
"offer_id": "offeridl23000002300000230000023000002300000230000023000002300000",
"active": true,
"single_use": false,
"bolt12": "lno1qgsq000bolt230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000230002300023000",
"used": true,
"used_count": 1
}
]
}
Expand Down
23 changes: 23 additions & 0 deletions lightningd/offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <common/bolt12_id.h>
#include <common/bolt12_merkle.h>
#include <common/json_command.h>
#include <common/utils.h>
#include <hsmd/hsmd_wiregen.h>
#include <inttypes.h>
#include <lightningd/hsm_control.h>
Expand Down Expand Up @@ -148,6 +149,23 @@ static const struct json_command createoffer_command = {
};
AUTODATA(json_command, &createoffer_command);

/* Helper for fast in-memory lookup of an offer's successful payment count */
static u64 offer_payment_count_find(const struct offer_payment_count *counts,
const struct sha256 *id)
{
struct offer_payment_count key;
const struct offer_payment_count *match;

if (!counts || tal_count(counts) == 0)
return 0;

key.offer_id = *id;
match = bsearch(&key, counts, tal_count(counts), sizeof(*counts),
(int (*)(const void *, const void *))offer_payment_count_cmp);

return match ? match->count : 0;
}

static struct command_result *json_listoffers(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
Expand Down Expand Up @@ -182,11 +200,14 @@ static struct command_result *json_listoffers(struct command *cmd,
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
if (description)
json_add_stringn(response, "description", description, tal_bytelen(description));
u64 used_count = wallet_offer_count_payments(wallet, offer_id);
json_add_u64(response, "used_count", used_count);
json_object_end(response);
}
} else {
struct db_stmt *stmt;
struct sha256 id;
struct offer_payment_count *counts = wallet_offer_all_payment_counts(wallet, tmpctx);

for (stmt = wallet_offer_id_first(cmd->ld->wallet, &id);
stmt;
Expand All @@ -201,6 +222,8 @@ static struct command_result *json_listoffers(struct command *cmd,
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
if (description)
json_add_stringn(response, "description", description, tal_bytelen(description));
u64 used_count = offer_payment_count_find(counts, &id);
json_add_u64(response, "used_count", used_count);
json_object_end(response);
}
}
Expand Down
Loading