-
Notifications
You must be signed in to change notification settings - Fork 170
/
genesis.go
65 lines (57 loc) · 2.06 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
57
58
59
60
61
62
63
64
65
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,
historicPrices []Price,
medianPrices []Price,
medianDeviationPrices []Price,
) *GenesisState {
return &GenesisState{
Params: params,
ExchangeRates: rates,
FeederDelegations: feederDelegations,
MissCounters: missCounters,
AggregateExchangeRatePrevotes: aggregateExchangeRatePrevotes,
AggregateExchangeRateVotes: aggregateExchangeRateVotes,
HistoricPrices: historicPrices,
Medians: medianPrices,
MedianDeviations: medianDeviationPrices,
}
}
// DefaultGenesisState returns the default genesis state for the x/oracle
// module.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
ExchangeRates: []ExchangeRateTuple{},
FeederDelegations: []FeederDelegation{},
MissCounters: []MissCounter{},
AggregateExchangeRatePrevotes: []AggregateExchangeRatePrevote{},
AggregateExchangeRateVotes: []AggregateExchangeRateVote{},
HistoricPrices: []Price{},
Medians: []Price{},
MedianDeviations: []Price{},
}
}
// 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
}