|
| 1 | +use miden_objects::account::{ |
| 2 | + AccountId as NativeAccountId, FungibleAssetDelta as NativeFungibleAssetDelta, |
| 3 | +}; |
| 4 | +use wasm_bindgen::prelude::*; |
| 5 | + |
| 6 | +use super::account_id::AccountId; |
| 7 | + |
| 8 | +#[derive(Clone)] |
| 9 | +#[wasm_bindgen] |
| 10 | +pub struct FungibleAssetDeltaItem { |
| 11 | + faucet_id: AccountId, |
| 12 | + amount: i64, |
| 13 | +} |
| 14 | + |
| 15 | +#[wasm_bindgen] |
| 16 | +impl FungibleAssetDeltaItem { |
| 17 | + #[wasm_bindgen(getter, js_name = "faucetId")] |
| 18 | + pub fn faucet_id(&self) -> AccountId { |
| 19 | + self.faucet_id |
| 20 | + } |
| 21 | + |
| 22 | + #[wasm_bindgen(getter)] |
| 23 | + pub fn amount(&self) -> i64 { |
| 24 | + self.amount |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +impl From<(&NativeAccountId, &i64)> for FungibleAssetDeltaItem { |
| 29 | + fn from(native_fungible_asset_delta_item: (&NativeAccountId, &i64)) -> Self { |
| 30 | + Self { |
| 31 | + faucet_id: (*native_fungible_asset_delta_item.0).into(), |
| 32 | + amount: *native_fungible_asset_delta_item.1, |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +#[derive(Clone)] |
| 38 | +#[wasm_bindgen] |
| 39 | +pub struct FungibleAssetDelta(NativeFungibleAssetDelta); |
| 40 | + |
| 41 | +#[wasm_bindgen] |
| 42 | +impl FungibleAssetDelta { |
| 43 | + #[wasm_bindgen(js_name = "numAssets")] |
| 44 | + pub fn num_assets(&self) -> usize { |
| 45 | + self.0.num_assets() |
| 46 | + } |
| 47 | + |
| 48 | + #[wasm_bindgen(js_name = "isEmpty")] |
| 49 | + pub fn is_empty(&self) -> bool { |
| 50 | + self.0.is_empty() |
| 51 | + } |
| 52 | + |
| 53 | + pub fn assets(&self) -> Vec<FungibleAssetDeltaItem> { |
| 54 | + self.0.iter().map(Into::into).collect() |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// CONVERSIONS |
| 59 | +// ================================================================================================ |
| 60 | + |
| 61 | +impl From<NativeFungibleAssetDelta> for FungibleAssetDelta { |
| 62 | + fn from(native_fungible_asset_delta: NativeFungibleAssetDelta) -> Self { |
| 63 | + FungibleAssetDelta(native_fungible_asset_delta) |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +impl From<&NativeFungibleAssetDelta> for FungibleAssetDelta { |
| 68 | + fn from(native_fungible_asset_delta: &NativeFungibleAssetDelta) -> Self { |
| 69 | + FungibleAssetDelta(native_fungible_asset_delta.clone()) |
| 70 | + } |
| 71 | +} |
0 commit comments