Created
August 10, 2023 20:14
-
-
Save kalloc/90a06fe9075ba80416c716c100cd7ffa to your computer and use it in GitHub Desktop.
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
use cosmwasm_std::{Response, StdResult}; | |
use cw_storage_plus::Item; | |
use sylvia::{contract, entry_points}; | |
use sylvia::types::{InstantiateCtx, QueryCtx}; | |
use crate::response::CounterResponse; | |
pub struct Counter { | |
pub(crate) count: Item<'static, u64>, | |
} | |
#[contract] | |
#[entry_points(instantiate)] | |
impl Counter { | |
pub fn new() -> Self { | |
Self { | |
count: Item::new("count"), | |
} | |
} | |
#[msg(instantiate)] | |
pub fn instantiate(&self, _ctx: InstantiateCtx, count: u64) -> StdResult<Response> { | |
self.count.save(_ctx.deps.storage, &count)?; | |
Ok(Response::default()) | |
} | |
#[msg(query)] | |
pub fn query(&self, _ctx: QueryCtx) -> StdResult<CounterResponse> { | |
let count = self.count.load(_ctx.deps.storage)?; | |
Ok( CounterResponse { count } ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment