multiversx_sc_scenario/scenario/model/
block_info.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
use crate::scenario_format::{
    interpret_trait::{InterpretableFrom, InterpreterContext, IntoRaw},
    serde_raw::BlockInfoRaw,
};

use super::{BytesValue, U64Value};

#[derive(Debug, Default, Clone)]
pub struct BlockInfo {
    pub block_timestamp: Option<U64Value>,
    pub block_nonce: Option<U64Value>,
    pub block_round: Option<U64Value>,
    pub block_epoch: Option<U64Value>,
    pub block_random_seed: Option<BytesValue>,
}

impl InterpretableFrom<BlockInfoRaw> for BlockInfo {
    fn interpret_from(from: BlockInfoRaw, context: &InterpreterContext) -> Self {
        BlockInfo {
            block_timestamp: from
                .block_timestamp
                .map(|v| U64Value::interpret_from(v, context)),
            block_nonce: from
                .block_nonce
                .map(|v| U64Value::interpret_from(v, context)),
            block_round: from
                .block_round
                .map(|v| U64Value::interpret_from(v, context)),
            block_epoch: from
                .block_epoch
                .map(|v| U64Value::interpret_from(v, context)),
            block_random_seed: from
                .block_random_seed
                .map(|v| BytesValue::interpret_from(v, context)),
        }
    }
}

impl IntoRaw<BlockInfoRaw> for BlockInfo {
    fn into_raw(self) -> BlockInfoRaw {
        BlockInfoRaw {
            block_timestamp: self.block_timestamp.map(|value| value.original),
            block_nonce: self.block_nonce.map(|value| value.original),
            block_round: self.block_round.map(|value| value.original),
            block_epoch: self.block_epoch.map(|value| value.original),
            block_random_seed: self.block_random_seed.map(|value| value.original),
        }
    }
}