sui_analytics_indexer/
tables.rs

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