Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rtso committed Oct 23, 2024
1 parent 4cc90a3 commit 7c21f9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 8 additions & 7 deletions rust/processor/src/processors/fungible_asset_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) =
Expand All @@ -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() {
Expand All @@ -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) =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}
Expand Down

0 comments on commit 7c21f9f

Please sign in to comment.