use js_export_macro::js_export;
use miden_client::account::AccountDelta as NativeAccountDelta;
use crate::models::account_id::AccountId;
use crate::models::felt::Felt;
use crate::platform::{JsBytes, JsErr};
use crate::utils::{deserialize_from_bytes, serialize_to_bytes};
#[derive(Clone)]
#[js_export]
pub struct AccountDelta(NativeAccountDelta);
pub mod storage;
pub mod vault;
use storage::AccountStorageDelta;
use vault::AccountVaultDelta;
#[js_export]
impl AccountDelta {
pub fn serialize(&self) -> JsBytes {
serialize_to_bytes(&self.0)
}
pub fn deserialize(bytes: JsBytes) -> Result<AccountDelta, JsErr> {
deserialize_from_bytes::<NativeAccountDelta>(&bytes).map(AccountDelta)
}
pub fn id(&self) -> AccountId {
self.0.id().into()
}
#[js_export(js_name = "isEmpty")]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn storage(&self) -> AccountStorageDelta {
self.0.storage().into()
}
pub fn vault(&self) -> AccountVaultDelta {
self.0.vault().into()
}
#[js_export(js_name = "nonceDelta")]
pub fn nonce_delta(&self) -> Felt {
self.0.nonce_delta().into()
}
}
impl From<NativeAccountDelta> for AccountDelta {
fn from(native_account_delta: NativeAccountDelta) -> Self {
AccountDelta(native_account_delta)
}
}
impl From<&NativeAccountDelta> for AccountDelta {
fn from(native_account_delta: &NativeAccountDelta) -> Self {
AccountDelta(native_account_delta.clone())
}
}
impl From<AccountDelta> for NativeAccountDelta {
fn from(account_delta: AccountDelta) -> Self {
account_delta.0
}
}
impl From<&AccountDelta> for NativeAccountDelta {
fn from(account_delta: &AccountDelta) -> Self {
account_delta.0.clone()
}
}