eth

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: GPL-3.0 Imports: 22 Imported by: 2

Documentation

Overview

Package eth implements the bridge interfaces for eth-like blockchain.

Index

Constants

View Source
const (
	ERC20TokenType = "ERC20"
)

token types (should be all upper case)

Variables

View Source
var (
	// ETH chain
	EthNetworkAndChainIDMap = map[string]*big.Int{
		"mainnet": big.NewInt(1),
		"rinkeby": big.NewInt(4),
		"goerli":  big.NewInt(5),
	}

	// ETC chain
	EtcNetworkAndChainIDMap = map[string]*big.Int{
		"mainnet": big.NewInt(61),
		"kotti":   big.NewInt(6),
		"mordor":  big.NewInt(63),
	}

	// FSN chain
	FsnNetworkAndChainIDMap = map[string]*big.Int{
		"mainnet": big.NewInt(32659),
		"testnet": big.NewInt(46688),
		"devnet":  big.NewInt(55555),
	}

	// OKEX chain
	OkexNetworkAndChainIDMap = map[string]*big.Int{
		"mainnet": big.NewInt(66),
	}
)

known network and chainID map

View Source
var (
	// ExtCodeParts extended func hashes and log topics
	ExtCodeParts map[string][]byte
)

Functions

func GetChainIDOfNetwork added in v0.3.8

func GetChainIDOfNetwork(networkAndChainIDMap map[string]*big.Int, networkID string) *big.Int

GetChainIDOfNetwork get chainID of networkID

func InitExtCodeParts

func InitExtCodeParts()

InitExtCodeParts init extended code parts

func InitExtCodePartsWithFlag added in v0.3.0

func InitExtCodePartsWithFlag(isMbtc bool)

InitExtCodePartsWithFlag init extended code parts with flag

func IsCustomNetwork added in v0.3.8

func IsCustomNetwork(networkID string) bool

IsCustomNetwork is custom network

func PackData

func PackData(args ...interface{}) []byte

PackData pack data nolint:makezero // keep it

func PackDataWithFuncHash

func PackDataWithFuncHash(funcHash []byte, args ...interface{}) []byte

PackDataWithFuncHash pack data with func hash

func ParseErc20SwapinTxLogs

func ParseErc20SwapinTxLogs(logs []*types.RPCLog, contractAddress, checkToAddress string) (from, to string, value *big.Int, err error)

ParseErc20SwapinTxLogs parse erc20 swapin tx logs

func VerifyContractCodeParts

func VerifyContractCodeParts(code []byte, codePartsSlice ...map[string][]byte) (err error)

VerifyContractCodeParts verify contract code parts

func VerifyErc20ContractCode

func VerifyErc20ContractCode(code []byte) (err error)

VerifyErc20ContractCode verify erc20 contract code

func VerifySwapContractCode

func VerifySwapContractCode(code []byte) (err error)

VerifySwapContractCode verify swap contract code

Types

type Bridge

type Bridge struct {
	Inherit interface{}
	*tokens.CrossChainBridgeBase
	*NonceSetterBase
	Signer        types.Signer
	SignerChainID *big.Int
}

Bridge eth bridge

func NewCrossChainBridge

func NewCrossChainBridge(isSrc bool) *Bridge

NewCrossChainBridge new bridge

func (*Bridge) AdjustNonce

func (b *Bridge) AdjustNonce(pairID string, value uint64) (nonce uint64)

AdjustNonce adjust account nonce (eth like chain)

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) CalcTransactionHash added in v0.3.7

func (b *Bridge) CalcTransactionHash(tx *types.Transaction) (txHash string, err error)

CalcTransactionHash calc tx hash

func (*Bridge) CallContract

func (b *Bridge) CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)

CallContract call eth_call

func (*Bridge) ChainID

func (b *Bridge) ChainID() (*big.Int, error)

ChainID call eth_chainId Notice: eth_chainId return 0x0 for mainnet which is wrong (use net_version instead)

func (*Bridge) DcrmSignTransaction

func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)

DcrmSignTransaction dcrm sign raw tx

func (*Bridge) EstimateGas added in v0.3.9

func (b *Bridge) EstimateGas(from, to string, value *big.Int, data []byte) (uint64, error)

