9 releases (4 breaking)
new 1.0.0-rc.0 | Apr 11, 2025 |
---|---|
0.5.0 | Mar 18, 2025 |
0.4.0 | Feb 20, 2025 |
0.3.0 | Feb 11, 2025 |
0.1.0 | Sep 30, 2024 |
#15 in Magic Beans
951 downloads per month
Used in 17 crates
(3 directly)
19MB
341K
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
:AvsRegistryChainReader
to 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(
logger.clone(),
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
~85MB
~1.5M SLoC