Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migration of pundix bank code #802

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func checkPundixChainMigrate(t *testing.T, ctx sdk.Context, myApp *app.App) {
appState, err := nextversion.ReadGenesisState(pundixGenesisPath)
require.NoError(t, err)

checkPundixBank(t, ctx, myApp, appState[banktypes.ModuleName])
bankGenesis, ok := appState[banktypes.ModuleName]
require.True(t, ok)
require.NotEmpty(t, bankGenesis)
checkPundixBank(t, ctx, myApp, bankGenesis)
}

func checkPundixBank(t *testing.T, ctx sdk.Context, myApp *app.App, raw json.RawMessage) {
Expand Down
10 changes: 7 additions & 3 deletions app/upgrades/v8/pundix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/ethereum/go-ethereum/common"
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/functionx/fx-core/v8/app/keepers"
"github.com/functionx/fx-core/v8/contract"
Expand Down Expand Up @@ -62,7 +62,11 @@ func (m *Pundix) Migrate(ctx sdk.Context) error {
return err
}
// todo migrate other data
return m.migrateBank(ctx, appState[banktypes.ModuleName])
bankGenesis, ok := appState[banktypes.ModuleName]
if !ok || len(bankGenesis) == 0 {
return sdkerrors.ErrNotFound.Wrap("bank genesis")
}
return m.migrateBank(ctx, bankGenesis)
}

func (m *Pundix) migrateBank(ctx sdk.Context, bankRaw json.RawMessage) error {
Expand Down Expand Up @@ -287,7 +291,7 @@ func (m *Pundix) migratePundixPurse(

func (m *Pundix) updatePurseErc20Owner(ctx sdk.Context, erc20Token erc20types.ERC20Token) error {
erc20ModuleHexAddress := common.BytesToAddress(types.NewModuleAddress(erc20types.ModuleName).Bytes())
newOwner := common.BytesToAddress(types.NewModuleAddress(govtypes.ModuleName))
newOwner := common.BytesToAddress(types.NewModuleAddress(evmtypes.ModuleName))
if _, err := m.erc20TokenKeeper.TransferOwnership(ctx, erc20Token.GetERC20Contract(), erc20ModuleHexAddress, newOwner); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v8/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
}

if err = NewPundix(app).Migrate(cacheCtx); err != nil {
return nil, err
return fromVM, err
}

if err = migrateBridgeBalance(cacheCtx, app.BankKeeper, app.AccountKeeper); err != nil {
Expand Down