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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use super::*;
use std::collections::BTreeMap;

#[derive(Debug)]
pub struct Account {
    pub comment: Option<String>,
    pub nonce: U64Value,
    pub balance: BigUintValue,
    pub storage: BTreeMap<BytesKey, BytesValue>,
    pub code: Option<BytesValue>,
}

impl InterpretableFrom<AccountRaw> for Account {
    fn interpret_from(from: AccountRaw, context: &InterpreterContext) -> Self {
        Account {
            comment: from.comment,
            nonce: U64Value::interpret_from(from.nonce, context),
            balance: BigUintValue::interpret_from(from.balance, context),
            storage: from.storage.into_iter().map(|(k, v)| (
                BytesKey::interpret_from(k, context), 
                BytesValue::interpret_from(v, context))).collect(),
            code: from.code.map(|c| BytesValue::interpret_from(c, context)),
        }
    }
}

#[derive(Debug)]
pub enum CheckStorage {
    Star,
    Equal(BTreeMap<BytesKey, CheckValue<BytesValue>>),
}

impl InterpretableFrom<CheckStorageRaw> for CheckStorage {
    fn interpret_from(from: CheckStorageRaw, context: &InterpreterContext) -> Self {
        match from {
            CheckStorageRaw::Star => CheckStorage::Star,
            CheckStorageRaw::Equal(m) => CheckStorage::Equal(
                m.into_iter().map(|(k, v)| (
                    BytesKey::interpret_from(k, context), 
                    CheckValue::<BytesValue>::interpret_from(v, context))).collect(),
            )
        }
    }
}

impl CheckStorage {
    pub fn is_star(&self) -> bool {
        matches!(self, CheckStorage::Star)
    }
}

#[derive(Debug)]
pub struct CheckAccount {
    pub comment: Option<String>,
    pub nonce: CheckValue<U64Value>,
    pub balance: CheckValue<BigUintValue>,
    pub storage: CheckStorage,
    pub code: Option<CheckValue<BytesValue>>,
    pub async_call_data: CheckValue<BytesValue>,
}

impl InterpretableFrom<CheckAccountRaw> for CheckAccount {
    fn interpret_from(from: CheckAccountRaw, context: &InterpreterContext) -> Self {
        CheckAccount {
            comment: from.comment,
            nonce: CheckValue::<U64Value>::interpret_from(from.nonce, context),
            balance: CheckValue::<BigUintValue>::interpret_from(from.balance, context),
            storage: CheckStorage::interpret_from(from.storage, context),
            code: from.code.map(|c| CheckValue::<BytesValue>::interpret_from(c, context)),
            async_call_data: CheckValue::<BytesValue>::interpret_from(from.async_call_data, context),
        }
    }
}

#[derive(Debug)]
pub struct CheckAccounts {
    pub other_accounts_allowed: bool,
    pub accounts: BTreeMap<AddressKey, CheckAccount>
}

impl InterpretableFrom<CheckAccountsRaw> for CheckAccounts {
    fn interpret_from(from: CheckAccountsRaw, context: &InterpreterContext) -> Self {
        CheckAccounts {
            other_accounts_allowed: from.other_accounts_allowed,
            accounts: from.accounts.into_iter().map(|(k, v)| (
                AddressKey::interpret_from(k, context), 
                CheckAccount::interpret_from(v, context))).collect(),
        }
    }
}