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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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 esdt: Option<BTreeMap<BytesKey, BigUintValue>>,
	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(),
			esdt: from.esdt.map(|tree| {
				tree.into_iter()
					.map(|(k, v)| {
						(
							BytesKey::interpret_from(k, context),
							BigUintValue::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 enum CheckEsdt {
	Star,
	Equal(BTreeMap<BytesKey, CheckValue<BigUintValue>>),
}

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

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

#[derive(Debug)]
pub struct CheckAccount {
	pub comment: Option<String>,
	pub nonce: CheckValue<U64Value>,
	pub balance: CheckValue<BigUintValue>,
	pub storage: CheckStorage,
	pub esdt: Option<CheckEsdt>,
	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),
			esdt: from.esdt.map(|e| CheckEsdt::interpret_from(e, 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(),
		}
	}
}