/
genesis.go
56 lines (48 loc) · 1.7 KB
/
genesis.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
package types
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
)
// NewGenesisState creates a new GenesisState object
func NewGenesisState(
params Params,
rates []ExchangeRateTuple,
feederDelegations []FeederDelegation,
missCounters []MissCounter,
aggregateExchangeRatePrevotes []AggregateExchangeRatePrevote,
aggregateExchangeRateVotes []AggregateExchangeRateVote,
) *GenesisState {
return &GenesisState{
Params: params,
ExchangeRates: rates,
FeederDelegations: feederDelegations,
MissCounters: missCounters,
AggregateExchangeRatePrevotes: aggregateExchangeRatePrevotes,
AggregateExchangeRateVotes: aggregateExchangeRateVotes,
}
}
// DefaultGenesisState returns the default genesesis state for the x/oracle
// module.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
ExchangeRates: []ExchangeRateTuple{},
FeederDelegations: []FeederDelegation{},
MissCounters: []MissCounter{},
AggregateExchangeRatePrevotes: []AggregateExchangeRatePrevote{},
AggregateExchangeRateVotes: []AggregateExchangeRateVote{},
}
}
// ValidateGenesis validates the oracle genesis state.
func ValidateGenesis(data *GenesisState) error {
return data.Params.Validate()
}
// GetGenesisStateFromAppState returns x/oracle GenesisState given raw application
// genesis state.
func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *GenesisState {
var genesisState GenesisState
if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
}
return &genesisState
}