Skip to content

Commit

Permalink
skip if no active_price
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Nov 29, 2024
1 parent 813cbce commit b65d14b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/ain-ocean/src/indexer/loan_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,29 @@ fn map_active_price(
block: &BlockContext,
aggregated_price: OraclePriceAggregated,
prev_price: Option<OraclePriceActive>,
) -> OraclePriceActive {
let next_price = if is_aggregate_valid(&aggregated_price, block) {
Some(aggregated_price.aggregated)
} else {
None
};

) -> Option<OraclePriceActive> {
let active_price = if let Some(prev_price) = prev_price {
if let Some(next) = prev_price.next {
Some(next)
} else {
prev_price.active
}
} else {
return None
};

let next_price = if is_aggregate_valid(&aggregated_price, block) {
Some(aggregated_price.aggregated)
} else {
None
};

OraclePriceActive {
Some(OraclePriceActive {
active: active_price.clone(),
next: next_price.clone(),
is_live: is_live(active_price, next_price),
block: block.clone(),
}
})
}

pub fn invalidate_active_price(services: &Arc<Services>, block: &BlockContext) -> Result<()> {
Expand Down Expand Up @@ -205,6 +205,9 @@ pub fn perform_active_price_tick(
};

let active_price = map_active_price(block, aggregated_price, prev_price);
let Some(active_price) = active_price else {
return Ok(())
};

repo.by_id
.put(&(id.0, id.1, block.height.to_be_bytes()), &active_price)?;
Expand Down

0 comments on commit b65d14b

Please sign in to comment.