evm

package
v1.109.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxContractGasLimit = 400000
)
View Source
const (
	NativeTokenAddr = "0x0000000000000000000000000000000000000000"
)

Variables

This section is empty.

Functions

func GetContractABI

func GetContractABI(routerContractABI, erc20ContractABI string) (*abi.ABI, *abi.ABI, error)

initSmartContracts load the erc20 contract and vault contract

func GetPrivateKey

func GetPrivateKey(key cryptotypes.PrivKey) (*ecdsa.PrivateKey, error)

func IsNative

func IsNative(token string) bool

IsNative returns true if the token address equals the native token address

Types

type BlockMetaAccessor

type BlockMetaAccessor interface {
	GetBlockMetas() ([]*evmtypes.BlockMeta, error)
	GetBlockMeta(height int64) (*evmtypes.BlockMeta, error)
	SaveBlockMeta(height int64, block *evmtypes.BlockMeta) error
	PruneBlockMeta(height int64) error
	AddSignedTxItem(item evmtypes.SignedTxItem) error
	RemoveSignedTxItem(hash string) error
	GetSignedTxItems() ([]evmtypes.SignedTxItem, error)
}

BlockMetaAccessor define methods need to access block meta storage

type EthRPC

type EthRPC struct {
	// contains filtered or unexported fields
}

EthRPC is a struct that interacts with an ETH RPC compatible blockchain

func NewEthRPC

func NewEthRPC(host string, timeout time.Duration, chain string) (*EthRPC, error)

func (*EthRPC) CheckTransaction

func (e *EthRPC) CheckTransaction(hash string) bool

CheckTransaction returns true if a tx can be found by TransactionByHash rpc method

func (*EthRPC) EstimateGas

func (e *EthRPC) EstimateGas(from string, tx *etypes.Transaction) (uint64, error)

func (*EthRPC) GetBlock

func (e *EthRPC) GetBlock(height int64) (*etypes.Block, error)

func (*EthRPC) GetBlockHeight

func (e *EthRPC) GetBlockHeight() (int64, error)

func (*EthRPC) GetHeader

func (e *EthRPC) GetHeader(height int64) (*etypes.Header, error)

func (*EthRPC) GetNonce

func (e *EthRPC) GetNonce(addr string) (uint64, error)

GetNonce gets nonce

func (*EthRPC) GetRPCBlock

func (e *EthRPC) GetRPCBlock(height int64) (*etypes.Block, error)

func (*EthRPC) GetReceipt

func (e *EthRPC) GetReceipt(hash string) (*etypes.Receipt, error)

type KeySignWrapper

type KeySignWrapper struct {
	// contains filtered or unexported fields
}

KeySignWrapper is a wrap of private key and also tss instance

func NewKeySignWrapper

func NewKeySignWrapper(privateKey *ecdsa.PrivateKey, pubKey common.PubKey, keyManager tss.ThorchainKeyManager, chainID *big.Int, chain string) (*KeySignWrapper, error)

NewKeySignWrapper create a new instance of keysign wrapper

func (*KeySignWrapper) GetPrivKey

func (w *KeySignWrapper) GetPrivKey() *ecdsa.PrivateKey

GetPrivKey return the private key

func (*KeySignWrapper) GetPubKey

func (w *KeySignWrapper) GetPubKey() common.PubKey

GetPubKey return the public key

func (*KeySignWrapper) Sign

func (w *KeySignWrapper) Sign(tx *etypes.Transaction, poolPubKey common.PubKey) ([]byte, error)

Sign the given transaction

type LevelDBBlockMetaAccessor

type LevelDBBlockMetaAccessor struct {
	PrefixBlockMeta    string
	PrefixSignedTxItem string
	// contains filtered or unexported fields
}

LevelDBBlockMetaAccessor struct

func NewLevelDBBlockMetaAccessor

func NewLevelDBBlockMetaAccessor(prefixBlockMeta, prefixSignedTxItem string, db *leveldb.DB) (*LevelDBBlockMetaAccessor, error)

NewLevelDBBlockMetaAccessor creates a new level db backed BlockMeta accessor

func (*LevelDBBlockMetaAccessor) AddSignedTxItem

func (t *LevelDBBlockMetaAccessor) AddSignedTxItem(item evmtypes.SignedTxItem) error

AddSignedTxItem add a signed tx item to key value store

func (*LevelDBBlockMetaAccessor) GetBlockMeta

func (t *LevelDBBlockMetaAccessor) GetBlockMeta(height int64) (*evmtypes.BlockMeta, error)

GetBlockMeta at given block height , when the requested block meta doesn't exist , it will return nil , thus caller need to double check it

func (*LevelDBBlockMetaAccessor) GetBlockMetas

func (t *LevelDBBlockMetaAccessor) GetBlockMetas() ([]*evmtypes.BlockMeta, error)

GetBlockMetas returns all the block metas in storage The chain client will Prune block metas every time it finished scan a block , so at maximum it will keep BlockCacheSize blocks thus it should not grow out of control

func (*LevelDBBlockMetaAccessor) GetSignedTxItems

func (t *LevelDBBlockMetaAccessor) GetSignedTxItems() ([]evmtypes.SignedTxItem, error)

GetSignedTxItems get all the signed tx items that in the key value store

