-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathmod.rs
52 lines (45 loc) · 1.69 KB
/
mod.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types::Block;
use raiko_lib::consts::SupportedChainSpecs;
use reth_primitives::revm_primitives::AccountInfo;
use std::collections::HashMap;
use crate::{
interfaces::{RaikoError, RaikoResult},
provider::rpc::RpcBlockDataProvider,
MerkleProof,
};
pub mod db;
pub mod persistent_map;
pub mod rpc;
#[allow(async_fn_in_trait)]
pub trait BlockDataProvider {
async fn get_blocks(&self, blocks_to_fetch: &[(u64, bool)]) -> RaikoResult<Vec<Block>>;
async fn get_accounts(&self, accounts: &[Address]) -> RaikoResult<Vec<AccountInfo>>;
async fn get_storage_values(&self, accounts: &[(Address, U256)]) -> RaikoResult<Vec<U256>>;
async fn get_merkle_proofs(
&self,
block_number: u64,
accounts: HashMap<Address, Vec<U256>>,
offset: usize,
num_storage_proofs: usize,
) -> RaikoResult<MerkleProof>;
}
pub async fn get_task_data(
network: &str,
block_number: u64,
chain_specs: &SupportedChainSpecs,
) -> RaikoResult<(u64, B256)> {
let taiko_chain_spec = chain_specs
.get_chain_spec(network)
.ok_or_else(|| RaikoError::InvalidRequestConfig("Unsupported raiko network".to_string()))?;
let provider = RpcBlockDataProvider::new(&taiko_chain_spec.rpc.clone(), block_number - 1)?;
let blocks = provider.get_blocks(&[(block_number, true)]).await?;
let block = blocks
.first()
.ok_or_else(|| RaikoError::RPC("No block for requested block number".to_string()))?;
let blockhash = block
.header
.hash
.ok_or_else(|| RaikoError::RPC("No block hash for requested block".to_string()))?;
Ok((taiko_chain_spec.chain_id, blockhash))
}