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