Skip to content

Commit

Permalink
Adding ConcurrentFugibleAssetBalance support
Browse files Browse the repository at this point in the history
  • Loading branch information
vusirikala committed Apr 3, 2024
1 parent f41ee8b commit 5271672
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#![allow(clippy::unused_unit)]

use super::{
v2_fungible_asset_activities::EventToCoinType, v2_fungible_asset_utils::FungibleAssetStore,
v2_fungible_asset_activities::EventToCoinType,
v2_fungible_asset_utils::{ConcurrentFungibleAssetBalance, FungibleAssetStore},
v2_fungible_metadata::FungibleAssetMetadataModel,
};
use crate::{
Expand Down Expand Up @@ -94,6 +95,15 @@ impl FungibleAssetBalance {
}
let is_primary = Self::is_primary(&owner_address, &asset_type, &storage_id);

let concurrent_balance: Option<BigDecimal> =
ConcurrentFungibleAssetBalance::from_write_resource(
write_resource,
txn_version,
)
.ok()
.and_then(|balance| balance.map(|b| Some(b.balance.value.clone())))
.unwrap_or(None);

let coin_balance = Self {
transaction_version: txn_version,
write_set_change_index,
Expand All @@ -102,7 +112,9 @@ impl FungibleAssetBalance {
asset_type: asset_type.clone(),
is_primary,
is_frozen: inner.frozen,
amount: inner.balance.clone(),
amount: concurrent_balance
.clone()
.unwrap_or_else(|| inner.balance.clone()),
transaction_timestamp: txn_timestamp,
token_standard: TokenStandard::V2.to_string(),
};
Expand All @@ -112,7 +124,7 @@ impl FungibleAssetBalance {
asset_type: asset_type.clone(),
is_primary,
is_frozen: inner.frozen,
amount: inner.balance.clone(),
amount: concurrent_balance.unwrap_or_else(|| inner.balance.clone()),
last_transaction_version: txn_version,
last_transaction_timestamp: txn_timestamp,
token_standard: TokenStandard::V2.to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl FungibleAssetSupply {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ConcurrentFungibleAssetSupply {
pub aggregator: AggregatorU128,
pub current: AggregatorU128,
}

impl ConcurrentFungibleAssetSupply {
Expand Down Expand Up @@ -224,7 +224,7 @@ impl ConcurrentFungibleAssetSupply {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ConcurrentFungibleAssetBalance {
pub aggregator: AggregatorU64,
pub balance: AggregatorU64,
}

impl ConcurrentFungibleAssetBalance {
Expand Down Expand Up @@ -317,7 +317,7 @@ impl V2FungibleAssetResource {
serde_json::from_value(data.clone())
.map(|inner| Some(Self::FungibleAssetStore(inner)))
},
x if x == format!("{}::fungible_asset::ConcurrentBalance", COIN_ADDR) => {
x if x == format!("{}::fungible_asset::ConcurrentFungibleBalance", COIN_ADDR) => {
serde_json::from_value(data.clone())
.map(|inner| Some(Self::ConcurrentFungibleAssetBalance(inner)))
},
Expand Down

0 comments on commit 5271672

Please sign in to comment.