sui_analytics_indexer/
tables.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5use serde::Serialize;
6use strum_macros::Display;
7use sui_analytics_indexer_derive::SerializeRow;
8use sui_types::dynamic_field::DynamicFieldType;
9
10// Checkpoint information.
11#[derive(Serialize, Clone, SerializeRow)]
12pub struct CheckpointRow {
13    // indexes
14    pub(crate) checkpoint_digest: String,
15    pub(crate) sequence_number: u64,
16    pub(crate) epoch: u64,
17    pub(crate) timestamp_ms: u64,
18
19    pub(crate) previous_checkpoint_digest: Option<String>,
20    pub(crate) end_of_epoch: bool,
21    // gas stats
22    pub(crate) total_gas_cost: i64,
23    pub(crate) computation_cost: u64,
24    pub(crate) storage_cost: u64,
25    pub(crate) storage_rebate: u64,
26    pub(crate) non_refundable_storage_fee: u64,
27    // transaction stats
28    pub(crate) total_transaction_blocks: u64,
29    pub(crate) total_transactions: u64,
30    pub(crate) total_successful_transaction_blocks: u64,
31    pub(crate) total_successful_transactions: u64,
32
33    pub(crate) network_total_transaction: u64,
34    pub(crate) validator_signature: String,
35}
36
37// Transaction information.
38#[derive(Serialize, Clone, SerializeRow)]
39pub struct TransactionRow {
40    // main indexes
41    pub(crate) transaction_digest: String,
42    pub(crate) checkpoint: u64,
43    pub(crate) epoch: u64,
44    pub(crate) timestamp_ms: u64,
45    // transaction info
46    pub(crate) sender: String,
47    pub(crate) transaction_kind: String,
48    pub(crate) is_system_txn: bool,
49    pub(crate) is_sponsored_tx: bool,
50    pub(crate) transaction_count: u64,
51    pub(crate) execution_success: bool,
52    // object info
53    pub(crate) input: u64,
54    pub(crate) shared_input: u64,
55    pub(crate) gas_coins: u64,
56    // objects are broken up in created, mutated and deleted.
57    // No wrap or unwrap information is provided
58    pub(crate) created: u64,
59    pub(crate) mutated: u64,
60    pub(crate) deleted: u64,
61    // PTB info
62    pub(crate) transfers: u64,
63    pub(crate) split_coins: u64,
64    pub(crate) merge_coins: u64,
65    pub(crate) publish: u64,
66    pub(crate) upgrade: u64,
67    // move_vec or default for future commands
68    pub(crate) others: u64,
69    pub(crate) move_calls: u64,
70    // pub(crate) packages: BTreeSet<String>,
71    // commas separated list of packages used by the transaction.
72    // Use as a simple way to query for transactions that use a specific package.
73    pub(crate) packages: String,
74    // gas info
75    pub(crate) gas_owner: String,
76    pub(crate) gas_object_id: String,
77    pub(crate) gas_object_sequence: u64,
78    pub(crate) gas_object_digest: String,
79    pub(crate) gas_budget: u64,
80    pub(crate) total_gas_cost: i64,
81    pub(crate) computation_cost: u64,
82    pub(crate) storage_cost: u64,
83    pub(crate) storage_rebate: u64,
84    pub(crate) non_refundable_storage_fee: u64,
85    pub(crate) gas_price: u64,
86    // Deprecated. Left in place for backwards compatibility with SZNS BigQuery Infra.
87    pub(crate) raw_transaction: String,
88    pub(crate) has_zklogin_sig: bool,
89    pub(crate) has_upgraded_multisig: bool,
90    pub(crate) transaction_json: Option<String>,
91    pub(crate) effects_json: Option<String>,
92    pub(crate) transaction_position: u64,
93    pub(crate) events_digest: Option<String>,
94    pub(crate) transaction_data_bcs_length: u64,
95    pub(crate) effects_bcs_length: u64,
96    pub(crate) events_bcs_length: u64,
97    pub(crate) signatures_bcs_length: u64,
98}
99
100// Raw Transaction bytes (used by security team).
101#[derive(Serialize, Clone, SerializeRow)]
102pub struct TransactionBCSRow {
103    pub(crate) transaction_digest: String,
104    pub(crate) checkpoint: u64,
105    pub(crate) epoch: u64,
106    pub(crate) timestamp_ms: u64,
107    pub(crate) bcs: String,
108}
109
110// Raw Package bytes (BCS encoded package data).
111#[derive(Serialize, Clone, SerializeRow)]
112pub struct PackageBCSRow {
113    pub(crate) package_id: String,
114    pub(crate) checkpoint: u64,
115    pub(crate) epoch: u64,
116    pub(crate) timestamp_ms: u64,
117    pub(crate) bcs: String,
118}
119
120// Event information.
121// Events identity is via `transaction_digest` and `event_index`.
122#[derive(Serialize, Clone, SerializeRow)]
123pub struct EventRow {
124    // indexes
125    pub(crate) transaction_digest: String,
126    pub(crate) event_index: u64,
127    pub(crate) checkpoint: u64,
128    pub(crate) epoch: u64,
129    pub(crate) timestamp_ms: u64,
130    // sender
131    pub(crate) sender: String,
132    // event type
133    pub(crate) package: String,
134    pub(crate) module: String,
135    pub(crate) event_type: String,
136    // Left in place for backwards compatibility with SZNS BigQuery Infra.
137    pub(crate) bcs: String,
138    pub(crate) event_json: String,
139    pub(crate) bcs_length: u64,
140}
141
142// Used in the transaction object table to identify the type of input object.
143#[derive(Serialize, Clone, Display)]
144pub enum InputObjectKind {
145    Input,
146    SharedInput,
147    GasCoin,
148}
149
150// Used in the object table to identify the status of object, its result in the last transaction
151// effect.
152#[derive(Serialize, Clone, Display)]
153pub enum ObjectStatus {
154    Created,
155    Mutated,
156    Deleted,
157}
158
159// Object owner information.
160#[derive(Serialize, Clone, Display)]
161pub enum OwnerType {
162    AddressOwner,
163    ObjectOwner,
164    Shared,
165    Immutable,
166}
167
168// Object information.
169// A row in the live object table.
170#[derive(Serialize, Clone, SerializeRow)]
171pub struct ObjectRow {
172    // indexes
173    pub(crate) object_id: String,
174    pub(crate) version: u64,
175    pub(crate) digest: String,
176    pub(crate) type_: Option<String>, // None is for packages
177    pub(crate) checkpoint: u64,
178    pub(crate) epoch: u64,
179    pub(crate) timestamp_ms: u64,
180    // owner info
181    pub(crate) owner_type: Option<OwnerType>,
182    pub(crate) owner_address: Option<String>,
183    // object info
184    pub(crate) object_status: ObjectStatus,
185    pub(crate) initial_shared_version: Option<u64>,
186    pub(crate) previous_transaction: String,
187    pub(crate) has_public_transfer: bool,
188    pub(crate) is_consensus: bool,
189    pub(crate) storage_rebate: Option<u64>,
190    // Left in place for backwards compatibility with SZNS BigQuery Infra.
191    pub(crate) bcs: String,
192    pub(crate) coin_type: Option<String>,
193    pub(crate) coin_balance: Option<u64>,
194    pub(crate) struct_tag: Option<String>,
195    pub(crate) object_json: Option<String>,
196    pub(crate) bcs_length: u64,
197}
198
199// Objects used and manipulated in a transaction.
200// Both input object and objects in effects are reported here with the proper
201// input kind (for input objects) and status (for objets in effects).
202// An object may appear twice as an input and output object. In that case, the
203// version will be different.
204#[derive(Serialize, Clone, SerializeRow)]
205pub struct TransactionObjectRow {
206    // indexes
207    pub(crate) object_id: String,
208    pub(crate) version: Option<u64>,
209    pub(crate) transaction_digest: String,
210    pub(crate) checkpoint: u64,
211    pub(crate) epoch: u64,
212    pub(crate) timestamp_ms: u64,
213    // input/output information
214    pub(crate) input_kind: Option<InputObjectKind>,
215    pub(crate) object_status: Option<ObjectStatus>,
216}
217
218// A Move call expressed as a package, module and function.
219// Move call identity is via `transaction_digest` and `call_index`.
220#[derive(Serialize, Clone, SerializeRow)]
221pub struct MoveCallRow {
222    // indexes
223    pub(crate) transaction_digest: String,
224    pub(crate) cmd_idx: u64,
225    pub(crate) checkpoint: u64,
226    pub(crate) epoch: u64,
227    pub(crate) timestamp_ms: u64,
228    // move call info
229    pub(crate) package: String,
230    pub(crate) module: String,
231    pub(crate) function: String,
232}
233
234// A Move package. Package id and MovePackage object bytes
235#[derive(Serialize, Clone, SerializeRow)]
236pub struct MovePackageRow {
237    // indexes
238    pub(crate) package_id: String,
239    pub(crate) checkpoint: u64,
240    pub(crate) epoch: u64,
241    pub(crate) timestamp_ms: u64,
242    // Left in place for backwards compatibility with SZNS BigQuery Infra.
243    pub(crate) bcs: String,
244    // txn publishing the package
245    pub(crate) transaction_digest: String,
246    pub(crate) package_version: Option<u64>,
247    pub(crate) original_package_id: Option<String>,
248    pub(crate) bcs_length: u64,
249}
250
251#[derive(Serialize, Clone, SerializeRow)]
252pub struct DynamicFieldRow {
253    // indexes
254    pub(crate) parent_object_id: String,
255    pub(crate) transaction_digest: String,
256    pub(crate) checkpoint: u64,
257    pub(crate) epoch: u64,
258    pub(crate) timestamp_ms: u64,
259    // df information
260    pub(crate) name: String,
261    pub(crate) bcs_name: String,
262    pub(crate) type_: DynamicFieldType,
263    pub(crate) object_id: String,
264    pub(crate) version: u64,
265    pub(crate) digest: String,
266    pub(crate) object_type: String,
267}
268
269// Object information.
270// A row in the live object table.
271#[derive(Serialize, Clone, SerializeRow)]
272pub struct WrappedObjectRow {
273    // indexes
274    pub(crate) object_id: Option<String>,
275    pub(crate) root_object_id: String,
276    pub(crate) root_object_version: u64,
277    pub(crate) checkpoint: u64,
278    pub(crate) epoch: u64,
279    pub(crate) timestamp_ms: u64,
280    // wrapped info
281    pub(crate) json_path: String,
282    pub(crate) struct_tag: Option<String>,
283}