Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [Reading and Writing From State](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/read-write-state)
- [Response and Attributes](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/responses-attributes)
- [Cosmwasm Math Examples](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/cosmwasm-math)
- [Guestbook](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/guestbook)
- [Cross-Contract Instantiation](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/cross-contract-instatiation)
- [Receiving CW20 Tokens](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/receiving-cw20-tokens)

Expand Down
4 changes: 4 additions & 0 deletions guestbook/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
47 changes: 47 additions & 0 deletions guestbook/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "guestbook"
version = "0.1.0"
authors = ["alexgduarte"]
edition = "2021"

exclude = [
"contract.wasm",
"hash.txt",
]

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

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
backtraces = ["cosmwasm-std/backtraces"]
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache,target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.10
"""

[dependencies]
cosmwasm-schema = "1.1.3"
cosmwasm-std = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }

[dev-dependencies]
cw-multi-test = "0.16.2"
95 changes: 95 additions & 0 deletions guestbook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Guestbook

This example shows how to build a small owner-managed guestbook in CosmWasm.

The contract lets any address sign the guestbook with a display name and message. Each address can keep one current entry, edit it by signing again, and remove its own entry. The contract owner can update the guestbook settings or remove any entry if needed.

## What this example teaches

- Storing contract configuration with `Item`
- Storing one record per account with `Map`
- Validating message length before saving state
- Owner-only configuration updates
- Allowing either the signer or owner to delete an entry
- Paginated list queries with `start_after` and `limit`

## Messages

### Instantiate

```json
{
"title": "Launch party",
"max_message_len": 140
}
```

`max_message_len` is optional. If omitted, the contract uses `280`.

### Sign

```json
{
"sign": {
"display_name": "Ada",
"message": "Excited to see this project launch."
}
}
```

### Remove Entry

```json
{
"remove_entry": {
"signer": "cosmos1..."
}
}
```

The signer can remove their own entry. The owner can remove any entry.

### Update Config

```json
{
"update_config": {
"title": "New title",
"max_message_len": 200,
"new_owner": "cosmos1..."
}
}
```

Only the owner can update configuration.

## Queries

### Config

```json
{ "config": {} }
```

### Entry

```json
{
"entry": {
"signer": "cosmos1..."
}
}
```

### Entries

```json
{
"entries": {
"start_after": "cosmos1...",
"limit": 10
}
}
```

The entries query returns signers in address order and caps the page size to keep queries predictable.
Loading