Skip to content

Commit ff04a33

Browse files
committed
add coin_store_deletion_event info to event_to_coin_type map
1 parent 1ca4c42 commit ff04a33

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ use serde::{Deserialize, Serialize};
2020
const FUNGIBLE_ASSET_LENGTH: usize = 32;
2121
const FUNGIBLE_ASSET_SYMBOL: usize = 10;
2222

23+
#[derive(Serialize, Deserialize, Debug, Clone)]
24+
pub struct CoinStoreDeletionEvent {
25+
pub coin_type: String,
26+
pub event_handle_creation_address: String,
27+
#[serde(deserialize_with = "deserialize_from_string")]
28+
pub deleted_deposit_event_handle_creation_number: u64,
29+
#[serde(deserialize_with = "deserialize_from_string")]
30+
pub deleted_withdraw_event_handle_creation_number: u64,
31+
}
32+
33+
impl CoinStoreDeletionEvent {
34+
pub fn from_event(data_type: &str, data: &str, txn_version: i64) -> Option<Self> {
35+
if data_type == "0x1::coin::CoinStoreDeletion" {
36+
let coin_store_deletion: CoinStoreDeletionEvent = serde_json::from_str(data)
37+
.unwrap_or_else(|_| {
38+
tracing::error!(
39+
transaction_version = txn_version,
40+
data = data,
41+
"failed to parse event for coin store deletion"
42+
);
43+
panic!();
44+
});
45+
Some(coin_store_deletion)
46+
} else {
47+
None
48+
}
49+
}
50+
}
51+
2352
#[derive(Serialize, Deserialize, Debug, Clone)]
2453
pub struct FeeStatement {
2554
#[serde(deserialize_with = "deserialize_from_string")]

rust/processor/src/processors/fungible_asset_processor.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ use crate::{
2525
},
2626
},
2727
postgres::models::{
28-
coin_models::coin_supply::CoinSupply,
28+
coin_models::{coin_supply::CoinSupply, coin_utils::EventGuidResource},
2929
fungible_asset_models::{
3030
v2_fungible_asset_activities::{EventToCoinType, FungibleAssetActivity},
3131
v2_fungible_asset_balances::{
3232
CurrentFungibleAssetBalance, CurrentUnifiedFungibleAssetBalance,
3333
FungibleAssetBalance,
3434
},
35-
v2_fungible_asset_utils::FeeStatement,
35+
v2_fungible_asset_utils::{CoinStoreDeletionEvent, FeeStatement},
3636
v2_fungible_metadata::FungibleAssetMetadataModel,
3737
},
3838
resources::{FromWriteResource, V2FungibleAssetResource},
@@ -683,6 +683,35 @@ pub async fn parse_v2_coin(
683683
fungible_asset_activities.push(gas_event);
684684
}
685685

686+
// The CoinStoreDeletionEvent, only need for v1 with migration
687+
if user_request.is_some() {
688+
let coin_store_deletion_event = events.iter().find_map(|event| {
689+
let event_type = event.type_str.as_str();
690+
CoinStoreDeletionEvent::from_event(event_type, &event.data, txn_version)
691+
});
692+
if let Some(coin_store_deletion) = coin_store_deletion_event {
693+
let addr = standardize_address(
694+
coin_store_deletion.event_handle_creation_address.as_str(),
695+
);
696+
let deposit_event_guid = EventGuidResource {
697+
addr: addr.clone(),
698+
creation_num: coin_store_deletion
699+
.deleted_deposit_event_handle_creation_number
700+
as i64,
701+
};
702+
let withdraw_event_guid = EventGuidResource {
703+
addr,
704+
creation_num: coin_store_deletion
705+
.deleted_withdraw_event_handle_creation_number
706+
as i64,
707+
};
708+
event_to_v1_coin_type
709+
.insert(deposit_event_guid, coin_store_deletion.coin_type.clone());
710+
event_to_v1_coin_type
711+
.insert(withdraw_event_guid, coin_store_deletion.coin_type);
712+
};
713+
}
714+
686715
// Loop 3 to handle events and collect additional metadata from events for v2
687716
for (index, event) in events.iter().enumerate() {
688717
if let Some(v1_activity) = RawFungibleAssetActivity::get_v1_from_event(

rust/processor/src/processors/parquet_processors/parquet_fungible_asset_activities_processor.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use crate::{
2222
},
2323
parquet::models::fungible_asset_models::parquet_v2_fungible_asset_activities::FungibleAssetActivity,
2424
postgres::models::{
25-
fungible_asset_models::v2_fungible_asset_utils::FeeStatement,
25+
coin_models::coin_utils::EventGuidResource,
26+
fungible_asset_models::v2_fungible_asset_utils::{
27+
CoinStoreDeletionEvent, FeeStatement,
28+
},
2629
resources::{FromWriteResource, V2FungibleAssetResource},
2730
},
2831
},
@@ -318,6 +321,35 @@ async fn parse_activities(
318321
.or_insert(1);
319322
}
320323

324+
// The CoinStoreDeletionEvent, only need for v1 with migration
325+
if user_request.is_some() {
326+
let coin_store_deletion_event = events.iter().find_map(|event| {
327+
let event_type = event.type_str.as_str();
328+
CoinStoreDeletionEvent::from_event(event_type, &event.data, txn_version)
329+
});
330+
if let Some(coin_store_deletion) = coin_store_deletion_event {
331+
let addr = standardize_address(
332+
coin_store_deletion.event_handle_creation_address.as_str(),
333+
);
334+
let deposit_event_guid = EventGuidResource {
335+
addr: addr.clone(),
336+
creation_num: coin_store_deletion
337+
.deleted_deposit_event_handle_creation_number
338+
as i64,
339+
};
340+
let withdraw_event_guid = EventGuidResource {
341+
addr,
342+
creation_num: coin_store_deletion
343+
.deleted_withdraw_event_handle_creation_number
344+
as i64,
345+
};
346+
event_to_v1_coin_type
347+
.insert(deposit_event_guid, coin_store_deletion.coin_type.clone());
348+
event_to_v1_coin_type
349+
.insert(withdraw_event_guid, coin_store_deletion.coin_type);
350+
};
351+
}
352+
321353
// Loop to handle events and collect additional metadata from events for v2
322354
for (index, event) in events.iter().enumerate() {
323355
if let Some(v1_activity) = RawFungibleAssetActivity::get_v1_from_event(

0 commit comments

Comments
 (0)