Current epoch queries

This commit is contained in:
Jędrzej Stuczyński
2022-04-19 12:20:08 +01:00
parent ac7ed0d0dd
commit d148726b4b
5 changed files with 33 additions and 8 deletions
@@ -23,7 +23,9 @@ pub enum ExecuteMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {}
pub enum QueryMsg {
GetCurrentEpoch {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
@@ -1,2 +1,11 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use super::storage;
use crate::ContractError;
use coconut_dkg_common::types::Epoch;
use cosmwasm_std::Storage;
pub(crate) fn query_current_epoch(storage: &dyn Storage) -> Result<Epoch, ContractError> {
storage::current_epoch(storage)
}
+9 -1
View File
@@ -1,7 +1,15 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::ContractError;
use coconut_dkg_common::types::Epoch;
use cosmwasm_std::Storage;
use cw_storage_plus::Item;
pub(crate) const CURRENT_EPOCH: Item<Epoch> = Item::new("current_epoch");
pub(crate) const CURRENT_EPOCH: Item<'_, Epoch> = Item::new("current_epoch");
pub(crate) fn current_epoch(storage: &dyn Storage) -> Result<Epoch, ContractError> {
CURRENT_EPOCH
.load(storage)
.map_err(|_| ContractError::EpochNotInitialised)
}
+3
View File
@@ -44,4 +44,7 @@ pub enum ContractError {
#[error("This sender is already a dealer for the epoch")]
AlreadyADealer,
#[error("Epoch hasn't been correctly initialised!")]
EpochNotInitialised,
}
+9 -6
View File
@@ -1,10 +1,13 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::epoch::queries::query_current_epoch;
use crate::error::ContractError;
use coconut_dkg_common::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use coconut_dkg_common::types::{Epoch, EpochState};
use cosmwasm_std::{entry_point, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response};
use cosmwasm_std::{
entry_point, to_binary, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
};
use epoch::storage as epoch_storage;
mod constants;
@@ -63,12 +66,12 @@ pub fn execute(
}
#[entry_point]
pub fn query(_deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result<QueryResponse, ContractError> {
match msg {
_ => (),
}
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result<QueryResponse, ContractError> {
let response = match msg {
QueryMsg::GetCurrentEpoch {} => to_binary(&query_current_epoch(deps.storage)?)?,
};
Ok(Default::default())
Ok(response)
}
#[entry_point]