iota_bridge_indexer/
models.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use diesel::{Identifiable, Insertable, Queryable, Selectable, data_types::PgTimestamp};
6use iota_indexer_builder::Task;
7
8use crate::schema::{
9    iota_error_transactions, iota_progress_store, progress_store, token_transfer,
10    token_transfer_data,
11};
12
13#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
14#[diesel(table_name = progress_store, primary_key(task_name))]
15pub struct ProgressStore {
16    pub task_name: String,
17    pub checkpoint: i64,
18    pub target_checkpoint: i64,
19    pub timestamp: Option<PgTimestamp>,
20}
21
22impl From<ProgressStore> for Task {
23    fn from(value: ProgressStore) -> Self {
24        Self {
25            task_name: value.task_name,
26            checkpoint: value.checkpoint as u64,
27            target_checkpoint: value.target_checkpoint as u64,
28            // Ok to unwrap, timestamp is defaulted to now() in database
29            timestamp: value.timestamp.expect("Timestamp not set").0 as u64,
30        }
31    }
32}
33
34#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
35#[diesel(table_name = iota_progress_store, primary_key(txn_digest))]
36pub struct IotaProgressStore {
37    pub id: i32, // Dummy value
38    pub txn_digest: Vec<u8>,
39}
40
41#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
42#[diesel(table_name = token_transfer, primary_key(chain_id, nonce))]
43pub struct TokenTransfer {
44    pub chain_id: i32,
45    pub nonce: i64,
46    pub status: String,
47    pub block_height: i64,
48    pub timestamp_ms: i64,
49    pub txn_hash: Vec<u8>,
50    pub txn_sender: Vec<u8>,
51    pub gas_usage: i64,
52    pub data_source: String,
53}
54
55#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
56#[diesel(table_name = token_transfer_data, primary_key(chain_id, nonce))]
57pub struct TokenTransferData {
58    pub chain_id: i32,
59    pub nonce: i64,
60    pub block_height: i64,
61    pub timestamp_ms: i64,
62    pub txn_hash: Vec<u8>,
63    pub sender_address: Vec<u8>,
64    pub destination_chain: i32,
65    pub recipient_address: Vec<u8>,
66    pub token_id: i32,
67    pub amount: i64,
68}
69
70#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
71#[diesel(table_name = iota_error_transactions, primary_key(txn_digest))]
72pub struct IotaErrorTransactions {
73    pub txn_digest: Vec<u8>,
74    pub sender_address: Vec<u8>,
75    pub timestamp_ms: i64,
76    pub failure_status: String,
77    pub cmd_idx: Option<i64>,
78}