From b9fb4c2c8d76a602c8bf590d917d0226110e42c4 Mon Sep 17 00:00:00 2001 From: Renee Tso <8248583+rtso@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:25:16 -0400 Subject: [PATCH] Revert "[fix] fix fa unrecognized v2 events (#445)" This reverts commit e2976d55291630f7e6fc6ce888a792a76af11ba1. --- .../v2_fungible_asset_activities.rs | 87 ++++++------------- .../v2_fungible_asset_utils.rs | 32 ------- 2 files changed, 25 insertions(+), 94 deletions(-) diff --git a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs index 80df475ab..c4ee7880b 100644 --- a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs +++ b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs @@ -72,36 +72,7 @@ impl FungibleAssetActivity { if let Some(fa_event) = &FungibleAssetEvent::from_event(event_type.as_str(), &event.data, txn_version)? { - let (storage_id, is_frozen, amount) = match fa_event { - FungibleAssetEvent::WithdrawEvent(inner) => ( - standardize_address(&event.key.as_ref().unwrap().account_address), - None, - Some(inner.amount.clone()), - ), - FungibleAssetEvent::DepositEvent(inner) => ( - standardize_address(&event.key.as_ref().unwrap().account_address), - None, - Some(inner.amount.clone()), - ), - FungibleAssetEvent::FrozenEvent(inner) => ( - standardize_address(&event.key.as_ref().unwrap().account_address), - Some(inner.frozen), - None, - ), - FungibleAssetEvent::WithdrawEventV2(inner) => ( - standardize_address(&inner.store), - None, - Some(inner.amount.clone()), - ), - FungibleAssetEvent::DepositEventV2(inner) => ( - standardize_address(&inner.store), - None, - Some(inner.amount.clone()), - ), - FungibleAssetEvent::FrozenEventV2(inner) => { - (standardize_address(&inner.store), Some(inner.frozen), None) - }, - }; + let storage_id = standardize_address(&event.key.as_ref().unwrap().account_address); // The event account address will also help us find fungible store which tells us where to find // the metadata @@ -110,6 +81,12 @@ impl FungibleAssetActivity { let fungible_asset = object_metadata.fungible_asset_store.as_ref().unwrap(); let asset_type = fungible_asset.metadata.get_reference_address(); + let (is_frozen, amount) = match fa_event { + FungibleAssetEvent::WithdrawEvent(inner) => (None, Some(inner.amount.clone())), + FungibleAssetEvent::DepositEvent(inner) => (None, Some(inner.amount.clone())), + FungibleAssetEvent::FrozenEvent(inner) => (Some(inner.frozen), None), + }; + return Ok(Some(Self { transaction_version: txn_version, event_index, @@ -145,47 +122,33 @@ impl FungibleAssetActivity { if let Some(inner) = CoinEvent::from_event(event.type_str.as_str(), &event.data, txn_version)? { - let (owner_address, amount, coin_type_option) = match inner { - CoinEvent::WithdrawCoinEvent(inner) => ( - standardize_address(&event.key.as_ref().unwrap().account_address), - inner.amount.clone(), - None, - ), - CoinEvent::DepositCoinEvent(inner) => ( - standardize_address(&event.key.as_ref().unwrap().account_address), - inner.amount.clone(), - None, - ), + let amount = match inner { + CoinEvent::WithdrawCoinEvent(inner) => inner.amount, + CoinEvent::DepositCoinEvent(inner) => inner.amount, }; - let coin_type = if let Some(coin_type) = coin_type_option { - coin_type - } else { - let event_key = event.key.as_ref().context("event must have a key")?; - let event_move_guid = EventGuidResource { - addr: standardize_address(event_key.account_address.as_str()), - creation_num: event_key.creation_number as i64, - }; - // Given this mapping only contains coin type < 1000 length, we should not assume that the mapping exists. - // If it doesn't exist, skip. - match event_to_coin_type.get(&event_move_guid) { - Some(coin_type) => coin_type.clone(), - None => { - tracing::warn!( + let event_key = event.key.as_ref().context("event must have a key")?; + let event_move_guid = EventGuidResource { + addr: standardize_address(event_key.account_address.as_str()), + creation_num: event_key.creation_number as i64, + }; + // Given this mapping only contains coin type < 1000 length, we should not assume that the mapping exists. + // If it doesn't exist, skip. + let coin_type = match event_to_coin_type.get(&event_move_guid) { + Some(coin_type) => coin_type.clone(), + None => { + tracing::warn!( "Could not find event in resources (CoinStore), version: {}, event guid: {:?}, mapping: {:?}", txn_version, event_move_guid, event_to_coin_type ); - return Ok(None); - }, - } + return Ok(None); + }, }; - let storage_id = - CoinInfoType::get_storage_id(coin_type.as_str(), owner_address.as_str()); - + CoinInfoType::get_storage_id(coin_type.as_str(), event_move_guid.addr.as_str()); Ok(Some(Self { transaction_version: txn_version, event_index, - owner_address, + owner_address: event_move_guid.addr, storage_id, asset_type: coin_type, is_frozen: None, diff --git a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_utils.rs b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_utils.rs index 3e5bc5fbe..5de2a9d49 100644 --- a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_utils.rs +++ b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_utils.rs @@ -274,26 +274,6 @@ pub struct FrozenEvent { pub frozen: bool, } -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct DepositEventV2 { - pub store: String, - #[serde(deserialize_with = "deserialize_from_string")] - pub amount: BigDecimal, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct WithdrawEventV2 { - pub store: String, - #[serde(deserialize_with = "deserialize_from_string")] - pub amount: BigDecimal, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct FrozenEventV2 { - pub store: String, - pub frozen: bool, -} - #[derive(Serialize, Deserialize, Debug, Clone)] pub enum V2FungibleAssetResource { FungibleAssetMetadata(FungibleAssetMetadata), @@ -358,9 +338,6 @@ pub enum FungibleAssetEvent { DepositEvent(DepositEvent), WithdrawEvent(WithdrawEvent), FrozenEvent(FrozenEvent), - DepositEventV2(DepositEventV2), - WithdrawEventV2(WithdrawEventV2), - FrozenEventV2(FrozenEventV2), } impl FungibleAssetEvent { @@ -375,15 +352,6 @@ impl FungibleAssetEvent { "0x1::fungible_asset::FrozenEvent" => { serde_json::from_str(data).map(|inner| Some(Self::FrozenEvent(inner))) }, - "0x1::fungible_asset::Deposit" => { - serde_json::from_str(data).map(|inner| Some(Self::DepositEventV2(inner))) - }, - "0x1::fungible_asset::Withdraw" => { - serde_json::from_str(data).map(|inner| Some(Self::WithdrawEventV2(inner))) - }, - "0x1::fungible_asset::Frozen" => { - serde_json::from_str(data).map(|inner| Some(Self::FrozenEventV2(inner))) - }, _ => Ok(None), } .context(format!(