hdp_primitives/task/datalake/block_sampled/
rand.rs

1use std::str::FromStr;
2
3use alloy::primitives::{Address, B256, U256};
4use rand::{
5    distributions::{Distribution, Standard},
6    Rng,
7};
8
9use crate::task::datalake::DatalakeField;
10
11use super::{AccountField, BlockSampledCollection, HeaderField};
12
13impl Distribution<BlockSampledCollection> for Standard {
14    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> BlockSampledCollection {
15        let index: u8 = rng.gen_range(0..3);
16        let rand_account = Address::from_str("0x7f2c6f930306d3aa736b3a6c6a98f512f74036d4").unwrap();
17        let rand_account_for_storage =
18            Address::from_str("0x75CeC1db9dCeb703200EAa6595f66885C962B920").unwrap();
19        let storage_index = rng.gen_range(0..5);
20        let storage_key = B256::from(U256::from(storage_index));
21        match index {
22            0 => BlockSampledCollection::Header(self.sample(rng)),
23            1 => BlockSampledCollection::Account(rand_account, self.sample(rng)),
24            2 => BlockSampledCollection::Storage(rand_account_for_storage, storage_key),
25            _ => unreachable!(),
26        }
27    }
28}
29
30impl Distribution<HeaderField> for Standard {
31    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> HeaderField {
32        let index = rng.gen_range(0..=8);
33        HeaderField::integer_variants_index(index)
34    }
35}
36
37impl Distribution<AccountField> for Standard {
38    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> AccountField {
39        let index: u8 = rng.gen_range(0..=1_u8);
40        AccountField::from_index(index).unwrap()
41    }
42}