evm

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RPCCallRetry                               = 5
	MaxGasPriceInceremtRetry                   = 5
	GasPriceRatio                              = 10.0
	DefaultGetTransactionResultPollingInterval = time.Millisecond * 500
)
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"
)

Variables

View Source
var (
	EmitMessage = "Message(string,uint256,bytes)"
	CallMessage = "CallMessage(string,string,uint256,uint256,bytes)"
)

All the events

View Source
var (
	// Connection contract
	MethodRecvMessage   = "recvMessage"
	MethodSetAdmin      = "setAdmin"
	MethodRevertMessage = "revertMessage"
	MethodClaimFees     = "claimFees"
	MethodSetFee        = "setFee"
	MethodGetFee        = "getFee"

	// Xcall contract
	MethodExecuteCall = "executeCall"
)

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) ClaimFee added in v1.1.0

func (c *Client) ClaimFee(opts *bind.TransactOpts) (*ethTypes.Transaction, error)

ClaimFee

func (*Client) EstimateGas added in v1.1.0

func (c *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

func (*Client) ExecuteCall added in v1.1.0

func (c *Client) ExecuteCall(opts *bind.TransactOpts, reqID *big.Int, data []byte) (*ethTypes.Transaction, error)

func (*Client) ExecuteRollback added in v1.1.0

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

ExecuteRollback

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) GetFee added in v1.1.0

func (c *Client) GetFee(opts *bind.CallOpts, networkID string) (*big.Int, error)

GetFee

func (*Client) GetHeaderByHeight

func (cl *Client) GetHeaderByHeight(ctx context.Context, height *big.Int) (*ethTypes.Header, 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 (c *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

func (*Client) ParseConnectionMessage added in v1.1.0

func (cl *Client) ParseConnectionMessage(log ethTypes.Log) (*bridgeContract.ConnectionMessage, error)

func (*Client) ParseXcallMessage added in v1.1.0

func (c *Client) ParseXcallMessage(log ethTypes.Log) (*bridgeContract.XcallCallMessage, 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) SetFee added in v1.1.0

func (c *Client) SetFee(opts *bind.TransactOpts, src string, msg, res *big.Int) (*ethTypes.Transaction, error)

SetFee

func (*Client) Subscribe added in v1.1.2

func (c *Client) Subscribe(ctx context.Context, q ethereum.FilterQuery, ch chan<- ethTypes.Log) (ethereum.Subscription, error)

Subscribe

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 Config added in v1.1.0

type Config struct {
	ChainName      string                          `json:"-" yaml:"-"`
	RPCUrl         string                          `json:"rpc-url" yaml:"rpc-url"`
	WebsocketUrl   string                          `json:"websocket-url" yaml:"websocket-url"`
	VerifierRPCUrl string                          `json:"verifier-rpc-url" yaml:"verifier-rpc-url"`
	StartHeight    uint64                          `json:"start-height" yaml:"start-height"`
	Address        string                          `json:"address" yaml:"address"`
	GasPrice       uint64                          `json:"gas-price" yaml:"gas-price"`
	GasMin         uint64                          `json:"gas-min" yaml:"gas-min"`
	GasLimit       uint64                          `json:"gas-limit" yaml:"gas-limit"`
	Contracts      providerTypes.ContractConfigMap `json:"contracts" yaml:"contracts"`
	Concurrency    uint64                          `json:"concurrency" yaml:"concurrency"`
	FinalityBlock  uint64                          `json:"finality-block" yaml:"finality-block"`
	BlockInterval  time.Duration                   `json:"block-interval" yaml:"block-interval"`
	NID            string                          `json:"nid" yaml:"nid"`
	HomeDir        string                          `json:"-" yaml:"-"`
}

func (*Config) GetMonitorEventFilters added in v1.1.0

func (p *Config) GetMonitorEventFilters() ethereum.FilterQuery

func (*Config) GetWallet added in v1.1.0

func (p *Config) GetWallet() string

func (*Config) NewProvider added in v1.1.0

func (p *Config) NewProvider(ctx context.Context, log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error)

func (*Config) SetWallet added in v1.1.0

func (p *Config) SetWallet(addr string)

func (*Config) Validate added in v1.1.0

func (p *Config) 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)
	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) (*big.Int, 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)
	EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	SendTransaction(ctx context.Context, tx *ethTypes.Transaction) error
	Subscribe(ctx context.Context, q ethereum.FilterQuery, ch chan<- ethTypes.Log) (ethereum.Subscription, error)

	// abiContract for connection
	ParseConnectionMessage(log ethTypes.Log) (*bridgeContract.ConnectionMessage, 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)
	GetFee(opts *bind.CallOpts, networkID string) (*big.Int, error)
	SetFee(opts *bind.TransactOpts, src string, msg, res *big.Int) (*ethTypes.Transaction, error)
	ClaimFee(opts *bind.TransactOpts) (*ethTypes.Transaction, error)

	// abiContract for xcall
	ParseXcallMessage(log ethTypes.Log) (*bridgeContract.XcallCallMessage, error)
	ExecuteCall(opts *bind.TransactOpts, reqID *big.Int, data []byte) (*ethTypes.Transaction, error)
	ExecuteRollback(opts *bind.TransactOpts, sn *big.Int) (*ethTypes.Transaction, error)
}

