-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenesis.go
34 lines (29 loc) · 1013 Bytes
/
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
package poa
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ltacker/poa/keeper"
"github.com/ltacker/poa/types"
abci "github.com/tendermint/tendermint/abci/types"
)
// InitGenesis initialize default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) (res []abci.ValidatorUpdate) {
k.SetParams(ctx, data.Params)
// Set validators in the storage
for _, validator := range data.Validators {
k.SetValidator(ctx, validator)
k.SetValidatorByConsAddr(ctx, validator)
k.SetValidatorState(ctx, validator, types.ValidatorStateJoined)
res = append(res, validator.ABCIValidatorUpdateAppend())
}
return res
}
// ExportGenesis writes the current store values
// to a genesis file, which can be imported again
// with InitGenesis
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) (data types.GenesisState) {
return types.GenesisState{
Params: k.GetParams(ctx),
Validators: k.GetAllValidators(ctx),
}
}