-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from x/params for emergencybutton module
- Loading branch information
1 parent
3aa4b10
commit 65e08d4
Showing
16 changed files
with
616 additions
and
76 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 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
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,18 @@ | ||
package exported | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
) | ||
|
||
type ( | ||
ParamSet = paramtypes.ParamSet | ||
|
||
// Subspace defines an interface that implements the legacy x/params Subspace | ||
// type. | ||
// | ||
// NOTE: This is used solely for migration of x/params managed parameters. | ||
Subspace interface { | ||
GetParamSet(ctx sdk.Context, ps ParamSet) | ||
} | ||
) |
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,28 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/scrtlabs/SecretNetwork/x/emergencybutton/exported" | ||
v2 "github.com/scrtlabs/SecretNetwork/x/emergencybutton/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place state migrations. | ||
type Migrator struct { | ||
keeper Keeper | ||
legacySubspace exported.Subspace | ||
} | ||
|
||
func NewMigrator(k Keeper, ss exported.Subspace) Migrator { | ||
return Migrator{ | ||
keeper: k, | ||
legacySubspace: ss, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates the x/emergencybutton module state from the consensus version 1 to | ||
// version 2. Specifically, it takes the parameters that are currently stored | ||
// and managed by the x/params modules and stores them directly into the x/emergencybutton | ||
// module state. | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc) | ||
} |
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,40 @@ | ||
package v2 | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/scrtlabs/SecretNetwork/x/emergencybutton/exported" | ||
"github.com/scrtlabs/SecretNetwork/x/emergencybutton/types" | ||
) | ||
|
||
const ( | ||
ModuleName = "emergencybutton" | ||
) | ||
|
||
var ( | ||
ParamsKey = []byte{0x01} | ||
) | ||
|
||
// Migrate migrates the x/emergencybutton module state from the consensus version 1 to | ||
// version 2. Specifically, it takes the parameters that are currently stored | ||
// and managed by the x/params modules and stores them directly into the x/emergencybutton | ||
// module state. | ||
func Migrate( | ||
ctx sdk.Context, | ||
store storetypes.KVStore, | ||
legacySubspace exported.Subspace, | ||
cdc codec.BinaryCodec, | ||
) error { | ||
var currParams types.Params | ||
legacySubspace.GetParamSet(ctx, &currParams) | ||
|
||
if err := currParams.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
bz := cdc.MustMarshal(&currParams) | ||
store.Set(ParamsKey, bz) | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.