cmd/lncli: add confirmation to sendcoins

This commit is contained in:
zx9r 2022-12-13 20:54:40 +01:00 committed by Oliver Gugger
parent 63b32b9e4a
commit 3a5d67a16b
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 29 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/signal" "github.com/lightningnetwork/lnd/signal"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/term"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -302,6 +303,14 @@ var sendCoinsCommand = cli.Command{
"must satisfy", "must satisfy",
Value: defaultUtxoMinConf, 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, txLabelFlag,
}, },
Action: actionDecorator(sendCoins), Action: actionDecorator(sendCoins),
@ -364,6 +373,19 @@ func sendCoins(ctx *cli.Context) error {
"sweep all coins out of the wallet") "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) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()

View File

@ -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. * 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 ## Bug Fix
* Make sure payment stream returns all the events by [subscribing it before * Make sure payment stream returns all the events by [subscribing it before