From 7c09cc3326609be67c5112f38e0e8422c57fd9c5 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 7 Nov 2023 13:05:53 +0100 Subject: [PATCH] lncli: add new removetx cmd. This new command calls the new rpc endpoint RemoveTransaction. --- cmd/lncli/walletrpc_active.go | 62 ++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index 2eea5a3c9..3d8f6a471 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -75,6 +75,7 @@ func walletCommands() []cli.Command { labelTxCommand, publishTxCommand, getTxCommand, + removeTxCommand, releaseOutputCommand, leaseOutputCommand, listLeasesCommand, @@ -545,7 +546,6 @@ func publishTransaction(ctx *cli.Context) error { req := &walletrpc.Transaction{ TxHex: tx, - Label: ctx.String("label"), } _, err = walletClient.PublishTransaction(ctxc, req) @@ -599,6 +599,66 @@ func getTransaction(ctx *cli.Context) error { return nil } +var removeTxCommand = cli.Command{ + Name: "removetx", + Usage: "Attempts to remove the unconfirmed transaction with the " + + "specified txid and all its children from the underlying " + + "internal wallet.", + ArgsUsage: "txid", + Description: ` + Removes the transaction with the specified txid from the underlying + wallet which must still be unconfirmmed (in mempool). This command is + useful when a transaction is RBFed by another transaction. The wallet + will only resolve this conflict when the other transaction is mined + (which can take time). If a transaction was removed erronously a simple + rebroadcast of the former transaction with the "publishtx" cmd will + register the relevant outputs of the raw tx again with the wallet + (if there are no errors broadcasting this transaction due to an RBF + replacement sitting in the mempool). As soon as a removed transaction + is confirmed funds will be registered with the wallet again.`, + Flags: []cli.Flag{}, + Action: actionDecorator(removeTransaction), +} + +func removeTransaction(ctx *cli.Context) error { + ctxc := getContext() + + // Display the command's help message if we do not have the expected + // number of arguments/flags. + if ctx.NArg() != 1 { + return cli.ShowCommandHelp(ctx, "removetx") + } + + // Fetch the only cmd argument which must be a valid txid. + txid := ctx.Args().First() + txHash, err := chainhash.NewHashFromStr(txid) + if err != nil { + return err + } + + walletClient, cleanUp := getWalletClient(ctx) + defer cleanUp() + + req := &walletrpc.GetTransactionRequest{ + Txid: txHash.String(), + } + + resp, err := walletClient.RemoveTransaction(ctxc, req) + if err != nil { + return err + } + + printJSON(&struct { + Status string `json:"status"` + TxID string `json:"txid"` + }{ + Status: resp.GetStatus(), + TxID: txHash.String(), + }) + + return nil +} + // utxoLease contains JSON annotations for a lease on an unspent output. type utxoLease struct { ID string `json:"id"`