Skip to content

Commit 3852730

Browse files
lndclient: add DeleteCanceledInvoice to LightningClient
1 parent c15464d commit 3852730

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lightning_client.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ type LightningClient interface {
111111
// LookupInvoice looks up an invoice by hash.
112112
LookupInvoice(ctx context.Context, hash lntypes.Hash) (*Invoice, error)
113113

114+
// DeleteCanceledInvoice deletes a canceled invoice identified by its
115+
// payment hash. Only invoices in the canceled state can be deleted;
116+
// attempting to delete an invoice in any other state returns an error.
117+
DeleteCanceledInvoice(ctx context.Context, hash lntypes.Hash) error
118+
114119
// ListTransactions returns all known transactions of the backing lnd
115120
// node. It takes a start and end block height which can be used to
116121
// limit the block range that we query over. These values can be left
@@ -1855,6 +1860,24 @@ func (s *lightningClient) LookupInvoice(ctx context.Context,
18551860
return invoice, nil
18561861
}
18571862

1863+
// DeleteCanceledInvoice deletes a canceled invoice from lnd's database. Only
1864+
// invoices in the canceled state can be deleted; attempting to delete an
1865+
// invoice in any other state returns an error from lnd.
1866+
func (s *lightningClient) DeleteCanceledInvoice(ctx context.Context,
1867+
hash lntypes.Hash) error {
1868+
1869+
rpcCtx, cancel := context.WithTimeout(ctx, s.timeout)
1870+
defer cancel()
1871+
1872+
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)
1873+
_, err := s.client.DeleteCanceledInvoice(
1874+
rpcCtx, &lnrpc.DelCanceledInvoiceReq{
1875+
InvoiceHash: hash.String(),
1876+
},
1877+
)
1878+
return err
1879+
}
1880+
18581881
// unmarshalInvoice creates an invoice from the rpc response provided.
18591882
func unmarshalInvoice(resp *lnrpc.Invoice) (*Invoice, error) {
18601883
hash, err := lntypes.MakeHash(resp.RHash)

testdata/permissions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,14 @@
472472
}
473473
]
474474
},
475+
"/lnrpc.Lightning/DeleteCanceledInvoice": {
476+
"permissions": [
477+
{
478+
"entity": "invoices",
479+
"action": "write"
480+
}
481+
]
482+
},
475483
"/lnrpc.Lightning/NewAddress": {
476484
"permissions": [
477485
{

0 commit comments

Comments
 (0)