Skip to content

Commit e33fc67

Browse files
committed
Weightage as u32
1 parent 5ec692f commit e33fc67

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

lib/ain-dftx/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::custom_tx::CustomTxType;
2626

2727
pub type Token = String;
2828
pub type Currency = String;
29-
pub type Weightage = u8;
29+
pub type Weightage = u32;
3030

3131
#[derive(Debug, PartialEq, Eq)]
3232
pub enum DfTx {

lib/ain-dftx/src/types/oracles.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bitcoin::{hash_types::Txid, io, ScriptBuf};
44
use super::{
55
common::CompactVec,
66
price::{CurrencyPair, TokenPrice},
7+
Weightage,
78
};
89

910
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
@@ -21,14 +22,14 @@ pub struct RemoveOracle {
2122
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
2223
pub struct AppointOracle {
2324
pub script: ScriptBuf,
24-
pub weightage: u8,
25+
pub weightage: Weightage,
2526
pub price_feeds: CompactVec<CurrencyPair>,
2627
}
2728

2829
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
2930
pub struct UpdateOracle {
3031
pub oracle_id: Txid,
3132
pub script: ScriptBuf,
32-
pub weightage: u8,
33+
pub weightage: Weightage,
3334
pub price_feeds: CompactVec<CurrencyPair>,
3435
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn map_price_aggregated(
402402

403403
let mut aggregated_total = Decimal::zero();
404404
let mut aggregated_count = 0;
405-
let mut aggregated_weightage = 0u8;
405+
let mut aggregated_weightage = 0;
406406

407407
let oracles_len = oracles.len();
408408
for oracle in oracles {
@@ -424,12 +424,8 @@ fn map_price_aggregated(
424424
let time_diff = Decimal::from(feed.time) - Decimal::from(context.block.time);
425425
if Decimal::abs(&time_diff) < dec!(3600) {
426426
aggregated_count += 1;
427-
aggregated_weightage =
428-
aggregated_weightage
429-
.checked_add(oracle.weightage)
430-
.context(OtherSnafu {
431-
msg: "Error adding oracle weightage",
432-
})?;
427+
aggregated_weightage += oracle.weightage;
428+
433429
log::trace!(
434430
"SetOracleData weightage: {:?} * oracle_price.amount: {:?}",
435431
aggregated_weightage,
@@ -785,8 +781,8 @@ pub fn invalidate_oracle_interval(
785781
aggregated: OraclePriceAggregatedIntervalAggregated {
786782
amount: aggregated_amount.to_string(),
787783
weightage: aggregated_weightage
788-
.to_u8()
789-
.context(ToPrimitiveSnafu { msg: "to_u8" })?,
784+
.to_u32()
785+
.context(ToPrimitiveSnafu { msg: "to_u32" })?,
790786
count,
791787
oracles: OraclePriceAggregatedIntervalAggregatedOracles {
792788
active: aggregated_active
@@ -847,8 +843,8 @@ fn forward_aggregate(
847843
aggregated: OraclePriceAggregatedIntervalAggregated {
848844
amount: aggregated_amount.to_string(),
849845
weightage: aggregated_weightage
850-
.to_u8()
851-
.context(ToPrimitiveSnafu { msg: "to_u8" })?,
846+
.to_u32()
847+
.context(ToPrimitiveSnafu { msg: "to_u32" })?,
852848
count,
853849
oracles: OraclePriceAggregatedIntervalAggregatedOracles {
854850
active: aggregated_active

0 commit comments

Comments
 (0)