Skip to content

Commit

Permalink
add transactions that account signs
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenyang007 committed Jul 14, 2023
1 parent 060c6b8 commit 26344ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
19 changes: 16 additions & 3 deletions crates/indexer/src/models/coin_models/account_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#![allow(clippy::unused_unit)]

use crate::{
models::token_models::v2_token_utils::ObjectWithMetadata, schema::account_transactions,
models::{
token_models::v2_token_utils::ObjectWithMetadata, user_transactions::UserTransaction,
},
schema::account_transactions,
util::standardize_address,
};
use aptos_api_types::{DeleteResource, Event, Transaction, WriteResource, WriteSetChange};
Expand All @@ -27,34 +30,44 @@ pub struct AccountTransaction {
impl AccountTransaction {
/// This table will record every transaction that touch an account which could be
/// a user account, an object, or a resource account.
/// Touching here means that a resource or event was triggered related to the 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 from_transaction(
transaction: &Transaction,
) -> anyhow::Result<HashMap<AccountTransactionPK, Self>> {
let (events, wscs, txn_version) = match transaction {
let (events, wscs, signatures, txn_version) = match transaction {
Transaction::UserTransaction(inner) => (
&inner.events,
&inner.info.changes,
UserTransaction::get_signatures(inner, inner.info.version.0 as i64, 0),
inner.info.version.0 as i64,
),
Transaction::GenesisTransaction(inner) => (
&inner.events,
&inner.info.changes,
vec![],
inner.info.version.0 as i64,
),
Transaction::BlockMetadataTransaction(inner) => (
&inner.events,
&inner.info.changes,
vec![],
inner.info.version.0 as i64,
),
_ => {
return Ok(HashMap::new());
},
};
let mut account_transactions = HashMap::new();
for sig in &signatures {
account_transactions.insert((sig.signer.clone(), txn_version), Self {
transaction_version: txn_version,
account_address: sig.signer.clone(),
});
}
for event in events {
account_transactions.extend(Self::from_event(event, txn_version));
}
Expand Down
35 changes: 22 additions & 13 deletions crates/indexer/src/models/user_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,30 @@ impl UserTransaction {
},
epoch,
},
txn.request
.signature
.as_ref()
.map(|s| {
Signature::from_user_transaction(
s,
&txn.request.sender.to_string(),
version,
block_height,
)
.unwrap()
})
.unwrap_or_default(), // empty vec if signature is None
Self::get_signatures(txn, version, block_height),
)
}

/// Empty vec if signature is None
pub fn get_signatures(
txn: &APIUserTransaction,
version: i64,
block_height: i64,
) -> Vec<Signature> {
txn.request
.signature
.as_ref()
.map(|s| {
Signature::from_user_transaction(
s,
&txn.request.sender.to_string(),
version,
block_height,
)
.unwrap()
})
.unwrap_or_default() // empty vec if signature is None
}
}

// Prevent conflicts with other things named `Transaction`
Expand Down

0 comments on commit 26344ea

Please sign in to comment.