Skip to content

Commit 3314ca8

Browse files
committed
invalidate block end implementation
1 parent 57baa0f commit 3314ca8

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/ain-ocean/src/indexer/loan_token.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,21 @@ fn is_live(active: Option<OraclePriceActiveActive>, next: Option<OraclePriceActi
206206

207207
true
208208
}
209-
fn invalidate_block_end(service: &Arc<Services>, block: Block<Transaction>) {}
209+
pub fn invalidate_block_end(services: &Arc<Services>, block: Block<Transaction>) -> Result<()> {
210+
let pt = services
211+
.price_ticker
212+
.by_id
213+
.list(None, SortOrder::Ascending)?
214+
.map(|item| {
215+
let (_, priceticker) = item?;
216+
Ok(priceticker)
217+
})
218+
.collect::<Result<Vec<_>>>()?;
219+
220+
for ticker in pt {
221+
let id_with_height = (ticker.id.0.clone(), ticker.id.1.clone(), block.height);
222+
services.oracle_price_active.by_id.delete(&id_with_height)?;
223+
}
224+
225+
Ok(())
226+
}

lib/ain-ocean/src/indexer/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod helper;
1212

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

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

574-
pub fn invalidate_block(_block: Block<Transaction>) -> Result<()> {
576+
pub fn invalidate_block(services: &Arc<Services>,_block: Block<Transaction>) -> Result<()> {
577+
invalidate_block_end(services,_block)?;
578+
invalidate_(services,_block)?;
575579
Ok(())
576580
}

0 commit comments

Comments
 (0)