Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Aug 21, 2024
1 parent 07a2b4e commit b7052d4
Showing 1 changed file with 79 additions and 3 deletions.
82 changes: 79 additions & 3 deletions src/pages/cw-multi-test/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,97 @@ import { Tabs } from "nextra/components";

# Getting started

Counter example
```text
├── Cargo.toml
└── src
├── contract.rs
└── lib.rs
```

<Tabs items={['CosmWasm', 'Sylvia']}>

<Tabs.Tab>

```rust showLineNumbers copy
// CosmWasm
```

</Tabs.Tab>

<Tabs.Tab>

```rust showLineNumbers copy
// Sylvia
```toml copy filename="Cargo.toml"
[package]
name = "counter"
version = "0.0.1"
edition = "2021"

[features]
library = []

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cosmwasm-std = { version = "2" }
cosmwasm-schema = "2"
cw-storage-plus = "2"
schemars = "0.8"
serde = "1.0"
sylvia = "1"

[dev-dependencies]
sylvia = { version = "1", features = ["mt"] }
cw-multi-test = { version = "2", features = ["cosmwasm_2_0"] }
```

```rust showLineNumbers copy filename="lib.rs"
pub mod contract;
```

```rust showLineNumbers copy filename="contract.rs"
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Response, StdResult};
use cw_storage_plus::Item;
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};

#[cw_serde]
pub struct CountResponse {
pub count: u8,
}

pub struct CounterContract {
pub count: Item<u8>,
}

#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
#[contract]
impl CounterContract {
pub const fn new() -> Self {
Self { count: Item::new("count") }
}

#[sv::msg(instantiate)]
fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> {
self.count.save(ctx.deps.storage, &0)?;
Ok(Response::new())
}

#[sv::msg(exec)]
fn increment(&self, ctx: ExecCtx) -> StdResult<Response> {
self.count.update(ctx.deps.storage, |count| -> StdResult<u8> { Ok(count.saturating_add(1)) })?;
Ok(Response::new())
}

#[sv::msg(query)]
fn count(&self, ctx: QueryCtx) -> StdResult<CountResponse> {
let count = self.count.load(ctx.deps.storage)?;
Ok(CountResponse { count })
}
}
```

</Tabs.Tab>

</Tabs>

0 comments on commit b7052d4

Please sign in to comment.