From c8acf02bbb194556553ad4072665b629cfd6cc66 Mon Sep 17 00:00:00 2001 From: Renee Tso <8248583+rtso@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:21:44 -0400 Subject: [PATCH] Documentation for FA processor (#546) --- .../v2_fungible_asset_activities.rs | 10 ++++++---- .../src/processors/fungible_asset_processor.rs | 15 ++++++++------- .../fungible_asset_extractor.rs | 1 + 3 files changed, 15 insertions(+), 11 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 f0e000aa7..29e625c52 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 @@ -103,14 +103,16 @@ impl FungibleAssetActivity { }, }; - // The event account address will also help us find fungible store which tells us where to find - // the metadata + // Lookup the event address in the object_aggregated_data_mapping to get additional metadata + // The events are emitted on the address of the fungible store. let maybe_object_metadata = object_aggregated_data_mapping.get(&storage_id); - // The ObjectCore might not exist in the transaction if the object got deleted + // Get the store's owner address from ObjectCore. + // The ObjectCore might not exist in the transaction if the object got deleted in the same transaction let maybe_owner_address = maybe_object_metadata .map(|metadata| &metadata.object.object_core) .map(|object_core| object_core.get_owner_address()); - // The FungibleStore might not exist in the transaction if it's a secondary store that got burnt + // Get the store's asset type + // The FungibleStore might not exist in the transaction if it's a secondary store that got burnt in the same transaction let maybe_asset_type = maybe_object_metadata .and_then(|metadata| metadata.fungible_asset_store.as_ref()) .map(|fa| fa.metadata.get_reference_address()); diff --git a/rust/processor/src/processors/fungible_asset_processor.rs b/rust/processor/src/processors/fungible_asset_processor.rs index fdd68ff17..2b288d7bf 100644 --- a/rust/processor/src/processors/fungible_asset_processor.rs +++ b/rust/processor/src/processors/fungible_asset_processor.rs @@ -476,7 +476,7 @@ pub async fn parse_v2_coin( let mut current_fungible_asset_balances: CurrentFungibleAssetMapping = AHashMap::new(); let mut fungible_asset_metadata: FungibleAssetMetadataMapping = AHashMap::new(); - // Get Metadata for fungible assets by object + // Get Metadata for fungible assets by object address let mut fungible_asset_object_helper: ObjectAggregatedDataMapping = AHashMap::new(); let txn_version = txn.version as i64; @@ -523,8 +523,8 @@ pub async fn parse_v2_coin( // the event to the resource using the event guid let mut event_to_v1_coin_type: EventToCoinType = AHashMap::new(); - // First loop to get all objects - // Need to do a first pass to get all the objects + // Loop 1: to get all object addresses + // Need to do a first pass to get all the object addresses and insert them into the helper for wsc in transaction_info.changes.iter() { if let Change::WriteResource(wr) = wsc.change.as_ref().unwrap() { if let Some(object) = @@ -540,7 +540,7 @@ pub async fn parse_v2_coin( } } } - // Loop to get the metadata relevant to parse v1 and v2. + // Loop 2: Get the metadata relevant to parse v1 coin and v2 fungible asset. // As an optimization, we also handle v1 balances in the process for (index, wsc) in transaction_info.changes.iter().enumerate() { if let Change::WriteResource(write_resource) = wsc.change.as_ref().unwrap() { @@ -558,7 +558,8 @@ pub async fn parse_v2_coin( .insert(current_balance.storage_id.clone(), current_balance.clone()); event_to_v1_coin_type.extend(event_to_coin); } - // Fill the v2 object metadata + // Fill the v2 fungible_asset_object_helper. This is used to track which objects exist at each object address. + // The data will be used to reconstruct the full data in Loop 4. let address = standardize_address(&write_resource.address.to_string()); if let Some(aggregated_data) = fungible_asset_object_helper.get_mut(&address) { if let Some(fungible_asset_metadata) = @@ -643,7 +644,7 @@ pub async fn parse_v2_coin( fungible_asset_activities.push(gas_event); } - // Loop to handle events and collect additional metadata from events for v2 + // Loop 3 to handle events and collect additional metadata from events for v2 for (index, event) in events.iter().enumerate() { if let Some(v1_activity) = FungibleAssetActivity::get_v1_from_event( event, @@ -685,7 +686,7 @@ pub async fn parse_v2_coin( } } - // Loop to handle all the other changes + // Loop 4 to handle write set changes for metadata, balance, and v1 supply for (index, wsc) in transaction_info.changes.iter().enumerate() { match wsc.change.as_ref().unwrap() { Change::WriteResource(write_resource) => { diff --git a/rust/sdk-processor/src/steps/fungible_asset_processor/fungible_asset_extractor.rs b/rust/sdk-processor/src/steps/fungible_asset_processor/fungible_asset_extractor.rs index 8a3d1b61b..cd4a51a6d 100644 --- a/rust/sdk-processor/src/steps/fungible_asset_processor/fungible_asset_extractor.rs +++ b/rust/sdk-processor/src/steps/fungible_asset_processor/fungible_asset_extractor.rs @@ -20,6 +20,7 @@ use processor::{ processors::fungible_asset_processor::parse_v2_coin, }; +/// Extracts fungible asset events, metadata, balances, and v1 supply from transactions pub struct FungibleAssetExtractor where Self: Sized + Send + 'static, {}