@@ -13,28 +13,18 @@ import (
1313 "regexp"
1414 "runtime/debug"
1515 "strings"
16+ "sync"
1617 "syscall/js"
1718
1819 "github.com/btcsuite/btcd/btcec/v2"
1920 "github.com/golang/protobuf/proto"
2021 "github.com/jessevdk/go-flags"
21- "github.com/lightninglabs/faraday/frdrpc"
22- "github.com/lightninglabs/lightning-node-connect/core"
2322 "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 "
2625 "github.com/lightningnetwork/lnd/build"
2726 "github.com/lightningnetwork/lnd/keychain"
2827 "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"
3828 "github.com/lightningnetwork/lnd/macaroons"
3929 "github.com/lightningnetwork/lnd/signal"
4030 "google.golang.org/grpc"
@@ -43,28 +33,12 @@ import (
4333 "gopkg.in/macaroon.v2"
4434)
4535
46- type stubPackageRegistration func (map [string ]func (context.Context ,
47- * grpc.ClientConn , string , func (string , error )))
48-
4936var (
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
6842
6943 jsonCBRegex = regexp .MustCompile ("(\\ w+)\\ .(\\ w+)\\ .(\\ w+)" )
7044)
@@ -77,6 +51,12 @@ func main() {
7751 }
7852 }()
7953
54+ // Initialise any global variables if they have not yet been
55+ // initialised.
56+ if err := initGlobals (); err != nil {
57+ exit (err )
58+ }
59+
8060 // Parse command line flags.
8161 cfg := config {}
8262 parser := flags .NewParser (& cfg , flags .Default )
@@ -123,7 +103,7 @@ func main() {
123103 callbacks .Set ("wasmClientIsCustom" , js .FuncOf (wc .IsCustom ))
124104 js .Global ().Set (cfg .NameSpace , callbacks )
125105
126- for _ , registration := range registrations {
106+ for _ , registration := range litclient . Registrations {
127107 registration (wc .registry )
128108 }
129109
@@ -137,6 +117,22 @@ func main() {
137117 }
138118}
139119
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+
140136type wasmClient struct {
141137 cfg * config
142138
@@ -399,7 +395,7 @@ func (w *wasmClient) HasPermissions(_ js.Value, args []js.Value) interface{} {
399395 // first `/` back to a `.` and then we prepend the result with a `/`.
400396 uri := jsonCBRegex .ReplaceAllString (args [0 ].String (), "/$1.$2/$3" )
401397
402- ops , ok := perms [ uri ]
398+ ops , ok := permsMgr . URIPermissions ( uri )
403399 if ! ok {
404400 log .Errorf ("uri %s not found in known permissions list" , uri )
405401 return js .ValueOf (false )
0 commit comments