evm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RPCCallRetry             = 5
	MaxGasPriceInceremtRetry = 10
	GasPriceRatio            = 10.0
)
View Source
const (
	BlockInterval           = 2 * time.Second
	BlockHeightPollInterval = 60 * time.Second

	DefaultFinalityBlock = 10
)
View Source
const (
	ErrorLessGas          = "transaction underpriced"
	ErrorLimitLessThanGas = "max fee per gas less than block base fee"
	ErrUnKnown            = "unknown"
	ErrMaxTried           = "max tried"
	ErrNonceTooLow        = "nonce too low"
)
View Source
const (
	EmitMessageSig = "Message(string,uint256,bytes)"
)

All the events

Variables

Functions

This section is empty.

Types

type BnOptions

type BnOptions struct {
	StartHeight uint64
	Concurrency uint64
}

type Client

type Client struct {

	// evm chain ID
	EVMChainID *big.Int
	// contains filtered or unexported fields
}

grouped rpc api clients

func (*Client) CallContract

func (cl *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*Client) FilterLogs

func (cl *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethTypes.Log, error)

func (*Client) GetBalance

func (cl *Client) GetBalance(ctx context.Context, hexAddr string) (*big.Int, error)

func (*Client) GetBlockByHash

func (cl *Client) GetBlockByHash(hash common.Hash) (*types.Block, error)

func (*Client) GetBlockNumber

func (cl *Client) GetBlockNumber() (uint64, error)

func (*Client) GetBlockReceipts

func (cl *Client) GetBlockReceipts(hash common.Hash) (ethTypes.Receipts, error)

func (*Client) GetChainID

func (c *Client) GetChainID() *big.Int

func (*Client) GetEthClient

func (c *Client) GetEthClient() *ethclient.Client

func (*Client) GetHeaderByHeight

func (cl *Client) GetHeaderByHeight(ctx context.Context, height *big.Int) (*ethTypes.Header, error)

func (*Client) GetMedianGasPriceForBlock

func (cl *Client) GetMedianGasPriceForBlock(ctx context.Context) (gasPrice *big.Int, gasHeight *big.Int, err error)

func (*Client) Log

func (c *Client) Log() *zap.Logger

func (*Client) MessageReceived

func (c *Client) MessageReceived(opts *bind.CallOpts, srcNetwork string, _connSn *big.Int) (bool, error)

func (*Client) NonceAt

func (cl *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

func (*Client) ParseMessage

func (cl *Client) ParseMessage(log ethTypes.Log) (*bridgeContract.AbiMessage, error)

func (*Client) ReceiveMessage

func (c *Client) ReceiveMessage(opts *bind.TransactOpts, srcNID string, sn *big.Int, msg []byte) (*ethTypes.Transaction, error)

func (*Client) RevertMessage

func (c *Client) RevertMessage(opts *bind.TransactOpts, sn *big.Int) (*ethTypes.Transaction, error)

func (*Client) SendMessage

func (c *Client) SendMessage(opts *bind.TransactOpts, _to string, _svc string, _sn *big.Int, _msg []byte) (*ethTypes.Transaction, error)

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx *ethTypes.Transaction) error

func (*Client) SetAdmin

func (c *Client) SetAdmin(opts *bind.TransactOpts, newAdmin common.Address) (*ethTypes.Transaction, error)

func (*Client) SuggestGasPrice

func (cl *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*Client) TransactionByHash

func (cl *Client) TransactionByHash(ctx context.Context, blockHash common.Hash) (tx *ethTypes.Transaction, isPending bool, err error)

func (*Client) TransactionCount

