@@ -13,11 +13,8 @@ use crate::{
13
13
schema:: account_transactions,
14
14
utils:: { counters:: PROCESSOR_UNKNOWN_TYPE_COUNT , util:: standardize_address} ,
15
15
} ;
16
- use ahash:: AHashMap ;
17
- use aptos_protos:: transaction:: v1:: {
18
- transaction:: TxnData , write_set_change:: Change , DeleteResource , Event , Transaction ,
19
- WriteResource ,
20
- } ;
16
+ use ahash:: AHashSet ;
17
+ use aptos_protos:: transaction:: v1:: { transaction:: TxnData , write_set_change:: Change , Transaction } ;
21
18
use field_count:: FieldCount ;
22
19
use serde:: { Deserialize , Serialize } ;
23
20
@@ -39,7 +36,7 @@ impl AccountTransaction {
39
36
/// We will also consider transactions that the account signed or is part of a multi sig / multi agent.
40
37
/// TODO: recursively find the parent account of an object
41
38
/// TODO: include table items in the detection path
42
- pub fn from_transaction ( transaction : & Transaction ) -> AHashMap < AccountTransactionPK , Self > {
39
+ pub fn get_accounts ( transaction : & Transaction ) -> AHashSet < String > {
43
40
let txn_version = transaction. version as i64 ;
44
41
let txn_data = match transaction. txn_data . as_ref ( ) {
45
42
Some ( data) => data,
@@ -51,7 +48,7 @@ impl AccountTransaction {
51
48
transaction_version = transaction. version,
52
49
"Transaction data doesn't exist" ,
53
50
) ;
54
- return AHashMap :: new ( ) ;
51
+ return AHashSet :: new ( ) ;
55
52
} ,
56
53
} ;
57
54
let transaction_info = transaction. info . as_ref ( ) . unwrap_or_else ( || {
@@ -73,82 +70,43 @@ impl AccountTransaction {
73
70
TxnData :: BlockMetadata ( inner) => ( & inner. events , vec ! [ ] ) ,
74
71
TxnData :: Validator ( inner) => ( & inner. events , vec ! [ ] ) ,
75
72
_ => {
76
- return AHashMap :: new ( ) ;
73
+ return AHashSet :: new ( ) ;
77
74
} ,
78
75
} ;
79
- let mut account_transactions = AHashMap :: new ( ) ;
80
- for sig in & signatures {
81
- account_transactions. insert ( ( sig. signer . clone ( ) , txn_version) , Self {
82
- transaction_version : txn_version,
83
- account_address : sig. signer . clone ( ) ,
84
- } ) ;
76
+ let mut accounts = AHashSet :: new ( ) ;
77
+ for sig in signatures {
78
+ accounts. insert ( sig. signer ) ;
85
79
}
86
80
for event in events {
87
- account_transactions. extend ( Self :: from_event ( event, txn_version) ) ;
81
+ // Record event account address. We don't really have to worry about objects here
82
+ // because it'll be taken care of in the resource section.
83
+ accounts. insert ( standardize_address (
84
+ event. key . as_ref ( ) . unwrap ( ) . account_address . as_str ( ) ,
85
+ ) ) ;
88
86
}
89
87
for wsc in wscs {
90
88
match wsc. change . as_ref ( ) . unwrap ( ) {
91
89
Change :: DeleteResource ( res) => {
92
- account_transactions
93
- . extend ( Self :: from_delete_resource ( res, txn_version) . unwrap ( ) ) ;
90
+ // Record resource account.
91
+ // TODO: If the resource is an object, then we need to look for the latest
92
+ // owner. This isn't really possible right now given we have parallel threads
93
+ // so it'll be very difficult to ensure that we have the correct latest owner.
94
+ accounts. insert ( standardize_address ( res. address . as_str ( ) ) ) ;
94
95
} ,
95
96
Change :: WriteResource ( res) => {
96
- account_transactions
97
- . extend ( Self :: from_write_resource ( res, txn_version) . unwrap ( ) ) ;
97
+ // Record resource account. If the resource is an object, then we record the
98
+ // owner as well.
99
+ // This handles partial deletes as well.
100
+ accounts. insert ( standardize_address ( res. address . as_str ( ) ) ) ;
101
+ if let Some ( inner) =
102
+ & ObjectWithMetadata :: from_write_resource ( res, txn_version) . unwrap ( )
103
+ {
104
+ accounts. insert ( inner. object_core . get_owner_address ( ) ) ;
105
+ }
98
106
} ,
99
107
_ => { } ,
100
108
}
101
109
}
102
- account_transactions
103
- }
104
-
105
- /// Base case, record event account address. We don't really have to worry about
106
- /// objects here because it'll be taken care of in the resource section
107
- fn from_event ( event : & Event , txn_version : i64 ) -> AHashMap < AccountTransactionPK , Self > {
108
- let account_address =
109
- standardize_address ( event. key . as_ref ( ) . unwrap ( ) . account_address . as_str ( ) ) ;
110
- AHashMap :: from ( [ ( ( account_address. clone ( ) , txn_version) , Self {
111
- transaction_version : txn_version,
112
- account_address,
113
- } ) ] )
114
- }
115
-
116
- /// Base case, record resource account. If the resource is an object, then we record the owner as well
117
- /// This handles partial deletes as well
118
- fn from_write_resource (
119
- write_resource : & WriteResource ,
120
- txn_version : i64 ,
121
- ) -> anyhow:: Result < AHashMap < AccountTransactionPK , Self > > {
122
- let mut result = AHashMap :: new ( ) ;
123
- let account_address = standardize_address ( write_resource. address . as_str ( ) ) ;
124
- result. insert ( ( account_address. clone ( ) , txn_version) , Self {
125
- transaction_version : txn_version,
126
- account_address,
127
- } ) ;
128
- if let Some ( inner) = & ObjectWithMetadata :: from_write_resource ( write_resource, txn_version) ?
129
- {
130
- result. insert ( ( inner. object_core . get_owner_address ( ) , txn_version) , Self {
131
- transaction_version : txn_version,
132
- account_address : inner. object_core . get_owner_address ( ) ,
133
- } ) ;
134
- }
135
- Ok ( result)
136
- }
137
-
138
- /// Base case, record resource account.
139
- /// TODO: If the resource is an object, then we need to look for the latest owner. This isn't really possible
140
- /// right now given we have parallel threads so it'll be very difficult to ensure that we have the correct
141
- /// latest owner
142
- fn from_delete_resource (
143
- delete_resource : & DeleteResource ,
144
- txn_version : i64 ,
145
- ) -> anyhow:: Result < AHashMap < AccountTransactionPK , Self > > {
146
- let mut result = AHashMap :: new ( ) ;
147
- let account_address = standardize_address ( delete_resource. address . as_str ( ) ) ;
148
- result. insert ( ( account_address. clone ( ) , txn_version) , Self {
149
- transaction_version : txn_version,
150
- account_address,
151
- } ) ;
152
- Ok ( result)
110
+ accounts
153
111
}
154
112
}
0 commit comments