Skip to content

Commit

Permalink
add fa tabless
Browse files Browse the repository at this point in the history
  • Loading branch information
yuunlimm committed Dec 5, 2024
1 parent 2c6b2ec commit 6052d0f
Show file tree
Hide file tree
Showing 18 changed files with 966 additions and 660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

pub mod raw_v2_fungible_asset_activities;
pub mod raw_v2_fungible_asset_balances;
pub mod raw_v2_fungible_metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ impl RawFungibleAssetActivity {
),
CoinEvent::WithdrawCoinEventV2(inner) => (
standardize_address(&inner.account),
inner.amount.to_string(),
inner.amount,
Some(inner.coin_type.clone()),
),
CoinEvent::DepositCoinEventV2(inner) => (
standardize_address(&inner.account),
inner.amount.to_string(),
inner.amount,
Some(inner.coin_type.clone()),
),
};
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

pub mod parquet_v2_fungible_asset_activities;
pub mod parquet_v2_fungible_asset_balances;
pub mod parquet_v2_fungible_metadata;
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// 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::fungible_asset_models::raw_v2_fungible_asset_balances::{
CurrentFungibleAssetBalanceConvertible, CurrentUnifiedFungibleAssetBalanceConvertible,
FungibleAssetBalanceConvertible, RawCurrentFungibleAssetBalance,
RawCurrentUnifiedFungibleAssetBalance, RawFungibleAssetBalance,
},
};
use allocative_derive::Allocative;
use field_count::FieldCount;
use lazy_static::lazy_static;
use parquet_derive::ParquetRecordWriter;
use serde::{Deserialize, Serialize};

lazy_static! {
pub static ref DEFAULT_AMOUNT_VALUE: String = "0".to_string();
}

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

Check warning on line 27 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L27

Added line #L27 was not covered by tests
)]
pub struct FungibleAssetBalance {

Check warning on line 29 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L29

Added line #L29 was not covered by tests
pub txn_version: i64,
pub write_set_change_index: i64,
pub storage_id: String,
pub owner_address: String,
pub asset_type: String,
pub is_primary: bool,
pub is_frozen: bool,
pub amount: String, // it is a string representation of the u128
#[allocative(skip)]
pub block_timestamp: chrono::NaiveDateTime,
pub token_standard: String,
}

impl NamedTable for FungibleAssetBalance {
const TABLE_NAME: &'static str = "fungible_asset_balances";
}

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

Check warning on line 50 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L48-L50

Added lines #L48 - L50 were not covered by tests
}

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

Check warning on line 56 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L54-L56

Added lines #L54 - L56 were not covered by tests
}

impl FungibleAssetBalanceConvertible for FungibleAssetBalance {
fn from_raw(raw_item: RawFungibleAssetBalance) -> Self {
Self {
txn_version: raw_item.transaction_version,
write_set_change_index: raw_item.write_set_change_index,
storage_id: raw_item.storage_id,
owner_address: raw_item.owner_address,
asset_type: raw_item.asset_type,
is_primary: raw_item.is_primary,
is_frozen: raw_item.is_frozen,
amount: raw_item.amount.to_string(),
block_timestamp: raw_item.transaction_timestamp,
token_standard: raw_item.token_standard,
}
}

Check warning on line 73 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L60-L73

Added lines #L60 - L73 were not covered by tests
}

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

Check warning on line 77 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L77

Added line #L77 was not covered by tests
)]
pub struct CurrentFungibleAssetBalance {

Check warning on line 79 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L79

Added line #L79 was not covered by tests
pub storage_id: String,
pub owner_address: String,
pub asset_type: String,
pub is_primary: bool,
pub is_frozen: bool,
pub amount: String, // it is a string representation of the u128
pub last_transaction_version: i64,
#[allocative(skip)]
pub last_transaction_timestamp: chrono::NaiveDateTime,
pub token_standard: String,
}

impl NamedTable for CurrentFungibleAssetBalance {
const TABLE_NAME: &'static str = "current_fungible_asset_balances_legacy";
}

impl HasVersion for CurrentFungibleAssetBalance {
fn version(&self) -> i64 {
self.last_transaction_version
}

Check warning on line 99 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L97-L99

Added lines #L97 - L99 were not covered by tests
}

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

