Skip to content

Commit

Permalink
invalidate block end implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarajm22 committed Jul 17, 2024
1 parent 57baa0f commit 3314ca8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/ain-ocean/src/indexer/loan_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,21 @@ fn is_live(active: Option<OraclePriceActiveActive>, next: Option<OraclePriceActi

true
}
fn invalidate_block_end(service: &Arc<Services>, block: Block<Transaction>) {}
pub fn invalidate_block_end(services: &Arc<Services>, block: Block<Transaction>) -> Result<()> {
let pt = services
.price_ticker
.by_id
.list(None, SortOrder::Ascending)?
.map(|item| {
let (_, priceticker) = item?;
Ok(priceticker)
})
.collect::<Result<Vec<_>>>()?;

for ticker in pt {
let id_with_height = (ticker.id.0.clone(), ticker.id.1.clone(), block.height);
services.oracle_price_active.by_id.delete(&id_with_height)?;
}

Ok(())
}
6 changes: 5 additions & 1 deletion lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub mod helper;

use std::{collections::HashMap, sync::Arc, time::Instant};

use std::{sync::Arc, time::Instant};
use crate::indexer::loan_token::invalidate_block_end;
use ain_dftx::{deserialize, is_skipped_tx, DfTx, Stack};
use defichain_rpc::json::blockchain::{Block, Transaction, Vin, VinStandard};
use helper::check_if_evm_tx;
Expand Down Expand Up @@ -571,6 +573,8 @@ pub fn index_block(services: &Arc<Services>, block: Block<Transaction>) -> Resul
Ok(())
}

pub fn invalidate_block(_block: Block<Transaction>) -> Result<()> {
pub fn invalidate_block(services: &Arc<Services>,_block: Block<Transaction>) -> Result<()> {
invalidate_block_end(services,_block)?;
invalidate_(services,_block)?;
Ok(())
}

0 comments on commit 3314ca8

Please sign in to comment.