From 1b58ee91ed265ac06c9e97f4c3269302fbc50691 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Fri, 22 Nov 2024 15:11:03 +0800 Subject: [PATCH] fmt_rs --- lib/ain-ocean/src/api/address.rs | 8 ++----- lib/ain-ocean/src/api/loan.rs | 5 +++- lib/ain-ocean/src/api/prices.rs | 15 ++---------- lib/ain-ocean/src/indexer/loan_token.rs | 19 ++++++++++----- lib/ain-ocean/src/indexer/mod.rs | 32 ++++++++++++++++++++----- lib/ain-ocean/src/indexer/oracle.rs | 7 +++++- 6 files changed, 53 insertions(+), 33 deletions(-) diff --git a/lib/ain-ocean/src/api/address.rs b/lib/ain-ocean/src/api/address.rs index e41ff07373..a685b42119 100644 --- a/lib/ain-ocean/src/api/address.rs +++ b/lib/ain-ocean/src/api/address.rs @@ -460,16 +460,12 @@ async fn list_transaction_unspent( let txid = Txid::from_str(txid)?; let decoded_n = hex::decode(n)?; let n = decoded_n.try_into().map_err(|_| Error::Other { - msg: format!("Invalid txno: {}", n) + msg: format!("Invalid txno: {}", n), })?; Ok::<([u8; 4], Txid, [u8; 8]), Error>((height, txid, n)) }) .transpose()? - .unwrap_or(( - [0u8; 4], - Txid::from_byte_array([0x00u8; 32]), - [0u8; 8], - )); + .unwrap_or(([0u8; 4], Txid::from_byte_array([0x00u8; 32]), [0u8; 8])); let res = ctx .services diff --git a/lib/ain-ocean/src/api/loan.rs b/lib/ain-ocean/src/api/loan.rs index 7316561754..fb67b4b63f 100644 --- a/lib/ain-ocean/src/api/loan.rs +++ b/lib/ain-ocean/src/api/loan.rs @@ -138,7 +138,10 @@ fn get_active_price( .services .oracle_price_active .by_id - .list(Some((token.clone(), currency.clone(), [0xffu8; 4])), SortOrder::Descending)? + .list( + Some((token.clone(), currency.clone(), [0xffu8; 4])), + SortOrder::Descending, + )? .take_while(|item| match item { Ok((k, _)) => k.0 == token && k.1 == currency, _ => true, diff --git a/lib/ain-ocean/src/api/prices.rs b/lib/ain-ocean/src/api/prices.rs index e780ec921f..47e0d44f32 100644 --- a/lib/ain-ocean/src/api/prices.rs +++ b/lib/ain-ocean/src/api/prices.rs @@ -202,7 +202,6 @@ async fn get_feed( .transpose()? .unwrap_or(([0xffu8; 8], [0xffu8; 4])); - let repo = &ctx.services.oracle_price_aggregated; let id = (token.clone(), currency.clone(), next.0, next.1); let oracle_aggregated = repo @@ -387,12 +386,7 @@ async fn get_feed_with_interval( .transpose()? .unwrap_or([0xffu8; 4]); - let id = ( - token.clone(), - currency.clone(), - interval_type.clone(), - next, - ); + let id = (token.clone(), currency.clone(), interval_type.clone(), next); let items = ctx .services @@ -476,12 +470,7 @@ async fn list_price_oracles( .transpose()? .unwrap_or(Txid::from_byte_array([0xffu8; 32])); - - let id = ( - token.clone(), - currency.clone(), - next, - ); + let id = (token.clone(), currency.clone(), next); let token_currencies = ctx .services .oracle_token_currency diff --git a/lib/ain-ocean/src/indexer/loan_token.rs b/lib/ain-ocean/src/indexer/loan_token.rs index 964fea963b..cc35ca42ef 100644 --- a/lib/ain-ocean/src/indexer/loan_token.rs +++ b/lib/ain-ocean/src/indexer/loan_token.rs @@ -144,10 +144,11 @@ pub fn invalidate_active_price(services: &Arc, block: &BlockContext) - .collect::>(); for ((token, currency), _) in price_tickers.into_iter().rev() { - services - .oracle_price_active - .by_id - .delete(&(token, currency, block.height.to_be_bytes()))?; + services.oracle_price_active.by_id.delete(&( + token, + currency, + block.height.to_be_bytes(), + ))?; } } @@ -159,7 +160,12 @@ pub fn perform_active_price_tick( ticker_id: (Token, Currency), block: &BlockContext, ) -> Result<()> { - let id = (ticker_id.0.clone(), ticker_id.1.clone(), [0xffu8; 8], [0xffu8; 4]); + let id = ( + ticker_id.0.clone(), + ticker_id.1.clone(), + [0xffu8; 8], + [0xffu8; 4], + ); let prev = services .oracle_price_aggregated @@ -188,7 +194,8 @@ pub fn perform_active_price_tick( let active_price = map_active_price(block, aggregated_price, prev_price); - repo.by_id.put(&(id.0, id.1, block.height.to_be_bytes()), &active_price)?; + repo.by_id + .put(&(id.0, id.1, block.height.to_be_bytes()), &active_price)?; Ok(()) } diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index 1824e285f4..a0e78fb3e2 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -160,7 +160,11 @@ fn index_script_unspent_vin( vin: &VinStandard, ctx: &Context, ) -> Result<()> { - let key = (ctx.block.height.to_be_bytes(), vin.txid, vin.vout.to_be_bytes()); + let key = ( + ctx.block.height.to_be_bytes(), + vin.txid, + vin.vout.to_be_bytes(), + ); let id = services.script_unspent.by_key.get(&key)?; if let Some(id) = id { services.script_unspent.by_id.delete(&id)?; @@ -255,7 +259,12 @@ fn index_script_unspent_vout(services: &Arc, vout: &Vout, ctx: &Contex }, }; - let id = (hid, block.height.to_be_bytes(), tx.txid, vout.n.to_be_bytes()); + let id = ( + hid, + block.height.to_be_bytes(), + tx.txid, + vout.n.to_be_bytes(), + ); let key = (block.height.to_be_bytes(), tx.txid, vout.n.to_be_bytes()); services.script_unspent.by_key.put(&key, &id)?; services.script_unspent.by_id.put(&id, &script_unspent)?; @@ -341,8 +350,10 @@ fn index_script(services: &Arc, ctx: &Context, txs: &[Transaction]) -> aggregation.statistic.tx_in_count + aggregation.statistic.tx_out_count; aggregation.amount.unspent = aggregation.amount.tx_in - aggregation.amount.tx_out; - repo.by_id - .put(&(aggregation.hid, ctx.block.height.to_be_bytes()), &aggregation)?; + repo.by_id.put( + &(aggregation.hid, ctx.block.height.to_be_bytes()), + &aggregation, + )?; record.insert(aggregation.hid, aggregation); } @@ -496,8 +507,17 @@ fn invalidate_script_unspent_vout( vout: &Vout, ) -> Result<()> { let hid = as_sha256(&vout.script_pub_key.hex); - let id = (hid, ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n.to_be_bytes()); - let key = (ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n.to_be_bytes()); + let id = ( + hid, + ctx.block.height.to_be_bytes(), + ctx.tx.txid, + vout.n.to_be_bytes(), + ); + let key = ( + ctx.block.height.to_be_bytes(), + ctx.tx.txid, + vout.n.to_be_bytes(), + ); services.script_unspent.by_id.delete(&id)?; services.script_unspent.by_key.delete(&key)?; diff --git a/lib/ain-ocean/src/indexer/oracle.rs b/lib/ain-ocean/src/indexer/oracle.rs index 77ab02710f..6ca9d02aeb 100644 --- a/lib/ain-ocean/src/indexer/oracle.rs +++ b/lib/ain-ocean/src/indexer/oracle.rs @@ -550,7 +550,12 @@ pub fn index_interval_mapper( let previous = repo .by_id .list( - Some((token.clone(), currency.clone(), interval.clone(), [0xffu8; 4])), + Some(( + token.clone(), + currency.clone(), + interval.clone(), + [0xffu8; 4], + )), SortOrder::Descending, )? .take_while(|item| match item {