Skip to content

Instantly share code, notes, and snippets.

@kalloc
Created August 10, 2023 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalloc/90a06fe9075ba80416c716c100cd7ffa to your computer and use it in GitHub Desktop.
Save kalloc/90a06fe9075ba80416c716c100cd7ffa to your computer and use it in GitHub Desktop.
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