-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af382ad
commit 64b63c2
Showing
12 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "timestamp-oracle" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
authors = ["you"] | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.53.2" | ||
|
||
[dependencies.common_structs] | ||
path = "../../common/common_structs" | ||
|
||
[dev-dependencies] | ||
num-bigint = "0.4" | ||
|
||
[dev-dependencies.multiversx-sc-scenario] | ||
version = "=0.53.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "timestamp-oracle-meta" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies.timestamp-oracle] | ||
path = ".." | ||
|
||
[dependencies.multiversx-sc-meta-lib] | ||
version = "=0.53.2" | ||
default-features = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
multiversx_sc_meta_lib::cli_main::<timestamp_oracle::AbiProvider>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"language": "rust" | ||
} |
29 changes: 29 additions & 0 deletions
29
energy-integration/timestamp-oracle/src/epoch_to_timestamp.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use common_structs::{Epoch, Timestamp}; | ||
|
||
multiversx_sc::imports!(); | ||
|
||
#[multiversx_sc::module] | ||
pub trait EpochToTimestampModule { | ||
#[endpoint(updateAndGetTimestampStartEpoch)] | ||
fn update_and_get_timestamp_start_epoch(&self) -> Timestamp { | ||
let current_epoch = self.blockchain().get_block_epoch(); | ||
let last_update_epoch = self.epoch_last_interaction().get(); | ||
if current_epoch == last_update_epoch { | ||
return self.timestamp_start_epoch_last_interaction().get(); | ||
} | ||
|
||
self.epoch_last_interaction().set(current_epoch); | ||
|
||
let current_timestamp = self.blockchain().get_block_timestamp(); | ||
self.timestamp_start_epoch_last_interaction() | ||
.set(current_timestamp); | ||
|
||
current_timestamp | ||
} | ||
|
||
#[storage_mapper("epochLastInteraction")] | ||
fn epoch_last_interaction(&self) -> SingleValueMapper<Epoch>; | ||
|
||
#[storage_mapper("timestampStartEpochLastInter")] | ||
fn timestamp_start_epoch_last_interaction(&self) -> SingleValueMapper<Timestamp>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![no_std] | ||
|
||
use common_structs::Timestamp; | ||
|
||
multiversx_sc::imports!(); | ||
|
||
pub mod epoch_to_timestamp; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait TimestampOracle: epoch_to_timestamp::EpochToTimestampModule { | ||
#[init] | ||
fn init(&self, current_epoch_start_timestamp: Timestamp) { | ||
let current_epoch = self.blockchain().get_block_epoch(); | ||
self.epoch_last_interaction().set(current_epoch); | ||
self.timestamp_start_epoch_last_interaction() | ||
.set(current_epoch_start_timestamp); | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.