multiversx_sc_scenario/scenario/model/account_data/
accounts_check.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
use std::collections::BTreeMap;

use crate::scenario_format::{
    interpret_trait::{InterpretableFrom, InterpreterContext, IntoRaw},
    serde_raw::CheckAccountsRaw,
};

use crate::scenario::model::AddressKey;

use super::CheckAccount;

#[derive(Debug, Default, Clone)]
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(),
        }
    }
}

impl IntoRaw<CheckAccountsRaw> for CheckAccounts {
    fn into_raw(self) -> CheckAccountsRaw {
        CheckAccountsRaw {
            other_accounts_allowed: self.other_accounts_allowed,
            accounts: self
                .accounts
                .into_iter()
                .map(|(k, v)| (k.into_raw(), Box::new(v.into_raw())))
                .collect(),
        }
    }
}