Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos-rebegea committed Oct 7, 2024
1 parent f0a369f commit 9c18d7c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions contracts/price-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,17 @@ pub trait PriceAggregator:
self.require_not_paused();
self.require_is_oracle();

let current_timestamp = self.blockchain().get_block_timestamp();
require!(
submission_timestamp <= current_timestamp,
"Timestamp is from the future"
);
self.require_valid_submission_timestamp(submission_timestamp);

self.check_decimals(&from, &to, decimals);

self.submit_unchecked(from, to, submission_timestamp, price, decimals);
self.submit_unchecked(from, to, price, decimals);
}

fn submit_unchecked(
&self,
from: ManagedBuffer,
to: ManagedBuffer,
submission_timestamp: u64,
price: BigUint,
decimals: u8,
) {
Expand Down Expand Up @@ -206,7 +201,7 @@ pub trait PriceAggregator:
self.emit_discard_submission_event(
&token_pair,
round_id,
submission_timestamp,
current_timestamp,
first_submission_timestamp,
has_caller_already_submitted,
);
Expand All @@ -220,7 +215,8 @@ pub trait PriceAggregator:
});
}

fn require_valid_submission_timestamp(&self, submission_timestamp: u64, current_timestamp: u64) {
fn require_valid_submission_timestamp(&self, submission_timestamp: u64) {
let current_timestamp = self.blockchain().get_block_timestamp();
require!(
submission_timestamp <= current_timestamp,
"Timestamp is from the future"
Expand All @@ -239,16 +235,15 @@ pub trait PriceAggregator:
self.require_not_paused();
self.require_is_oracle();

let current_timestamp = self.blockchain().get_block_timestamp();
for (from, to, submission_timestamp, price, decimals) in submissions
.into_iter()
.map(|submission| submission.into_tuple())
{
self.require_valid_submission_timestamp(submission_timestamp, current_timestamp);
self.require_valid_submission_timestamp(submission_timestamp);

self.check_decimals(&from, &to, decimals);

self.submit_unchecked(from, to, submission_timestamp, price, decimals);
self.submit_unchecked(from, to, price, decimals);
}
}

Expand Down

0 comments on commit 9c18d7c

Please sign in to comment.