nautilus_blockchain/rpc/chains/
ethereum.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 EthereumRpcClient {
26 base_client: CoreBlockchainRpcClient,
27}
28
29impl EthereumRpcClient {
30 pub fn new(wss_rpc_url: String, proxy_url: Option<String>) -> Self {
31 let base_client =
32 CoreBlockchainRpcClient::new(chains::ETHEREUM.clone(), wss_rpc_url, proxy_url);
33
34 Self { base_client }
35 }
36}
37
38#[async_trait::async_trait]
39impl BlockchainRpcClient for EthereumRpcClient {
40 async fn connect(&mut self) -> anyhow::Result<()> {
41 self.base_client.connect().await
42 }
43
44 async fn subscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
45 self.base_client.subscribe_blocks().await
46 }
47
48 async fn unsubscribe_blocks(&mut self) -> Result<(), BlockchainRpcClientError> {
49 self.base_client.unsubscribe_blocks().await
50 }
51
52 async fn next_rpc_message(&mut self) -> Result<BlockchainMessage, BlockchainRpcClientError> {
53 self.base_client.next_rpc_message().await
54 }
55
56 fn set_transport_backend(&mut self, backend: TransportBackend) {
57 self.base_client.set_transport_backend(backend);
58 }
59}