diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 077d3332a..1a4e961ef 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -23,6 +23,7 @@ import ( "github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/signal" "github.com/urfave/cli" + "golang.org/x/term" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" @@ -302,6 +303,14 @@ var sendCoinsCommand = cli.Command{ "must satisfy", Value: defaultUtxoMinConf, }, + cli.BoolFlag{ + Name: "force, f", + Usage: "if set, the transaction will be broadcast " + + "without asking for confirmation; this is " + + "set to true by default if stdout is not a " + + "terminal avoid breaking existing shell " + + "scripts", + }, txLabelFlag, }, Action: actionDecorator(sendCoins), @@ -364,6 +373,19 @@ func sendCoins(ctx *cli.Context) error { "sweep all coins out of the wallet") } + // Ask for confirmation if we're on an actual terminal and the output is + // not being redirected to another command. This prevents existing shell + // scripts from breaking. + if !ctx.Bool("force") && term.IsTerminal(int(os.Stdout.Fd())) { + fmt.Printf("Amount: %d\n", amt) + fmt.Printf("Destination address: %v\n", addr) + + confirm := promptForConfirmation("Confirm payment (yes/no): ") + if !confirm { + return nil + } + } + client, cleanUp := getClient(ctx) defer cleanUp() diff --git a/docs/release-notes/release-notes-0.17.0.md b/docs/release-notes/release-notes-0.17.0.md index f1d443a6a..3fd8b6592 100644 --- a/docs/release-notes/release-notes-0.17.0.md +++ b/docs/release-notes/release-notes-0.17.0.md @@ -115,6 +115,13 @@ unlock or create. * Added ability to use [ENV variables to override `lncli` global flags](https://github.com/lightningnetwork/lnd/pull/7693). Flags will have preference over ENVs. +* The `lncli sendcoins` command now asks for manual confirmation when invoked + on the command line. This can be skipped by adding the `--force` (or `-f`) + flag, similar to how `lncli payinvoice` works. To not break any existing + scripts the confirmation is also skipped if `stdout` is not a terminal/tty + (e.g. when capturing the output in a shell script variable or piping the + output to another program). + ## Bug Fix * Make sure payment stream returns all the events by [subscribing it before