Skip to content

Commit

Permalink
add coin_store_deletion_event info to event_to_coin_type map
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Jan 23, 2025
1 parent 1ca4c42 commit ff04a33
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ use serde::{Deserialize, Serialize};
const FUNGIBLE_ASSET_LENGTH: usize = 32;
const FUNGIBLE_ASSET_SYMBOL: usize = 10;

#[derive(Serialize, Deserialize, Debug, Clone)]

Check warning on line 23 in rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs#L23

Added line #L23 was not covered by tests
pub struct CoinStoreDeletionEvent {
pub coin_type: String,
pub event_handle_creation_address: String,
#[serde(deserialize_with = "deserialize_from_string")]
pub deleted_deposit_event_handle_creation_number: u64,
#[serde(deserialize_with = "deserialize_from_string")]
pub deleted_withdraw_event_handle_creation_number: u64,
}

impl CoinStoreDeletionEvent {
pub fn from_event(data_type: &str, data: &str, txn_version: i64) -> Option<Self> {
if data_type == "0x1::coin::CoinStoreDeletion" {
let coin_store_deletion: CoinStoreDeletionEvent = serde_json::from_str(data)
.unwrap_or_else(|_| {
tracing::error!(

Check warning on line 38 in rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs#L36-L38

Added lines #L36 - L38 were not covered by tests
transaction_version = txn_version,
data = data,
"failed to parse event for coin store deletion"

Check warning on line 41 in rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs#L41

Added line #L41 was not covered by tests
);
panic!();
});
Some(coin_store_deletion)

Check warning on line 45 in rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/postgres/models/fungible_asset_models/v2_fungible_asset_utils.rs#L43-L45

Added lines #L43 - L45 were not covered by tests
} else {
None
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FeeStatement {
#[serde(deserialize_with = "deserialize_from_string")]
Expand Down
33 changes: 31 additions & 2 deletions rust/processor/src/processors/fungible_asset_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use crate::{
},
},
postgres::models::{
coin_models::coin_supply::CoinSupply,
coin_models::{coin_supply::CoinSupply, coin_utils::EventGuidResource},
fungible_asset_models::{
v2_fungible_asset_activities::{EventToCoinType, FungibleAssetActivity},
v2_fungible_asset_balances::{
CurrentFungibleAssetBalance, CurrentUnifiedFungibleAssetBalance,
FungibleAssetBalance,
},
v2_fungible_asset_utils::FeeStatement,
v2_fungible_asset_utils::{CoinStoreDeletionEvent, FeeStatement},
v2_fungible_metadata::FungibleAssetMetadataModel,
},
resources::{FromWriteResource, V2FungibleAssetResource},
Expand Down Expand Up @@ -683,6 +683,35 @@ pub async fn parse_v2_coin(
fungible_asset_activities.push(gas_event);
}

// The CoinStoreDeletionEvent, only need for v1 with migration
if user_request.is_some() {
let coin_store_deletion_event = events.iter().find_map(|event| {
let event_type = event.type_str.as_str();
CoinStoreDeletionEvent::from_event(event_type, &event.data, txn_version)
});
if let Some(coin_store_deletion) = coin_store_deletion_event {
let addr = standardize_address(
coin_store_deletion.event_handle_creation_address.as_str(),
);
let deposit_event_guid = EventGuidResource {
addr: addr.clone(),
creation_num: coin_store_deletion
.deleted_deposit_event_handle_creation_number
as i64,
};
let withdraw_event_guid = EventGuidResource {
addr,
creation_num: coin_store_deletion
.deleted_withdraw_event_handle_creation_number
as i64,
};
event_to_v1_coin_type
.insert(deposit_event_guid, coin_store_deletion.coin_type.clone());
event_to_v1_coin_type
.insert(withdraw_event_guid, coin_store_deletion.coin_type);

Check warning on line 711 in rust/processor/src/processors/fungible_asset_processor.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/processors/fungible_asset_processor.rs#L693-L711

Added lines #L693 - L711 were not covered by tests
};
}

// 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) = RawFungibleAssetActivity::get_v1_from_event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use crate::{
},
parquet::models::fungible_asset_models::parquet_v2_fungible_asset_activities::FungibleAssetActivity,
postgres::models::{
fungible_asset_models::v2_fungible_asset_utils::FeeStatement,
coin_models::coin_utils::EventGuidResource,
fungible_asset_models::v2_fungible_asset_utils::{
CoinStoreDeletionEvent, FeeStatement,
},
resources::{FromWriteResource, V2FungibleAssetResource},
},
},
Expand Down Expand Up @@ -318,6 +321,35 @@ async fn parse_activities(
.or_insert(1);
}

// The CoinStoreDeletionEvent, only need for v1 with migration
if user_request.is_some() {
let coin_store_deletion_event = events.iter().find_map(|event| {
let event_type = event.type_str.as_str();
CoinStoreDeletionEvent::from_event(event_type, &event.data, txn_version)
});
if let Some(coin_store_deletion) = coin_store_deletion_event {
let addr = standardize_address(
coin_store_deletion.event_handle_creation_address.as_str(),
);
let deposit_event_guid = EventGuidResource {
addr: addr.clone(),
creation_num: coin_store_deletion
.deleted_deposit_event_handle_creation_number
as i64,
};
let withdraw_event_guid = EventGuidResource {
addr,
creation_num: coin_store_deletion
.deleted_withdraw_event_handle_creation_number
as i64,
};
event_to_v1_coin_type
.insert(deposit_event_guid, coin_store_deletion.coin_type.clone());
event_to_v1_coin_type
.insert(withdraw_event_guid, coin_store_deletion.coin_type);
};
}

Check warning on line 351 in rust/processor/src/processors/parquet_processors/parquet_fungible_asset_activities_processor.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/processors/parquet_processors/parquet_fungible_asset_activities_processor.rs#L325-L351

Added lines #L325 - L351 were not covered by tests

// Loop to handle events and collect additional metadata from events for v2
for (index, event) in events.iter().enumerate() {
if let Some(v1_activity) = RawFungibleAssetActivity::get_v1_from_event(
Expand Down

0 comments on commit ff04a33

Please sign in to comment.