diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 46f5251..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,28 +0,0 @@ -# https://ectobit.com/blog/speed-up-github-actions-rust-pipelines/ -name: Test - -on: - push: - branches: - - develop - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.cargo - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: Build and Test - run: | - cargo test - if [ $? -ne 0 ]; then - exit 1 - fi \ No newline at end of file diff --git a/src/routes/message.rs b/src/routes/message.rs index fcd72ae..7a473a4 100644 --- a/src/routes/message.rs +++ b/src/routes/message.rs @@ -93,12 +93,16 @@ struct HodlMessage { #[derive(Debug, EnumIter)] pub enum EventType { TokenSwapped, + PoolExited, + PoolJoined, } impl Display for EventType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = match self { EventType::TokenSwapped => "token_swapped", + EventType::PoolExited => "pool_exited", + EventType::PoolJoined => "pool_joined", }; write!(f, "{}", s) } diff --git a/src/routes/query.rs b/src/routes/query.rs index 5bb0b60..34b4b8c 100644 --- a/src/routes/query.rs +++ b/src/routes/query.rs @@ -148,19 +148,85 @@ pub async fn track_messages( for hm in HodlMessageType::iter() { if doesContainMessageType(tx, &hm) { - hodl_messages - .entry(hm.to_string()) - .or_insert(vec![]) - .push(tx.clone()); + let response = getTxRawByHash(&tx.TxHash.to_string(), &target_chain).await; + let unwrapped_response = response.clone(); + let unwrapped_response = match unwrapped_response { + Ok(response) => response, + Err(_) => continue, + }; + if unwrapped_response.tx_response.is_none() { + continue; + } + + let tx_response = response.clone().unwrap().tx_response.unwrap(); + if !isSucceedTransaction(&tx_response) { + continue; + } + + let supported_blockchains = get_supported_blockchains(); + let cosmos_blockchains = supported_blockchains.get(&token_denom).unwrap(); + let cosmos_token_denom = cosmos_blockchains.clone().cosmos_token_denom; + let cosmos_blockchain_denom = cosmos_token_denom.clone().unwrap_or_default(); + + let events = tx_response.clone().events; + for event in events { + if event.r#type == EventType::PoolJoined.to_string() { + for attribute in &event.attributes { + if attribute.key == "pool_id" && attribute.value == "722" { + for attribute in &event.attributes { + if attribute.value.contains(&cosmos_blockchain_denom) { + hodl_messages + .entry(hm.to_string()) + .or_insert(vec![]) + .push(tx.clone()); + } + } + } + } + } + } } } for dm in DumpMessageType::iter() { if doesContainMessageType(tx, &dm) { - dump_messages - .entry(dm.to_string()) - .or_insert(vec![]) - .push(tx.clone()); + let response = getTxRawByHash(&tx.TxHash.to_string(), &target_chain).await; + let unwrapped_response = response.clone(); + let unwrapped_response = match unwrapped_response { + Ok(response) => response, + Err(_) => continue, + }; + if unwrapped_response.tx_response.is_none() { + continue; + } + + let tx_response = response.clone().unwrap().tx_response.unwrap(); + if !isSucceedTransaction(&tx_response) { + continue; + } + + let supported_blockchains = get_supported_blockchains(); + let cosmos_blockchains = supported_blockchains.get(&token_denom).unwrap(); + let cosmos_token_denom = cosmos_blockchains.clone().cosmos_token_denom; + let cosmos_blockchain_denom = cosmos_token_denom.clone().unwrap_or_default(); + + let events = tx_response.clone().events; + for event in events { + if event.r#type == EventType::PoolExited.to_string() { + for attribute in &event.attributes { + if attribute.key == "pool_id" && attribute.value == "722" { + for attribute in &event.attributes { + if attribute.value.contains(&cosmos_blockchain_denom) { + dump_messages + .entry(dm.to_string()) + .or_insert(vec![]) + .push(tx.clone()); + } + } + } + } + } + } } } } @@ -225,11 +291,12 @@ async fn getTxRawByHash(tx_hash: &str, target_chain: &str) -> Result return Err(e.to_string()), }; - let deserialized: IntermediateGetTxResponse = serde_json::from_str(&*json_str).map_err(|e| { - println!("json_str: {}", json_str); - println!("deserialized error: {}", e.to_string()); - e.to_string() - })?; + let deserialized: IntermediateGetTxResponse = + serde_json::from_str(&*json_str).map_err(|e| { + println!("json_str: {}", json_str); + println!("deserialized error: {}", e.to_string()); + e.to_string() + })?; let tx_response = match deserialized.tx_response { Some(s) => {