From e6a420647c88a698b42f8047ee649b9c69af0f6b Mon Sep 17 00:00:00 2001 From: MPins Date: Fri, 21 Mar 2025 00:07:56 -0300 Subject: [PATCH] commands: add command to delete canceled invoice Adds the deletecanceledinvoice by payment hash command. --- cmd/commands/cmd_invoice.go | 54 +++++++++++++++++++++++++++++++++++++ cmd/commands/main.go | 1 + 2 files changed, 55 insertions(+) diff --git a/cmd/commands/cmd_invoice.go b/cmd/commands/cmd_invoice.go index 4f2ae5441..24f6aa8bd 100644 --- a/cmd/commands/cmd_invoice.go +++ b/cmd/commands/cmd_invoice.go @@ -8,6 +8,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc" "github.com/urfave/cli" + "google.golang.org/protobuf/proto" ) var AddInvoiceCommand = cli.Command{ @@ -440,3 +441,56 @@ func decodePayReq(ctx *cli.Context) error { printRespJSON(resp) return nil } + +var deleteCanceledInvoiceCommand = cli.Command{ + Name: "deletecanceledinvoice", + Category: "Invoices", + Usage: "Delete a canceled invoice from the database.", + ArgsUsage: "invoice_hash", + Description: ` + This command deletes a canceled invoice from the database. Note that + expired invoices are automatically moved to the canceled state. + Once canceled, they can be deleted using this command. + `, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "invoice_hash", + Usage: "the invoice hash to be deleted", + }, + }, + Action: actionDecorator(deleteCanceledInvoice), +} + +func deleteCanceledInvoice(ctx *cli.Context) error { + ctxc := getContext() + client, cleanUp := getClient(ctx) + defer cleanUp() + + var ( + invoiceHash string + err error + resp proto.Message + ) + + switch { + case ctx.IsSet("invoice_hash"): + invoiceHash = ctx.String("invoice_hash") + case ctx.Args().Present(): + invoiceHash = ctx.Args().First() + default: + return fmt.Errorf("invoice_hash argument missing") + } + + req := &lnrpc.DelCanceledInvoiceReq{ + InvoiceHash: invoiceHash, + } + + resp, err = client.DeleteCanceledInvoice(ctxc, req) + if err != nil { + return err + } + + printJSON(resp) + + return nil +} diff --git a/cmd/commands/main.go b/cmd/commands/main.go index ec593f1ad..a11b63b9d 100644 --- a/cmd/commands/main.go +++ b/cmd/commands/main.go @@ -478,6 +478,7 @@ func Main() { AddInvoiceCommand, lookupInvoiceCommand, listInvoicesCommand, + deleteCanceledInvoiceCommand, ListChannelsCommand, closedChannelsCommand, listPaymentsCommand,