Skip to content

Commit

Permalink
feat: compatible BaseAccount and initGenesis proposalAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
fx0x55 committed Jul 10, 2024
1 parent a4e82cc commit 5a099f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions x/evm/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, cha
ethCfg := params.ChainConfig.EthereumConfig(chainID)

// get the coinbase address from the block proposer
coinbase, err := k.GetCoinbaseAddress(ctx, proposerAddress)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to obtain coinbase address")
coinbase := common.Address{}
if !proposerAddress.Empty() || len(ctx.BlockHeader().ProposerAddress) > 0 {
var err error
coinbase, err = k.GetCoinbaseAddress(ctx, proposerAddress)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to obtain coinbase address")
}
}

var txConfig statedb.TxConfig
Expand Down
12 changes: 12 additions & 0 deletions x/evm/keeper/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
Expand Down Expand Up @@ -121,6 +122,17 @@ func (k *Keeper) SetAccount(ctx sdk.Context, addr common.Address, account stated
if err := ethAcct.SetCodeHash(codeHash); err != nil {
return err
}
} else {
if account.IsContract() {
if baseAcct, isBaseAccount := acct.(*authtypes.BaseAccount); isBaseAccount {
acct = &ethermint.EthAccount{
BaseAccount: baseAcct,
CodeHash: codeHash.Hex(),
}
} else {
return errorsmod.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
}
}
}

k.accountKeeper.SetAccount(ctx, acct)
Expand Down

0 comments on commit 5a099f3

Please sign in to comment.