Skip to content

Commit f62e7fe

Browse files
committed
Changelog-Added: Adding an "usable_only" argument to the listoffers command.
1 parent 2bba6f0 commit f62e7fe

File tree

9 files changed

+682
-653
lines changed

9 files changed

+682
-653
lines changed

.msggen.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,8 @@
28692869
},
28702870
"ListoffersRequest": {
28712871
"ListOffers.active_only": 2,
2872-
"ListOffers.offer_id": 1
2872+
"ListOffers.offer_id": 1,
2873+
"ListOffers.usable_only": 3
28732874
},
28742875
"ListoffersResponse": {
28752876
"ListOffers.offers[]": 1
@@ -10600,6 +10601,10 @@
1060010601
"added": "pre-v0.10.1",
1060110602
"deprecated": null
1060210603
},
10604+
"ListOffers.usable_only": {
10605+
"added": "v26.04",
10606+
"deprecated": null
10607+
},
1060310608
"ListPays": {
1060410609
"added": "pre-v0.10.1",
1060510610
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23271,6 +23271,12 @@
2327123271
"description": [
2327223272
"If set and is true, only offers with `active` true are returned."
2327323273
]
23274+
},
23275+
"usable_only": {
23276+
"type": "boolean",
23277+
"description": [
23278+
"If set and is true, only offers that can be either used multiple times or that have not been used yet are returned."
23279+
]
2327423280
}
2327523281
}
2327623282
},

contrib/pyln-client/pyln/client/lightning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def listnodes(self, node_id=None):
10231023
}
10241024
return self.call("listnodes", payload)
10251025

1026-
def listoffers(self, offer_id=None, active_only=None):
1026+
def listoffers(self, offer_id=None, active_only=None, usable_only=None):
10271027
"""List offers
10281028
10291029
List all offers, or with {offer_id}, only the offer with that {offer_id} (if it exists).
@@ -1032,6 +1032,7 @@ def listoffers(self, offer_id=None, active_only=None):
10321032
payload = {
10331033
"offer_id": offer_id,
10341034
"active_only": active_only,
1035+
"usable_only": usable_only,
10351036
}
10361037
return self.call("listoffers", payload)
10371038

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 649 additions & 649 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/schemas/listoffers.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"description": [
2525
"If set and is true, only offers with `active` true are returned."
2626
]
27+
},
28+
"usable_only": {
29+
"type": "boolean",
30+
"description": [
31+
"If set and is true, only offers that can be either used multiple times or that have not been used yet are returned."
32+
]
2733
}
2834
}
2935
},

lightningd/offer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ static struct command_result *json_listoffers(struct command *cmd,
157157
const char *description;
158158
const struct json_escape *label;
159159
bool *active_only;
160+
bool *usable_only;
160161
enum offer_status status;
161162

162163
if (!param(cmd, buffer, params,
163164
p_opt("offer_id", param_sha256, &offer_id),
164165
p_opt_def("active_only", param_bool, &active_only, false),
166+
p_opt_def("usable_only", param_bool, &usable_only, false),
165167
NULL))
166168
return command_param_failed();
167169

@@ -170,7 +172,9 @@ static struct command_result *json_listoffers(struct command *cmd,
170172
if (offer_id) {
171173
b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label,
172174
&status);
173-
if (b12 && offer_status_active(status) >= *active_only) {
175+
if (b12 && offer_status_active(status) >= *active_only &&
176+
(offer_status_single(status) == 0 ||
177+
offer_status_used(status) == 0) >= *usable_only) {
174178
json_object_start(response, NULL);
175179
json_populate_offer(response,
176180
offer_id, b12,
@@ -189,7 +193,9 @@ static struct command_result *json_listoffers(struct command *cmd,
189193
stmt = wallet_offer_id_next(cmd->ld->wallet, stmt, &id)) {
190194
b12 = wallet_offer_find(tmpctx, wallet, &id,
191195
&label, &status);
192-
if (offer_status_active(status) >= *active_only) {
196+
if (offer_status_active(status) >= *active_only &&
197+
(offer_status_single(status) == 0 ||
198+
offer_status_used(status) == 0) >= *usable_only) {
193199
json_object_start(response, NULL);
194200
json_populate_offer(response,
195201
&id, b12,

0 commit comments

Comments
 (0)