get_current_epoch tauri

This commit is contained in:
durch
2022-03-22 11:10:41 +01:00
parent fb5a9a7a3e
commit b710f796f9
5 changed files with 40 additions and 1 deletions
@@ -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,
+1
View File
@@ -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,
@@ -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<Interval> 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<RwLock<State>>>,
) -> Result<Epoch, BackendError> {
let interval = nymd_client!(state).get_current_epoch().await?;
Ok(interval.into())
}
@@ -2,4 +2,5 @@ pub mod account;
pub mod admin;
pub mod bond;
pub mod delegate;
pub mod epoch;
pub mod send;
+2
View File
@@ -0,0 +1,2 @@
export interface Epoch { id: number, start: bigint, end: bigint, duration_seconds: bigint, }