-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
53 lines (43 loc) · 881 Bytes
/
server.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
package cowallet
import (
"context"
"github.com/dgraph-io/badger/v4"
"github.com/fox-one/mixin-sdk-go/v2"
"github.com/fox-one/mixin-sdk-go/v2/mixinnet"
"github.com/shopspring/decimal"
"github.com/yiplee/go-cache"
"golang.org/x/sync/errgroup"
)
type Config struct {
SpendKey mixinnet.Key
PayAssetID string
PayAmount decimal.Decimal
}
type Server struct {
db *badger.DB
client *mixin.Client
cfg Config
assets *cache.Cache[string, *mixin.SafeAsset]
}
func NewServer(
db *badger.DB,
client *mixin.Client,
cfg Config,
) Server {
return Server{
db: db,
client: client,
cfg: cfg,
assets: cache.New[string, *mixin.SafeAsset](),
}
}
func (s *Server) Run(ctx context.Context) error {
var g errgroup.Group
g.Go(func() error {
return s.LoopOutputs(ctx)
})
g.Go(func() error {
return s.HandlePendingJobs(ctx)
})
return g.Wait()
}