lncli: Add outpoints flag to sendcoins command

Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
This commit is contained in:
Ononiwu Maureen
2024-05-22 12:02:04 +01:00
committed by yyforyongyu
parent 900d7fdd17
commit 018484628a

View File

@@ -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 {