eest_types/
account_info.rs1use cfx_rpc_primitives::Bytes;
2use cfx_types::U256;
3use serde::Deserialize;
4use std::collections::HashMap;
5
6use super::deserializer::deserialize_str_as_u64;
7
8#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
10#[serde(rename_all = "camelCase", deny_unknown_fields)]
11pub struct AccountInfo {
12 pub balance: U256,
13 pub code: Bytes,
14 #[serde(deserialize_with = "deserialize_str_as_u64")]
15 pub nonce: u64,
16 pub storage: HashMap<U256, U256>,
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22
23 #[test]
24 fn deserialize_account_info() {
25 let json = r#"
26 {
27 "balance": "0x1",
28 "code": "0x1234",
29 "nonce": "0x2",
30 "storage": {
31 "0x1": "0x3",
32 "0x2": "0x4"
33 }
34 }
35 "#;
36
37 let account_info: AccountInfo = serde_json::from_str(json).unwrap();
38 assert_eq!(account_info.balance, U256::from(1));
39 assert_eq!(account_info.code, Bytes::from(vec![0x12, 0x34]));
40 assert_eq!(account_info.nonce, 2);
41 assert_eq!(
42 account_info.storage,
43 HashMap::from([
44 (U256::from(1), U256::from(3)),
45 (U256::from(2), U256::from(4))
46 ])
47 );
48 }
49}