nautilus_blockchain/rpc/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3// https://poseitrader.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;
24
25use crate::rpc::{
26 chains::{
27 arbitrum::ArbitrumRpcClient, base::BaseRpcClient, ethereum::EthereumRpcClient,
28 polygon::PolygonRpcClient,
29 },
30 error::BlockchainRpcClientError,
31 types::BlockchainMessage,
32};
33
34pub mod chains;
35pub mod core;
36pub mod error;
37pub mod http;
38pub mod types;
39pub mod utils;
40
41#[enum_dispatch(BlockchainRpcClient)]
42#[derive(Debug)]
43pub enum BlockchainRpcClientAny {
44 Arbitrum(ArbitrumRpcClient),
45 Base(BaseRpcClient),
46 Ethereum(EthereumRpcClient),
47 Polygon(PolygonRpcClient),
48}
49
50#[async_trait::async_trait]
51#[enum_dispatch]
52pub trait BlockchainRpcClient {
53 async fn connect(&mut self) -> anyhow::Result<()>;
54 async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
55 async fn subscribe_swaps(&mut self) -> Result<(), BlockchainRpcClientError> {
56 todo!("Not implemented")
57 }
58 async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError>;
59 async fn unsubscribe_swaps(&mut self) -> Result<(), BlockchainRpcClientError> {
60 todo!("Not implemented")
61 }
62 async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError>;
63}