EstimateGas call eth_estimateGas

func (*Bridge) FeeHistory added in v0.3.9

func (b *Bridge) FeeHistory(blockCount int, rewardPercentiles []float64) (*types.FeeHistoryResult, error)

FeeHistory call eth_feeHistory

func (*Bridge) GetBalance

func (b *Bridge) GetBalance(account string) (*big.Int, error)

GetBalance call eth_getBalance

func (*Bridge) GetBaseFee added in v0.3.9

func (b *Bridge) GetBaseFee(blockCount int) (*big.Int, error)

GetBaseFee get base fee

func (*Bridge) GetBlockByHash

func (b *Bridge) GetBlockByHash(blockHash string) (*types.RPCBlock, error)

GetBlockByHash call eth_getBlockByHash

func (*Bridge) GetBlockByNumber

func (b *Bridge) GetBlockByNumber(number *big.Int) (*types.RPCBlock, error)

GetBlockByNumber call eth_getBlockByNumber

func (*Bridge) GetBlockHash added in v0.3.7

func (b *Bridge) GetBlockHash(height uint64) (hash string, err error)

GetBlockHash impl

func (*Bridge) GetBlockHashOf added in v0.3.7

func (b *Bridge) GetBlockHashOf(urls []string, height uint64) (hash string, err error)

GetBlockHashOf impl

func (*Bridge) GetCode

func (b *Bridge) GetCode(contract string) (code []byte, err error)

GetCode call eth_getCode

func (*Bridge) GetContractLogs

func (b *Bridge) GetContractLogs(contractAddresses []common.Address, logTopics [][]common.Hash, blockHeight uint64) ([]*types.RPCLog, error)

GetContractLogs get contract logs

func (*Bridge) GetErc20Balance

func (b *Bridge) GetErc20Balance(contract, address string) (*big.Int, error)

GetErc20Balance get erc20 balacne of address

func (*Bridge) GetErc20Decimals

func (b *Bridge) GetErc20Decimals(contract string) (uint8, error)

GetErc20Decimals get erc20 decimals

func (*Bridge) GetErc20TotalSupply

func (b *Bridge) GetErc20TotalSupply(contract string) (*big.Int, error)

GetErc20TotalSupply get erc20 total supply of address

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (uint64, error)

GetLatestBlockNumber call eth_blockNumber

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(url string) (latest uint64, err error)

GetLatestBlockNumberOf call eth_blockNumber

func (*Bridge) GetLogs

func (b *Bridge) GetLogs(filterQuery *types.FilterQuery) (result []*types.RPCLog, err error)

GetLogs call eth_getLogs

func (*Bridge) GetPendingTransactions

func (b *Bridge) GetPendingTransactions() (result []*types.RPCTransaction, err error)

GetPendingTransactions call eth_pendingTransactions

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, height string) (uint64, error)

GetPoolNonce call eth_getTransactionCount

func (*Bridge) GetSignedTxHashOfKeyID added in v0.3.8

func (b *Bridge) GetSignedTxHashOfKeyID(keyID, pairID string, rawTx interface{}) (txHash string, err error)

GetSignedTxHashOfKeyID get signed tx hash by keyID (called by oracle)

func (*Bridge) GetSignerChainID added in v0.3.4

func (b *Bridge) GetSignerChainID() (*big.Int, error)

GetSignerChainID default way to get signer chain id use chain ID first, if missing then use network ID instead. normally this way works, but sometimes it failed (eg. ETC), then we should overwrite this function

func (*Bridge) GetTokenBalance

func (b *Bridge) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error)

GetTokenBalance api

func (*Bridge) GetTokenSupply

func (b *Bridge) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error)

GetTokenSupply impl

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)

GetTransaction impl

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (*types.RPCTransaction, error)

GetTransactionByHash call eth_getTransactionByHash

func (*Bridge) GetTransactionReceipt

func (b *Bridge) GetTransactionReceipt(txHash string) (receipt *types.RPCTxReceipt, url string, err error)

GetTransactionReceipt call eth_getTransactionReceipt

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (*tokens.TxStatus, error)

GetTransactionStatus impl

func (*Bridge) GetTxBlockInfo added in v0.3.7

