71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package gov
|
|
|
|
import (
|
|
"time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// GenesisState - all staking state that must be provided at genesis
|
|
type GenesisState struct {
|
|
StartingProposalID uint64 `json:"starting_proposalID"`
|
|
DepositParams DepositParams `json:"deposit_params"`
|
|
VotingParams VotingParams `json:"voting_params"`
|
|
TallyParams TallyParams `json:"tally_params"`
|
|
}
|
|
|
|
func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParams, tp TallyParams) GenesisState {
|
|
return GenesisState{
|
|
StartingProposalID: startingProposalID,
|
|
DepositParams: dp,
|
|
VotingParams: vp,
|
|
TallyParams: tp,
|
|
}
|
|
}
|
|
|
|
// get raw genesis raw message for testing
|
|
func DefaultGenesisState() GenesisState {
|
|
return GenesisState{
|
|
StartingProposalID: 1,
|
|
DepositParams: DepositParams{
|
|
MinDeposit: sdk.Coins{sdk.NewInt64Coin("steak", 10)},
|
|
MaxDepositPeriod: time.Duration(172800) * time.Second,
|
|
},
|
|
VotingParams: VotingParams{
|
|
VotingPeriod: time.Duration(172800) * time.Second,
|
|
},
|
|
TallyParams: TallyParams{
|
|
Threshold: sdk.NewDecWithPrec(5, 1),
|
|
Veto: sdk.NewDecWithPrec(334, 3),
|
|
GovernancePenalty: sdk.NewDecWithPrec(1, 2),
|
|
},
|
|
}
|
|
}
|
|
|
|
// InitGenesis - store genesis parameters
|
|
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) {
|
|
err := k.setInitialProposalID(ctx, data.StartingProposalID)
|
|
if err != nil {
|
|
// TODO: Handle this with #870
|
|
panic(err)
|
|
}
|
|
k.setDepositParams(ctx, data.DepositParams)
|
|
k.setVotingParams(ctx, data.VotingParams)
|
|
k.setTallyParams(ctx, data.TallyParams)
|
|
}
|
|
|
|
// WriteGenesis - output genesis parameters
|
|
func WriteGenesis(ctx sdk.Context, k Keeper) GenesisState {
|
|
startingProposalID, _ := k.getNewProposalID(ctx)
|
|
depositParams := k.GetDepositParams(ctx)
|
|
votingParams := k.GetVotingParams(ctx)
|
|
tallyParams := k.GetTallyParams(ctx)
|
|
|
|
return GenesisState{
|
|
StartingProposalID: startingProposalID,
|
|
DepositParams: depositParams,
|
|
VotingParams: votingParams,
|
|
TallyParams: tallyParams,
|
|
}
|
|
}
|