From 900d7fdd17bfb550ec5b1b4507f649a5018b2a87 Mon Sep 17 00:00:00 2001 From: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:06:33 +0100 Subject: [PATCH] cmd: Export and move `utxosToOutpoint`. Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com> --- cmd/lncli/cmd_open_channel.go | 20 +------------------- cmd/lncli/types.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cmd/lncli/cmd_open_channel.go b/cmd/lncli/cmd_open_channel.go index e3044c835..f0585ed47 100644 --- a/cmd/lncli/cmd_open_channel.go +++ b/cmd/lncli/cmd_open_channel.go @@ -406,7 +406,7 @@ func openChannel(ctx *cli.Context) error { if ctx.IsSet("utxo") { utxos := ctx.StringSlice("utxo") - outpoints, err := utxosToOutpoints(utxos) + outpoints, err := UtxosToOutpoints(utxos) if err != nil { return fmt.Errorf("unable to decode utxos: %w", err) } @@ -1141,21 +1141,3 @@ func decodePsbt(psbt string) ([]byte, error) { return nil, fmt.Errorf("not a PSBT") } } - -// parseUtxos parses a comma separated list of utxos into outpoints that are -// passed to the server. -func utxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) { - var outpoints []*lnrpc.OutPoint - if len(utxos) == 0 { - return nil, fmt.Errorf("no utxos specified") - } - for _, utxo := range utxos { - outpoint, err := NewProtoOutPoint(utxo) - if err != nil { - return nil, err - } - outpoints = append(outpoints, outpoint) - } - - return outpoints, nil -} diff --git a/cmd/lncli/types.go b/cmd/lncli/types.go index b878811a0..a93d3e2c6 100644 --- a/cmd/lncli/types.go +++ b/cmd/lncli/types.go @@ -85,3 +85,22 @@ func NewFailedUpdateFromProto(update *lnrpc.FailedUpdate) *FailedUpdate { UpdateError: update.UpdateError, } } + +// UtxosToOutpoints converts a slice of UTXO strings into a slice of OutPoint +// protobuf objects. It returns an error if no UTXOs are specified or if any +// UTXO string cannot be parsed into an OutPoint. +func UtxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) { + var outpoints []*lnrpc.OutPoint + if len(utxos) == 0 { + return nil, fmt.Errorf("no utxos specified") + } + for _, utxo := range utxos { + outpoint, err := NewProtoOutPoint(utxo) + if err != nil { + return nil, err + } + outpoints = append(outpoints, outpoint) + } + + return outpoints, nil +}