pub struct CoreBlockchainRpcClient { /* private fields */ }
Expand description
Core implementation of a blockchain RPC client that serves as the base for all chain-specific clients. It provides a shared implementation of common blockchain RPC functionality. It handles:
- WebSocket connection management with blockchain RPC node
- Subscription lifecycle (creation, tracking, and termination)
- Message serialization and deserialization of RPC messages
- Event type mapping and dispatching
Implementations§
Source§impl CoreBlockchainRpcClient
impl CoreBlockchainRpcClient
pub fn new(chain: Chain, wss_rpc_url: String) -> Self
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Establishes a WebSocket connection to the blockchain node and sets up the message channel.
§Errors
Returns an error if the WebSocket connection fails.
Sourcepub async fn wait_on_rpc_channel(&mut self) -> Option<Message>
pub async fn wait_on_rpc_channel(&mut self) -> Option<Message>
Waits for and returns the next available message from the WebSocket channel.
Sourcepub async fn next_rpc_message(
&mut self,
) -> Result<BlockchainMessage, BlockchainRpcClientError>
pub async fn next_rpc_message( &mut self, ) -> Result<BlockchainMessage, BlockchainRpcClientError>
Retrieves, parses, and returns the next blockchain RPC message as a structured BlockchainRpcMessage
type.
§Panics
Panics if expected fields (id
, result
) are missing or cannot be converted when handling subscription confirmations or events.
§Errors
Returns an error if the RPC channel encounters an error or if deserialization of the message fails.
Sourcepub async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>
pub async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>
Subscribes to real-time block updates from the blockchain node.
§Errors
Returns an error if the subscription request fails or if the client is not connected.
Sourcepub async fn unsubscribe_blocks(
&mut self,
) -> Result<(), BlockchainRpcClientError>
pub async fn unsubscribe_blocks( &mut self, ) -> Result<(), BlockchainRpcClientError>
Cancels the subscription to real-time block updates.
§Errors
Returns an error if the unsubscription request fails or if the client is not connected.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CoreBlockchainRpcClient
impl !RefUnwindSafe for CoreBlockchainRpcClient
impl Send for CoreBlockchainRpcClient
impl Sync for CoreBlockchainRpcClient
impl Unpin for CoreBlockchainRpcClient
impl !UnwindSafe for CoreBlockchainRpcClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more