lncli: add label transaction command to walletkit cli

Two additional errors are added to the itest error whitelist because we
are specifically trigerring these errors.
This commit is contained in:
carla 2020-05-25 08:38:25 +02:00
parent 97a843f3cd
commit 210a0f428b
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

View File

@ -28,6 +28,7 @@ func walletCommands() []cli.Command {
bumpFeeCommand, bumpFeeCommand,
bumpCloseFeeCommand, bumpCloseFeeCommand,
listSweepsCommand, listSweepsCommand,
labelTxCommand,
}, },
}, },
} }
@ -340,3 +341,58 @@ func listSweeps(ctx *cli.Context) error {
return nil return nil
} }
var labelTxCommand = cli.Command{
Name: "labeltx",
Usage: "adds a label to a transaction",
ArgsUsage: "txid label",
Description: `
Add a label to a transaction. If the transaction already has a label,
this call will fail unless the overwrite option is set. The label is
limited to 500 characters. Note that multi word labels must be contained
in quotation marks ("").
`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "overwrite",
Usage: "set to overwrite existing labels",
},
},
Action: actionDecorator(labelTransaction),
}
func labelTransaction(ctx *cli.Context) error {
// Display the command's help message if we do not have the expected
// number of arguments/flags.
if ctx.NArg() != 2 {
return cli.ShowCommandHelp(ctx, "labeltx")
}
// Get the transaction id and check that it is a valid hash.
txid := ctx.Args().Get(0)
hash, err := chainhash.NewHashFromStr(txid)
if err != nil {
return err
}
label := ctx.Args().Get(1)
walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp()
ctxb := context.Background()
_, err = walletClient.LabelTransaction(
ctxb, &walletrpc.LabelTransactionRequest{
Txid: hash[:],
Label: label,
Overwrite: ctx.Bool("overwrite"),
},
)
if err != nil {
return err
}
fmt.Printf("Transaction: %v labelled with: %v\n", txid, label)
return nil
}