Skip to content

Commit

Permalink
indexer schema updates and logging (#17948)
Browse files Browse the repository at this point in the history
## Description 

Added few columns to make the usage of single table more expressive
without joins. Look at the difference in the schema (`up.sql`)
Also added logging api and changed `println` to `info`.
Logs are reasonably verbose now but that should not be a problem for
prod and should be helpful for debugging.
I run it this way to get logs in a file `RUST_LOG_FILE="filename" cargo
run --release`
Reverted back to `Vec<u8>` instead of `String` for `txn_hash` and
`sender/receiver`.
The difference between the 2 when looking at the table are as follows 

```
-- String based data
 chain_id | nonce |  status   | block_height | timestamp_ms  |                   txn_hash                   |                           sender_address                           | gas_usage | data_source 
----------+-------+-----------+--------------+---------------+----------------------------------------------+--------------------------------------------------------------------+-----------+-------------
       11 |     0 | Deposited |      5861340 | 1715174472000 | HUU2xuBxHaDfxiEpWyexh1Z7DDUVzncuRP2a4tsrTVgU | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    220828 | ETH
       11 |     1 | Deposited |      5862057 | 1715184816000 | A4bDLKbYK1MegEjbn6EEzpgVbJ1jCK4irAKoYRbAx6i9 | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    195193 | ETH
       11 |     2 | Deposited |      5862071 | 1715185020000 | 2t3CVHWMJczuK2ThZThjhBPAEL6UTwM5HnRMzyMX9YKp | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
       11 |     3 | Deposited |      5862103 | 1715185440000 | J34bAwQfGquGbFSA8eF6jG9nhxQk2FbdnnYRiq6T3mNA | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    169135 | ETH
       11 |     4 | Deposited |      5862135 | 1715185968000 | 5doepLHWdFB1AsfgkdESCaCn9E9rtNsghapDmmHnZrLf | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    190218 | ETH
        2 |     0 | Claimed   |      5862564 | 1715192124000 | 2EVyKTS5ouRWxVHqPcX3bmCQTcmjrNgDrTJjuuajxUB1 | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    472674 | ETH
        2 |     1 | Claimed   |      5862923 | 1715197332000 | 77F1vKs1FcWSwVLEXTvDUwe7PVLcodGs5futoyFiLFjs | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    472711 | ETH
        2 |     2 | Claimed   |      5862932 | 1715197488000 | 8rEhXieaZZrYTmQzU5i2a1kZtTvzC2wmumScKt5nTpVx | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    446617 | ETH
       11 |     5 | Deposited |      5862954 | 1715197836000 | AHqBqy76PAoxcTMwrUCZbCdbiqN3tdfek6T5Yd98HFJV | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
       11 |     6 | Deposited |      5862954 | 1715197836000 | HQcFiEDstCzKK2ii4m2j3agTcHBE43rVQSjUJ9oE8pjd | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
        2 |     4 | Claimed   |      5862991 | 1715198352000 | 5CTYtwXYLpBiSbWFmF53GNLwrjPCyopSthzwwRcwHQ9W | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |    460354 | ETH
       11 |     7 | Deposited |      5863012 | 1715198616000 | 7BLsDhMzTN5GweH4X1dPZ5YkwzuEG4YAKXdRSAGNXom3 | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    169155 | ETH
       11 |     8 | Deposited |      5863020 | 1715198724000 | 4pUJs6HfTiq9Q23GjE3e2Ci92wnbX3LYjUQqyJtKudpY | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    195211 | ETH
       11 |     9 | Deposited |      5863031 | 1715198880000 | 8rbnDQCGGCnEaCxGxRYGJVBNr9dtTyNi3SYRDZV3AJW8 | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    164179 | ETH


-- Binary (bytearray) based data
 chain_id | nonce |  status   | block_height | timestamp_ms  |                              txn_hash                              |                             txn_sender                             | gas_usage | data_source 
----------+-------+-----------+--------------+---------------+--------------------------------------------------------------------+--------------------------------------------------------------------+-----------+-------------
       11 |     0 | Deposited |      5861340 | 1715174472000 | \xf4c43d6d3908eb9faff1ffa11cdb6646c7aa42e82d3a77a806370f5694d90b81 | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    220828 | ETH
       11 |     1 | Deposited |      5862057 | 1715184816000 | \x86a49bef44073ccd2a826145296f143fa0fcbab5cc249834328274a29da4d7ee | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    195193 | ETH
       11 |     2 | Deposited |      5862071 | 1715185020000 | \x1beecb25e80fa2445262809d39547ad7c53eca1193ba34d5d564c0ec594ed1bf | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
       11 |     3 | Deposited |      5862103 | 1715185440000 | \xfd1de5cbf82edf244e55e1ba78d8985458a3493b80d8ddceddabe03a2e488f8b | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    169135 | ETH
       11 |     4 | Deposited |      5862135 | 1715185968000 | \x44dc680b05c2a2768908234ad09e7b246a9d2a06c2aca1bcec1bdaa913bc3a28 | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |    190218 | ETH
        2 |     0 | Claimed   |      5862564 | 1715192124000 | \x1250febc68e3dff8ca20d1d71d24d2e412c66ef0991d5283459e9a40d5118ce8 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    472674 | ETH
        2 |     1 | Claimed   |      5862923 | 1715197332000 | \x5abf7445934a77bf3f6f38f755b416c6a5e4f4488d85205511163db2de254cf6 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    472711 | ETH
        2 |     2 | Claimed   |      5862932 | 1715197488000 | \x749ec1e4bceb4397213f39ab549da0a49b60a054bc954d0260b6dcdf9064334b | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |    446617 | ETH
       11 |     5 | Deposited |      5862954 | 1715197836000 | \x8a08f5e0e97eb71da1b5e30a88c3a828cb386bfab60eb587174af3206ab9315e | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
       11 |     6 | Deposited |      5862954 | 1715197836000 | \xf3c735f9c5d51218b7b3f0a18fd4d5888d975fe3d1a497c8ae5381daadbd366c | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    168732 | ETH
        2 |     4 | Claimed   |      5862991 | 1715198352000 | \x3e5e281d660eb0f9251f46ffccd5bda5667fe1d7cef69c26045462cdbc7c5de9 | \x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |    460354 | ETH
       11 |     7 | Deposited |      5863012 | 1715198616000 | \x5bcc645c06121e738d52f3806975627f6590e753d0dc7deb837172de6e0b8492 | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |    169155 | ETH
        2 |    43 | Approved  |      4873316 | 1716918029329 | \x7a997c9292d9269e58f62c66f9a68777678e593a55d3d1079781ba13d1f6e9cc | \xfc7184a6a8b1e46a649fbdb7458433182974eb76966ab622952473f399dced6f |   2574488 | SUI
        2 |    43 | Deposited |      4873310 | 1716918027775 | \x0681e6af27a82441889f4e05eedcbd26af13b049111a7358071a90d8db5b62e1 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |   5123988 | SUI


-- String based data
 chain_id | nonce | block_height | timestamp_ms  |                   txn_hash                   |                           sender_address                           | destination_chain |                         recipient_address                          | token_id |     amount     
----------+-------+--------------+---------------+----------------------------------------------+--------------------------------------------------------------------+-------------------+--------------------------------------------------------------------+----------+----------------
       11 |     0 |      5861340 | 1715174472000 | HUU2xuBxHaDfxiEpWyexh1Z7DDUVzncuRP2a4tsrTVgU | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        2 |           1000
       11 |     1 |      5862057 | 1715184816000 | A4bDLKbYK1MegEjbn6EEzpgVbJ1jCK4irAKoYRbAx6i9 | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        3 |        1000000
       11 |     2 |      5862071 | 1715185020000 | 2t3CVHWMJczuK2ThZThjhBPAEL6UTwM5HnRMzyMX9YKp | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |       10000000
       11 |     3 |      5862103 | 1715185440000 | J34bAwQfGquGbFSA8eF6jG9nhxQk2FbdnnYRiq6T3mNA | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        3 |        1000000
       11 |     4 |      5862135 | 1715185968000 | 5doepLHWdFB1AsfgkdESCaCn9E9rtNsghapDmmHnZrLf | 0x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | 0x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        4 |        1000000
       11 |     5 |      5862954 | 1715197836000 | AHqBqy76PAoxcTMwrUCZbCdbiqN3tdfek6T5Yd98HFJV | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |      100000000
       11 |     6 |      5862954 | 1715197836000 | HQcFiEDstCzKK2ii4m2j3agTcHBE43rVQSjUJ9oE8pjd | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |      100000000
       11 |     7 |      5863012 | 1715198616000 | 7BLsDhMzTN5GweH4X1dPZ5YkwzuEG4YAKXdRSAGNXom3 | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        3 |     1000000000
       11 |     8 |      5863020 | 1715198724000 | 4pUJs6HfTiq9Q23GjE3e2Ci92wnbX3LYjUQqyJtKudpY | 0x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | 0x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        1


-- Binary (bytearray)  based data
 chain_id | nonce | block_height | timestamp_ms  |                              txn_hash                              |                           sender_address                           | destination_chain |                         recipient_address                          | token_id |    amount    
----------+-------+--------------+---------------+--------------------------------------------------------------------+--------------------------------------------------------------------+-------------------+--------------------------------------------------------------------+----------+--------------
       11 |     0 |      5861340 | 1715174472000 | \xf4c43d6d3908eb9faff1ffa11cdb6646c7aa42e82d3a77a806370f5694d90b81 | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        2 |         1000
       11 |     1 |      5862057 | 1715184816000 | \x86a49bef44073ccd2a826145296f143fa0fcbab5cc249834328274a29da4d7ee | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        3 |      1000000
       11 |     2 |      5862071 | 1715185020000 | \x1beecb25e80fa2445262809d39547ad7c53eca1193ba34d5d564c0ec594ed1bf | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | \x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |     10000000
       11 |     3 |      5862103 | 1715185440000 | \xfd1de5cbf82edf244e55e1ba78d8985458a3493b80d8ddceddabe03a2e488f8b | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        3 |      1000000
       11 |     4 |      5862135 | 1715185968000 | \x44dc680b05c2a2768908234ad09e7b246a9d2a06c2aca1bcec1bdaa913bc3a28 | \x1a8579b81db07f6e4828cb47d3f130314f10653b                         |                 2 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |        4 |      1000000
       11 |     5 |      5862954 | 1715197836000 | \x8a08f5e0e97eb71da1b5e30a88c3a828cb386bfab60eb587174af3206ab9315e | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | \x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |    100000000
       11 |     6 |      5862954 | 1715197836000 | \xf3c735f9c5d51218b7b3f0a18fd4d5888d975fe3d1a497c8ae5381daadbd366c | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | \x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        2 |    100000000
       11 |     7 |      5863012 | 1715198616000 | \x5bcc645c06121e738d52f3806975627f6590e753d0dc7deb837172de6e0b8492 | \x25044d9f0cdd1df5a9aaba174adc8416f58dcfbc                         |                 2 | \x1b54fa3e1629cc72093bd9f6b9cf4a88091f67c9da811bdfc9a54e439c179aa6 |        3 |   1000000000
        2 |    43 |      4873310 | 1716918027775 | \x0681e6af27a82441889f4e05eedcbd26af13b049111a7358071a90d8db5b62e1 | \x2fd42dfdbd2eb7055a7bc7d4ce000ae53cc22f0c2f2006862bebc8df1f676027 |                11 | \x1a8579b81db07f6e4828cb47d3f130314f10653b             

```

## Test plan 

This is it and run the indexer for a while

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
dariorussi authored May 30, 2024
1 parent d44f1c0 commit c953994
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions crates/sui-bridge-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ serde.workspace = true
diesel = { version = "2.1.4", features = ["postgres", "r2d2", "serde_json"] }
ethers = "2.0"
tokio = { workspace = true, features = ["full"] }
sui-types.workspace = true
prometheus.workspace = true
anyhow.workspace = true
async-trait.workspace = true
sui-data-ingestion-core.workspace = true
sui-bridge.workspace = true
clap.workspace = true
tracing.workspace = true
bcs.workspace = true
bin-version.workspace = true
anyhow.workspace = true
clap.workspace = true
mysten-metrics.workspace = true
bcs.workspace = true
prometheus.workspace = true
serde_yaml.workspace = true
sui-bridge.workspace = true
sui-data-ingestion-core.workspace = true
sui-types.workspace = true
telemetry-subscribers.workspace = true
tracing.workspace = true

[dev-dependencies]
sui-types = { workspace = true, features = ["test-utils"] }
Expand Down
5 changes: 5 additions & 0 deletions crates/sui-bridge-indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct TokenTransfer {
block_height: u64,
timestamp_ms: u64,
txn_hash: Vec<u8>,
txn_sender: Vec<u8>,
status: TokenTransferStatus,
gas_usage: i64,
data_source: BridgeDataSource,
Expand All @@ -40,6 +41,7 @@ impl From<TokenTransfer> for DBTokenTransfer {
block_height: value.block_height as i64,
timestamp_ms: value.timestamp_ms as i64,
txn_hash: value.txn_hash,
txn_sender: value.txn_sender.clone(),
status: value.status.to_string(),
gas_usage: value.gas_usage,
data_source: value.data_source.to_string(),
Expand All @@ -63,6 +65,9 @@ impl TryFrom<&TokenTransfer> for DBTokenTransferData {
.map(|data| DBTokenTransferData {
chain_id: value.chain_id as i32,
nonce: value.nonce as i64,
block_height: value.block_height as i64,
timestamp_ms: value.timestamp_ms as i64,
txn_hash: value.txn_hash.clone(),
sender_address: data.sender_address.clone(),
destination_chain: data.destination_chain as i32,
recipient_address: data.recipient_address.clone(),
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-bridge-indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct Args {

#[tokio::main]
async fn main() -> Result<()> {
let _guard = telemetry_subscribers::TelemetryConfig::new()
.with_env()
.init();

let args = Args::parse();

// load config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ CREATE TABLE token_transfer_data
(
chain_id INT NOT NULL,
nonce BIGINT NOT NULL,
block_height BIGINT NOT NULL,
timestamp_ms BIGINT NOT NULL,
txn_hash bytea NOT NULL,
sender_address bytea NOT NULL,
destination_chain INT NOT NULL,
recipient_address bytea NOT NULL,
token_id INT NOT NULL,
amount BIGINT NOT NULL,
PRIMARY KEY(chain_id, nonce)
);
CREATE INDEX token_transfer_data_block_height ON token_transfer_data (block_height);
CREATE INDEX token_transfer_data_timestamp_ms ON token_transfer_data (timestamp_ms);
CREATE INDEX token_transfer_data_sender_address ON token_transfer_data (sender_address);
CREATE INDEX token_transfer_data_destination_chain ON token_transfer_data (destination_chain);
CREATE INDEX token_transfer_data_token_id ON token_transfer_data (token_id);

Expand All @@ -20,7 +26,10 @@ CREATE TABLE token_transfer
block_height BIGINT NOT NULL,
timestamp_ms BIGINT NOT NULL,
txn_hash bytea NOT NULL,
txn_sender bytea NOT NULL,
gas_usage BIGINT NOT NULL,
data_source TEXT NOT NULL,
PRIMARY KEY(chain_id, nonce, status)
);
);
CREATE INDEX token_transfer_block_height ON token_transfer (block_height);
CREATE INDEX token_transfer_timestamp_ms ON token_transfer (timestamp_ms);
4 changes: 4 additions & 0 deletions crates/sui-bridge-indexer/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct TokenTransfer {
pub block_height: i64,
pub timestamp_ms: i64,
pub txn_hash: Vec<u8>,
pub txn_sender: Vec<u8>,
pub gas_usage: i64,
pub data_source: String,
}
Expand All @@ -22,6 +23,9 @@ pub struct TokenTransfer {
pub struct TokenTransferData {
pub chain_id: i32,
pub nonce: i64,
pub block_height: i64,
pub timestamp_ms: i64,
pub txn_hash: Vec<u8>,
pub sender_address: Vec<u8>,
pub destination_chain: i32,
pub recipient_address: Vec<u8>,
Expand Down
6 changes: 5 additions & 1 deletion crates/sui-bridge-indexer/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ diesel::table! {
block_height -> Int8,
timestamp_ms -> Int8,
txn_hash -> Bytea,
txn_sender -> Bytea,
gas_usage -> Int8,
data_source -> Text,
}
Expand All @@ -20,6 +21,9 @@ diesel::table! {
token_transfer_data (chain_id, nonce) {
chain_id -> Int4,
nonce -> Int8,
block_height -> Int8,
timestamp_ms -> Int8,
txn_hash -> Bytea,
sender_address -> Bytea,
destination_chain -> Int4,
recipient_address -> Bytea,
Expand All @@ -28,4 +32,4 @@ diesel::table! {
}
}

diesel::allow_tables_to_appear_in_same_query!(token_transfer, token_transfer_data,);
diesel::allow_tables_to_appear_in_same_query!(token_transfer, token_transfer_data);
45 changes: 25 additions & 20 deletions crates/sui-bridge-indexer/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use sui_bridge::events::{
};
use sui_bridge::types::EthLog;
use sui_data_ingestion_core::Worker;
use sui_types::effects::TransactionEffectsAPI;
use sui_types::{
base_types::ObjectID,
effects::TransactionEffectsAPI,
full_checkpoint_content::{CheckpointData, CheckpointTransaction},
transaction::{TransactionDataAPI, TransactionKind},
BRIDGE_ADDRESS, SUI_BRIDGE_OBJECT_ID,
Expand Down Expand Up @@ -57,35 +57,36 @@ impl BridgeWorker {

// Process a transaction that has been identified as a bridge transaction.
fn process_transaction(&self, tx: &CheckpointTransaction, checkpoint: u64, timestamp_ms: u64) {
if let Some(event) = &tx.events {
event.data.iter().for_each(|ev| {
if let Some(events) = &tx.events {
events.data.iter().for_each(|ev| {
if ev.type_.address == BRIDGE_ADDRESS {
let token_transfer = match ev.type_.name.as_str() {
"TokenDepositedEvent" => {
println!("Observed Sui Deposit");
// todo: handle deserialization error
let event: MoveTokenDepositedEvent =
info!("Observed Sui Deposit {:?}", ev);
// TODO: handle deserialization error
let move_event: MoveTokenDepositedEvent =
bcs::from_bytes(&ev.contents).unwrap();
Some(TokenTransfer {
chain_id: event.source_chain,
nonce: event.seq_num,
chain_id: move_event.source_chain,
nonce: move_event.seq_num,
block_height: checkpoint,
timestamp_ms,
txn_hash: tx.transaction.digest().inner().to_vec(),
txn_sender: ev.sender.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,
recipient_address: event.target_address,
token_id: event.token_type,
amount: event.amount_sui_adjusted,
destination_chain: move_event.target_chain,
sender_address: move_event.sender_address.clone(),
recipient_address: move_event.target_address.clone(),
token_id: move_event.token_type,
amount: move_event.amount_sui_adjusted,
}),
})
}
"TokenTransferApproved" => {
println!("Observed Sui Approval");
info!("Observed Sui Approval {:?}", ev);
let event: MoveTokenTransferApproved =
bcs::from_bytes(&ev.contents).unwrap();
Some(TokenTransfer {
Expand All @@ -94,14 +95,15 @@ impl BridgeWorker {
block_height: checkpoint,
timestamp_ms,
txn_hash: tx.transaction.digest().inner().to_vec(),
txn_sender: ev.sender.to_vec(),
status: TokenTransferStatus::Approved,
gas_usage: tx.effects.gas_cost_summary().net_gas_usage(),
data_source: BridgeDataSource::Sui,
data: None,
})
}
"TokenTransferClaimed" => {
println!("Observed Sui Claim");
info!("Observed Sui Claim {:?}", ev);
let event: MoveTokenTransferClaimed =
bcs::from_bytes(&ev.contents).unwrap();
Some(TokenTransfer {
Expand All @@ -110,6 +112,7 @@ impl BridgeWorker {
block_height: checkpoint,
timestamp_ms,
txn_hash: tx.transaction.digest().inner().to_vec(),
txn_sender: ev.sender.to_vec(),
status: TokenTransferStatus::Claimed,
gas_usage: tx.effects.gas_cost_summary().net_gas_usage(),
data_source: BridgeDataSource::Sui,
Expand All @@ -120,7 +123,7 @@ impl BridgeWorker {
};

if let Some(transfer) = token_transfer {
println!("SUI: Storing bridge event : {:?}", ev.type_);
info!("SUI: Storing bridge event : {:?}", ev.type_);
write(&self.pg_pool, transfer);
}
};
Expand Down Expand Up @@ -152,24 +155,25 @@ pub async fn process_eth_transaction(
let gas = transaction.gas;
let tx_hash = log.tx_hash;

println!("Observed Eth bridge event: {:#?}", bridge_event);
info!("Observed Eth bridge event: {:?}", bridge_event);

match bridge_event {
EthBridgeEvent::EthSuiBridgeEvents(bridge_event) => match bridge_event {
EthSuiBridgeEvents::TokensDepositedFilter(bridge_event) => {
println!("Observed Eth Deposit");
info!("Observed Eth Deposit {:?}", bridge_event);
let transfer = TokenTransfer {
chain_id: bridge_event.source_chain_id,
nonce: bridge_event.nonce,
block_height: block_number,
timestamp_ms: timestamp,
txn_hash: tx_hash.as_bytes().to_vec(),
txn_sender: bridge_event.sender_address.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,
sender_address: bridge_event.sender_address.as_bytes().to_vec(),
recipient_address: bridge_event.recipient_address.to_vec(),
token_id: bridge_event.token_id,
amount: bridge_event.sui_adjusted_amount,
Expand All @@ -179,13 +183,14 @@ pub async fn process_eth_transaction(
write(&pool, transfer);
}
EthSuiBridgeEvents::TokensClaimedFilter(bridge_event) => {
println!("Observed Eth Claim");
info!("Observed Eth Claim {:?}", bridge_event);
let transfer = TokenTransfer {
chain_id: bridge_event.source_chain_id,
nonce: bridge_event.nonce,
block_height: block_number,
timestamp_ms: timestamp,
txn_hash: tx_hash.as_bytes().to_vec(),
txn_sender: bridge_event.sender_address.to_vec(),
status: TokenTransferStatus::Claimed,
gas_usage: gas.as_u64() as i64,
data_source: BridgeDataSource::Eth,
Expand Down

0 comments on commit c953994

Please sign in to comment.