Skip to content

Commit

Permalink
fmt_rs
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Nov 22, 2024
1 parent 59795e9 commit 1b58ee9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
8 changes: 2 additions & 6 deletions lib/ain-ocean/src/api/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/ain-ocean/src/api/loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 2 additions & 13 deletions lib/ain-ocean/src/api/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions lib/ain-ocean/src/indexer/loan_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ pub fn invalidate_active_price(services: &Arc<Services>, block: &BlockContext) -
.collect::<Vec<_>>();

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(),
))?;
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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(())
}
32 changes: 26 additions & 6 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -255,7 +259,12 @@ fn index_script_unspent_vout(services: &Arc<Services>, 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)?;
Expand Down Expand Up @@ -341,8 +350,10 @@ fn index_script(services: &Arc<Services>, 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);
}
Expand Down Expand Up @@ -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)?;

Expand Down
7 changes: 6 additions & 1 deletion lib/ain-ocean/src/indexer/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1b58ee9

Please sign in to comment.