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) and common
21//! utilities for handling RPC requests and responses.
22
23use enum_dispatch::enum_dispatch;
24use nautilus_network::websocket::TransportBackend;
25
26use crate::rpc::{
27    chains::{
28        arbitrum::ArbitrumRpcClient, base::BaseRpcClient, ethereum::EthereumRpcClient,
29        polygon::PolygonRpcClient,
30    },
31    error::BlockchainRpcClientError,
32    types::BlockchainMessage,
33};
34
35pub mod chains;
36pub mod core;
37pub mod error;
38pub mod helpers;
39pub mod http;
40pub mod providers;
41pub mod types;
42pub mod utils;
43
44#[enum_dispatch(BlockchainRpcClient)]
45#[derive(Debug)]
46pub enum BlockchainRpcClientAny {
47    Arbitrum(ArbitrumRpcClient),
48    Base(BaseRpcClient),
49    Ethereum(EthereumRpcClient),
50    Polygon(PolygonRpcClient),
51}
52
53#[async_trait::async_trait]
54#[enum_dispatch]
55pub trait BlockchainRpcClient {
56    async fn connect(&mut self) -> anyhow::Result<()>;
57    async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
58    async fn subscribe_swaps(&mut self) -> Result<(), BlockchainRpcClientError> {
59        todo!("Not implemented")
60    }
61    async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
62    async fn unsubscribe_swaps(&mut self) -> Result<(), BlockchainRpcClientError> {
63        todo!("Not implemented")
64    }
65    async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError>;
66    fn set_transport_backend(&mut self, backend: TransportBackend);
67}