From b2c712fb67ead324bdc77ca6e6524817aee03a88 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 17 Nov 2018 21:11:47 -0800 Subject: [PATCH] cmd/lncli: add new --sweepall flag to sendcoins In this commit, we add a new flag to the sendcoins command that allows callers to sweep all funds out of the daemon's wallet. This CANNOT be set at the same time that an amount is specified. --- cmd/lncli/commands.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index e1e511b94..228ca6b48 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -161,7 +161,13 @@ var sendCoinsCommand = cli.Command{ Name: "addr", Usage: "the BASE58 encoded bitcoin address to send coins to on-chain", }, - // TODO(roasbeef): switch to BTC on command line? int may not be sufficient + cli.BoolFlag{ + Name: "sweepall", + Usage: "if set, then the amount field will be ignored, " + + "and all the wallet will attempt to sweep all " + + "outputs within the wallet to the target " + + "address", + }, cli.Int64Flag{ Name: "amt", Usage: "the number of bitcoin denominated in satoshis to send", @@ -215,14 +221,18 @@ func sendCoins(ctx *cli.Context) error { amt = ctx.Int64("amt") case args.Present(): amt, err = strconv.ParseInt(args.First(), 10, 64) - default: + case !ctx.Bool("sweepall"): return fmt.Errorf("Amount argument missing") } - if err != nil { return fmt.Errorf("unable to decode amount: %v", err) } + if amt != 0 && ctx.Bool("sweepall") { + return fmt.Errorf("amount cannot be set if attempting to " + + "sweep all coins out of the wallet") + } + ctxb := context.Background() client, cleanUp := getClient(ctx) defer cleanUp() @@ -232,6 +242,7 @@ func sendCoins(ctx *cli.Context) error { Amount: amt, TargetConf: int32(ctx.Int64("conf_target")), SatPerByte: ctx.Int64("sat_per_byte"), + SendAll: ctx.Bool("sweepall"), } txid, err := client.SendCoins(ctxb, req) if err != nil {