Skip to content

Commit 7d79dd1

Browse files
committed
[oracle] i64 -> [u8;8]
1 parent cc10ac4 commit 7d79dd1

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ async fn get_feed(
195195
let median_time = &q[..16];
196196
let height = &q[16..];
197197

198-
let median_time = median_time.parse::<i64>()?;
198+
let median_time = median_time.parse::<i64>()?.to_be_bytes();
199199
let height = height.parse::<u32>()?.to_be_bytes();
200-
Ok::<(i64, [u8; 4]), Error>((median_time, height))
200+
Ok::<([u8; 8], [u8; 4]), Error>((median_time, height))
201201
})
202202
.transpose()?
203-
.unwrap_or((i64::MAX, [0xffu8; 4]));
203+
.unwrap_or(([0xffu8; 8], [0xffu8; 4]));
204204

205205

206206
let repo = &ctx.services.oracle_price_aggregated;
@@ -216,7 +216,7 @@ async fn get_feed(
216216
.map(|item| {
217217
let (k, v) = item?;
218218
let res = OraclePriceAggregatedResponse {
219-
id: format!("{}-{}-{}", k.0, k.1, k.2),
219+
id: format!("{}-{}-{}", k.0, k.1, i64::from_be_bytes(k.2)),
220220
key: format!("{}-{}", k.0, k.1),
221221
sort: format!(
222222
"{}{}",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn perform_active_price_tick(
159159
ticker_id: (Token, Currency),
160160
block: &BlockContext,
161161
) -> Result<()> {
162-
let id = (ticker_id.0.clone(), ticker_id.1.clone(), i64::MAX, [0xffu8; 4]);
162+
let id = (ticker_id.0.clone(), ticker_id.1.clone(), [0xffu8; 8], [0xffu8; 4]);
163163

164164
let prev = services
165165
.oracle_price_aggregated

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn index_set_oracle_data(
375375
let id = (
376376
token.clone(),
377377
currency.clone(),
378-
price_aggregated.block.median_time,
378+
price_aggregated.block.median_time.to_be_bytes(),
379379
price_aggregated.block.height.to_be_bytes(),
380380
);
381381
oracle_repo.by_id.put(&id, &price_aggregated)?;
@@ -406,7 +406,7 @@ fn index_set_oracle_data_interval(
406406
let aggregated = services.oracle_price_aggregated.by_id.get(&(
407407
token.clone(),
408408
currency.clone(),
409-
context.block.median_time,
409+
context.block.median_time.to_be_bytes(),
410410
context.block.height.to_be_bytes(),
411411
))?;
412412

@@ -456,7 +456,7 @@ impl Index for SetOracleData {
456456
let id = (
457457
token.clone(),
458458
currency.clone(),
459-
context.block.median_time,
459+
context.block.median_time.to_be_bytes(),
460460
context.block.height.to_be_bytes(),
461461
);
462462

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, i64, [u8; 4]); //token-currency-mediantime-height
5+
pub type OraclePriceAggregatedId = (String, String, [u8; 8], [u8; 4]); //token-currency-mediantime-height
66

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

0 commit comments

Comments
 (0)