Skip to content

Commit

Permalink
[parquet-sdk][token_v2] migrate TokenActivityV2
Browse files Browse the repository at this point in the history
  • Loading branch information
yuunlimm committed Dec 11, 2024
1 parent f80f6c1 commit 2448db8
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 349 deletions.
1 change: 1 addition & 0 deletions rust/processor/src/db/common/models/token_v2_models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod raw_token_claims;
pub mod raw_v1_token_royalty;
pub mod raw_v2_token_activities;
pub mod raw_v2_token_metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#![allow(clippy::unused_unit)]

use crate::{
db::postgres::models::{
token_models::{token_utils::TokenWriteSet, tokens::TableHandleToOwner},
token_v2_models::v2_token_activities::TokenActivityHelperV1,
db::{
common::models::token_v2_models::raw_v2_token_activities::TokenActivityHelperV1,
postgres::models::token_models::{token_utils::TokenWriteSet, tokens::TableHandleToOwner},
},
utils::util::standardize_address,
};
Expand Down

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions rust/processor/src/db/parquet/models/token_v2_models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod token_claims;
pub mod v1_token_royalty;
pub mod v2_token_activities;
pub mod v2_token_metadata;

pub mod v2_token_ownerships;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

// This is required because a diesel macro makes clippy sad
#![allow(clippy::extra_unused_lifetimes)]
#![allow(clippy::unused_unit)]

use crate::{
bq_analytics::generic_parquet_processor::{GetTimeStamp, HasVersion, NamedTable},
db::common::models::token_v2_models::raw_v2_token_activities::{
RawTokenActivityV2, TokenActivityV2Convertible,
},
};
use allocative_derive::Allocative;
use bigdecimal::ToPrimitive;
use field_count::FieldCount;
use parquet_derive::ParquetRecordWriter;
use serde::{Deserialize, Serialize};

#[derive(
Allocative, Clone, Debug, Default, Deserialize, FieldCount, ParquetRecordWriter, Serialize,

Check warning on line 21 in rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs#L21

Added line #L21 was not covered by tests
)]
pub struct TokenActivityV2 {

Check warning on line 23 in rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs#L23

Added line #L23 was not covered by tests
pub txn_version: i64,
pub event_index: i64,
pub event_account_address: String,
pub token_data_id: String,
pub property_version_v1: u64, // BigDecimal
pub type_: String,
pub from_address: Option<String>,
pub to_address: Option<String>,
pub token_amount: String, // BigDecimal
pub before_value: Option<String>,
pub after_value: Option<String>,
pub entry_function_id_str: Option<String>,
pub token_standard: String,
pub is_fungible_v2: Option<bool>,
#[allocative(skip)]
pub block_timestamp: chrono::NaiveDateTime,
}

impl NamedTable for TokenActivityV2 {
const TABLE_NAME: &'static str = "token_activities_v2";
}

impl HasVersion for TokenActivityV2 {
fn version(&self) -> i64 {
self.txn_version
}

Check warning on line 49 in rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs#L47-L49

Added lines #L47 - L49 were not covered by tests
}

impl GetTimeStamp for TokenActivityV2 {
fn get_timestamp(&self) -> chrono::NaiveDateTime {
self.block_timestamp
}

Check warning on line 55 in rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs#L53-L55

Added lines #L53 - L55 were not covered by tests
}

impl TokenActivityV2Convertible for TokenActivityV2 {
// TODO: consider returning a Result
fn from_raw(raw_item: RawTokenActivityV2) -> Self {
Self {
txn_version: raw_item.transaction_version,
event_index: raw_item.event_index,
event_account_address: raw_item.event_account_address,
token_data_id: raw_item.token_data_id,
property_version_v1: raw_item.property_version_v1.to_u64().unwrap(),
type_: raw_item.type_,
from_address: raw_item.from_address,
to_address: raw_item.to_address,
token_amount: raw_item.token_amount.to_string(),
before_value: raw_item.before_value,
after_value: raw_item.after_value,
entry_function_id_str: raw_item.entry_function_id_str,
token_standard: raw_item.token_standard,
is_fungible_v2: raw_item.is_fungible_v2,
block_timestamp: raw_item.transaction_timestamp,
}
}

Check warning on line 78 in rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/token_v2_models/v2_token_activities.rs#L60-L78

Added lines #L60 - L78 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ pub mod v2_token_utils;
// parquet models
// pub mod parquet_v2_collections; // revisit this
pub mod parquet_v2_token_datas;
pub mod parquet_v2_token_ownerships;
Loading

0 comments on commit 2448db8

Please sign in to comment.