func (*LevelDBBlockMetaAccessor) PruneBlockMeta

func (t *LevelDBBlockMetaAccessor) PruneBlockMeta(height int64) error

PruneBlockMeta remove all block meta that is older than the given block height with exception, if there are unspent transaction output in it , then the block meta will not be removed

func (*LevelDBBlockMetaAccessor) RemoveSignedTxItem

func (t *LevelDBBlockMetaAccessor) RemoveSignedTxItem(hash string) error

RemoveSignedTxItem remove a signed item from key value store

func (*LevelDBBlockMetaAccessor) SaveBlockMeta

func (t *LevelDBBlockMetaAccessor) SaveBlockMeta(height int64, blockMeta *evmtypes.BlockMeta) error

SaveBlockMeta persistent the given BlockMeta into storage

type LevelDBTokenMeta

type LevelDBTokenMeta struct {
	// contains filtered or unexported fields
}

LevelDBTokenMeta struct

func NewLevelDBTokenMeta

func NewLevelDBTokenMeta(db *leveldb.DB, prefixTokenMeta string) (*LevelDBTokenMeta, error)

NewLevelDBTokenMeta creates a new level db backed TokenMeta

func (*LevelDBTokenMeta) GetTokenMeta

func (t *LevelDBTokenMeta) GetTokenMeta(address string) (types.TokenMeta, error)

GetTokenMeta for given token address

func (*LevelDBTokenMeta) GetTokens

func (t *LevelDBTokenMeta) GetTokens() ([]*types.TokenMeta, error)

GetTokens returns all the token metas in storage

func (*LevelDBTokenMeta) SaveTokenMeta

func (t *LevelDBTokenMeta) SaveTokenMeta(symbol, address string, decimals uint64) error

SaveTokenMeta persistent the given TokenMeta into storage

type RouterCoin

type RouterCoin struct {
	Asset  ecommon.Address
	Amount *big.Int
}

RouterCoin represent the coins transfer between vault

type SmartContractLogParser

type SmartContractLogParser struct {
	// contains filtered or unexported fields
}

func NewSmartContractLogParser

func NewSmartContractLogParser(validator contractAddressValidator,
	resolver assetResolver,
	decimalResolver tokenDecimalResolver,
	amtConverter amountConverter,
	vaultABI *abi.ABI,
	nativeAsset common.Asset,
) SmartContractLogParser

func (*SmartContractLogParser) GetTxInItem

func (scp *SmartContractLogParser) GetTxInItem(logs []*etypes.Log, txInItem *types.TxInItem) (bool, error)

type THORChainRouterTransferOutAndCall

type THORChainRouterTransferOutAndCall struct {
	Vault        ecommon.Address
	Target       ecommon.Address
	Amount       *big.Int
	FinalAsset   ecommon.Address
	To           ecommon.Address
	AmountOutMin *big.Int
	Memo         string
}

THORChainRouterTransferOutAndCall represents a TransferOutAndCall event raised by the THORChainRouter contract.

type TokenManager

type TokenManager struct {
	// contains filtered or unexported fields
}

TokenManager manages a LevelDB of ERC20 token meta data and interfaces with token smart contracts

func NewTokenManager

func NewTokenManager(db *leveldb.DB,
	prefixTokenMeta string,
	nativeAsset common.Asset,
	defaultDecimals uint64,
	requestTimeout time.Duration,
	tokenWhitelist []tokenlist.ERC20Token,
	ethClient *ethclient.Client,
	routerContractABI,
	erc20ContractABI string,
) (*TokenManager, error)

NewTokenManager returns an instance of TokenManager

func (*TokenManager) ConvertAmount

func (h *TokenManager) ConvertAmount(token string, amt *big.Int) cosmos.Uint

convertAmount will convert the amount to 1e8 , the decimals used by THORChain

func (*TokenManager) ConvertSigningAmount

func (h *TokenManager) ConvertSigningAmount(amt *big.Int, token string) *big.Int

ConvertSigningAmount converts a value of a token to wei (1e18 decimals)

func (*TokenManager) ConvertThorchainAmountToWei

func (h *TokenManager) ConvertThorchainAmountToWei(amt *big.Int) *big.Int

ConvertThorchainAmountToWei converts amt in 1e8 decimals to wei (1e18 decimals)

func (*TokenManager) GetAssetFromTokenAddress

func (h *TokenManager) GetAssetFromTokenAddress(token string) (common.Asset, error)

func (*TokenManager) GetBalance

func (h *TokenManager) GetBalance(addr, token string, height *big.Int, vaultAddr string) (*big.Int, error)

GetBalance call smart contract to find out the balance of the given address and token

func (*TokenManager) GetTokenDecimalsForTHORChain

func (h *TokenManager) GetTokenDecimalsForTHORChain(token string) int64

return value 0 means use the default value which is common.THORChainDecimals, use 1e8 as precision

func (*TokenManager) GetTokenMeta

func (h *TokenManager) GetTokenMeta(token string) (types.TokenMeta, error)

func (*TokenManager) GetTokens

func (h *TokenManager) GetTokens() ([]*types.TokenMeta, error)

GetTokens return all the token meta data

func (*TokenManager) SaveTokenMeta

func (h *TokenManager) SaveTokenMeta(symbol, address string, decimals uint64) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL