-
Notifications
You must be signed in to change notification settings - Fork 41
/
genesis.go
47 lines (41 loc) · 1.43 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
package oracle
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bandprotocol/chain/v2/x/oracle/keeper"
"github.com/bandprotocol/chain/v2/x/oracle/types"
)
// InitGenesis performs genesis initialization for the oracle module.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data *types.GenesisState) {
k.SetParams(ctx, data.Params)
k.SetDataSourceCount(ctx, 0)
k.SetOracleScriptCount(ctx, 0)
k.SetRequestCount(ctx, 0)
k.SetRequestLastExpired(ctx, 0)
k.SetRollingSeed(ctx, make([]byte, types.RollingSeedSizeInBytes))
for _, dataSource := range data.DataSources {
_ = k.AddDataSource(ctx, dataSource)
}
for _, oracleScript := range data.OracleScripts {
_ = k.AddOracleScript(ctx, oracleScript)
}
k.SetPort(ctx, types.PortID)
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(ctx, types.PortID) {
// oracle module binds to the oracle port on InitChain
// and claims the returned capability
err := k.BindPort(ctx, types.PortID)
if err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
}
// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
DataSources: k.GetAllDataSources(ctx),
OracleScripts: k.GetAllOracleScripts(ctx),
}
}