Skip to content

Commit

Permalink
Remove clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Nov 4, 2024
1 parent 1b527c3 commit 10da700
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
29 changes: 14 additions & 15 deletions lib/ain-ocean/src/api/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,33 @@ async fn get_feed(

let key = (token, currency, txid);

let price_feed_list = ctx
let oracle_price_feeds = ctx
.services
.oracle_price_feed
.by_id
.list(None, SortOrder::Descending)?
.paginate(&query)
.flatten()
.collect::<Vec<_>>();

let mut oracle_price_feeds = Vec::new();

for ((token, currency, oracle_id, txid), feed) in &price_feed_list {
if key.0.eq(token) && key.1.eq(currency) && key.2.eq(oracle_id) {
.into_iter()
.filter(|((token, currency, oracle_id, _), _)| {
key.0.eq(token) && key.1.eq(currency) && key.2.eq(oracle_id)
})
.map(|((token, currency, oracle_id, txid), feed)| {
let amount = Decimal::from(feed.amount) / Decimal::from(COIN);
oracle_price_feeds.push(OraclePriceFeedResponse {
OraclePriceFeedResponse {
id: format!("{}-{}-{}-{}", token, currency, oracle_id, txid),
key: format!("{}-{}-{}", token, currency, oracle_id),
sort: hex::encode(feed.block.height.to_string() + &txid.to_string()),
token: token.to_owned(),
currency: currency.to_owned(),
oracle_id: oracle_id.to_owned(),
txid: *txid,
token,
currency,
oracle_id,
txid,
time: feed.time,
amount: amount.normalize().to_string(),
block: feed.block.clone(),
});
}
}
}
})
.collect::<Vec<_>>();

Ok(ApiPagedResponse::of(
oracle_price_feeds,
Expand Down
15 changes: 7 additions & 8 deletions lib/ain-ocean/src/indexer/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,18 @@ impl Index for RemoveOracle {
let oracle_id = self.oracle_id;
services.oracle.by_id.delete(&oracle_id)?;

let (_, previous) = get_previous_oracle(services, oracle_id)?
.context(NotFoundIndexSnafu {
let (_, mut previous) =
get_previous_oracle(services, oracle_id)?.context(NotFoundIndexSnafu {
action: IndexAction::Index,
r#type: "RemoveOracle".to_string(),
id: oracle_id.to_string(),
})?;

for PriceFeed { token, currency } in &previous.price_feeds {
services.oracle_token_currency.by_id.delete(&(
token.to_owned(),
currency.to_owned(),
oracle_id,
))?;
for PriceFeed { token, currency } in previous.price_feeds.drain(..) {
services
.oracle_token_currency
.by_id
.delete(&(token, currency, oracle_id))?;
}

Ok(())
Expand Down

0 comments on commit 10da700

Please sign in to comment.