diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/interval.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/interval.rs index 8b1e8c2476..1062980cdb 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/interval.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/interval.rs @@ -56,7 +56,6 @@ pub(crate) mod string_rfc3339_offset_date_time { } } -/// Representation of rewarding interval. #[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)] pub struct Interval { id: u32, diff --git a/nym-wallet/src-tauri/src/main.rs b/nym-wallet/src-tauri/src/main.rs index 7ade07deaf..07671da836 100644 --- a/nym-wallet/src-tauri/src/main.rs +++ b/nym-wallet/src-tauri/src/main.rs @@ -55,6 +55,7 @@ fn main() { mixnet::delegate::get_reverse_mix_delegations_paged, mixnet::delegate::undelegate_from_mixnode, mixnet::delegate::get_pending_delegation_events, + mixnet::epoch::get_current_epoch, mixnet::send::send, utils::major_to_minor, utils::minor_to_major, diff --git a/nym-wallet/src-tauri/src/operations/mixnet/epoch.rs b/nym-wallet/src-tauri/src/operations/mixnet/epoch.rs new file mode 100644 index 0000000000..085564ca06 --- /dev/null +++ b/nym-wallet/src-tauri/src/operations/mixnet/epoch.rs @@ -0,0 +1,36 @@ +use crate::error::BackendError; +use crate::nymd_client; +use crate::state::State; +use mixnet_contract_common::Interval; +use serde::{Deserialize, Serialize}; +use std::sync::Arc; +use tokio::sync::RwLock; + +#[cfg_attr(test, derive(ts_rs::TS))] +#[cfg_attr(test, ts(export, export_to = "../src/types/rust/epoch.ts"))] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)] +pub struct Epoch { + id: u32, + start: i64, + end: i64, + duration_seconds: u64, +} + +impl From for Epoch { + fn from(interval: Interval) -> Self { + Self { + id: interval.id(), + start: interval.start_unix_timestamp(), + end: interval.end_unix_timestamp(), + duration_seconds: interval.length().as_secs(), + } + } +} + +#[tauri::command] +pub async fn get_current_epoch( + state: tauri::State<'_, Arc>>, +) -> Result { + let interval = nymd_client!(state).get_current_epoch().await?; + Ok(interval.into()) +} diff --git a/nym-wallet/src-tauri/src/operations/mixnet/mod.rs b/nym-wallet/src-tauri/src/operations/mixnet/mod.rs index 47f4788d6c..e59890f38e 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/mod.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/mod.rs @@ -2,4 +2,5 @@ pub mod account; pub mod admin; pub mod bond; pub mod delegate; +pub mod epoch; pub mod send; diff --git a/nym-wallet/src/types/rust/epoch.ts b/nym-wallet/src/types/rust/epoch.ts new file mode 100644 index 0000000000..eaa95571ff --- /dev/null +++ b/nym-wallet/src/types/rust/epoch.ts @@ -0,0 +1,2 @@ + +export interface Epoch { id: number, start: bigint, end: bigint, duration_seconds: bigint, } \ No newline at end of file