iota_analytics_indexer/
tables.rs

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