Documentation ¶
Overview ¶
Package eth implements the bridge interfaces for eth-like blockchain.
Index ¶
- Constants
- Variables
- func GetChainIDOfNetwork(networkAndChainIDMap map[string]*big.Int, networkID string) *big.Int
- func InitExtCodeParts()
- func InitExtCodePartsWithFlag(isMbtc bool)
- func IsCustomNetwork(networkID string) bool
- func PackData(args ...interface{}) []byte
- func PackDataWithFuncHash(funcHash []byte, args ...interface{}) []byte
- func ParseErc20SwapinTxLogs(logs []*types.RPCLog, contractAddress, checkToAddress string) (from, to string, value *big.Int, err error)
- func VerifyContractCodeParts(code []byte, codePartsSlice ...map[string][]byte) (err error)
- func VerifyErc20ContractCode(code []byte) (err error)
- func VerifySwapContractCode(code []byte) (err error)
- type Bridge
- func (b *Bridge) AdjustNonce(pairID string, value uint64) (nonce uint64)
- func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)
- func (b *Bridge) CalcTransactionHash(tx *types.Transaction) (txHash string, err error)
- func (b *Bridge) CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)
- func (b *Bridge) ChainID() (*big.Int, error)
- func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)
- func (b *Bridge) EstimateGas(from, to string, value *big.Int, data []byte) (uint64, error)
- func (b *Bridge) FeeHistory(blockCount int, rewardPercentiles []float64) (*types.FeeHistoryResult, error)
- func (b *Bridge) GetBalance(account string) (*big.Int, error)
- func (b *Bridge) GetBaseFee(blockCount int) (*big.Int, error)
- func (b *Bridge) GetBlockByHash(blockHash string) (*types.RPCBlock, error)
- func (b *Bridge) GetBlockByNumber(number *big.Int) (*types.RPCBlock, error)
- func (b *Bridge) GetBlockHash(height uint64) (hash string, err error)
- func (b *Bridge) GetBlockHashOf(urls []string, height uint64) (hash string, err error)
- func (b *Bridge) GetCode(contract string) (code []byte, err error)
- func (b *Bridge) GetContractLogs(contractAddresses []common.Address, logTopics [][]common.Hash, ...) ([]*types.RPCLog, error)
- func (b *Bridge) GetErc20Balance(contract, address string) (*big.Int, error)
- func (b *Bridge) GetErc20Decimals(contract string) (uint8, error)
- func (b *Bridge) GetErc20TotalSupply(contract string) (*big.Int, error)
- func (b *Bridge) GetLatestBlockNumber() (uint64, error)
- func (b *Bridge) GetLatestBlockNumberOf(url string) (latest uint64, err error)
- func (b *Bridge) GetLogs(filterQuery *types.FilterQuery) (result []*types.RPCLog, err error)
- func (b *Bridge) GetPendingTransactions() (result []*types.RPCTransaction, err error)
- func (b *Bridge) GetPoolNonce(address, height string) (uint64, error)
- func (b *Bridge) GetSignedTxHashOfKeyID(keyID, pairID string, rawTx interface{}) (txHash string, err error)
- func (b *Bridge) GetSignerChainID() (*big.Int, error)
- func (b *Bridge) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error)
- func (b *Bridge) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error)
- func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)
- func (b *Bridge) GetTransactionByHash(txHash string) (*types.RPCTransaction, error)
- func (b *Bridge) GetTransactionReceipt(txHash string) (receipt *types.RPCTxReceipt, url string, err error)
- func (b *Bridge) GetTransactionStatus(txHash string) (*tokens.TxStatus, error)
- func (b *Bridge) GetTxBlockInfo(txHash string) (blockHeight, blockTime uint64)
- func (b *Bridge) Init()
- func (b *Bridge) InitLatestBlockNumber()
- func (b *Bridge) InitNonces(nonces map[string]uint64)
- func (b *Bridge) IsContractAddress(address string) (bool, error)
- func (b *Bridge) IsValidAddress(address string) bool
- func (b *Bridge) MakeSigner(chainID *big.Int) types.Signer
- func (b *Bridge) NetworkID() (*big.Int, error)
- func (b *Bridge) SendSignedTransaction(tx *types.Transaction) (txHash string, err error)
- func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)
- func (b *Bridge) SetChainAndGateway(chainCfg *tokens.ChainConfig, gatewayCfg *tokens.GatewayConfig)
- func (b *Bridge) SetNonce(pairID string, value uint64)
- func (b *Bridge) ShouldCheckAddressMixedCase() bool
- func (b *Bridge) SignTransaction(rawTx interface{}, pairID string) (signTx interface{}, txHash string, err error)
- func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, privKey *ecdsa.PrivateKey) (signTx interface{}, txHash string, err error)
- func (b *Bridge) SuggestGasTipCap() (maxGasTipCap *big.Int, err error)
- func (b *Bridge) SuggestPrice() (*big.Int, error)
- func (b *Bridge) VerifyAnyswapContractAddress(contract string) (err error)
- func (b *Bridge) VerifyChainID()
- func (b *Bridge) VerifyContractCode(contract string, codePartsSlice ...map[string][]byte) (err error)
- func (b *Bridge) VerifyErc20ContractAddress(contract, codeHash string, isProxy bool) (err error)
- func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) error
- func (b *Bridge) VerifyTokenConfig(tokenCfg *tokens.TokenConfig) (err error)
- func (b *Bridge) VerifyTransaction(pairID, txHash string, allowUnstable bool) (*tokens.TxSwapInfo, error)
- type NonceSetterBase
Constants ¶
const (
ERC20TokenType = "ERC20"
)
token types (should be all upper case)
Variables ¶
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
var ( // ExtCodeParts extended func hashes and log topics ExtCodeParts map[string][]byte )
Functions ¶
func GetChainIDOfNetwork ¶ added in v0.3.8
GetChainIDOfNetwork get chainID of networkID
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
IsCustomNetwork is custom network
func PackData ¶
func PackData(args ...interface{}) []byte
PackData pack data nolint:makezero // keep it
func PackDataWithFuncHash ¶
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 ¶
VerifyContractCodeParts verify contract code parts
func VerifyErc20ContractCode ¶
VerifyErc20ContractCode verify erc20 contract code
func VerifySwapContractCode ¶
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 ¶
NewCrossChainBridge new bridge
func (*Bridge) AdjustNonce ¶
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 ¶
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
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 ¶
GetBalance call eth_getBalance
func (*Bridge) GetBaseFee ¶ added in v0.3.9
GetBaseFee get base fee
func (*Bridge) GetBlockByHash ¶
GetBlockByHash call eth_getBlockByHash
func (*Bridge) GetBlockByNumber ¶
GetBlockByNumber call eth_getBlockByNumber
func (*Bridge) GetBlockHash ¶ added in v0.3.7
GetBlockHash impl
func (*Bridge) GetBlockHashOf ¶ added in v0.3.7
GetBlockHashOf impl
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 ¶
GetErc20Balance get erc20 balacne of address
func (*Bridge) GetErc20Decimals ¶
GetErc20Decimals get erc20 decimals
func (*Bridge) GetErc20TotalSupply ¶
GetErc20TotalSupply get erc20 total supply of address
func (*Bridge) GetLatestBlockNumber ¶
GetLatestBlockNumber call eth_blockNumber
func (*Bridge) GetLatestBlockNumberOf ¶
GetLatestBlockNumberOf call eth_blockNumber
func (*Bridge) GetPendingTransactions ¶
func (b *Bridge) GetPendingTransactions() (result []*types.RPCTransaction, err error)
GetPendingTransactions call eth_pendingTransactions
func (*Bridge) GetPoolNonce ¶
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
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 ¶
GetTokenBalance api
func (*Bridge) GetTokenSupply ¶
GetTokenSupply impl
func (*Bridge) GetTransaction ¶
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 ¶
GetTransactionStatus impl
func (*Bridge) GetTxBlockInfo ¶ added in v0.3.7
GetTxBlockInfo impl
func (*Bridge) InitLatestBlockNumber ¶
func (b *Bridge) InitLatestBlockNumber()
InitLatestBlockNumber init latest block number
func (*Bridge) InitNonces ¶ added in v0.3.6
InitNonces init nonces
func (*Bridge) IsContractAddress ¶
IsContractAddress is contract address
func (*Bridge) IsValidAddress ¶
IsValidAddress check address
func (*Bridge) MakeSigner ¶ added in v0.3.9
MakeSigner make signer
func (*Bridge) SendSignedTransaction ¶
func (b *Bridge) SendSignedTransaction(tx *types.Transaction) (txHash string, err error)
SendSignedTransaction call eth_sendRawTransaction
func (*Bridge) SendTransaction ¶
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) ShouldCheckAddressMixedCase ¶ added in v0.3.8
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
SuggestGasTipCap call eth_maxPriorityFeePerGas
func (*Bridge) SuggestPrice ¶
SuggestPrice call eth_gasPrice
func (*Bridge) VerifyAnyswapContractAddress ¶ added in v0.3.7
VerifyAnyswapContractAddress verify anyswap contract
func (*Bridge) VerifyContractCode ¶
func (b *Bridge) VerifyContractCode(contract string, codePartsSlice ...map[string][]byte) (err error)
VerifyContractCode verify contract code
func (*Bridge) VerifyErc20ContractAddress ¶
VerifyErc20ContractAddress verify erc20 contract For proxy contract delegating erc20 contract, verify its contract code hash
func (*Bridge) VerifyMsgHash ¶
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 ¶
NonceSetterBase base nonce setter
func NewNonceSetterBase ¶
func NewNonceSetterBase() *NonceSetterBase
NewNonceSetterBase new base nonce setter