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 6f7da33
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ 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 37 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-L37

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

Check warning on line 40 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#L40

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

Check warning on line 44 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#L42-L44

Added lines #L42 - L44 were not covered by tests
} else {
None
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FeeStatement {
#[serde(deserialize_with = "deserialize_from_string")]
Expand Down
23 changes: 23 additions & 0 deletions rust/processor/src/processors/fungible_asset_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ use diesel::{
use rayon::prelude::*;
use std::fmt::Debug;
use tracing::error;
use crate::db::postgres::models::coin_models::coin_utils::EventGuidResource;
use crate::db::postgres::models::fungible_asset_models::v2_fungible_asset_utils::CoinStoreDeletionEvent;

pub struct FungibleAssetProcessor {
connection_pool: ArcDbPool,
Expand Down Expand Up @@ -683,6 +685,27 @@ pub async fn parse_v2_coin(
fungible_asset_activities.push(gas_event);
}

// The CoinStoreDeletionEvent, only need for v1 with migration
if let Some(_) = user_request {
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 705 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#L695-L705

Added lines #L695 - L705 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 @@ -41,6 +41,9 @@ use chrono::NaiveDateTime;
use kanal::AsyncSender;
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, time::Duration};
use crate::db::postgres::models::coin_models::coin_utils::CoinResource::CoinStoreDeletion;
use crate::db::postgres::models::coin_models::coin_utils::EventGuidResource;
use crate::db::postgres::models::fungible_asset_models::v2_fungible_asset_utils::CoinStoreDeletionEvent;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -318,6 +321,27 @@ async fn parse_activities(
.or_insert(1);
}

// The CoinStoreDeletionEvent, only need for v1 with migration
if let Some(_) = user_request {
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 343 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-L343

Added lines #L325 - L343 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 6f7da33

Please sign in to comment.