func (cl *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

func (*Client) TransactionInBlock

func (cl *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*ethTypes.Transaction, error)

func (*Client) TransactionReceipt

func (cl *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*ethTypes.Receipt, error)

type EVMProvider

type EVMProvider struct {
	StartHeight uint64
	// contains filtered or unexported fields
}

func (*EVMProvider) AddressFromKeyStore

func (p *EVMProvider) AddressFromKeyStore(keystoreFile, auth string) (string, error)

AddressFromKeyStore returns the address of the key stored in the given keystore file.

func (*EVMProvider) ChainName

func (p *EVMProvider) ChainName() string

func (*EVMProvider) FinalityBlock

func (p *EVMProvider) FinalityBlock(ctx context.Context) uint64

func (*EVMProvider) FindMessages

func (p *EVMProvider) FindMessages(ctx context.Context, lbn *types.BlockNotification) ([]*relayertypes.Message, error)

func (*EVMProvider) GenerateMessage

func (ip *EVMProvider) GenerateMessage(ctx context.Context, key *types.MessageKeyWithMessageHeight) (*types.Message, error)

TODO: may not be need anytime soon so its ok to implement later on

func (*EVMProvider) GetConcurrency

func (p *EVMProvider) GetConcurrency(ctx context.Context, startHeight, currentHeight uint64) int

func (*EVMProvider) GetTransationOpts

func (p *EVMProvider) GetTransationOpts(ctx context.Context) (*bind.TransactOpts, error)

func (*EVMProvider) Init

func (p *EVMProvider) Init(ctx context.Context, homePath string, kms kms.KMS) error

func (*EVMProvider) Listener

func (r *EVMProvider) Listener(ctx context.Context, lastSavedHeight uint64, blockInfoChan chan relayertypes.BlockInfo) error

func (*EVMProvider) LogFailedTx

func (p *EVMProvider) LogFailedTx(messageKey providerTypes.MessageKey, result *types.Receipt, err error)

func (*EVMProvider) LogSuccessTx

func (p *EVMProvider) LogSuccessTx(messageKey providerTypes.MessageKey, receipt *types.Receipt)

func (*EVMProvider) MessageReceived

func (p *EVMProvider) MessageReceived(ctx context.Context, messageKey types.MessageKey) (bool, error)

func (*EVMProvider) NID

func (p *EVMProvider) NID() string

func (*EVMProvider) NewKeyStore

func (p *EVMProvider) NewKeyStore(dir, password string) (string, error)

func (*EVMProvider) ProviderConfig

func (p *EVMProvider) ProviderConfig() provider.ProviderConfig

func (*EVMProvider) QueryBalance

func (p *EVMProvider) QueryBalance(ctx context.Context, addr string) (*types.Coin, error)

func (*EVMProvider) QueryLatestHeight

func (p *EVMProvider) QueryLatestHeight(ctx context.Context) (height uint64, err error)

func (*EVMProvider) QueryTransactionReceipt

func (icp *EVMProvider) QueryTransactionReceipt(ctx context.Context, txHash string) (*types.Receipt, error)

func (*EVMProvider) RestoreKeyStore

func (p *EVMProvider) RestoreKeyStore(ctx context.Context, homepath string, client kms.KMS) error

func (*EVMProvider) RevertMessage

func (p *EVMProvider) RevertMessage(ctx context.Context, sn *big.Int) error

RevertMessage

func (*EVMProvider) Route

this will be executed in go route

func (*EVMProvider) SendTransaction

func (p *EVMProvider) SendTransaction(ctx context.Context, opts *bind.TransactOpts, message *providerTypes.Message, maxRetry uint8) (*types.Transaction, error)

func (*EVMProvider) SetAdmin

func (p *EVMProvider) SetAdmin(ctx context.Context, admin string) error

SetAdmin sets the admin address of the bridge contract

func (*EVMProvider) ShouldReceiveMessage

func (p *EVMProvider) ShouldReceiveMessage(ctx context.Context, messagekey types.Message) (bool, error)

func (*EVMProvider) ShouldSendMessage

func (p *EVMProvider) ShouldSendMessage(ctx context.Context, messageKey types.Message) (bool, error)

func (*EVMProvider) Type

func (p *EVMProvider) Type() string

func (*EVMProvider) WaitForResults

func (p *EVMProvider) WaitForResults(ctx context.Context, txHash common.Hash) (txr *ethTypes.Receipt, err error)

func (*EVMProvider) WaitForTxResult

func (p *EVMProvider) WaitForTxResult(
	ctx context.Context,
	tx *types.Transaction,
	messageKey providerTypes.MessageKey,
	callback providerTypes.TxResponseFunc,
)

func (*EVMProvider) Wallet

func (p *EVMProvider) Wallet() (*keystore.Key, error)

type EVMProviderConfig

type EVMProviderConfig struct {
	ChainName       string `json:"-" yaml:"-"`
	RPCUrl          string `json:"rpc-url" yaml:"rpc-url"`
	VerifierRPCUrl  string `json:"verifier-rpc-url" yaml:"verifier-rpc-url"`
	StartHeight     uint64 `json:"start-height" yaml:"start-height"`
	Keystore        string `json:"keystore" yaml:"keystore"`
	Password        string `json:"password" yaml:"password"`
	GasPrice        int64  `json:"gas-price" yaml:"gas-price"`
	GasLimit        uint64 `json:"gas-limit" yaml:"gas-limit"`
	ContractAddress string `json:"contract-address" yaml:"contract-address"`
	Concurrency     uint64 `json:"concurrency" yaml:"concurrency"`
	FinalityBlock   uint64 `json:"finality-block" yaml:"finality-block"`
	NID             string `json:"nid" yaml:"nid"`
}

func (*EVMProviderConfig) GetWallet

func (p *EVMProviderConfig) GetWallet() string

func (*EVMProviderConfig) NewProvider

func (p *EVMProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error)

func (*EVMProviderConfig) SetWallet

func (p *EVMProviderConfig) SetWallet(addr string)

func (*EVMProviderConfig) Validate

func (p *EVMProviderConfig) Validate() error

type IClient

type IClient interface {
	Log() *zap.Logger
	GetBalance(ctx context.Context, hexAddr string) (*big.Int, error)
	GetBlockNumber() (uint64, error)
	GetBlockByHash(hash common.Hash) (*types.Block, error)
	GetHeaderByHeight(ctx context.Context, height *big.Int) (*ethTypes.Header, error)
	GetBlockReceipts(hash common.Hash) (ethTypes.Receipts, error)
	GetMedianGasPriceForBlock(ctx context.Context) (gasPrice *big.Int, gasHeight *big.Int, err error)
	GetChainID() *big.Int

	// ethClient
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethTypes.Log, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	TransactionByHash(ctx context.Context, blockHash common.Hash) (tx *ethTypes.Transaction, isPending bool, err error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*ethTypes.Receipt, error)
	TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
	TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*ethTypes.Transaction, error)

	// transaction
	SendTransaction(ctx context.Context, tx *ethTypes.Transaction) error

	// abiContract
	ParseMessage(log ethTypes.Log) (*bridgeContract.AbiMessage, error)
	SendMessage(opts *bind.TransactOpts, _to string, _svc string, _sn *big.Int, _msg []byte) (*ethTypes.Transaction, error)
	ReceiveMessage(opts *bind.TransactOpts, srcNID string, sn *big.Int, msg []byte) (*ethTypes.Transaction, error)
	MessageReceived(opts *bind.CallOpts, srcNetwork string, _connSn *big.Int) (bool, error)
	SetAdmin(opts *bind.TransactOpts, newAdmin common.Address) (*ethTypes.Transaction, error)
	RevertMessage(opts *bind.TransactOpts, sn *big.Int) (*ethTypes.Transaction, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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