diff --git a/doc/lightning-createinvoice.7.md b/doc/lightning-createinvoice.7.md index 36f6b48fb3f2..420e20eb4f7b 100644 --- a/doc/lightning-createinvoice.7.md +++ b/doc/lightning-createinvoice.7.md @@ -45,6 +45,9 @@ On success, an object is returned, containing: - **pay\_index** (u64, optional): Incrementing id for when this was paid (**status** *paid* only) - **amount\_received\_msat** (msat, optional): Amount actually received (**status** *paid* only) - **paid\_at** (u64, optional): UNIX timestamp of when invoice was paid (**status** *paid* only) +- **paid\_outpoint** (object, optional): Outpoint this invoice was paid with (**status** *paid* only) *(added v23.11)*: + - **txid** (txid): ID of the transaction that paid the invoice (**status** *paid* only) *(added v23.11)* + - **outnum** (u32): The 0-based output number of the transaction that paid the invoice (**status** *paid* only) *(added v23.11)* - **payment\_preimage** (secret, optional): the proof of payment: SHA256 of this **payment\_hash** - **local\_offer\_id** (hex, optional): the *id* of our offer which created this invoice (**experimental-offers** only). (always 64 characters) - **invreq\_payer\_note** (string, optional): the optional *invreq\_payer\_note* from invoice\_request which created this invoice (**experimental-offers** only). @@ -77,4 +80,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:2d2180c9e903e2b79d5ddb2b0cf995b1f7aa27b0f9bb1f6e19252b94dcd46ef1) +[comment]: # ( SHA256STAMP:51966a70e3eaa77c703fbd8d00cfb3f7f7602b50149ba6cb8fa0fc115cf05450) diff --git a/doc/lightning-listinvoices.7.md b/doc/lightning-listinvoices.7.md index 2e7c0025ea07..6358b3567934 100644 --- a/doc/lightning-listinvoices.7.md +++ b/doc/lightning-listinvoices.7.md @@ -47,6 +47,9 @@ If **status** is "paid": - **amount\_received\_msat** (msat): the amount actually received (could be slightly greater than *amount\_msat*, since clients may overpay) - **paid\_at** (u64): UNIX timestamp of when it was paid - **payment\_preimage** (secret): proof of payment + - **paid\_outpoint** (object, optional): Outpoint this invoice was paid with *(added v23.11)*: + - **txid** (txid): ID of the transaction that paid the invoice *(added v23.11)* + - **outnum** (u32): The 0-based output number of the transaction that paid the invoice *(added v23.11)* [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -65,4 +68,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:e698b0e345ed4912b7699b43f2571a4cc3bb4ae909efeb631b02dd94a87e765c) +[comment]: # ( SHA256STAMP:7e4b1182ba879bea892d143b53cdc31350a9668c734c6bb8f86ab9b6e3f0b06e) diff --git a/doc/lightning-sql.7.md b/doc/lightning-sql.7.md index 910daa024818..952735263a75 100644 --- a/doc/lightning-sql.7.md +++ b/doc/lightning-sql.7.md @@ -88,7 +88,6 @@ a foreign key. [comment]: # (GENERATE-DOC-START) The following tables are currently supported: - - `bkpr_accountevents` (see lightning-bkpr-listaccountevents(7)) - `account` (type `string`, sqltype `TEXT`) - `type` (type `string`, sqltype `TEXT`) @@ -211,6 +210,8 @@ The following tables are currently supported: - `pay_index` (type `u64`, sqltype `INTEGER`) - `amount_received_msat` (type `msat`, sqltype `INTEGER`) - `paid_at` (type `u64`, sqltype `INTEGER`) + - `paid_outpoint_txid` (type `txid`, sqltype `BLOB`, from JSON object `paid_outpoint`) + - `paid_outpoint_outnum` (type `u32`, sqltype `INTEGER`, from JSON object `paid_outpoint`) - `payment_preimage` (type `secret`, sqltype `BLOB`) - `nodes` indexed by `nodeid` (see lightning-listnodes(7)) @@ -515,4 +516,4 @@ RESOURCES --------- Main web site: -[comment]: # ( SHA256STAMP:2f77078555f16a9dbee5f068d4d0ba18727aeb378be674cd96bf7c1554a74ce5) +[comment]: # ( SHA256STAMP:b14fce571cf85639c460c59ddec117ce1cb23bd219618730b164ea3cc979b1aa) diff --git a/doc/lightning-waitanyinvoice.7.md b/doc/lightning-waitanyinvoice.7.md index 9bda5e145b8a..2013a182e51e 100644 --- a/doc/lightning-waitanyinvoice.7.md +++ b/doc/lightning-waitanyinvoice.7.md @@ -53,6 +53,9 @@ If **status** is "paid": - **amount\_received\_msat** (msat): the amount actually received (could be slightly greater than *amount\_msat*, since clients may overpay) - **paid\_at** (u64): UNIX timestamp of when it was paid - **payment\_preimage** (secret): proof of payment + - **paid\_outpoint** (object, optional): Outpoint this invoice was paid with *(added v23.11)*: + - **txid** (txid): ID of the transaction that paid the invoice *(added v23.11)* + - **outnum** (u32): The 0-based output number of the transaction that paid the invoice *(added v23.11)* [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -77,4 +80,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:a0ace35f11efcdfbac39ef830cd7b2b6c8f48816c5512d7d2300edb9463aa4e6) +[comment]: # ( SHA256STAMP:4c8ba0c4aec4f9507588fcbe35c07c0a9761a65b78664afafe228c18b306f8c4) diff --git a/doc/lightning-waitinvoice.7.md b/doc/lightning-waitinvoice.7.md index 639f5f1a2a22..29a453241f94 100644 --- a/doc/lightning-waitinvoice.7.md +++ b/doc/lightning-waitinvoice.7.md @@ -35,6 +35,9 @@ If **status** is "paid": - **amount\_received\_msat** (msat): the amount actually received (could be slightly greater than *amount\_msat*, since clients may overpay) - **paid\_at** (u64): UNIX timestamp of when it was paid - **payment\_preimage** (secret): proof of payment + - **paid\_outpoint** (object, optional): Outpoint this invoice was paid with *(added v23.11)*: + - **txid** (txid): ID of the transaction that paid the invoice *(added v23.11)* + - **outnum** (u32): The 0-based output number of the transaction that paid the invoice *(added v23.11)* [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -62,4 +65,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:a0ace35f11efcdfbac39ef830cd7b2b6c8f48816c5512d7d2300edb9463aa4e6) +[comment]: # ( SHA256STAMP:4c8ba0c4aec4f9507588fcbe35c07c0a9761a65b78664afafe228c18b306f8c4) diff --git a/doc/schemas/createinvoice.schema.json b/doc/schemas/createinvoice.schema.json index f7f49d76a21a..d01e8a39315f 100644 --- a/doc/schemas/createinvoice.schema.json +++ b/doc/schemas/createinvoice.schema.json @@ -65,6 +65,28 @@ "type": "u64", "description": "UNIX timestamp of when invoice was paid (**status** *paid* only)" }, + "paid_outpoint": { + "type": "object", + "description": "Outpoint this invoice was paid with (**status** *paid* only)", + "added": "v23.11", + "additionalProperties": false, + "required": [ + "txid", + "outnum" + ], + "properties": { + "txid": { + "added": "v23.11", + "type": "txid", + "description": "ID of the transaction that paid the invoice (**status** *paid* only)" + }, + "outnum": { + "added": "v23.11", + "type": "u32", + "description": "The 0-based output number of the transaction that paid the invoice (**status** *paid* only)" + } + } + }, "payment_preimage": { "type": "secret", "description": "the proof of payment: SHA256 of this **payment_hash**" diff --git a/doc/schemas/listinvoices.schema.json b/doc/schemas/listinvoices.schema.json index 3043c0ee503a..34b87d1812df 100644 --- a/doc/schemas/listinvoices.schema.json +++ b/doc/schemas/listinvoices.schema.json @@ -121,6 +121,28 @@ "type": "u64", "description": "UNIX timestamp of when it was paid" }, + "paid_outpoint": { + "type": "object", + "description": "Outpoint this invoice was paid with", + "added": "v23.11", + "additionalProperties": false, + "required": [ + "txid", + "outnum" + ], + "properties": { + "txid": { + "added": "v23.11", + "type": "txid", + "description": "ID of the transaction that paid the invoice" + }, + "outnum": { + "added": "v23.11", + "type": "u32", + "description": "The 0-based output number of the transaction that paid the invoice" + } + } + }, "payment_preimage": { "type": "secret", "description": "proof of payment" diff --git a/doc/schemas/waitanyinvoice.schema.json b/doc/schemas/waitanyinvoice.schema.json index 076be7604ab3..89e7eb70b443 100644 --- a/doc/schemas/waitanyinvoice.schema.json +++ b/doc/schemas/waitanyinvoice.schema.json @@ -102,6 +102,28 @@ "type": "u64", "description": "UNIX timestamp of when it was paid" }, + "paid_outpoint": { + "type": "object", + "description": "Outpoint this invoice was paid with", + "added": "v23.11", + "additionalProperties": false, + "required": [ + "txid", + "outnum" + ], + "properties": { + "txid": { + "added": "v23.11", + "type": "txid", + "description": "ID of the transaction that paid the invoice" + }, + "outnum": { + "added": "v23.11", + "type": "u32", + "description": "The 0-based output number of the transaction that paid the invoice" + } + } + }, "payment_preimage": { "type": "secret", "description": "proof of payment" diff --git a/doc/schemas/waitinvoice.schema.json b/doc/schemas/waitinvoice.schema.json index 076be7604ab3..89e7eb70b443 100644 --- a/doc/schemas/waitinvoice.schema.json +++ b/doc/schemas/waitinvoice.schema.json @@ -102,6 +102,28 @@ "type": "u64", "description": "UNIX timestamp of when it was paid" }, + "paid_outpoint": { + "type": "object", + "description": "Outpoint this invoice was paid with", + "added": "v23.11", + "additionalProperties": false, + "required": [ + "txid", + "outnum" + ], + "properties": { + "txid": { + "added": "v23.11", + "type": "txid", + "description": "ID of the transaction that paid the invoice" + }, + "outnum": { + "added": "v23.11", + "type": "u32", + "description": "The 0-based output number of the transaction that paid the invoice" + } + } + }, "payment_preimage": { "type": "secret", "description": "proof of payment" diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 26ab207f00a0..5d72725eea34 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -909,6 +909,28 @@ def test_listinvoices_index(node_factory, executor): assert only_one(l2.rpc.listinvoices(index='updated', start=i, limit=1)['invoices'])['label'] == str(70 + 1 - i) +def test_unified_invoices(node_factory, executor, bitcoind): + l1, l2 = node_factory.line_graph(2, opts={'invoices-onchain-fallback': None}) + amount_sat = 1000 + inv = l1.rpc.invoice(amount_sat * 1000, "inv1", "test_unified_invoices") + b11 = l1.rpc.decodepay(inv['bolt11']) + + assert len(b11['fallbacks']) == 1 + + # Pay invoice on-chain + addr = b11['fallbacks'][0]['addr'] + + # save txid + txid = bitcoind.rpc.sendtoaddress(addr, amount_sat / 10**8) + + # confirm spend + bitcoind.generate_block(1) + + res = l1.rpc.waitinvoice('inv1') + + assert(txid == res['paid_outpoint']['txid']) + + def test_expiry_startup_crash(node_factory, bitcoind): """We crash trying to expire invoice on startup""" l1 = node_factory.get_node() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index d7434baff2ee..0db388f5de19 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -3608,6 +3608,10 @@ def test_sql(node_factory, bitcoind): 'type': 'msat'}, {'name': 'paid_at', 'type': 'u64'}, + {'name': 'paid_outpoint_txid', + 'type': 'txid'}, + {'name': 'paid_outpoint_outnum', + 'type': 'u32'}, {'name': 'payment_preimage', 'type': 'secret'}]}, 'offers': {