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 @@ -36,6 +36,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [TimeLock Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/timelock)
- [Crowdfunding Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/crowdfunding)
- [Token Vault](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/token-vault)
- [Achievement Badges](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/achievement-badges)

### :three: Complex Applications
- [Constant Product AMM](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/constant-product-amm)
Expand Down
43 changes: 43 additions & 0 deletions achievement-badges/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "achievement-badges"
version = "0.1.0"
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" }
85 changes: 85 additions & 0 deletions achievement-badges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Achievement Badges Contract

This example shows a simple on-chain achievement badge registry.

The contract owner creates badge definitions and manages issuer accounts. The owner or an approved issuer can award a badge to an address. Awarded badges can be queried by badge id, holder address, or holder-and-badge pair.

## Features

- Owner-managed badge definitions.
- Optional issuer accounts for awarding badges.
- One award per holder per badge.
- Per-holder badge limit.
- Badge archiving to stop future awards without deleting history.
- Queries for config, badge definitions, holder badges, and badge ownership.

## Instantiate

```json
{
"name": "Learning Badges",
"description": "Badges for completed tutorials",
"issuers": ["cosmos1issuer..."],
"max_badges_per_holder": 25
}
```
## Execute

Create a badge:

```json
{
"create_badge": {
"badge_id": "first-contract",
"title": "First Contract",
"description": "Completed a first CosmWasm contract"
}
}
```

Award a badge:

```json
{
"award_badge": {
"badge_id": "first-contract",
"recipient": "cosmos1recipient...",
"note": "Completed the hello-world lesson"
}
}
```

Archive a badge:

```json
{
"archive_badge": {
"badge_id": "first-contract"
}
}
```

## Query

Query one holder's badges:

```json
{
"holder_badges": {
"holder": "cosmos1recipient...",
"start_after": null,
"limit": 10
}
}
```

Check whether a holder has a badge:

```json
{
"has_badge": {
"holder": "cosmos1recipient...",
"badge_id": "first-contract"
}
}
```
10 changes: 10 additions & 0 deletions achievement-badges/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use achievement_badges::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use cosmwasm_schema::write_api;

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
Loading