use crate::num_bigint::BigUint;
use alloc::vec::Vec;
use dharitri_wasm::types::heap::Address;
use std::{collections::HashMap, fmt, fmt::Write};
use crate::key_hex;
use super::AccountDct;
pub type AccountStorage = HashMap<Vec<u8>, Vec<u8>>;
#[derive(Clone, Debug)]
pub struct AccountData {
pub address: Address,
pub nonce: u64,
pub moax_balance: BigUint,
pub dct: AccountDct,
pub storage: AccountStorage,
pub username: Vec<u8>,
pub contract_path: Option<Vec<u8>>,
pub contract_owner: Option<Address>,
pub developer_rewards: BigUint,
}
impl fmt::Display for AccountData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut storage_buf = String::new();
let mut storage_keys: Vec<Vec<u8>> = self.storage.keys().cloned().collect();
storage_keys.sort();
for key in &storage_keys {
let value = self.storage.get(key).unwrap();
write!(
storage_buf,
"\n\t\t\t{} -> 0x{}",
key_hex(key.as_slice()),
hex::encode(value.as_slice())
)
.unwrap();
}
write!(
f,
"AccountData {{
nonce: {},
balance: {},
dct: [{} ],
username: {},
storage: [{} ],
developerRewards: {},
}}",
self.nonce,
self.moax_balance,
self.dct,
String::from_utf8(self.username.clone()).unwrap(),
storage_buf,
self.developer_rewards
)
}
}