type Provider added in v1.1.0

type Provider struct {
	StartHeight uint64

	NonceTracker types.NonceTrackerI
	// contains filtered or unexported fields
}

func (*Provider) ClaimFee added in v1.1.0

func (p *Provider) ClaimFee(ctx context.Context) error

ClaimFees

func (*Provider) Config added in v1.1.0

func (p *Provider) Config() provider.Config

func (*Provider) EstimateGas added in v1.1.0

func (p *Provider) EstimateGas(ctx context.Context, message *providerTypes.Message) (uint64, error)

EstimateGas

func (*Provider) ExecuteRollback added in v1.1.0

func (p *Provider) ExecuteRollback(ctx context.Context, sn uint64) error

ExecuteRollback

func (*Provider) FinalityBlock added in v1.1.0

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

func (*Provider) FindMessages added in v1.1.0

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

func (*Provider) GenerateMessages added in v1.1.0

func (p *Provider) GenerateMessages(ctx context.Context, key *types.MessageKeyWithMessageHeight) ([]*types.Message, error)

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

func (*Provider) GetAddressByEventType added in v1.1.0

func (p *Provider) GetAddressByEventType(eventType string) *common.Address

func (*Provider) GetConcurrency added in v1.1.0

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

func (*Provider) GetEventName added in v1.1.0

func (p *Provider) GetEventName(sig string) string

func (*Provider) GetFee added in v1.1.0

func (p *Provider) GetFee(ctx context.Context, networkID string, responseFee bool) (uint64, error)

GetFee

func (*Provider) GetTransationOpts added in v1.1.0

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

func (*Provider) ImportKeystore added in v1.1.0

func (p *Provider) ImportKeystore(ctx context.Context, keyPath, passphrase string) (string, error)

ImportKeystore imports a keystore from a file

func (*Provider) Init added in v1.1.0

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

func (*Provider) Listener added in v1.1.0

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

func (*Provider) LogFailedTx added in v1.1.0

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

func (*Provider) LogSuccessTx added in v1.1.0

func (p *Provider) LogSuccessTx(message *providerTypes.MessageKey, receipt *types.Receipt)

func (*Provider) MessageReceived added in v1.1.0

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

func (*Provider) NID added in v1.1.0

func (p *Provider) NID() string

func (*Provider) Name added in v1.1.0

func (p *Provider) Name() string

func (*Provider) NewKeystore added in v1.1.0

func (p *Provider) NewKeystore(password string) (string, error)

func (*Provider) QueryBalance added in v1.1.0

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

func (*Provider) QueryLatestHeight added in v1.1.0

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

func (*Provider) QueryTransactionReceipt added in v1.1.0

func (p *Provider) QueryTransactionReceipt(ctx context.Context, txHash string) (*types.Receipt, error)

func (*Provider) RestoreKeystore added in v1.1.0

func (p *Provider) RestoreKeystore(ctx context.Context) error

func (*Provider) RevertMessage added in v1.1.0

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

RevertMessage

func (*Provider) Route added in v1.1.0

func (p *Provider) Route(ctx context.Context, message *providerTypes.Message, callback providerTypes.TxResponseFunc) error

this will be executed in go route

func (*Provider) SendTransaction added in v1.1.0

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

func (*Provider) SetAdmin added in v1.1.0

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

SetAdmin sets the admin address of the bridge contract

func (*Provider) SetFee added in v1.1.0

func (p *Provider) SetFee(ctx context.Context, networkID string, msgFee, resFee uint64) error

SetFee

func (*Provider) ShouldReceiveMessage added in v1.1.0

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

func (*Provider) ShouldSendMessage added in v1.1.0

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

func (*Provider) Subscribe added in v1.1.2

func (p *Provider) Subscribe(ctx context.Context, blockInfoChan chan *relayertypes.BlockInfo)

Subscribe listens to new blocks and sends them to the channel

func (*Provider) Type added in v1.1.0

func (p *Provider) Type() string

func (*Provider) WaitForResults added in v1.1.0

func (p *Provider) WaitForResults(ctx context.Context, txHash common.Hash) (*coreTypes.Receipt, error)

func (*Provider) WaitForTxResult added in v1.1.0

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

func (*Provider) Wallet added in v1.1.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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