Check warning on line 105 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L103-L105

Added lines #L103 - L105 were not covered by tests
}

impl CurrentFungibleAssetBalanceConvertible for CurrentFungibleAssetBalance {
fn from_raw(raw_item: RawCurrentFungibleAssetBalance) -> Self {
Self {
storage_id: raw_item.storage_id,
owner_address: raw_item.owner_address,
asset_type: raw_item.asset_type,
is_primary: raw_item.is_primary,
is_frozen: raw_item.is_frozen,
amount: raw_item.amount.to_string(),
last_transaction_version: raw_item.last_transaction_version,
last_transaction_timestamp: raw_item.last_transaction_timestamp,
token_standard: raw_item.token_standard,
}
}

Check warning on line 121 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L109-L121

Added lines #L109 - L121 were not covered by tests
}

/// Note that this used to be called current_unified_fungible_asset_balances_to_be_renamed

Check warning on line 124 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L124

Added line #L124 was not covered by tests
/// and was renamed to current_fungible_asset_balances to facilitate migration
#[derive(
Allocative, Clone, Debug, Default, Deserialize, FieldCount, ParquetRecordWriter, Serialize,

Check warning on line 127 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L127

Added line #L127 was not covered by tests
)]
pub struct CurrentUnifiedFungibleAssetBalance {
pub storage_id: String,
pub owner_address: String,
// metadata address for (paired) Fungible Asset
pub asset_type_v1: Option<String>,
pub asset_type_v2: Option<String>,
pub is_primary: bool,
pub is_frozen: bool,
pub amount_v1: Option<String>, // it is a string representation of the u128
pub amount_v2: Option<String>, // it is a string representation of the u128
pub last_transaction_version_v1: Option<i64>,
pub last_transaction_version_v2: Option<i64>,
#[allocative(skip)]
pub last_transaction_timestamp_v1: Option<chrono::NaiveDateTime>,
#[allocative(skip)]
pub last_transaction_timestamp_v2: Option<chrono::NaiveDateTime>,
}

impl NamedTable for CurrentUnifiedFungibleAssetBalance {
const TABLE_NAME: &'static str = "current_fungible_asset_balances";
}

/// This will be deprecated.
impl HasVersion for CurrentUnifiedFungibleAssetBalance {
fn version(&self) -> i64 {
-1
}

Check warning on line 155 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L153-L155

Added lines #L153 - L155 were not covered by tests
}

/// This will be deprecated.
impl GetTimeStamp for CurrentUnifiedFungibleAssetBalance {
fn get_timestamp(&self) -> chrono::NaiveDateTime {
#[allow(deprecated)]
chrono::NaiveDateTime::from_timestamp(0, 0)
}

Check warning on line 163 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L160-L163

Added lines #L160 - L163 were not covered by tests
}

impl CurrentUnifiedFungibleAssetBalanceConvertible for CurrentUnifiedFungibleAssetBalance {
fn from_raw(raw_item: RawCurrentUnifiedFungibleAssetBalance) -> Self {
Self {
storage_id: raw_item.storage_id,
owner_address: raw_item.owner_address,
asset_type_v1: raw_item.asset_type_v1,
asset_type_v2: raw_item.asset_type_v2,
is_primary: raw_item.is_primary,
is_frozen: raw_item.is_frozen,
amount_v1: raw_item.amount_v1.map(|x| x.to_string()),
amount_v2: raw_item.amount_v2.map(|x| x.to_string()),
last_transaction_version_v1: raw_item.last_transaction_version_v1,
last_transaction_version_v2: raw_item.last_transaction_version_v2,
last_transaction_timestamp_v1: raw_item.last_transaction_timestamp_v1,
last_transaction_timestamp_v2: raw_item.last_transaction_timestamp_v2,
}
}

Check warning on line 182 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

View check run for this annotation

Codecov / codecov/patch

rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L167-L182

Added lines #L167 - L182 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ pub mod v2_fungible_metadata;

// parquet models
pub mod parquet_coin_supply;
pub mod parquet_v2_fungible_asset_balances;
Loading

0 comments on commit 6052d0f

Please sign in to comment.