Documentation ¶
Overview ¶
Package observer implements the EVM chain observer
Index ¶
- func FetchConnectorContractEth(addr ethcommon.Address, client interfaces.EVMRPCClient) (*zetaconnectoreth.ZetaConnectorEth, error)
- func FetchZetaTokenContract(addr ethcommon.Address, client interfaces.EVMRPCClient) (*zeta.ZetaNonEth, error)
- func ParseAndCheckWithdrawnEvent(cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, ...) (*erc20custody.ERC20CustodyWithdrawn, error)
- func ParseAndCheckZetaEvent(cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, ...) (*zetaconnector.ZetaConnectorNonEthZetaReceived, ...)
- func ParseOutboundReceivedValue(cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, ...) (*big.Int, chains.ReceiveStatus, error)
- type Observer
- func (ob *Observer) BlockByNumber(blockNumber int) (*ethrpc.Block, error)
- func (ob *Observer) BuildInboundVoteMsgForDepositedEvent(event *erc20custody.ERC20CustodyDeposited, sender ethcommon.Address) *types.MsgVoteInbound
- func (ob *Observer) BuildInboundVoteMsgForTokenSentToTSS(tx *ethrpc.Transaction, sender ethcommon.Address, blockNumber uint64) *types.MsgVoteInbound
- func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent(appContext *zctx.AppContext, event *zetaconnector.ZetaConnectorNonEthZetaSent) *types.MsgVoteInbound
- func (ob *Observer) CheckAndVoteInboundTokenERC20(ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, ...) (string, error)
- func (ob *Observer) CheckAndVoteInboundTokenGas(ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, ...) (string, error)
- func (ob *Observer) CheckAndVoteInboundTokenZeta(ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, ...) (string, error)
- func (ob *Observer) CheckTxInclusion(tx *ethtypes.Transaction, receipt *ethtypes.Receipt) error
- func (ob *Observer) GetBlockByNumberCached(blockNumber uint64) (*ethrpc.Block, error)
- func (ob *Observer) GetBlockHeaderCached(ctx context.Context, blockNumber uint64) (*ethtypes.Header, error)
- func (ob *Observer) GetChainParams() observertypes.ChainParams
- func (ob *Observer) GetConnectorContract() (ethcommon.Address, *zetaconnector.ZetaConnectorNonEth, error)
- func (ob *Observer) GetConnectorContractEth() (ethcommon.Address, *zetaconnectoreth.ZetaConnectorEth, error)
- func (ob *Observer) GetERC20CustodyContract() (ethcommon.Address, *erc20custody.ERC20Custody, error)
- func (ob *Observer) GetPendingTx(nonce uint64) *ethtypes.Transaction
- func (ob *Observer) GetTxID(nonce uint64) string
- func (ob *Observer) GetTxNReceipt(nonce uint64) (*ethtypes.Receipt, *ethtypes.Transaction)
- func (ob *Observer) HasEnoughConfirmations(receipt *ethtypes.Receipt, lastHeight uint64) bool
- func (ob *Observer) IsOutboundProcessed(ctx context.Context, cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger) (bool, bool, error)
- func (ob *Observer) IsTxConfirmed(nonce uint64) bool
- func (ob *Observer) LoadDB(ctx context.Context, dbPath string) error
- func (ob *Observer) LoadLastBlockScanned(ctx context.Context) error
- func (ob *Observer) ObserveERC20Deposited(ctx context.Context, startBlock, toBlock uint64) uint64
- func (ob *Observer) ObserveInbound(ctx context.Context, sampledLogger zerolog.Logger) error
- func (ob *Observer) ObserveTSSReceiveInBlock(ctx context.Context, blockNumber uint64) error
- func (ob *Observer) ObserveZetaSent(ctx context.Context, startBlock, toBlock uint64) (uint64, error)
- func (ob *Observer) ObserverTSSReceive(ctx context.Context, startBlock, toBlock uint64) (uint64, error)
- func (ob *Observer) PostGasPrice(ctx context.Context) error
- func (ob *Observer) PostVoteInbound(ctx context.Context, msg *types.MsgVoteInbound, coinType coin.CoinType, ...) (string, error)
- func (ob *Observer) PostVoteOutbound(ctx context.Context, cctxIndex string, receipt *ethtypes.Receipt, ...)
- func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error
- func (ob *Observer) RemoveCachedBlock(blockNumber uint64)
- func (ob *Observer) SetChainParams(params observertypes.ChainParams)
- func (ob *Observer) SetPendingTx(nonce uint64, transaction *ethtypes.Transaction)
- func (ob *Observer) SetTxNReceipt(nonce uint64, receipt *ethtypes.Receipt, transaction *ethtypes.Transaction)
- func (ob *Observer) Start(ctx context.Context)
- func (ob *Observer) TransactionByHash(txHash string) (*ethrpc.Transaction, bool, error)
- func (ob *Observer) WatchGasPrice(ctx context.Context) error
- func (ob *Observer) WatchInbound(ctx context.Context) error
- func (ob *Observer) WatchInboundTracker(ctx context.Context) error
- func (ob *Observer) WatchOutbound(ctx context.Context) error
- func (ob *Observer) WatchRPCStatus(ctx context.Context) error
- func (ob *Observer) WithEvmClient(client interfaces.EVMRPCClient)
- func (ob *Observer) WithEvmJSONRPC(client interfaces.EVMJSONRPCClient)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchConnectorContractEth ¶
func FetchConnectorContractEth( addr ethcommon.Address, client interfaces.EVMRPCClient, ) (*zetaconnectoreth.ZetaConnectorEth, error)
FetchConnectorContractEth returns the Eth connector address and binder TODO(revamp): move this to a contract package
func FetchZetaTokenContract ¶
func FetchZetaTokenContract( addr ethcommon.Address, client interfaces.EVMRPCClient, ) (*zeta.ZetaNonEth, error)
FetchZetaTokenContract returns the non-Eth ZETA token binder TODO(revamp): move this to a contract package
func ParseAndCheckWithdrawnEvent ¶
func ParseAndCheckWithdrawnEvent( cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, custodyAddr ethcommon.Address, custody *erc20custody.ERC20Custody, ) (*erc20custody.ERC20CustodyWithdrawn, error)
ParseAndCheckWithdrawnEvent parses and checks erc20 Withdrawn event from the outbound receipt
func ParseAndCheckZetaEvent ¶
func ParseAndCheckZetaEvent( cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, connectorAddr ethcommon.Address, connector *zetaconnector.ZetaConnectorNonEth, ) (*zetaconnector.ZetaConnectorNonEthZetaReceived, *zetaconnector.ZetaConnectorNonEthZetaReverted, error)
ParseAndCheckZetaEvent parses and checks ZetaReceived/ZetaReverted event from the outbound receipt It either returns an ZetaReceived or an ZetaReverted event, or an error if no event found
func ParseOutboundReceivedValue ¶
func ParseOutboundReceivedValue( cctx *crosschaintypes.CrossChainTx, receipt *ethtypes.Receipt, transaction *ethtypes.Transaction, cointype coin.CoinType, connectorAddress ethcommon.Address, connector *zetaconnector.ZetaConnectorNonEth, custodyAddress ethcommon.Address, custody *erc20custody.ERC20Custody, ) (*big.Int, chains.ReceiveStatus, error)
ParseOutboundReceivedValue parses the received value and status from the outbound receipt The receivd value is the amount of Zeta/ERC20/Gas token (released from connector/custody/TSS) sent to the receiver
Types ¶
type Observer ¶
type Observer struct { // base.Observer implements the base chain observer base.Observer // contains filtered or unexported fields }
Observer is the observer for evm chains
func NewObserver ¶
func NewObserver( ctx context.Context, evmCfg config.EVMConfig, evmClient interfaces.EVMRPCClient, chainParams observertypes.ChainParams, zetacoreClient interfaces.ZetacoreClient, tss interfaces.TSSSigner, dbpath string, logger base.Logger, ts *metrics.TelemetryServer, ) (*Observer, error)
NewObserver returns a new EVM chain observer
func (*Observer) BlockByNumber ¶
BlockByNumber query block by number via JSON-RPC
func (*Observer) BuildInboundVoteMsgForDepositedEvent ¶
func (ob *Observer) BuildInboundVoteMsgForDepositedEvent( event *erc20custody.ERC20CustodyDeposited, sender ethcommon.Address, ) *types.MsgVoteInbound
BuildInboundVoteMsgForDepositedEvent builds a inbound vote message for a Deposited event
func (*Observer) BuildInboundVoteMsgForTokenSentToTSS ¶
func (ob *Observer) BuildInboundVoteMsgForTokenSentToTSS( tx *ethrpc.Transaction, sender ethcommon.Address, blockNumber uint64, ) *types.MsgVoteInbound
BuildInboundVoteMsgForTokenSentToTSS builds a inbound vote message for a token sent to TSS
func (*Observer) BuildInboundVoteMsgForZetaSentEvent ¶
func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent( appContext *zctx.AppContext, event *zetaconnector.ZetaConnectorNonEthZetaSent, ) *types.MsgVoteInbound
BuildInboundVoteMsgForZetaSentEvent builds a inbound vote message for a ZetaSent event
func (*Observer) CheckAndVoteInboundTokenERC20 ¶
func (ob *Observer) CheckAndVoteInboundTokenERC20( ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, vote bool, ) (string, error)
CheckAndVoteInboundTokenERC20 checks and votes on the given inbound ERC20 token
func (*Observer) CheckAndVoteInboundTokenGas ¶
func (ob *Observer) CheckAndVoteInboundTokenGas( ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, vote bool, ) (string, error)
CheckAndVoteInboundTokenGas checks and votes on the given inbound gas token
func (*Observer) CheckAndVoteInboundTokenZeta ¶
func (ob *Observer) CheckAndVoteInboundTokenZeta( ctx context.Context, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, vote bool, ) (string, error)
CheckAndVoteInboundTokenZeta checks and votes on the given inbound Zeta token
func (*Observer) CheckTxInclusion ¶
CheckTxInclusion returns nil only if tx is included at the position indicated by the receipt ([block, index])
func (*Observer) GetBlockByNumberCached ¶
GetBlockByNumberCached get block by number from cache returns block, ethrpc.Block, isFallback, isSkip, error
func (*Observer) GetBlockHeaderCached ¶
func (ob *Observer) GetBlockHeaderCached(ctx context.Context, blockNumber uint64) (*ethtypes.Header, error)
GetBlockHeaderCached get block header by number from cache
func (*Observer) GetChainParams ¶
func (ob *Observer) GetChainParams() observertypes.ChainParams
GetChainParams returns the chain params for the observer Note: chain params is accessed concurrently
func (*Observer) GetConnectorContract ¶
func (ob *Observer) GetConnectorContract() (ethcommon.Address, *zetaconnector.ZetaConnectorNonEth, error)
GetConnectorContract returns the non-Eth connector address and binder
func (*Observer) GetConnectorContractEth ¶
func (ob *Observer) GetConnectorContractEth() (ethcommon.Address, *zetaconnectoreth.ZetaConnectorEth, error)
GetConnectorContractEth returns the Eth connector address and binder
func (*Observer) GetERC20CustodyContract ¶
func (ob *Observer) GetERC20CustodyContract() (ethcommon.Address, *erc20custody.ERC20Custody, error)
GetERC20CustodyContract returns ERC20Custody contract address and binder
func (*Observer) GetPendingTx ¶
func (ob *Observer) GetPendingTx(nonce uint64) *ethtypes.Transaction
GetPendingTx gets the pending transaction from memory
func (*Observer) GetTxNReceipt ¶
GetTxNReceipt gets the receipt and transaction from memory
func (*Observer) HasEnoughConfirmations ¶
HasEnoughConfirmations checks if the given receipt has enough confirmations
func (*Observer) IsOutboundProcessed ¶
func (ob *Observer) IsOutboundProcessed( ctx context.Context, cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger, ) (bool, bool, error)
IsOutboundProcessed checks outbound status and returns (isIncluded, isConfirmed, error) It also posts vote to zetacore if the tx is confirmed TODO(revamp): rename as it also vote the outbound
func (*Observer) IsTxConfirmed ¶
IsTxConfirmed returns true if there is a confirmed tx for 'nonce'
func (*Observer) LoadDB ¶
LoadDB open sql database and load data into EVM observer TODO(revamp): move to a db file
func (*Observer) LoadLastBlockScanned ¶
LoadLastBlockScanned loads the last scanned block from the database TODO(revamp): move to a db file
func (*Observer) ObserveERC20Deposited ¶
ObserveERC20Deposited queries the ERC20CustodyDeposited event from the ERC20Custody contract and posts to zetacore returns the last block successfully scanned
func (*Observer) ObserveInbound ¶
ObserveInbound observes the evm chain for inbounds and posts votes to zetacore
func (*Observer) ObserveTSSReceiveInBlock ¶
ObserveTSSReceiveInBlock queries the incoming gas asset to TSS address in a single block and posts votes
func (*Observer) ObserveZetaSent ¶
func (ob *Observer) ObserveZetaSent(ctx context.Context, startBlock, toBlock uint64) (uint64, error)
ObserveZetaSent queries the ZetaSent event from the connector contract and posts to zetacore returns the last block successfully scanned
func (*Observer) ObserverTSSReceive ¶
func (ob *Observer) ObserverTSSReceive(ctx context.Context, startBlock, toBlock uint64) (uint64, error)
ObserverTSSReceive queries the incoming gas asset to TSS address and posts to zetacore returns the last block successfully scanned
func (*Observer) PostGasPrice ¶
PostGasPrice posts gas price to zetacore TODO(revamp): move to gas price file
func (*Observer) PostVoteInbound ¶
func (ob *Observer) PostVoteInbound( ctx context.Context, msg *types.MsgVoteInbound, coinType coin.CoinType, retryGasLimit uint64, ) (string, error)
PostVoteInbound posts a vote for the given vote message
func (*Observer) PostVoteOutbound ¶
func (ob *Observer) PostVoteOutbound( ctx context.Context, cctxIndex string, receipt *ethtypes.Receipt, transaction *ethtypes.Transaction, receiveValue *big.Int, receiveStatus chains.ReceiveStatus, nonce uint64, coinType coin.CoinType, logger zerolog.Logger, )
PostVoteOutbound posts vote to zetacore for the confirmed outbound
func (*Observer) ProcessInboundTrackers ¶
ProcessInboundTrackers processes inbound trackers from zetacore TODO(revamp): move inbound tracker function to a separate file
func (*Observer) RemoveCachedBlock ¶
RemoveCachedBlock remove block from cache
func (*Observer) SetChainParams ¶
func (ob *Observer) SetChainParams(params observertypes.ChainParams)
SetChainParams sets the chain params for the observer Note: chain params is accessed concurrently
func (*Observer) SetPendingTx ¶
func (ob *Observer) SetPendingTx(nonce uint64, transaction *ethtypes.Transaction)
SetPendingTx sets the pending transaction in memory
func (*Observer) SetTxNReceipt ¶
func (ob *Observer) SetTxNReceipt(nonce uint64, receipt *ethtypes.Receipt, transaction *ethtypes.Transaction)
SetTxNReceipt sets the receipt and transaction in memory
func (*Observer) TransactionByHash ¶
TransactionByHash query transaction by hash via JSON-RPC TODO(revamp): update this method as a pure RPC method that takes two parameters (jsonRPC, and txHash) and move to upper package to file rpc.go
func (*Observer) WatchGasPrice ¶
WatchGasPrice watches evm chain for gas prices and post to zetacore TODO(revamp): move ticker to ticker file TODO(revamp): move inner logic to a separate function
func (*Observer) WatchInbound ¶
WatchInbound watches evm chain for incoming txs and post votes to zetacore TODO(revamp): move ticker function to a separate file
func (*Observer) WatchInboundTracker ¶
WatchInboundTracker gets a list of Inbound tracker suggestions from zeta-core at each tick and tries to check if the in-tx was confirmed. If it was, it tries to broadcast the confirmation vote. If this zeta client has previously broadcast the vote, the tx would be rejected TODO(revamp): move inbound tracker function to a separate file
func (*Observer) WatchOutbound ¶
WatchOutbound watches evm chain for outgoing txs status TODO(revamp): move ticker function to ticker file TODO(revamp): move inner logic to a separate function
func (*Observer) WatchRPCStatus ¶
WatchRPCStatus watches the RPC status of the evm chain TODO(revamp): move ticker to ticker file TODO(revamp): move inner logic to a separate function
func (*Observer) WithEvmClient ¶
func (ob *Observer) WithEvmClient(client interfaces.EVMRPCClient)
WithEvmClient attaches a new evm client to the observer
func (*Observer) WithEvmJSONRPC ¶
func (ob *Observer) WithEvmJSONRPC(client interfaces.EVMJSONRPCClient)
WithEvmJSONRPC attaches a new evm json rpc client to the observer