Skip to content

Commit 177b5af

Browse files
committed
near: use Seconds alias to document units, fix calc
1 parent 5b7ada5 commit 177b5af

File tree

1 file changed

+10
-3
lines changed
  • target_chains/near/receiver/src

1 file changed

+10
-3
lines changed

target_chains/near/receiver/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ enum StorageKeys {
7272
Prices,
7373
}
7474

75+
/// Alias to document time unit Pyth expects data to be in.
76+
type Seconds = u64;
77+
7578
/// The `State` contains all persisted state for the contract. This includes runtime configuration.
7679
///
7780
/// There is no valid Default state for this contract, so we derive PanicOnDefault to force
@@ -461,7 +464,11 @@ impl Pyth {
461464

462465
/// Get the latest available price cached for the given price identifier, if that price is
463466
/// no older than the given age.
464-
pub fn get_price_no_older_than(&self, price_id: PriceIdentifier, age: u64) -> Option<Price> {
467+
pub fn get_price_no_older_than(
468+
&self,
469+
price_id: PriceIdentifier,
470+
age: Seconds,
471+
) -> Option<Price> {
465472
self.prices.get(&price_id).and_then(|feed| {
466473
let block_timestamp = env::block_timestamp() / 1_000_000_000;
467474
let price_timestamp = feed.price.publish_time;
@@ -491,10 +498,10 @@ impl Pyth {
491498
pub fn get_ema_price_no_older_than(
492499
&self,
493500
price_id: PriceIdentifier,
494-
age: u64,
501+
age: Seconds,
495502
) -> Option<Price> {
496503
self.prices.get(&price_id).and_then(|feed| {
497-
let block_timestamp = env::block_timestamp();
504+
let block_timestamp = env::block_timestamp() / 1_000_000_000;
498505
let price_timestamp = feed.ema_price.publish_time;
499506

500507
// - If Price older than STALENESS_THRESHOLD, set status to Unknown.

0 commit comments

Comments
 (0)