Skip to content

Commit

Permalink
convert base account to eth account if exist code hash
Browse files Browse the repository at this point in the history
  • Loading branch information
peara authored Jul 23, 2024
1 parent 0c98ddf commit 70a1f19
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x/evm/keeper/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package keeper

import (
"bytes"
"fmt"
"math/big"

Expand All @@ -11,6 +12,7 @@ import (
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
evmostypes "github.com/evmos/evmos/v18/types"
"github.com/evmos/evmos/v18/x/evm/statedb"
Expand Down Expand Up @@ -129,6 +131,26 @@ func (k *Keeper) SetAccount(ctx sdk.Context, addr common.Address, account stated

codeHash := common.BytesToHash(account.CodeHash)

if _, ok := acct.(evmostypes.EthAccountI); !ok && !bytes.Equal(account.CodeHash, types.EmptyCodeHash) {
newAcct := evmostypes.EthAccount{
BaseAccount: &authtypes.BaseAccount{},
CodeHash: common.BytesToHash(types.EmptyCodeHash).String(),
}
err := newAcct.SetAddress(cosmosAddr)
if err != nil {
panic(err)
}
newBaseAccount := newAcct.GetBaseAccount()
newBaseAccount.SetAccountNumber(acct.GetAccountNumber())
newBaseAccount.SetPubKey(acct.GetPubKey())
newBaseAccount.SetSequence(acct.GetSequence())

k.accountKeeper.SetAccount(ctx, &newAcct)

acct = k.accountKeeper.GetAccount(ctx, cosmosAddr)
}


if ethAcct, ok := acct.(evmostypes.EthAccountI); ok {
if err := ethAcct.SetCodeHash(codeHash); err != nil {
return err
Expand Down

0 comments on commit 70a1f19

Please sign in to comment.