Skip to content

Commit eab455a

Browse files
stariushieblmi
authored andcommitted
multi: dedup the code from LND
Removed and deduplicated LND functions working with lnrpc types.
1 parent 647f9b0 commit eab455a

File tree

7 files changed

+50
-102
lines changed

7 files changed

+50
-102
lines changed

cmd/loop/openchannel.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/lightninglabs/loop/looprpc"
10+
lndcommands "github.com/lightningnetwork/lnd/cmd/commands"
1011
"github.com/lightningnetwork/lnd/lnrpc"
1112
"github.com/urfave/cli/v3"
1213
)
@@ -258,7 +259,7 @@ func openChannel(ctx context.Context, cmd *cli.Command) error {
258259
if cmd.IsSet("utxo") {
259260
utxos := cmd.StringSlice("utxo")
260261

261-
outpoints, err := UtxosToOutpoints(utxos)
262+
outpoints, err := lndcommands.UtxosToOutpoints(utxos)
262263
if err != nil {
263264
return fmt.Errorf("unable to decode utxos: %w", err)
264265
}
@@ -332,25 +333,6 @@ func openChannel(ctx context.Context, cmd *cli.Command) error {
332333
return err
333334
}
334335

335-
// UtxosToOutpoints converts a slice of UTXO strings into a slice of OutPoint
336-
// protobuf objects. It returns an error if no UTXOs are specified or if any
337-
// UTXO string cannot be parsed into an OutPoint.
338-
func UtxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) {
339-
var outpoints []*lnrpc.OutPoint
340-
if len(utxos) == 0 {
341-
return nil, fmt.Errorf("no utxos specified")
342-
}
343-
for _, utxo := range utxos {
344-
outpoint, err := NewProtoOutPoint(utxo)
345-
if err != nil {
346-
return nil, err
347-
}
348-
outpoints = append(outpoints, outpoint)
349-
}
350-
351-
return outpoints, nil
352-
}
353-
354336
// checkNotBothSet accepts two flag names, a and b, and checks that only flag a
355337
// or flag b can be set, but not both. It returns the name of the flag or an
356338
// error.

cmd/loop/staticaddr.go

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ package main
22

33
import (
44
"context"
5-
"encoding/hex"
65
"errors"
76
"fmt"
8-
"strconv"
9-
"strings"
107

11-
"github.com/btcsuite/btcd/chaincfg/chainhash"
128
"github.com/lightninglabs/loop/labels"
139
"github.com/lightninglabs/loop/looprpc"
1410
"github.com/lightninglabs/loop/staticaddr/deposit"
1511
"github.com/lightninglabs/loop/staticaddr/loopin"
1612
"github.com/lightninglabs/loop/swapserverrpc"
13+
lndcommands "github.com/lightningnetwork/lnd/cmd/commands"
1714
"github.com/lightningnetwork/lnd/lnrpc"
1815
"github.com/lightningnetwork/lnd/routing/route"
1916
"github.com/urfave/cli/v3"
@@ -195,7 +192,7 @@ func withdraw(ctx context.Context, cmd *cli.Command) error {
195192
case isAllSelected:
196193
case isUtxoSelected:
197194
utxos := cmd.StringSlice("utxo")
198-
outpoints, err = utxosToOutpoints(utxos)
195+
outpoints, err = lndcommands.UtxosToOutpoints(utxos)
199196
if err != nil {
200197
return err
201198
}
@@ -415,46 +412,6 @@ func summary(ctx context.Context, cmd *cli.Command) error {
415412
return nil
416413
}
417414

418-
func utxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) {
419-
outpoints := make([]*lnrpc.OutPoint, 0, len(utxos))
420-
if len(utxos) == 0 {
421-
return nil, fmt.Errorf("no utxos specified")
422-
}
423-
424-
for _, utxo := range utxos {
425-
outpoint, err := NewProtoOutPoint(utxo)
426-
if err != nil {
427-
return nil, err
428-
}
429-
outpoints = append(outpoints, outpoint)
430-
}
431-
432-
return outpoints, nil
433-
}
434-
435-
// NewProtoOutPoint parses an OutPoint into its corresponding lnrpc.OutPoint
436-
// type.
437-
func NewProtoOutPoint(op string) (*lnrpc.OutPoint, error) {
438-
parts := strings.Split(op, ":")
439-
if len(parts) != 2 {
440-
return nil, errors.New("outpoint should be of the form " +
441-
"txid:index")
442-
}
443-
txid := parts[0]
444-
if hex.DecodedLen(len(txid)) != chainhash.HashSize {
445-
return nil, fmt.Errorf("invalid hex-encoded txid %v", txid)
446-
}
447-
outputIndex, err := strconv.Atoi(parts[1])
448-
if err != nil {
449-
return nil, fmt.Errorf("invalid output index: %v", err)
450-
}
451-
452-
return &lnrpc.OutPoint{
453-
TxidStr: txid,
454-
OutputIndex: uint32(outputIndex),
455-
}, nil
456-
}
457-
458415
var staticAddressLoopInCommand = &cli.Command{
459416
Name: "in",
460417
Usage: "Loop in funds from static address deposits.",

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ require (
5757
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
5858
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
5959
github.com/aead/siphash v1.0.1 // indirect
60+
github.com/andybalholm/brotli v1.0.4 // indirect
6061
github.com/beorn7/perks v1.0.1 // indirect
6162
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
6263
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 // indirect
@@ -112,6 +113,7 @@ require (
112113
github.com/jackc/puddle/v2 v2.2.2 // indirect
113114
github.com/jackpal/gateway v1.0.5 // indirect
114115
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad // indirect
116+
github.com/jedib0t/go-pretty/v6 v6.2.7 // indirect
115117
github.com/jonboulle/clockwork v0.2.2 // indirect
116118
github.com/jrick/logrotate v1.1.2 // indirect
117119
github.com/json-iterator/go v1.1.12 // indirect
@@ -130,6 +132,7 @@ require (
130132
github.com/lightningnetwork/lnd/sqldb v1.0.11 // indirect
131133
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
132134
github.com/mattn/go-isatty v0.0.20 // indirect
135+
github.com/mattn/go-runewidth v0.0.13 // indirect
133136
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
134137
github.com/mholt/acmez v1.0.4 // indirect
135138
github.com/miekg/dns v1.1.50 // indirect
@@ -149,6 +152,7 @@ require (
149152
github.com/prometheus/common v0.37.0 // indirect
150153
github.com/prometheus/procfs v0.8.0 // indirect
151154
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
155+
github.com/rivo/uniseg v0.2.0 // indirect
152156
github.com/rogpeppe/fastuuid v1.2.0 // indirect
153157
github.com/rogpeppe/go-internal v1.14.1 // indirect
154158
github.com/russross/blackfriday/v2 v2.1.0 // indirect
@@ -159,6 +163,7 @@ require (
159163
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
160164
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
161165
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 // indirect
166+
github.com/urfave/cli v1.22.14 // indirect
162167
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
163168
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
164169
github.com/xeipuuv/gojsonschema v1.2.0 // indirect

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3p
600600
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
601601
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
602602
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
603+
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
603604
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
604605
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
605606
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@@ -631,6 +632,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
631632
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
632633
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
633634
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
635+
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
634636
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
635637
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
636638
github.com/apache/arrow/go/v10 v10.0.1/go.mod h1:YvhnlEePVnBS4+0z3fhPfUy7W1Ikj0Ih0vcRo/gZ1M0=
@@ -1042,6 +1044,8 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc
10421044
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
10431045
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad h1:heFfj7z0pGsNCekUlsFhO2jstxO4b5iQ665LjwM5mDc=
10441046
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
1047+
github.com/jedib0t/go-pretty/v6 v6.2.7 h1:4823Lult/tJ0VI1PgW3aSKw59pMWQ6Kzv9b3Bj6MwY0=
1048+
github.com/jedib0t/go-pretty/v6 v6.2.7/go.mod h1:FMkOpgGD3EZ91cW8g/96RfxoV7bdeJyzXPYgz1L1ln0=
10451049
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
10461050
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
10471051
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -1162,6 +1166,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
11621166
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
11631167
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
11641168
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1169+
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
1170+
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
11651171
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
11661172
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
11671173
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
@@ -1224,6 +1230,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
12241230
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
12251231
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
12261232
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1233+
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
12271234
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
12281235
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
12291236
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -1257,6 +1264,8 @@ github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0ua
12571264
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
12581265
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
12591266
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
1267+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
1268+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
12601269
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
12611270
github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s=
12621271
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
@@ -1308,6 +1317,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
13081317
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
13091318
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
13101319
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
1320+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
13111321
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
13121322
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
13131323
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
@@ -1316,6 +1326,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4
13161326
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
13171327
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 h1:tcJ6OjwOMvExLlzrAVZute09ocAGa7KqOON60++Gz4E=
13181328
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02/go.mod h1:tHlrkM198S068ZqfrO6S8HsoJq2bF3ETfTL+kt4tInY=
1329+
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
1330+
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
13191331
github.com/urfave/cli-docs/v3 v3.1.0 h1:Sa5xm19IpE5gpm6tZzXdfjdFxn67PnEsE4dpXF7vsKw=
13201332
github.com/urfave/cli-docs/v3 v3.1.0/go.mod h1:59d+5Hz1h6GSGJ10cvcEkbIe3j233t4XDqI72UIx7to=
13211333
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
@@ -1619,6 +1631,7 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJ
16191631
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16201632
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
16211633
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
1634+
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16221635
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16231636
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16241637
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

loopd/swapclient_server.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import (
3333
"github.com/lightninglabs/loop/staticaddr/deposit"
3434
"github.com/lightninglabs/loop/staticaddr/loopin"
3535
"github.com/lightninglabs/loop/staticaddr/openchannel"
36+
"github.com/lightninglabs/loop/staticaddr/staticutil"
3637
"github.com/lightninglabs/loop/staticaddr/withdraw"
3738
"github.com/lightninglabs/loop/swap"
3839
"github.com/lightninglabs/loop/swapserverrpc"
3940
"github.com/lightninglabs/taproot-assets/rfqmath"
40-
"github.com/lightningnetwork/lnd/lnrpc"
4141
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
4242
"github.com/lightningnetwork/lnd/lntypes"
4343
"github.com/lightningnetwork/lnd/queue"
@@ -1736,7 +1736,7 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
17361736
}
17371737

17381738
case isUtxoSelected:
1739-
outpoints, err = toServerOutpoints(req.Outpoints)
1739+
outpoints, err = staticutil.ToWireOutpoints(req.Outpoints)
17401740
if err != nil {
17411741
return nil, err
17421742
}
@@ -2353,23 +2353,6 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
23532353
}
23542354
}
23552355

2356-
func toServerOutpoints(outpoints []*lnrpc.OutPoint) ([]wire.OutPoint,
2357-
error) {
2358-
2359-
var serverOutpoints []wire.OutPoint
2360-
for _, o := range outpoints {
2361-
outpointStr := fmt.Sprintf("%s:%d", o.TxidStr, o.OutputIndex)
2362-
newOutpoint, err := wire.NewOutPointFromString(outpointStr)
2363-
if err != nil {
2364-
return nil, err
2365-
}
2366-
2367-
serverOutpoints = append(serverOutpoints, *newOutpoint)
2368-
}
2369-
2370-
return serverOutpoints, nil
2371-
}
2372-
23732356
func rpcAutoloopReason(reason liquidity.Reason) (looprpc.AutoReason, error) {
23742357
switch reason {
23752358
case liquidity.ReasonNone:

staticaddr/openchannel/manager.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (m *Manager) OpenChannel(ctx context.Context,
182182
if len(req.Outpoints) > 0 {
183183
// Ensure that the deposits are in a state in which they are
184184
// available for a channel open.
185-
outpoints, err = toServerOutpoints(req.Outpoints)
185+
outpoints, err = staticutil.ToWireOutpoints(req.Outpoints)
186186
if err != nil {
187187
return nil, fmt.Errorf("error parsing outpoints: %w",
188188
err)
@@ -296,23 +296,6 @@ func (m *Manager) OpenChannel(ctx context.Context,
296296
return chanTxHash, nil
297297
}
298298

299-
func toServerOutpoints(outpoints []*lnrpc.OutPoint) ([]wire.OutPoint,
300-
error) {
301-
302-
var serverOutpoints []wire.OutPoint
303-
for _, o := range outpoints {
304-
outpointStr := fmt.Sprintf("%s:%d", o.TxidStr, o.OutputIndex)
305-
newOutpoint, err := wire.NewOutPointFromString(outpointStr)
306-
if err != nil {
307-
return nil, err
308-
}
309-
310-
serverOutpoints = append(serverOutpoints, *newOutpoint)
311-
}
312-
313-
return serverOutpoints, nil
314-
}
315-
316299
// openChannelPsbt starts an interactive channel open protocol that uses a
317300
// partially signed bitcoin transaction (PSBT) to fund the channel output. The
318301
// protocol involves several steps between the loop client and the server:

staticaddr/staticutil/outpoints.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package staticutil
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/btcsuite/btcd/wire"
7+
"github.com/lightningnetwork/lnd/lnrpc"
8+
)
9+
10+
// ToWireOutpoints converts lnrpc.OutPoint protos into wire.OutPoint structs so
11+
// they can be consumed by lower level transaction building code.
12+
func ToWireOutpoints(outpoints []*lnrpc.OutPoint) ([]wire.OutPoint, error) {
13+
serverOutpoints := make([]wire.OutPoint, 0, len(outpoints))
14+
for _, o := range outpoints {
15+
outpointStr := fmt.Sprintf("%s:%d", o.TxidStr, o.OutputIndex)
16+
newOutpoint, err := wire.NewOutPointFromString(outpointStr)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
serverOutpoints = append(serverOutpoints, *newOutpoint)
22+
}
23+
24+
return serverOutpoints, nil
25+
}

0 commit comments

Comments
 (0)