lncli: add new removetx cmd.

This new command calls the new rpc endpoint RemoveTransaction.
This commit is contained in:
ziggie
2023-11-07 13:05:53 +01:00
parent 1ca3732f25
commit 7c09cc3326

View File

@@ -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"`