Skip to content

Commit

Permalink
include missing function for provider
Browse files Browse the repository at this point in the history
  • Loading branch information
thetheveloper committed Jun 15, 2024
1 parent 050a329 commit e3a9eec
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
44 changes: 43 additions & 1 deletion starknet-providers/src/any.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use serde::Serialize;
use starknet_core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction,
BroadcastedDeployAccountTransaction, BroadcastedInvokeTransaction, BroadcastedTransaction,
Expand All @@ -11,7 +12,7 @@ use starknet_core::types::{
};

use crate::{
jsonrpc::{HttpTransport, JsonRpcClient},
jsonrpc::{HttpTransport, JsonRpcClient, JsonRpcMethod},
Provider, ProviderError, SequencerGatewayProvider,
};

Expand Down Expand Up @@ -667,4 +668,45 @@ impl Provider for AnyProvider {
}
}
}

async fn batch_requests<I, P>(
&self,
requests: I,
) -> Result<Vec<serde_json::Value>, ProviderError>
where
I: IntoIterator<Item = (JsonRpcMethod, P)> + Send + Sync,
P: Serialize + Send + Sync,
{
match self {
Self::JsonRpcHttp(inner) => {
<JsonRpcClient<HttpTransport> as Provider>::batch_requests(inner, requests).await
}
Self::SequencerGateway(inner) => {
<SequencerGatewayProvider as Provider>::batch_requests(inner, requests).await
}
}
}
async fn get_block_with_tx_hashes_batch<B>(
&self,
block_ids: Vec<B>,
) -> Result<Vec<MaybePendingBlockWithTxHashes>, ProviderError>
where
B: AsRef<BlockId> + Send + Sync,
{
match self {
Self::JsonRpcHttp(inner) => {
<JsonRpcClient<HttpTransport> as Provider>::get_block_with_tx_hashes_batch(
inner, block_ids,
)
.await
}
Self::SequencerGateway(inner) => {
<SequencerGatewayProvider as Provider>::get_block_with_tx_hashes_batch(
inner, block_ids,
)
.await
}
}
}

}
18 changes: 18 additions & 0 deletions starknet-providers/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use auto_impl::auto_impl;
use serde::Serialize;
use starknet_core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction,
BroadcastedDeployAccountTransaction, BroadcastedInvokeTransaction, BroadcastedTransaction,
Expand All @@ -12,6 +13,8 @@ use starknet_core::types::{
};
use std::{any::Any, error::Error, fmt::Debug};

use crate::jsonrpc::JsonRpcMethod;

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[auto_impl(&, Box, Arc)]
Expand Down Expand Up @@ -298,6 +301,21 @@ pub trait Provider {
Err(ProviderError::ArrayLengthMismatch)
}
}

async fn batch_requests<I, P>(
&self,
requests: I,
) -> Result<Vec<serde_json::Value>, ProviderError>
where
I: IntoIterator<Item = (JsonRpcMethod, P)> + Send + Sync,
P: Serialize + Send + Sync;

async fn get_block_with_tx_hashes_batch<B>(
&self,
block_ids: Vec<B>,
) -> Result<Vec<MaybePendingBlockWithTxHashes>, ProviderError>
where
B: AsRef<BlockId> + Send + Sync;
}

/// Trait for implementation-specific error type. These errors are irrelevant in most cases,
Expand Down

0 comments on commit e3a9eec

Please sign in to comment.