laconicd/types/account.go
Ramiro Carlucho b9804505a3
evm: change Hook to use tx Receipt (#849)
* Change evm_hook to use Transaction Receipt

* use ethtypes.Receipt

* wip changes

* fix receipt creation

* receipt fixes

* check for contract addr

* changelog

* test

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-01-03 17:18:13 +01:00

58 lines
1.6 KiB
Go

package types
import (
"bytes"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
var (
_ authtypes.AccountI = (*EthAccount)(nil)
_ authtypes.GenesisAccount = (*EthAccount)(nil)
_ codectypes.UnpackInterfacesMessage = (*EthAccount)(nil)
)
var emptyCodeHash = crypto.Keccak256(nil)
const (
// AccountTypeEOA defines the type for externally owned accounts (EOAs)
AccountTypeEOA = int8(iota + 1)
// AccountTypeContract defines the type for contract accounts
AccountTypeContract
)
// ----------------------------------------------------------------------------
// Main Ethermint account
// ----------------------------------------------------------------------------
// ProtoAccount defines the prototype function for BaseAccount used for an
// AccountKeeper.
func ProtoAccount() authtypes.AccountI {
return &EthAccount{
BaseAccount: &authtypes.BaseAccount{},
CodeHash: common.BytesToHash(emptyCodeHash).String(),
}
}
// EthAddress returns the account address ethereum format.
func (acc EthAccount) EthAddress() common.Address {
return common.BytesToAddress(acc.GetAddress().Bytes())
}
// GetCodeHash returns the account code hash in byte format
func (acc EthAccount) GetCodeHash() common.Hash {
return common.HexToHash(acc.CodeHash)
}
// Type returns the type of Ethereum Account (EOA or Contract)
func (acc EthAccount) Type() int8 {
if bytes.Equal(emptyCodeHash, common.Hex2Bytes(acc.CodeHash)) {
return AccountTypeEOA
}
return AccountTypeContract
}