Skip to content

Commit 7e12d2a

Browse files
committed
cmd/wasm-client: move shared code to core package
1 parent 8afcf3f commit 7e12d2a

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

cmd/wasm-client/log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build js
12
// +build js
23

34
package main
@@ -61,4 +62,4 @@ func NewGrpcLogLogger(root *build.RotatingLogWriter,
6162
return &mailbox.GrpcLogLogger{
6263
Logger: logger,
6364
}
64-
}
65+
}

cmd/wasm-client/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/golang/protobuf/proto"
2121
"github.com/jessevdk/go-flags"
2222
"github.com/lightninglabs/faraday/frdrpc"
23+
"github.com/lightninglabs/lightning-node-connect/core"
2324
"github.com/lightninglabs/lightning-node-connect/mailbox"
2425
"github.com/lightninglabs/loop/looprpc"
2526
"github.com/lightninglabs/pool/poolrpc"
@@ -63,7 +64,7 @@ var (
6364
frdrpc.RegisterFaradayServerJSONCallbacks,
6465
}
6566

66-
perms = getAllMethodPermissions()
67+
perms = core.GetAllMethodPermissions()
6768

6869
jsonCBRegex = regexp.MustCompile("(\\w+)\\.(\\w+)\\.(\\w+)")
6970
)
@@ -140,7 +141,7 @@ type wasmClient struct {
140141

141142
lndConn *grpc.ClientConn
142143

143-
statusChecker func() mailbox.ClientStatus
144+
statusChecker func() mailbox.ConnStatus
144145

145146
mac *macaroon.Macaroon
146147

@@ -209,7 +210,7 @@ func (w *wasmClient) ConnectServer(_ js.Value, args []js.Value) interface{} {
209210
// in another goroutine here. See https://pkg.go.dev/syscall/js#FuncOf.
210211
go func() {
211212
var err error
212-
statusChecker, lndConnect, err := mailboxRPCConnection(
213+
statusChecker, lndConnect, err := core.MailboxRPCConnection(
213214
mailboxServer, pairingPhrase, localPriv, remotePub,
214215
func(key *btcec.PublicKey) error {
215216
return callJsCallback(

cmd/wasm-client/lnd_conn.go renamed to core/lnd_conn.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
//go:build js
2-
// +build js
3-
4-
package main
1+
package core
52

63
import (
74
"context"
85
"strings"
96

10-
"github.com/btcsuite/btcd/btcec/v2"
117
"github.com/lightninglabs/lightning-node-connect/mailbox"
8+
"github.com/btcsuite/btcd/btcec/v2"
129
"github.com/lightningnetwork/lnd/keychain"
1310
"google.golang.org/grpc"
1411
)
1512

16-
func mailboxRPCConnection(mailboxServer, pairingPhrase string,
13+
func MailboxRPCConnection(mailboxServer, pairingPhrase string,
1714
localStatic keychain.SingleKeyECDH, remoteStatic *btcec.PublicKey,
1815
onRemoteStatic func(key *btcec.PublicKey) error,
19-
onAuthData func(data []byte) error) (func() mailbox.ClientStatus,
16+
onAuthData func(data []byte) error) (func() mailbox.ConnStatus,
2017
func() (*grpc.ClientConn, error), error) {
2118

2219
words := strings.Split(pairingPhrase, " ")
@@ -30,9 +27,7 @@ func mailboxRPCConnection(mailboxServer, pairingPhrase string,
3027
)
3128

3229
ctx := context.Background()
33-
transportConn, err := mailbox.NewWebsocketsClient(
34-
ctx, mailboxServer, connData,
35-
)
30+
transportConn, err := mailbox.NewClient(ctx, connData)
3631
if err != nil {
3732
return nil, nil, err
3833
}

cmd/wasm-client/permissions.go renamed to core/permissions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package core
22

33
import (
44
"net"
@@ -45,7 +45,7 @@ var (
4545

4646
// getAllMethodPermissions returns a merged map of all litd's method
4747
// permissions.
48-
func getAllMethodPermissions() map[string][]bakery.Op {
48+
func GetAllMethodPermissions() map[string][]bakery.Op {
4949
allPerms := make(map[string][]bakery.Op)
5050

5151
lndMainPerms := lnd.MainRPCServerPermissions()

0 commit comments

Comments
 (0)