nautilus_blockchain/rpc/chains/
bsc.rs1use nautilus_model::defi::chain::chains;
17use nautilus_network::websocket::TransportBackend;
18
19use crate::rpc::{
20 BlockchainRpcClient, core::CoreBlockchainRpcClient, error::BlockchainRpcClientError,
21 types::BlockchainMessage,
22};
23
24#[derive(Debug)]
25pub struct BscRpcClient {
26 base_client: CoreBlockchainRpcClient,
27}
28
29impl BscRpcClient {
30 pub fn new(wss_rpc_url: String, proxy_url: Option<String>) -> Self {
31 let base_client = CoreBlockchainRpcClient::new(chains::BSC.clone(), wss_rpc_url, proxy_url);
32
33 Self { base_client }
34 }
35}
36
37#[async_trait::async_trait]
38impl BlockchainRpcClient for BscRpcClient {
39 async fn connect(&mut self) -> anyhow::Result<()> {
40 self.base_client.connect().await
41 }
42
43 async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
44 self.base_client.subscribe_blocks().await
45 }
46
47 async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
48 self.base_client.unsubscribe_blocks().await
49 }
50
51 async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError> {
52 self.base_client.next_rpc_message().await
53 }
54
55 fn set_transport_backend(&mut self, backend: TransportBackend) {
56 self.base_client.set_transport_backend(backend);
57 }
58}