From 018484628ad911989632129d6e95ad93b3735e8d Mon Sep 17 00:00:00 2001 From: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com> Date: Wed, 22 May 2024 12:02:04 +0100 Subject: [PATCH] lncli: Add `outpoints` flag to sendcoins command Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com> --- cmd/lncli/commands.go | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 04a70f903..fefef6ab2 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -288,10 +288,11 @@ var sendCoinsCommand = cli.Command{ }, cli.BoolFlag{ Name: "sweepall", - Usage: "if set, then the amount field will be ignored, " + - "and the wallet will attempt to sweep all " + - "outputs within the wallet to the target " + - "address", + Usage: "if set, then the amount field should be " + + "unset. This indicates that the wallet will " + + "attempt to sweep all outputs within the " + + "wallet or all funds in select utxos (when " + + "supplied) to the target address", }, cli.Int64Flag{ Name: "amt", @@ -330,6 +331,17 @@ var sendCoinsCommand = cli.Command{ "scripts", }, coinSelectionStrategyFlag, + cli.StringSliceFlag{ + Name: "utxo", + Usage: "a utxo specified as outpoint(tx:idx) which " + + "will be used as input for the transaction. " + + "This flag can be repeatedly used to specify " + + "multiple utxos as inputs. The selected " + + "utxos can either be entirely spent by " + + "specifying the sweepall flag or a specified " + + "amount can be spent in the utxos through " + + "the amt flag", + }, txLabelFlag, }, Action: actionDecorator(sendCoins), @@ -337,9 +349,10 @@ var sendCoinsCommand = cli.Command{ func sendCoins(ctx *cli.Context) error { var ( - addr string - amt int64 - err error + addr string + amt int64 + err error + outpoints []*lnrpc.OutPoint ) ctxc := getContext() args := ctx.Args() @@ -417,6 +430,15 @@ func sendCoins(ctx *cli.Context) error { displayAmt = balanceResponse.GetConfirmedBalance() } + if ctx.IsSet("utxo") { + utxos := ctx.StringSlice("utxo") + + outpoints, err = UtxosToOutpoints(utxos) + if err != nil { + return fmt.Errorf("unable to decode utxos: %w", err) + } + } + // 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. @@ -440,6 +462,7 @@ func sendCoins(ctx *cli.Context) error { MinConfs: minConfs, SpendUnconfirmed: minConfs == 0, CoinSelectionStrategy: coinSelectionStrategy, + Outpoints: outpoints, } txid, err := client.SendCoins(ctxc, req) if err != nil {