Skip to content

Commit fca6211

Browse files
plugin: fetchinvoice: set the quantity in invreq
While the user trying to fetch an invoice by specifing the quantity we do not work as expected. Running the command ``` lightning-cli fetchinvoice -k offer='lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqffqszsk2p6hycmgv9ek2grpyphxjcm9ypmkjer8v46pyzmhd9jxwet5wvhxxmmdzsqs593pq0ylsvakdua5h976f4g3eautgjt3udvtyga47eaw7339sjrhpwpwz' quantity=2 ``` and we answer back with ```json { "code": -32602, "message": "quantity parameter required" } ``` This is caused because we forget to bind the `quanity` field from the RPC into the `invrequest`. Reported-by: @aaronbarnardsound Link: #6089 Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Changelog-EXPERIMENTAL: fetchinvoice: fix: do not ignore the `quantity` field into the invreq field.
1 parent 6c641bd commit fca6211

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

plugins/fetchinvoice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ static struct command_result *json_fetchinvoice(struct command *cmd,
10291029
invreq = invoice_request_for_offer(sent, sent->offer);
10301030
invreq->invreq_recurrence_counter = tal_steal(invreq, recurrence_counter);
10311031
invreq->invreq_recurrence_start = tal_steal(invreq, recurrence_start);
1032+
invreq->invreq_quantity = tal_steal(invreq, quantity);
10321033

10331034
/* BOLT-offers-recurrence #12:
10341035
* - if `offer_amount` is not present:

tests/test_pay.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5395,3 +5395,29 @@ def test_delpay_works(node_factory, bitcoind):
53955395
status=failed['status'],
53965396
groupid=failed['groupid'],
53975397
partid=failed['partid'])
5398+
5399+
5400+
def test_fetchinvoice_with_no_quantity(node_factory):
5401+
"""
5402+
Reproducer for https://github.com/ElementsProject/lightning/issues/6089
5403+
5404+
The issue is when the offer has the quantity_max and the parameter.
5405+
5406+
In particular, in the fetchinvoice we forget to map the
5407+
quantity parameter with the invoice request quantity field.
5408+
"""
5409+
l1, l2 = node_factory.line_graph(2, wait_for_announce=True,
5410+
opts={'experimental-offers': None})
5411+
offer1 = l2.rpc.call('offer', {'amount': '2msat',
5412+
'description': 'simple test',
5413+
'quantity_max': 10})
5414+
5415+
assert offer1['created'] is True, f"offer created is {offer1['created']}"
5416+
5417+
with pytest.raises(RpcError, match="quantity parameter required"):
5418+
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
5419+
5420+
inv = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'quantity': 2})
5421+
inv = inv['invoice']
5422+
decode_inv = l2.rpc.decode(inv)
5423+
assert decode_inv['invreq_quantity'] == 2, f'`invreq_quantity` in the invoice did not match, received {decode_inv["quantity"]}, expected 2'

0 commit comments

Comments
 (0)