Skip to content

Commit ac54bdd

Browse files
committed
fix OraclePriceAggregatedId & OraclePriceFeedId sort key
1 parent f39c49c commit ac54bdd

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

lib/ain-ocean/src/api/oracle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ async fn get_feed(
103103
.list(None, SortOrder::Descending)?
104104
.paginate(&query)
105105
.flatten()
106-
.filter(|((token, currency, oracle_id, _), _)| {
106+
.filter(|((token, currency, oracle_id, _, _), _)| {
107107
key.0.eq(token) && key.1.eq(currency) && key.2.eq(oracle_id)
108108
})
109-
.map(|((token, currency, oracle_id, txid), feed)| {
109+
.map(|((token, currency, oracle_id, height, txid), feed)| {
110110
let amount = Decimal::from(feed.amount) / Decimal::from(COIN);
111111
OraclePriceFeedResponse {
112112
id: format!("{}-{}-{}-{}", token, currency, oracle_id, txid),
113113
key: format!("{}-{}-{}", token, currency, oracle_id),
114-
sort: hex::encode(feed.block.height.to_string() + &txid.to_string()),
114+
sort: hex::encode(height.to_string() + &txid.to_string()),
115115
token,
116116
currency,
117117
oracle_id,

lib/ain-ocean/src/api/prices.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async fn get_feed(
191191
let (token, currency) = parse_token_currency(&key)?;
192192

193193
let repo = &ctx.services.oracle_price_aggregated;
194-
let id = (token.to_string(), currency.to_string(), u32::MAX);
194+
let id = (token.to_string(), currency.to_string(), i64::MAX, u32::MAX);
195195
let oracle_aggregated = repo
196196
.by_id
197197
.list(Some(id), SortOrder::Descending)?
@@ -467,6 +467,7 @@ async fn list_price_oracles(
467467
token.clone(),
468468
currency.clone(),
469469
oracle_id,
470+
u32::MAX,
470471
Txid::from_byte_array([0xffu8; 32]),
471472
)),
472473
SortOrder::Descending,
@@ -490,11 +491,12 @@ async fn list_price_oracles(
490491
let token = id.0;
491492
let currency = id.1;
492493
let oracle_id = id.2;
493-
let txid = id.3;
494+
let height = id.3;
495+
let txid = id.4;
494496
OraclePriceFeedResponse {
495497
id: format!("{}-{}-{}-{}", token, currency, oracle_id, txid),
496498
key: format!("{}-{}-{}", token, currency, oracle_id),
497-
sort: hex::encode(f.block.height.to_string() + &txid.to_string()),
499+
sort: hex::encode(height.to_string() + &txid.to_string()),
498500
token: token.clone(),
499501
currency: currency.clone(),
500502
oracle_id,

lib/ain-ocean/src/indexer/loan_token.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn perform_active_price_tick(
169169
ticker_id: (Token, Currency),
170170
block: &BlockContext,
171171
) -> Result<()> {
172-
let id = (ticker_id.0, ticker_id.1, u32::MAX);
172+
let id = (ticker_id.0.clone(), ticker_id.1.clone(), i64::MAX, u32::MAX);
173173

174174
let prev = services
175175
.oracle_price_aggregated
@@ -182,6 +182,7 @@ pub fn perform_active_price_tick(
182182
return Ok(());
183183
};
184184

185+
let id = (ticker_id.0, ticker_id.1, u32::MAX);
185186
let repo = &services.oracle_price_active;
186187
let prev = repo
187188
.by_id

lib/ain-ocean/src/indexer/oracle.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn map_price_aggregated(
301301
let feed = services
302302
.oracle_price_feed
303303
.by_id
304-
.list(Some((id.0, id.1, id.2, base_id)), SortOrder::Descending)?
304+
.list(Some((id.0, id.1, id.2, u32::MAX, base_id)), SortOrder::Descending)?
305305
.next()
306306
.transpose()?;
307307

@@ -372,6 +372,7 @@ fn index_set_oracle_data(
372372
let id = (
373373
token.clone(),
374374
currency.clone(),
375+
price_aggregated.block.median_time,
375376
price_aggregated.block.height,
376377
);
377378
oracle_repo.by_id.put(&id, &price_aggregated)?;
@@ -402,6 +403,7 @@ fn index_set_oracle_data_interval(
402403
let aggregated = services.oracle_price_aggregated.by_id.get(&(
403404
token.clone(),
404405
currency.clone(),
406+
context.block.median_time,
405407
context.block.height,
406408
))?;
407409

@@ -447,8 +449,8 @@ impl Index for SetOracleData {
447449

448450
let feeds = map_price_feeds(self, context);
449451

450-
for ((token, currency, _, _), _) in feeds.iter().rev() {
451-
let id = (token.clone(), currency.clone(), context.block.height);
452+
for ((token, currency, _, _, _), _) in feeds.iter().rev() {
453+
let id = (token.clone(), currency.clone(), context.block.median_time, context.block.height);
452454

453455
let aggregated = oracle_repo.by_id.get(&id)?;
454456

@@ -485,6 +487,7 @@ fn map_price_feeds(
485487
token_price.token.clone(),
486488
token_amount.currency.clone(),
487489
data.oracle_id,
490+
ctx.block.height,
488491
ctx.tx.txid,
489492
);
490493

lib/ain-ocean/src/model/oracle_price_aggregated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22

33
use super::{BlockContext, OraclePriceActiveNext};
44

5-
pub type OraclePriceAggregatedId = (String, String, u32); //token-currency-height
5+
pub type OraclePriceAggregatedId = (String, String, i64, u32); //token-currency-mediantime-height
66

77
#[derive(Serialize, Deserialize, Debug, Clone)]
88
#[serde(rename_all = "camelCase")]

lib/ain-ocean/src/model/oracle_price_feed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bitcoin::Txid;
22
use serde::{Deserialize, Serialize};
33

44
use super::BlockContext;
5-
pub type OraclePriceFeedId = (String, String, Txid, Txid); // token-currency-oracle_id-txid
5+
pub type OraclePriceFeedId = (String, String, Txid, u32, Txid); // token-currency-oracle_id-height-txid
66

77
#[derive(Serialize, Deserialize, Debug, Clone)]
88
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)