-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L27
|
||
)] | ||
pub struct FungibleAssetBalance { | ||
Check warning on line 29 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L29
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L48-L50
|
||
} | ||
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L54-L56
|
||
} | ||
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L60-L73
|
||
} | ||
|
||
#[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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L77
|
||
)] | ||
pub struct CurrentFungibleAssetBalance { | ||
Check warning on line 79 in rust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L79
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L97-L99
|
||
} | ||
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L103-L105
|
||
} | ||
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L109-L121
|
||
} | ||
|
||
/// 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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L124
|
||
/// 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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L127
|
||
)] | ||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L153-L155
|
||
} | ||
|
||
/// 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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L160-L163
|
||
} | ||
|
||
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 Codecov / codecov/patchrust/processor/src/db/parquet/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs#L167-L182
|
||
} |