-
Notifications
You must be signed in to change notification settings - Fork 103
/
batch.rs
36 lines (33 loc) · 1.12 KB
/
batch.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use starknet::providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderRequestData, ProviderResponseData, Url,
};
use starknet_core::types::{
requests::{BlockNumberRequest, GetBlockTransactionCountRequest},
BlockId,
};
#[tokio::main]
async fn main() {
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-sepolia.public.blastapi.io/rpc/v0_7").unwrap(),
));
let responses = provider
.batch_requests([
ProviderRequestData::BlockNumber(BlockNumberRequest),
ProviderRequestData::GetBlockTransactionCount(GetBlockTransactionCountRequest {
block_id: BlockId::Number(100),
}),
])
.await
.unwrap();
match (&responses[0], &responses[1]) {
(
ProviderResponseData::BlockNumber(block_number),
ProviderResponseData::GetBlockTransactionCount(count),
) => {
println!("The latest block is #{}", block_number);
println!("Block #100 has {} transactions", count);
}
_ => panic!("unexpected response type"),
}
}