nautilus_blockchain/rpc/chains/
polygon.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
16use 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}