-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(hub-genesis): refactoring
x/hub-genesis
state (#374)
- Loading branch information
Showing
34 changed files
with
872 additions
and
946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
package rollapp.hub_genesis; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; | ||
|
||
// State holds the state of the genesis event | ||
message State { | ||
// is_locked is a boolean that indicates if the genesis event has occured | ||
bool is_locked = 1; | ||
|
||
// genesis_tokens is the list of tokens that are expected to be locked on genesis event | ||
repeated cosmos.base.v1beta1.Coin genesis_tokens = 2 [ | ||
(gogoproto.nullable) = false, | ||
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" | ||
) | ||
|
||
// InitGenesis new hub-genesis genesis. | ||
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { | ||
k.SetParams(ctx, genState.Params) | ||
|
||
modAddress := k.accountKeeper.GetModuleAddress(types.ModuleName) | ||
if !k.accountKeeper.HasAccount(ctx, modAddress) { | ||
k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) | ||
} | ||
|
||
// if tokens provided and waiting to be locked, verify the balance | ||
if !genState.State.IsLocked && !genState.State.GenesisTokens.IsZero() { | ||
// get spendable coins in the module account | ||
spendable := k.bankKeeper.SpendableCoins(ctx, modAddress) | ||
// we expect the genesis balance of the module account to be equal to required genesis tokens | ||
if !spendable.IsEqual(genState.State.GenesisTokens) { | ||
panic(types.ErrWrongGenesisBalance) | ||
} | ||
} | ||
k.SetState(ctx, genState.State) | ||
} | ||
|
||
// ExportGenesis returns a GenesisState for a given context and keeper. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
genesis := types.DefaultGenesisState() | ||
genesis.Params = k.GetParams(ctx) | ||
genesis.State = k.GetState(ctx) | ||
|
||
return genesis | ||
} |
11 changes: 3 additions & 8 deletions
11
x/hub-genesis/genesis_test.go → x/hub-genesis/keeper/genesis_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.