@@ -13,28 +13,18 @@ import (
13
13
"regexp"
14
14
"runtime/debug"
15
15
"strings"
16
+ "sync"
16
17
"syscall/js"
17
18
18
19
"github.com/btcsuite/btcd/btcec/v2"
19
20
"github.com/golang/protobuf/proto"
20
21
"github.com/jessevdk/go-flags"
21
- "github.com/lightninglabs/faraday/frdrpc"
22
- "github.com/lightninglabs/lightning-node-connect/core"
23
22
"github.com/lightninglabs/lightning-node-connect/mailbox"
24
- "github.com/lightninglabs/loop/looprpc "
25
- "github.com/lightninglabs/pool/poolrpc "
23
+ "github.com/lightninglabs/lightning-terminal/litclient "
24
+ "github.com/lightninglabs/lightning-terminal/perms "
26
25
"github.com/lightningnetwork/lnd/build"
27
26
"github.com/lightningnetwork/lnd/keychain"
28
27
"github.com/lightningnetwork/lnd/lnrpc"
29
- "github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
30
- "github.com/lightningnetwork/lnd/lnrpc/chainrpc"
31
- "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
32
- "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
33
- "github.com/lightningnetwork/lnd/lnrpc/signrpc"
34
- "github.com/lightningnetwork/lnd/lnrpc/verrpc"
35
- "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
36
- "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
37
- "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
38
28
"github.com/lightningnetwork/lnd/macaroons"
39
29
"github.com/lightningnetwork/lnd/signal"
40
30
"google.golang.org/grpc"
@@ -43,28 +33,12 @@ import (
43
33
"gopkg.in/macaroon.v2"
44
34
)
45
35
46
- type stubPackageRegistration func (map [string ]func (context.Context ,
47
- * grpc.ClientConn , string , func (string , error )))
48
-
49
36
var (
50
- registrations = []stubPackageRegistration {
51
- lnrpc .RegisterLightningJSONCallbacks ,
52
- lnrpc .RegisterStateJSONCallbacks ,
53
- autopilotrpc .RegisterAutopilotJSONCallbacks ,
54
- chainrpc .RegisterChainNotifierJSONCallbacks ,
55
- invoicesrpc .RegisterInvoicesJSONCallbacks ,
56
- routerrpc .RegisterRouterJSONCallbacks ,
57
- signrpc .RegisterSignerJSONCallbacks ,
58
- verrpc .RegisterVersionerJSONCallbacks ,
59
- walletrpc .RegisterWalletKitJSONCallbacks ,
60
- watchtowerrpc .RegisterWatchtowerJSONCallbacks ,
61
- wtclientrpc .RegisterWatchtowerClientJSONCallbacks ,
62
- looprpc .RegisterSwapClientJSONCallbacks ,
63
- poolrpc .RegisterTraderJSONCallbacks ,
64
- frdrpc .RegisterFaradayServerJSONCallbacks ,
65
- }
66
-
67
- perms = core .GetAllMethodPermissions ()
37
+ // initMu is to be used to guard global variables at initialisation
38
+ // time.
39
+ initMu sync.Mutex
40
+
41
+ permsMgr * perms.Manager
68
42
69
43
jsonCBRegex = regexp .MustCompile ("(\\ w+)\\ .(\\ w+)\\ .(\\ w+)" )
70
44
)
@@ -77,6 +51,12 @@ func main() {
77
51
}
78
52
}()
79
53
54
+ // Initialise any global variables if they have not yet been
55
+ // initialised.
56
+ if err := initGlobals (); err != nil {
57
+ exit (err )
58
+ }
59
+
80
60
// Parse command line flags.
81
61
cfg := config {}
82
62
parser := flags .NewParser (& cfg , flags .Default )
@@ -123,7 +103,7 @@ func main() {
123
103
callbacks .Set ("wasmClientIsCustom" , js .FuncOf (wc .IsCustom ))
124
104
js .Global ().Set (cfg .NameSpace , callbacks )
125
105
126
- for _ , registration := range registrations {
106
+ for _ , registration := range litclient . Registrations {
127
107
registration (wc .registry )
128
108
}
129
109
@@ -137,6 +117,22 @@ func main() {
137
117
}
138
118
}
139
119
120
+ // initGlobals initialises any global variables that have not yet been
121
+ // initialised.
122
+ func initGlobals () error {
123
+ initMu .Lock ()
124
+ defer initMu .Unlock ()
125
+
126
+ if permsMgr != nil {
127
+ return nil
128
+ }
129
+
130
+ var err error
131
+ permsMgr , err = perms .NewManager (true )
132
+
133
+ return err
134
+ }
135
+
140
136
type wasmClient struct {
141
137
cfg * config
142
138
@@ -399,7 +395,7 @@ func (w *wasmClient) HasPermissions(_ js.Value, args []js.Value) interface{} {
399
395
// first `/` back to a `.` and then we prepend the result with a `/`.
400
396
uri := jsonCBRegex .ReplaceAllString (args [0 ].String (), "/$1.$2/$3" )
401
397
402
- ops , ok := perms [ uri ]
398
+ ops , ok := permsMgr . URIPermissions ( uri )
403
399
if ! ok {
404
400
log .Errorf ("uri %s not found in known permissions list" , uri )
405
401
return js .ValueOf (false )
0 commit comments