nautilus_blockchain/rpc/chains/
base.rs1use alloy::primitives::Address;
17use nautilus_live::SocketControl;
18use nautilus_model::defi::chain::chains;
19use nautilus_network::websocket::TransportBackend;
20
21use crate::rpc::{
22 BlockchainRpcClient,
23 core::CoreBlockchainRpcClient,
24 error::BlockchainRpcClientError,
25 types::{BlockchainMessage, RpcEventType},
26};
27
28#[derive(Debug)]
29pub struct BaseRpcClient {
30 base_client: CoreBlockchainRpcClient,
31}
32
33impl BaseRpcClient {
34 pub fn new(wss_rpc_url: String, proxy_url: Option<String>) -> Self {
35 let base_client =
36 CoreBlockchainRpcClient::new(chains::BASE.clone(), wss_rpc_url, proxy_url);
37
38 Self { base_client }
39 }
40}
41
42#[async_trait::async_trait]
43impl BlockchainRpcClient for BaseRpcClient {
44 async fn connect(&mut self) -> anyhow::Result<()> {
45 self.base_client.connect().await
46 }
47
48 async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
49 self.base_client.subscribe_blocks().await
50 }
51
52 async fn subscribe_pool_events(
53 &mut self,
54 event_type: RpcEventType,
55 addresses: &[Address],
56 event_signature: String,
57 ) -> Result<(), BlockchainRpcClientError> {
58 self.base_client
59 .subscribe_pool_events(event_type, addresses, event_signature)
60 .await
61 }
62
63 async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
64 self.base_client.unsubscribe_blocks().await
65 }
66
67 async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError> {
68 self.base_client.next_rpc_message().await
69 }
70
71 fn set_transport_backend(&mut self, backend: TransportBackend) {
72 self.base_client.set_transport_backend(backend);
73 }
74
75 fn set_socket_control(&mut self, control: SocketControl) {
76 self.base_client.set_socket_control(control);
77 }
78}