func (b *Bridge) GetTxBlockInfo(txHash string) (blockHeight, blockTime uint64)

GetTxBlockInfo impl

func (*Bridge) Init

func (b *Bridge) Init()

Init init after verify

func (*Bridge) InitLatestBlockNumber

func (b *Bridge) InitLatestBlockNumber()

InitLatestBlockNumber init latest block number

func (*Bridge) InitNonces added in v0.3.6

func (b *Bridge) InitNonces(nonces map[string]uint64)

InitNonces init nonces

func (*Bridge) IsContractAddress

func (b *Bridge) IsContractAddress(address string) (bool, error)

IsContractAddress is contract address

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(address string) bool

IsValidAddress check address

func (*Bridge) MakeSigner added in v0.3.9

func (b *Bridge) MakeSigner(chainID *big.Int) types.Signer

MakeSigner make signer

func (*Bridge) NetworkID

func (b *Bridge) NetworkID() (*big.Int, error)

NetworkID call net_version

func (*Bridge) SendSignedTransaction

func (b *Bridge) SendSignedTransaction(tx *types.Transaction) (txHash string, err error)

SendSignedTransaction call eth_sendRawTransaction

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)

SendTransaction send signed tx

func (*Bridge) SetChainAndGateway added in v0.3.0

func (b *Bridge) SetChainAndGateway(chainCfg *tokens.ChainConfig, gatewayCfg *tokens.GatewayConfig)

SetChainAndGateway set chain and gateway config

func (*Bridge) SetNonce

func (b *Bridge) SetNonce(pairID string, value uint64)

SetNonce set nonce directly always increase

func (*Bridge) ShouldCheckAddressMixedCase added in v0.3.8

func (b *Bridge) ShouldCheckAddressMixedCase() bool

ShouldCheckAddressMixedCase check address mixed case eg. RSK chain do not check mixed case or not same as eth

func (*Bridge) SignTransaction added in v0.3.0

func (b *Bridge) SignTransaction(rawTx interface{}, pairID string) (signTx interface{}, txHash string, err error)

SignTransaction sign tx with pairID

func (*Bridge) SignTransactionWithPrivateKey added in v0.3.0

func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, privKey *ecdsa.PrivateKey) (signTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) SuggestGasTipCap added in v0.3.9

func (b *Bridge) SuggestGasTipCap() (maxGasTipCap *big.Int, err error)

SuggestGasTipCap call eth_maxPriorityFeePerGas

func (*Bridge) SuggestPrice

func (b *Bridge) SuggestPrice() (*big.Int, error)

SuggestPrice call eth_gasPrice

func (*Bridge) VerifyAnyswapContractAddress added in v0.3.7

func (b *Bridge) VerifyAnyswapContractAddress(contract string) (err error)

VerifyAnyswapContractAddress verify anyswap contract

func (*Bridge) VerifyChainID

func (b *Bridge) VerifyChainID()

VerifyChainID verify chain id

func (*Bridge) VerifyContractCode

func (b *Bridge) VerifyContractCode(contract string, codePartsSlice ...map[string][]byte) (err error)

VerifyContractCode verify contract code

func (*Bridge) VerifyErc20ContractAddress

func (b *Bridge) VerifyErc20ContractAddress(contract, codeHash string, isProxy bool) (err error)

VerifyErc20ContractAddress verify erc20 contract For proxy contract delegating erc20 contract, verify its contract code hash

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) error

VerifyMsgHash verify msg hash

func (*Bridge) VerifyTokenConfig added in v0.3.0

func (b *Bridge) VerifyTokenConfig(tokenCfg *tokens.TokenConfig) (err error)

VerifyTokenConfig verify token config

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(pairID, txHash string, allowUnstable bool) (*tokens.TxSwapInfo, error)

VerifyTransaction impl

type NonceSetterBase

type NonceSetterBase struct {
	SwapinNonce  map[string]uint64
	SwapoutNonce map[string]uint64
}

NonceSetterBase base nonce setter

func NewNonceSetterBase

func NewNonceSetterBase() *NonceSetterBase

NewNonceSetterBase new base nonce setter

Jump to

Keyboard shortcuts

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