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.
This commit is contained in:
parent
3a7b9c8367
commit
b2c712fb67
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user