diff --git a/crates/sui-bridge-indexer/src/lib.rs b/crates/sui-bridge-indexer/src/lib.rs index 6fb95e6887ad4a..bcd9beaedf67a3 100644 --- a/crates/sui-bridge-indexer/src/lib.rs +++ b/crates/sui-bridge-indexer/src/lib.rs @@ -20,6 +20,7 @@ pub struct TokenTransfer { txn_hash: Vec, status: TokenTransferStatus, gas_usage: i64, + data_source: BridgeDataSource, data: Option, } @@ -41,6 +42,7 @@ impl From for DBTokenTransfer { txn_hash: value.txn_hash, status: value.status.to_string(), gas_usage: value.gas_usage, + data_source: value.data_source.to_string(), } } } @@ -86,3 +88,18 @@ impl Display for TokenTransferStatus { write!(f, "{str}") } } + +enum BridgeDataSource { + SUI, + ETH, +} + +impl Display for BridgeDataSource { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let str = match self { + BridgeDataSource::ETH => "ETH", + BridgeDataSource::SUI => "SUI", + }; + write!(f, "{str}") + } +} diff --git a/crates/sui-bridge-indexer/src/main.rs b/crates/sui-bridge-indexer/src/main.rs index e6f83eb9e0d738..09210840ffb56a 100644 --- a/crates/sui-bridge-indexer/src/main.rs +++ b/crates/sui-bridge-indexer/src/main.rs @@ -75,7 +75,7 @@ async fn main() -> Result<()> { let contract_addresses = HashMap::from_iter(vec![(bridge_address, config.start_block)]); - let (_task_handles, mut eth_events_rx, _) = EthSyncer::new(eth_client, contract_addresses) + let (_task_handles, eth_events_rx, _) = EthSyncer::new(eth_client, contract_addresses) .run() .await .expect("Failed to start eth syncer"); diff --git a/crates/sui-bridge-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql b/crates/sui-bridge-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql index 8b4705b439b793..fffdaa5e6234b1 100644 --- a/crates/sui-bridge-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql +++ b/crates/sui-bridge-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql @@ -21,5 +21,6 @@ CREATE TABLE token_transfer timestamp_ms BIGINT NOT NULL, txn_hash bytea NOT NULL, gas_usage BIGINT NOT NULL, + data_source TEXT NOT NULL, PRIMARY KEY(chain_id, nonce, status) ); \ No newline at end of file diff --git a/crates/sui-bridge-indexer/src/models.rs b/crates/sui-bridge-indexer/src/models.rs index 09e4949fe36888..ee0bcc88ab6462 100644 --- a/crates/sui-bridge-indexer/src/models.rs +++ b/crates/sui-bridge-indexer/src/models.rs @@ -14,6 +14,7 @@ pub struct TokenTransfer { pub timestamp_ms: i64, pub txn_hash: Vec, pub gas_usage: i64, + pub data_source: String, } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] diff --git a/crates/sui-bridge-indexer/src/schema.rs b/crates/sui-bridge-indexer/src/schema.rs index f9b31f003822a8..e13e095c226544 100644 --- a/crates/sui-bridge-indexer/src/schema.rs +++ b/crates/sui-bridge-indexer/src/schema.rs @@ -12,6 +12,7 @@ diesel::table! { timestamp_ms -> Int8, txn_hash -> Bytea, gas_usage -> Int8, + data_source -> Text, } } diff --git a/crates/sui-bridge-indexer/src/worker.rs b/crates/sui-bridge-indexer/src/worker.rs index a7b28c2bc1dd66..d84d3a473be998 100644 --- a/crates/sui-bridge-indexer/src/worker.rs +++ b/crates/sui-bridge-indexer/src/worker.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::postgres_writer::{get_connection_pool, write, PgPool}; -use crate::{TokenTransfer, TokenTransferData, TokenTransferStatus}; +use crate::{BridgeDataSource, TokenTransfer, TokenTransferData, TokenTransferStatus}; use anyhow::Result; use async_trait::async_trait; use ethers::providers::Provider; @@ -74,6 +74,7 @@ impl BridgeWorker { txn_hash: tx.transaction.digest().inner().to_vec(), status: TokenTransferStatus::Deposited, gas_usage: tx.effects.gas_cost_summary().net_gas_usage(), + data_source: BridgeDataSource::SUI, data: Some(TokenTransferData { sender_address: event.sender_address, destination_chain: event.target_chain, @@ -95,6 +96,7 @@ impl BridgeWorker { txn_hash: tx.transaction.digest().inner().to_vec(), status: TokenTransferStatus::Approved, gas_usage: tx.effects.gas_cost_summary().net_gas_usage(), + data_source: BridgeDataSource::SUI, data: None, }) } @@ -110,6 +112,7 @@ impl BridgeWorker { txn_hash: tx.transaction.digest().inner().to_vec(), status: TokenTransferStatus::Claimed, gas_usage: tx.effects.gas_cost_summary().net_gas_usage(), + data_source: BridgeDataSource::SUI, data: None, }) } @@ -163,6 +166,7 @@ pub async fn process_eth_transaction( txn_hash: tx_hash.as_bytes().to_vec(), status: TokenTransferStatus::Deposited, gas_usage: gas.as_u64() as i64, + data_source: BridgeDataSource::ETH, data: Some(TokenTransferData { sender_address: bridge_event.sender_address.as_bytes().to_vec(), destination_chain: bridge_event.destination_chain_id, @@ -184,15 +188,16 @@ pub async fn process_eth_transaction( txn_hash: tx_hash.as_bytes().to_vec(), status: TokenTransferStatus::Claimed, gas_usage: gas.as_u64() as i64, + data_source: BridgeDataSource::ETH, data: None, }; write(&pool, transfer); } - EthSuiBridgeEvents::PausedFilter(_bridge_event) => (), - EthSuiBridgeEvents::UnpausedFilter(_bridge_event) => (), - EthSuiBridgeEvents::UpgradedFilter(_bridge_event) => (), - EthSuiBridgeEvents::InitializedFilter(_bridge_event) => (), + EthSuiBridgeEvents::PausedFilter(_) + | EthSuiBridgeEvents::UnpausedFilter(_) + | EthSuiBridgeEvents::UpgradedFilter(_) + | EthSuiBridgeEvents::InitializedFilter(_) => (), }, } }