-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement JsonRpc transport for batch requests
- Loading branch information
1 parent
56177d2
commit 9e898e8
Showing
7 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use starknet::{ | ||
core::types::{BlockId, BlockTag}, | ||
providers::{ | ||
jsonrpc::{HttpTransport, JsonRpcClient}, | ||
Provider, Url, | ||
}, | ||
}; | ||
use starknet_core::types::requests::{GetBlockWithTxHashesRequestRef, GetBlockWithTxsRequestRef}; | ||
use starknet_providers::jsonrpc::{JsonRpcMethod, JsonRpcRequestParams}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let provider = JsonRpcClient::new(HttpTransport::new( | ||
Url::parse("https://starknet-sepolia.public.blastapi.io/rpc/v0_7").unwrap(), | ||
)); | ||
|
||
let batch_mixed_results = provider.batch_requests(vec![(JsonRpcMethod::GetBlockWithTxHashes, JsonRpcRequestParams::GetBlockWithTxHashes(GetBlockWithTxHashesRequestRef { | ||
block_id: BlockId::Tag(BlockTag::Latest).as_ref(), | ||
})), (JsonRpcMethod::GetBlockWithTxs, JsonRpcRequestParams::GetBlockWithTxs(GetBlockWithTxsRequestRef { | ||
block_id: BlockId::Tag(BlockTag::Latest).as_ref(), | ||
}))]).await; | ||
|
||
match batch_mixed_results { | ||
Ok(v) => println!("{v:#?}"), | ||
Err(e) => println!("Error: {e:#?}"), | ||
} | ||
|
||
let batched_blocks = provider.get_block_with_tx_hashes_batch(vec![BlockId::Tag(BlockTag::Latest), BlockId::Tag(BlockTag::Latest)]).await; | ||
|
||
match batched_blocks { | ||
Ok(v) => println!("{v:#?}"), | ||
Err(e) => println!("Error: {e:#?}"), | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters