-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
19 changed files
with
831 additions
and
162 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "cron" | ||
version = "0.1.0" | ||
authors = ["joldie777 <aleksandr.pismenski@hadronlabs.org>"] | ||
edition = "2021" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
library = [] | ||
|
||
[dependencies] | ||
cosmwasm-std = { workspace = true } | ||
cw2 = { workspace = true } | ||
schemars = { workspace = true } | ||
serde = { workspace = true } | ||
neutron-sdk = { workspace = true } | ||
cw-storage-plus = { workspace = true } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { workspace = true } |
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,73 @@ | ||
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; | ||
use crate::state::{BEGIN_BLOCKER_SHEDULES, END_BLOCKER_SHEDULES}; | ||
use cosmwasm_std::{ | ||
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, | ||
StdResult, | ||
}; | ||
use cw2::set_contract_version; | ||
|
||
const CONTRACT_NAME: &str = concat!("crates.io:neutron-contracts__", env!("CARGO_PKG_NAME")); | ||
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
const MODULE_ACCOUNT: &str = "neutron1cd6wafvehv79pm2yxth40thpyc7dc0yrqkyk95"; | ||
|
||
#[entry_point] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
_msg: InstantiateMsg, | ||
) -> StdResult<Response> { | ||
deps.api.debug("WASMDEBUG: instantiate"); | ||
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; | ||
Ok(Response::default()) | ||
} | ||
|
||
#[entry_point] | ||
pub fn execute(deps: DepsMut, _: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> { | ||
deps.api | ||
.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); | ||
|
||
if info.sender.as_str() != MODULE_ACCOUNT { | ||
return Err(StdError::generic_err("Unauthorized")); | ||
} | ||
|
||
match msg { | ||
ExecuteMsg::AddBeginBlockerSchedule { name } => { | ||
let counter = BEGIN_BLOCKER_SHEDULES | ||
.may_load(deps.storage, name.clone())? | ||
.unwrap_or_default() | ||
.checked_add(1) | ||
.unwrap_or_default(); | ||
|
||
BEGIN_BLOCKER_SHEDULES.save(deps.storage, name, &counter)?; | ||
|
||
Ok(Response::default()) | ||
} | ||
ExecuteMsg::AddEndBlockerSchedule { name } => { | ||
let counter = END_BLOCKER_SHEDULES | ||
.may_load(deps.storage, name.clone())? | ||
.unwrap_or_default() | ||
.checked_add(1) | ||
.unwrap_or_default(); | ||
|
||
END_BLOCKER_SHEDULES.save(deps.storage, name, &counter)?; | ||
|
||
Ok(Response::default()) | ||
} | ||
} | ||
} | ||
|
||
#[entry_point] | ||
pub fn query(deps: Deps, _: Env, msg: QueryMsg) -> StdResult<Binary> { | ||
match msg { | ||
QueryMsg::GetBeginBlockerScheduleCounter { name } => { | ||
let res = BEGIN_BLOCKER_SHEDULES.may_load(deps.storage, name)?; | ||
to_json_binary(&res) | ||
} | ||
QueryMsg::GetEndBlockerScheduleCounter { name } => { | ||
let res = END_BLOCKER_SHEDULES.may_load(deps.storage, name)?; | ||
to_json_binary(&res) | ||
} | ||
} | ||
} |
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,19 @@ | ||
// Copyright 2022 Neutron | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#![warn(clippy::unwrap_used, clippy::expect_used)] | ||
|
||
pub mod contract; | ||
pub mod msg; | ||
pub mod state; |
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,19 @@ | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
pub struct InstantiateMsg {} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ExecuteMsg { | ||
AddBeginBlockerSchedule { name: String }, | ||
AddEndBlockerSchedule { name: String }, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum QueryMsg { | ||
GetBeginBlockerScheduleCounter { name: String }, | ||
GetEndBlockerScheduleCounter { name: String }, | ||
} |
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,4 @@ | ||
use cw_storage_plus::Map; | ||
|
||
pub const BEGIN_BLOCKER_SHEDULES: Map<String, u64> = Map::new("begin_blocker_shedules"); | ||
pub const END_BLOCKER_SHEDULES: Map<String, u64> = Map::new("end_blocker_shedules"); |
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
Oops, something went wrong.