Skip to content

Commit

Permalink
add genesis version verifier in validateGenesis
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragpg committed May 27, 2024
1 parent 960c4c8 commit dd1aa75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package upgrade
import (
"encoding/json"

sekaitypes "github.com/KiraCore/sekai/types"
"github.com/KiraCore/sekai/x/upgrade/client/cli"
"github.com/KiraCore/sekai/x/upgrade/keeper"
"github.com/KiraCore/sekai/x/upgrade/types"
Expand Down Expand Up @@ -41,6 +42,14 @@ func (b AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { //
}

func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
genesis := types.GenesisState{}
err := marshaler.UnmarshalJSON(message, &genesis)
if err != nil {
return err
}
if sekaitypes.SekaiVersion != genesis.Version {
return types.ErrInvalidGenesisVersion
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion x/upgrade/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
)

var (
ErrInvalidUpgradeTime = errors.Register(ModuleName, 1, "invalid upgrade time")
ErrInvalidUpgradeTime = errors.Register(ModuleName, 1, "invalid upgrade time")
ErrInvalidGenesisVersion = errors.Register(ModuleName, 2, "invalid genesis version")
)

0 comments on commit dd1aa75

Please sign in to comment.