Skip to content

Commit

Permalink
refactor: send only one webhook in the end
Browse files Browse the repository at this point in the history
  • Loading branch information
agustinustheo committed Jul 23, 2024
1 parent c044488 commit 986f177
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/icp_prototype_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ async fn call_query_blocks() {

ic_cdk::println!("Response: {:?}", response);

let mut first_block_hash = String::default();
let mut block_count = next_block;
response.blocks.iter().for_each(|block| {
if let Some(operation) = block.transaction.operation.as_ref() {
Expand Down Expand Up @@ -555,8 +556,10 @@ async fn call_query_blocks() {
ic_cdk::println!("Inserting transaction");
let _ = transactions.insert(block_count, transaction);

#[allow(clippy::let_underscore_future)]
let _ = send_webhook(hash);
// Track the first block hash in the iter
if block_count == next_block {
first_block_hash = hash;
}
} else {
ic_cdk::println!("Transaction already exists");
}
Expand All @@ -566,6 +569,7 @@ async fn call_query_blocks() {
block_count += 1;
});

let _ = send_webhook(first_block_hash).await;
let _ = NEXT_BLOCK.with(|next_block_ref| next_block_ref.borrow_mut().set(block_count));
}

Expand Down

0 comments on commit 986f177

Please sign in to comment.