-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod raw_account_transactions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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::{ | ||
db::postgres::models::{ | ||
object_models::v2_object_utils::ObjectWithMetadata, resources::FromWriteResource, | ||
user_transactions_models::user_transactions::UserTransaction, | ||
}, | ||
utils::{counters::PROCESSOR_UNKNOWN_TYPE_COUNT, util::standardize_address}, | ||
}; | ||
use ahash::AHashSet; | ||
use aptos_protos::transaction::v1::{transaction::TxnData, write_set_change::Change, Transaction}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub type AccountTransactionPK = (String, i64); | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
Check warning on line 21 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L21
|
||
pub struct RawAccountTransaction { | ||
pub transaction_version: i64, | ||
pub account_address: String, | ||
pub block_timestamp: chrono::NaiveDateTime, | ||
} | ||
|
||
impl RawAccountTransaction { | ||
/// This table will record every transaction that touch an account which could be | ||
/// a user account, an object, or a resource account. | ||
/// We will consider all transactions that modify a resource or event associated with a particular account. | ||
/// We will do 1 level of redirection for now (e.g. if it's an object, we will record the owner as account address). | ||
/// We will also consider transactions that the account signed or is part of a multi sig / multi agent. | ||
/// TODO: recursively find the parent account of an object | ||
/// TODO: include table items in the detection path | ||
pub fn get_accounts(transaction: &Transaction) -> AHashSet<String> { | ||
let txn_version = transaction.version as i64; | ||
let txn_data = match transaction.txn_data.as_ref() { | ||
Some(data) => data, | ||
None => { | ||
PROCESSOR_UNKNOWN_TYPE_COUNT | ||
.with_label_values(&["AccountTransaction"]) | ||
.inc(); | ||
tracing::warn!( | ||
Check warning on line 44 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L41-L44
|
||
transaction_version = transaction.version, | ||
"Transaction data doesn't exist", | ||
Check warning on line 46 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L46
|
||
); | ||
return AHashSet::new(); | ||
Check warning on line 48 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L48
|
||
}, | ||
}; | ||
let transaction_info = transaction.info.as_ref().unwrap_or_else(|| { | ||
panic!("Transaction info doesn't exist for version {}", txn_version) | ||
Check warning on line 52 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L52
|
||
}); | ||
let wscs = &transaction_info.changes; | ||
let (events, signatures) = match txn_data { | ||
TxnData::User(inner) => ( | ||
&inner.events, | ||
UserTransaction::get_signatures( | ||
inner.request.as_ref().unwrap_or_else(|| { | ||
panic!("User request doesn't exist for version {}", txn_version) | ||
Check warning on line 60 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L60
|
||
}), | ||
txn_version, | ||
transaction.block_height as i64, | ||
), | ||
), | ||
TxnData::Genesis(inner) => (&inner.events, vec![]), | ||
TxnData::BlockMetadata(inner) => (&inner.events, vec![]), | ||
TxnData::Validator(inner) => (&inner.events, vec![]), | ||
Check warning on line 68 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L66-L68
|
||
_ => { | ||
return AHashSet::new(); | ||
Check warning on line 70 in rust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/common/models/account_transaction_models/raw_account_transactions.rs#L70
|
||
}, | ||
}; | ||
let mut accounts = AHashSet::new(); | ||
for sig in signatures { | ||
accounts.insert(sig.signer); | ||
} | ||
for event in events { | ||
// Record event account address. We don't really have to worry about objects here | ||
// because it'll be taken care of in the resource section. | ||
accounts.insert(standardize_address( | ||
event.key.as_ref().unwrap().account_address.as_str(), | ||
)); | ||
} | ||
for wsc in wscs { | ||
match wsc.change.as_ref().unwrap() { | ||
Change::DeleteResource(res) => { | ||
// Record resource account. | ||
// TODO: If the resource is an object, then we need to look for the latest | ||
// owner. This isn't really possible right now given we have parallel threads | ||
// so it'll be very difficult to ensure that we have the correct latest owner. | ||
accounts.insert(standardize_address(res.address.as_str())); | ||
}, | ||
Change::WriteResource(res) => { | ||
// Record resource account. If the resource is an object, then we record the | ||
// owner as well. | ||
// This handles partial deletes as well. | ||
accounts.insert(standardize_address(res.address.as_str())); | ||
if let Some(inner) = &ObjectWithMetadata::from_write_resource(res).unwrap() { | ||
accounts.insert(inner.object_core.get_owner_address()); | ||
} | ||
}, | ||
_ => {}, | ||
} | ||
} | ||
accounts | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod account_transaction_models; | ||
pub mod ans_models; | ||
pub mod default_models; | ||
pub mod event_models; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod parquet_account_transactions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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}; | ||
use allocative_derive::Allocative; | ||
use field_count::FieldCount; | ||
use parquet_derive::ParquetRecordWriter; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub type AccountTransactionPK = (String, i64); | ||
|
||
#[derive( | ||
Allocative, Clone, Debug, Default, Deserialize, FieldCount, ParquetRecordWriter, Serialize, | ||
Check warning on line 17 in rust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs#L17
|
||
)] | ||
pub struct AccountTransaction { | ||
Check warning on line 19 in rust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs#L19
|
||
pub txn_version: i64, | ||
pub account_address: String, | ||
#[allocative(skip)] | ||
pub block_timestamp: chrono::NaiveDateTime, | ||
} | ||
|
||
impl NamedTable for AccountTransaction { | ||
const TABLE_NAME: &'static str = "fungible_asset_activities"; | ||
} | ||
|
||
impl HasVersion for AccountTransaction { | ||
fn version(&self) -> i64 { | ||
self.txn_version | ||
} | ||
Check warning on line 33 in rust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs#L31-L33
|
||
} | ||
|
||
impl GetTimeStamp for AccountTransaction { | ||
fn get_timestamp(&self) -> chrono::NaiveDateTime { | ||
self.block_timestamp | ||
} | ||
Check warning on line 39 in rust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs Codecov / codecov/patchrust/processor/src/db/parquet/models/account_transaction_models/parquet_account_transactions.rs#L37-L39
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod account_transaction_models; | ||
pub mod ans_models; | ||
pub mod default_models; | ||
pub mod event_models; | ||
|