nautilus_blockchain/rpc/chains/
bsc.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 BscRpcClient {
30 base_client: CoreBlockchainRpcClient,
31}
32
33impl BscRpcClient {
34 pub fn new(wss_rpc_url: String, proxy_url: Option<String>) -> Self {
35 let base_client = CoreBlockchainRpcClient::new(chains::BSC.clone(), wss_rpc_url, proxy_url);
36
37 Self { base_client }
38 }
39}
40
41#[async_trait::async_trait]
42impl BlockchainRpcClient for BscRpcClient {
43 async fn connect(&mut self) -> anyhow::Result<()> {
44 self.base_client.connect().await
45 }
46
47 async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
48 self.base_client.subscribe_blocks().await
49 }
50
51 async fn subscribe_pool_events(
52 &mut self,
53 event_type: RpcEventType,
54 addresses: &[Address],
55 event_signature: String,
56 ) -> Result<(), BlockchainRpcClientError> {
57 self.base_client
58 .subscribe_pool_events(event_type, addresses, event_signature)
59 .await
60 }
61
62 async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
63 self.base_client.unsubscribe_blocks().await
64 }
65
66 async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError> {
67 self.base_client.next_rpc_message().await
68 }
69
70 fn set_transport_backend(&mut self, backend: TransportBackend) {
71 self.base_client.set_transport_backend(backend);
72 }
73
74 fn set_socket_control(&mut self, control: SocketControl) {
75 self.base_client.set_socket_control(control);
76 }
77}