This repository has been archived by the owner on Jul 7, 2020. It is now read-only.
forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.go
61 lines (47 loc) · 1.34 KB
/
global.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package stellar
import (
"context"
"sync"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/stellar1"
"github.com/keybase/client/go/stellar/remote"
)
func ServiceInit(g *libkb.GlobalContext) {
g.SetStellar(NewStellar(g))
}
type Stellar struct {
libkb.Contextified
serverConfLock sync.Mutex
cachedServerConf stellar1.StellarServerDefinitions
}
var _ libkb.Stellar = (*Stellar)(nil)
func NewStellar(g *libkb.GlobalContext) *Stellar {
return &Stellar{
Contextified: libkb.NewContextified(g),
}
}
func (s *Stellar) CreateWalletGated(ctx context.Context) (bool, error) {
return CreateWalletGated(ctx, s.G())
}
func (s *Stellar) CreateWalletSoft(ctx context.Context) {
CreateWalletSoft(ctx, s.G())
}
func (s *Stellar) Upkeep(ctx context.Context) error {
return Upkeep(ctx, s.G())
}
func (s *Stellar) OnLogout() {}
func (s *Stellar) GetServerDefinitions(ctx context.Context) (ret stellar1.StellarServerDefinitions, err error) {
if s.cachedServerConf.Revision == 0 {
s.serverConfLock.Lock()
defer s.serverConfLock.Unlock()
if s.cachedServerConf.Revision == 0 {
// check if still 0, we might have waited for other thread
// to finish fetching.
if ret, err = remote.FetchServerConfig(ctx, s.G()); err != nil {
return ret, err
}
s.cachedServerConf = ret
}
}
return s.cachedServerConf, nil
}