Skip to main content

nautilus_blockchain/rpc/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! RPC client implementations for blockchain network communication.
17//!
18//! This module provides JSON-RPC client implementations for communicating with various
19//! blockchain networks via HTTP and WebSocket connections. It includes specialized
20//! clients for different networks (Ethereum, Polygon, Arbitrum, Base, BSC) and common
21//! utilities for handling RPC requests and responses.
22
23use alloy::primitives::Address;
24use enum_dispatch::enum_dispatch;
25use nautilus_live::SocketControl;
26use nautilus_network::websocket::TransportBackend;
27
28use crate::rpc::{
29    chains::{
30        arbitrum::ArbitrumRpcClient, base::BaseRpcClient, bsc::BscRpcClient,
31        ethereum::EthereumRpcClient, polygon::PolygonRpcClient,
32    },
33    error::BlockchainRpcClientError,
34    types::{BlockchainMessage, RpcEventType},
35};
36
37pub mod chains;
38pub mod core;
39pub mod error;
40pub mod helpers;
41pub mod http;
42pub mod providers;
43pub mod types;
44pub mod utils;
45
46#[cfg(feature = "hypersync")]
47pub(crate) mod verification;
48
49#[enum_dispatch(BlockchainRpcClient)]
50#[derive(Debug)]
51pub enum BlockchainRpcClientAny {
52    Arbitrum(ArbitrumRpcClient),
53    Base(BaseRpcClient),
54    Bsc(BscRpcClient),
55    Ethereum(EthereumRpcClient),
56    Polygon(PolygonRpcClient),
57}
58
59#[async_trait::async_trait]
60#[enum_dispatch]
61pub trait BlockchainRpcClient {
62    async fn connect(&mut self) -> anyhow::Result<()>;
63    async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
64    async fn subscribe_pool_events(
65        &mut self,
66        event_type: RpcEventType,
67        addresses: &[Address],
68        event_signature: String,
69    ) -> Result<(), BlockchainRpcClientError>;
70    async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
71    async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError>;
72    fn set_transport_backend(&mut self, backend: TransportBackend);
73    fn set_socket_control(&mut self, control: SocketControl);
74}