forked from ellipti-labs/terra-oracle
-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.go
63 lines (48 loc) · 1.26 KB
/
service.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
62
63
package oracle
import (
"time"
"github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/everett-protocol/terra-oracle/price"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
)
const VotePeriod = 12
type OracleService struct {
cmn.BaseService
ps price.PriceService
cdc *amino.Codec
passphrase string
txBldr authtxb.TxBuilder
cliCtx context.CLIContext
prevoteInited bool
salts map[string]string
lunaPrices map[string]sdk.Dec
preLunaPrices map[string]sdk.Dec
}
func NewOracleService(ps price.PriceService, cdc *amino.Codec) *OracleService {
os := &OracleService{
ps: ps,
cdc: cdc,
salts: make(map[string]string),
lunaPrices: make(map[string]sdk.Dec),
preLunaPrices: make(map[string]sdk.Dec),
}
os.BaseService = *cmn.NewBaseService(nil, "OracleService", os)
return os
}
func (os *OracleService) OnStart() error {
err := os.init()
if err != nil {
return err
}
err = os.ps.Start()
if err != nil {
return err
}
// Wait a second until price service fetchs price initially
time.Sleep(3 * time.Second)
go os.startRoutine()
return nil
}