diff --git a/lib/ain-ocean/src/indexer/loan_token.rs b/lib/ain-ocean/src/indexer/loan_token.rs index 4c6dafe2bf..3ae78b1e21 100644 --- a/lib/ain-ocean/src/indexer/loan_token.rs +++ b/lib/ain-ocean/src/indexer/loan_token.rs @@ -153,7 +153,7 @@ pub fn invalidate_active_price(services: &Arc, block: &BlockContext) - .flatten() .collect::>(); - for ((token, currency), _) in price_tickers { + for ((token, currency), _) in price_tickers.into_iter().rev() { services .oracle_price_active .by_id diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index 3299e63e7b..eea99999f9 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -298,7 +298,7 @@ fn index_script(services: &Arc, ctx: &Context, txs: &[Transaction]) -> return Err(Error::NotFoundIndex { action: IndexAction::Index, - r#type: "Script TransactionVout".to_string(), + r#type: "index_script TransactionVout".to_string(), id: format!("{}-{}", vin.txid, vin.vout), }); }; @@ -369,7 +369,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction let mut hid_set = HashSet::new(); - for vin in tx.vin.iter() { + for vin in tx.vin.iter().rev() { if is_evm_tx { continue; } @@ -387,7 +387,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction return Err(Error::NotFoundIndex { action: IndexAction::Invalidate, - r#type: "Script TransactionVout".to_string(), + r#type: "invalidate_script TransactionVout".to_string(), id: format!("{}-{}", vin.txid, vin.vout), }); }; @@ -397,7 +397,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction hid_set.insert(as_sha256(&vout.script.hex)); // part of invalidate_script_aggregation } - for vout in tx.vout.iter() { + for vout in tx.vout.iter().rev() { invalidate_script_unspent_vout(services, ctx, vout)?; if vout.script_pub_key.hex.starts_with(&[0x6a]) { @@ -428,7 +428,7 @@ fn invalidate_script_unspent_vin( let Some(transaction) = services.transaction.by_id.get(&vin.txid)? else { return Err(Error::NotFoundIndex { action: IndexAction::Invalidate, - r#type: "ScriptUnspentVin Transaction".to_string(), + r#type: "invalidate_script_unspent_vin Transaction".to_string(), id: vin.txid.to_string(), }); }; @@ -436,7 +436,7 @@ fn invalidate_script_unspent_vin( let Some(vout) = services.transaction.vout_by_id.get(&(vin.txid, vin.vout))? else { return Err(Error::NotFoundIndex { action: IndexAction::Invalidate, - r#type: "ScriptUnspentVin TransactionVout".to_string(), + r#type: "invalidate_script_unspent_vin TransactionVout".to_string(), id: format!("{}{}", vin.txid, vin.vout), }); }; @@ -664,7 +664,7 @@ pub fn invalidate_block(services: &Arc, block: Block) -> let mut dftxs = Vec::new(); - for (tx_idx, tx) in block.tx.clone().into_iter().enumerate() { + for (tx_idx, tx) in block.tx.clone().into_iter().rev().enumerate() { if is_skipped_tx(&tx.txid) { continue; } diff --git a/lib/ain-ocean/src/indexer/oracle.rs b/lib/ain-ocean/src/indexer/oracle.rs index 295ddbcbd6..461fc8c97e 100644 --- a/lib/ain-ocean/src/indexer/oracle.rs +++ b/lib/ain-ocean/src/indexer/oracle.rs @@ -90,7 +90,7 @@ impl Index for AppointOracle { .by_id .delete(&(oracle_id, context.block.height))?; - for currency_pair in self.price_feeds.as_ref() { + for currency_pair in self.price_feeds.iter().rev() { let token_currency_id = ( currency_pair.token.clone(), currency_pair.currency.clone(), @@ -146,7 +146,7 @@ impl Index for RemoveOracle { services.oracle.by_id.put(&oracle_id, &oracle)?; - for price_feed in previous.price_feeds { + for price_feed in previous.price_feeds.into_iter().rev() { let oracle_token_currency = OracleTokenCurrency { weightage: oracle.weightage, block: oracle.block.clone(), @@ -223,7 +223,7 @@ impl Index for UpdateOracle { .delete(&(oracle_id, context.block.height))?; let price_feeds = self.price_feeds.as_ref(); - for pair in price_feeds { + for pair in price_feeds.iter().rev() { services.oracle_token_currency.by_id.delete(&( pair.token.clone(), pair.currency.clone(), @@ -245,7 +245,7 @@ impl Index for UpdateOracle { }; services.oracle.by_id.put(&(prev_oracle_id), &prev_oracle)?; - for price_feed in &previous.price_feeds { + for price_feed in previous.price_feeds.iter().rev() { let oracle_token_currency = OracleTokenCurrency { weightage: previous.weightage, block: previous.block.clone(), @@ -447,7 +447,7 @@ impl Index for SetOracleData { let feeds = map_price_feeds(self, context); - for ((token, currency, _, _), _) in &feeds { + for ((token, currency, _, _), _) in feeds.iter().rev() { let id = (token.clone(), currency.clone(), context.block.height); let aggregated = oracle_repo.by_id.get(&id)?; @@ -456,7 +456,7 @@ impl Index for SetOracleData { continue; }; - for interval in AGGREGATED_INTERVALS { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { invalidate_oracle_interval( services, &context.block, diff --git a/lib/ain-ocean/src/indexer/poolswap.rs b/lib/ain-ocean/src/indexer/poolswap.rs index 3e424d0aaf..bc6bc8ad05 100644 --- a/lib/ain-ocean/src/indexer/poolswap.rs +++ b/lib/ain-ocean/src/indexer/poolswap.rs @@ -99,7 +99,7 @@ fn invalidate_swap_aggregated( from_amount: i64, txid: Txid, ) -> Result<()> { - for interval in AGGREGATED_INTERVALS { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { let repo = &services.pool_swap_aggregated; let prevs = repo .by_key @@ -231,8 +231,8 @@ impl IndexBlockStart for PoolSwap { let mut pool_pairs = ain_cpp_imports::get_pool_pairs(); pool_pairs.sort_by(|a, b| b.creation_height.cmp(&a.creation_height)); - for interval in AGGREGATED_INTERVALS { - for pool_pair in &pool_pairs { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { + for pool_pair in pool_pairs.iter().rev() { let pool_swap_aggregated_id = (pool_pair.id, interval, block.hash); services .pool_swap_aggregated @@ -400,7 +400,7 @@ impl Index for CompositeSwap { let from_token_id = self.pool_swap.from_token_id.0; let from_amount = self.pool_swap.from_amount; let txid = ctx.tx.txid; - for pool in self.pools.as_ref() { + for pool in self.pools.iter().rev() { let pool_id = pool.id.0 as u32; services .pool diff --git a/lib/ain-ocean/src/indexer/transaction.rs b/lib/ain-ocean/src/indexer/transaction.rs index ab39c1070a..43d9ace500 100644 --- a/lib/ain-ocean/src/indexer/transaction.rs +++ b/lib/ain-ocean/src/indexer/transaction.rs @@ -117,7 +117,7 @@ pub fn invalidate_transaction(services: &Arc, ctx: &Context) -> Result services.transaction.by_id.delete(&ctx.tx.txid)?; let is_evm = check_if_evm_tx(&ctx.tx); - for vin in ctx.tx.vin.clone().into_iter() { + for vin in ctx.tx.vin.clone().into_iter().rev() { if is_evm { continue; } @@ -133,7 +133,7 @@ pub fn invalidate_transaction(services: &Arc, ctx: &Context) -> Result } } - for vout in ctx.tx.vout.clone().into_iter() { + for vout in ctx.tx.vout.clone().into_iter().rev() { services .transaction .vout_by_id