11 releases (2 stable)
| 2.0.0 | Jun 20, 2025 |
|---|---|
| 1.0.0 | May 9, 2025 |
| 1.0.0-rc.0 | Apr 11, 2025 |
| 0.5.0 | Mar 18, 2025 |
| 0.1.1 | Nov 25, 2024 |
#10 in #avs
2,796 downloads per month
Used in 17 crates
(2 directly)
21MB
375K
SLoC
Operators Info
Example
lib.rs:
Operators Info Service
This crate provides traits and methods to get operator information.
Introduction
The Operators Info Service provides functionality to get operators Public Keys and Sockets.
The service is designed to be used in conjunction with the AvsRegistryServiceChainCaller
to get the operators information from the chain.
Main Components
OperatorInfoServiceInMemory
The main struct of the service, it implements the OperatorInfoService trait.
It fetches and stores operators info (addresses and public key) in memory.
avs_registry_reader:AvsRegistryChainReaderto get the operators information from the chain
OperatorSocket
Represents an operator with the ID and the socket.
id: Operator IDsocket: Operator socket
OperatorPubKeys
Represents the operator public keys.
g1_pub_key: Operator G1 public keyg2_pub_key: Operator G2 public key
Usage
Initialize the Service
When using the OperatorInfoServiceInMemory struct, you can initialize the service by calling the
new method. This method returns a tuple of the service and a channel to receive errors from the service. Also,
it creates a background task to process the OperatorsInfoMessage. The messages that the service will process are:
InsertOperatorInfo: Save the operator info in memory.Remove: Remove the operator info from state.GetPubKeys: Get the operator public keys from memory.GetSockets: Get the operator socket from memory.
#
#
#
let operators_info_service_in_memory = OperatorInfoServiceInMemory::new(
avs_registry_chain_reader,
ws_endpoint.to_string(),
)
.await
.unwrap();
Start the Service
Then you can start the service by calling the start_service method. It will listen to events of NEW_PUBKEY_REGISTRATION_EVENT
and OPERATOR_SOCKET_UPDATE and save the data in memory. To stop the service, you can use the CancellationToken.
#
#
#
#
#
tokio::spawn(async move {
let _ = clone_operators_info
.start_service(
&cloned_token,
0,
end_block,
)
.await;
});
Query Past Operator Registration Events and Fill the Database
To query past operator registration events and fill the database, you can call the query_past_registered_operator_events_and_fill_db method.
This function will send a OperatorsInfoMessage with the InsertOperatorInfo action to the service channel and store the data in OperatorState.
#
#
#
#
operators_info_service_in_memory
.query_past_registered_operator_events_and_fill_db(0, end_block)
.await;
Retrieve Operator information
To retrieve operator information, you can call the get_operator_info or get_operator_socket methods.
#
#
#
#
#
let operator_info = operators_info_service_in_memory
.get_operator_info(operator_address)
.await
.unwrap()
.unwrap();
#
let operator_socket = operators_info_service_in_memory
.get_operator_socket(operator_address)
.await
.unwrap()
.unwrap();
Dependencies
~72MB
~1M SLoC