-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix migration * add 039 pkg * lint * Fix pkg name * add v0.39 auth types * remove file * updates * updates * update godoc Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
- Loading branch information
1 parent
919e906
commit 3ff3e58
Showing
11 changed files
with
580 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 6 additions & 6 deletions
12
x/auth/legacy/v0_39/migrate.go → x/auth/legacy/v0_40/migrate.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package v039 | ||
package v040 | ||
|
||
import ( | ||
"fmt" | ||
|
||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38" | ||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39" | ||
) | ||
|
||
// Migrate accepts exported x/auth genesis state from v0.38 and migrates it to | ||
// v0.39 x/auth genesis state. The migration includes: | ||
// Migrate accepts exported x/auth genesis state from v0.38/v0.39 and migrates | ||
// it to v0.40 x/auth genesis state. The migration includes: | ||
// | ||
// - Removing coins from account encoding. | ||
func Migrate(authGenState v038auth.GenesisState) v038auth.GenesisState { | ||
func Migrate(authGenState v039auth.GenesisState) v039auth.GenesisState { | ||
for _, account := range authGenState.Accounts { | ||
// set coins to nil and allow the JSON encoding to omit coins | ||
if err := account.SetCoins(nil); err != nil { | ||
panic(fmt.Sprintf("failed to set account coins to nil: %s", err)) | ||
} | ||
} | ||
|
||
authGenState.Accounts = v038auth.SanitizeGenesisAccounts(authGenState.Accounts) | ||
authGenState.Accounts = v039auth.SanitizeGenesisAccounts(authGenState.Accounts) | ||
return authGenState | ||
} |
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,8 @@ | ||
package v040 | ||
|
||
// DONTCOVER | ||
// nolint | ||
|
||
const ( | ||
ModuleName = "auth" | ||
) |
10 changes: 5 additions & 5 deletions
10
x/bank/legacy/v0_39/migrate.go → x/bank/legacy/v0_40/migrate.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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v039 | ||
package v040 | ||
|
||
// DONTCOVER | ||
// nolint | ||
|
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,55 @@ | ||
package v040 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39" | ||
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_40" | ||
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38" | ||
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_40" | ||
"github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
) | ||
|
||
// Migrate migrates exported state from v0.39 to a v0.40 genesis state. | ||
func Migrate(appState types.AppMap) types.AppMap { | ||
v039Codec := codec.New() | ||
cryptocodec.RegisterCrypto(v039Codec) | ||
v039auth.RegisterCodec(v039Codec) | ||
|
||
v040Codec := codec.New() | ||
cryptocodec.RegisterCrypto(v040Codec) | ||
v039auth.RegisterCodec(v040Codec) | ||
|
||
// remove balances from existing accounts | ||
if appState[v039auth.ModuleName] != nil { | ||
// unmarshal relative source genesis application state | ||
var authGenState v039auth.GenesisState | ||
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState) | ||
|
||
// delete deprecated x/auth genesis state | ||
delete(appState, v039auth.ModuleName) | ||
|
||
// Migrate relative source genesis application state and marshal it into | ||
// the respective key. | ||
appState[v040auth.ModuleName] = v040Codec.MustMarshalJSON(v040auth.Migrate(authGenState)) | ||
} | ||
|
||
if appState[v038bank.ModuleName] != nil { | ||
// unmarshal relative source genesis application state | ||
var bankGenState v038bank.GenesisState | ||
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &bankGenState) | ||
|
||
// unmarshal x/auth genesis state to retrieve all account balances | ||
var authGenState v039auth.GenesisState | ||
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState) | ||
|
||
// delete deprecated x/bank genesis state | ||
delete(appState, v038bank.ModuleName) | ||
|
||
// Migrate relative source genesis application state and marshal it into | ||
// the respective key. | ||
appState[v040bank.ModuleName] = v040Codec.MustMarshalJSON(v040bank.Migrate(bankGenState, authGenState)) | ||
} | ||
|
||
return appState | ||
} |