2018-08-24 18:56:43 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2021-04-17 10:00:07 +00:00
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2019-11-13 17:00:21 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-07-02 15:19:48 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-09-03 18:06:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-08-24 18:56:43 +00:00
|
|
|
)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
var (
|
|
|
|
_ authtypes.AccountI = (*EthAccount)(nil)
|
|
|
|
_ authtypes.GenesisAccount = (*EthAccount)(nil)
|
|
|
|
_ codectypes.UnpackInterfacesMessage = (*EthAccount)(nil)
|
|
|
|
)
|
2020-08-23 21:41:54 +00:00
|
|
|
|
2018-10-03 14:57:02 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Main Ethermint account
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
// ProtoAccount defines the prototype function for BaseAccount used for an
|
|
|
|
// AccountKeeper.
|
2021-04-17 10:00:07 +00:00
|
|
|
func ProtoAccount() authtypes.AccountI {
|
2020-04-22 19:26:01 +00:00
|
|
|
return &EthAccount{
|
2021-04-17 10:00:07 +00:00
|
|
|
BaseAccount: &authtypes.BaseAccount{},
|
2021-09-03 18:06:36 +00:00
|
|
|
CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(),
|
2019-11-12 21:07:34 +00:00
|
|
|
}
|
2018-08-24 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 21:41:54 +00:00
|
|
|
// EthAddress returns the account address ethereum format.
|
2021-06-29 17:02:21 +00:00
|
|
|
func (acc EthAccount) EthAddress() common.Address {
|
|
|
|
return common.BytesToAddress(acc.GetAddress().Bytes())
|
2019-12-13 19:50:19 +00:00
|
|
|
}
|
2020-09-07 13:04:50 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// GetCodeHash returns the account code hash in byte format
|
|
|
|
func (acc EthAccount) GetCodeHash() common.Hash {
|
|
|
|
return common.HexToHash(acc.CodeHash)
|
2020-09-07 13:04:50 +00:00
|
|
|
}
|