From 26344ea9aad005a473711f2f5466812873de3f70 Mon Sep 17 00:00:00 2001 From: bowenyang007 Date: Thu, 13 Jul 2023 01:03:50 -0700 Subject: [PATCH] add transactions that account signs --- .../coin_models/account_transactions.rs | 19 ++++++++-- .../indexer/src/models/user_transactions.rs | 35 ++++++++++++------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/crates/indexer/src/models/coin_models/account_transactions.rs b/crates/indexer/src/models/coin_models/account_transactions.rs index 27c59f197e3e4e..cea220f92632f0 100644 --- a/crates/indexer/src/models/coin_models/account_transactions.rs +++ b/crates/indexer/src/models/coin_models/account_transactions.rs @@ -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}; @@ -27,27 +30,31 @@ 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> { - 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, ), _ => { @@ -55,6 +62,12 @@ impl AccountTransaction { }, }; 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)); } diff --git a/crates/indexer/src/models/user_transactions.rs b/crates/indexer/src/models/user_transactions.rs index 3cdc3f639b5a32..b5e7f92ba919f7 100644 --- a/crates/indexer/src/models/user_transactions.rs +++ b/crates/indexer/src/models/user_transactions.rs @@ -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 { + 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`