Skip to content

Commit

Permalink
add data source column
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo authored and dariorussi committed May 23, 2024
1 parent ed22782 commit 0a3c469
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
17 changes: 17 additions & 0 deletions crates/sui-bridge-indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct TokenTransfer {
txn_hash: Vec<u8>,
status: TokenTransferStatus,
gas_usage: i64,
data_source: BridgeDataSource,
data: Option<TokenTransferData>,
}

Expand All @@ -41,6 +42,7 @@ impl From<TokenTransfer> for DBTokenTransfer {
txn_hash: value.txn_hash,
status: value.status.to_string(),
gas_usage: value.gas_usage,
data_source: value.data_source.to_string(),
}
}
}
Expand Down Expand Up @@ -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}")
}
}
2 changes: 1 addition & 1 deletion crates/sui-bridge-indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
1 change: 1 addition & 0 deletions crates/sui-bridge-indexer/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct TokenTransfer {
pub timestamp_ms: i64,
pub txn_hash: Vec<u8>,
pub gas_usage: i64,
pub data_source: String,
}

#[derive(Queryable, Selectable, Insertable, Identifiable, Debug)]
Expand Down
1 change: 1 addition & 0 deletions crates/sui-bridge-indexer/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ diesel::table! {
timestamp_ms -> Int8,
txn_hash -> Bytea,
gas_usage -> Int8,
data_source -> Text,
}
}

Expand Down
15 changes: 10 additions & 5 deletions crates/sui-bridge-indexer/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
}
Expand All @@ -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,
})
}
Expand Down Expand Up @@ -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,
Expand All @@ -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(_) => (),
},
}
}
Expand Down

0 comments on commit 0a3c469

Please sign in to comment.