eth::EthWatchService¶
Ties together EventWatcher, ABI decoding, and eth message dispatch. More...
#include <eth_watch_service.hpp>
Public Functions¶
| Name | |
|---|---|
| EthWatchService() =default | |
| ~EthWatchService() =default | |
| EthWatchService(const EthWatchService & ) =delete | |
| EthWatchService & | operator=(const EthWatchService & ) =delete |
| EthWatchService(EthWatchService && ) =default | |
| EthWatchService & | operator=(EthWatchService && ) =default |
| void | set_send_callback(SendCallback cb) Provide a callback used to send outgoing eth messages. |
| EventWatchId | watch_event(const codec::Address & contract_address, const std::string & event_signature, const std::vector< abi::AbiParam > & params, DecodedEventCallback callback, std::optional< uint64_t > from_block =std::nullopt, std::optional< uint64_t > to_block =std::nullopt) Register a watch for a specific contract event. |
| uint64_t | tip() const Return the highest block number seen so far (0 if none). |
| std::optional< Hash256 > | tip_hash() const Return the hash of the highest block seen, if any. |
| void | unwatch(EventWatchId id) Remove a previously registered subscription. |
| size_t | subscription_count() const Return the number of active subscriptions. |
| void | process_message(uint8_t eth_msg_id, rlp::ByteView payload) Process a raw eth wire message payload. |
| void | process_receipts(const std::vector< codec::Receipt > & receipts, const std::vector< Hash256 > & tx_hashes, uint64_t block_number, const Hash256 & block_hash) Directly process a batch of receipts for a known block. |
| void | process_new_block(const NewBlockMessage & msg, const Hash256 & block_hash) Directly process a NewBlock message. |
| void | request_receipts(const Hash256 & block_hash, uint64_t block_number) Request receipts for a block by hash. |
Detailed Description¶
Ties together EventWatcher, ABI decoding, and eth message dispatch.
Usage:
- Call set_send_callback() so the service can emit GetReceipts requests.
- Register subscriptions via watch_event().
- Feed incoming eth wire messages via process_message().
- Matching logs trigger the registered DecodedEventCallback.
Thread-safety: not thread-safe; all calls must be externally synchronized.
Public Functions Documentation¶
function EthWatchService¶
function ~EthWatchService¶
function EthWatchService¶
function operator=¶
function EthWatchService¶
function operator=¶
function set_send_callback¶
Provide a callback used to send outgoing eth messages.
Must be called before process_message() if automatic GetReceipts requests are desired. Safe to omit if the caller handles receipts manually via process_receipts().
function watch_event¶
EventWatchId watch_event(
const codec::Address & contract_address,
const std::string & event_signature,
const std::vector< abi::AbiParam > & params,
DecodedEventCallback callback,
std::optional< uint64_t > from_block =std::nullopt,
std::optional< uint64_t > to_block =std::nullopt
)
Register a watch for a specific contract event.
Parameters:
- contract_address Contract to watch; empty address = any contract.
- event_signature Canonical Solidity signature, e.g. "Transfer(address,address,uint256)".
- params Full parameter list in declaration order (mark indexed ones with AbiParam::indexed = true).
- callback Called for each matching decoded log.
- from_block Optional lower block bound for the filter.
- to_block Optional upper block bound for the filter.
Return: WatchId that can be passed to unwatch().
function tip¶
Return the highest block number seen so far (0 if none).
function tip_hash¶
Return the hash of the highest block seen, if any.
function unwatch¶
Remove a previously registered subscription.
function subscription_count¶
Return the number of active subscriptions.
function process_message¶
Process a raw eth wire message payload.
Parameters:
- eth_msg_id Eth-layer message id (offset already subtracted).
- payload Raw message bytes.
Call this from your generic_handler with the eth-layer message id (i.e. already minus the rlpx offset) and the raw payload bytes.
Handles NewBlockHashes (0x01), NewBlock (0x07), Receipts (0x10). When a send callback is registered, automatically emits GetReceipts for new blocks.
function process_receipts¶
void process_receipts(
const std::vector< codec::Receipt > & receipts,
const std::vector< Hash256 > & tx_hashes,
uint64_t block_number,
const Hash256 & block_hash
)
Directly process a batch of receipts for a known block.
Parameters:
- receipts The receipts for all transactions in the block.
- tx_hashes Corresponding transaction hashes (same order).
- block_number Block number.
- block_hash Block hash.
function process_new_block¶
Directly process a NewBlock message.
function request_receipts¶
Request receipts for a block by hash.
Parameters:
- block_hash Hash of the block whose receipts are wanted.
- block_number Block number (stored for context in the callback).
Encodes and sends a GetReceipts message via the send callback. Records the pending request so the Receipts response can be correlated.
Updated on 2026-04-13 at 23:22:46 -0700