-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create cw4-group contract from template
- Loading branch information
Showing
15 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib --features backtraces" | ||
schema = "run --example schema" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "cw4-group" | ||
version = "0.1.0" | ||
authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"] | ||
edition = "2018" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"artifacts/*", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all init/handle/query exports | ||
library = [] | ||
|
||
[dependencies] | ||
cw2 = { path = "../../packages/cw2", version = "0.3.1" } | ||
cw-storage-plus = { path = "../../packages/storage-plus", version = "0.3.1", features = ["iterator"] } | ||
cosmwasm-std = { version = "0.11.1" } | ||
schemars = "0.7" | ||
serde = { version = "1.0.103", default-features = false, features = ["derive"] } | ||
thiserror = { version = "1.0.21" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "0.11.1" } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Cw4_group | ||
Copyright (C) 2020 Confio OÜ | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# CosmWasm Starter Pack | ||
|
||
This is a template to build smart contracts in Rust to run inside a | ||
[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. | ||
To understand the framework better, please read the overview in the | ||
[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), | ||
and dig into the [cosmwasm docs](https://www.cosmwasm.com). | ||
This assumes you understand the theory and just want to get coding. | ||
|
||
## Creating a new repo from template | ||
|
||
Assuming you have a recent version of rust and cargo (v1.44.1+) installed | ||
(via [rustup](https://rustup.rs/)), | ||
then the following should get you a new repo to start a contract: | ||
|
||
First, install | ||
[cargo-generate](https://github.com/ashleygwilliams/cargo-generate). | ||
Unless you did that before, run this line now: | ||
|
||
```sh | ||
cargo install cargo-generate --features vendored-openssl | ||
``` | ||
|
||
Now, use it to create your new contract. | ||
Go to the folder in which you want to place it and run: | ||
|
||
**0.11 (latest)** | ||
|
||
```sh | ||
cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --name PROJECT_NAME | ||
``` | ||
|
||
**0.10** | ||
|
||
```sh | ||
cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --branch 0.10 --name PROJECT_NAME | ||
``` | ||
|
||
**0.9** | ||
|
||
```sh | ||
cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --branch 0.9 --name PROJECT_NAME | ||
``` | ||
|
||
**0.8** | ||
|
||
```sh | ||
cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --branch 0.8 --name PROJECT_NAME | ||
``` | ||
|
||
You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) | ||
containing a simple working contract and build system that you can customize. | ||
|
||
## Create a Repo | ||
|
||
After generating, you have a initialized local git repo, but no commits, and no remote. | ||
Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). | ||
Then run the following: | ||
|
||
```sh | ||
# this is needed to create a valid Cargo.lock file (see below) | ||
cargo check | ||
git checkout -b master # in case you generate from non-master | ||
git add . | ||
git commit -m 'Initial Commit' | ||
git remote add origin YOUR-GIT-URL | ||
git push -u origin master | ||
``` | ||
|
||
## CI Support | ||
|
||
We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) | ||
and [Circle CI](.circleci/config.yml) in the generated project, so you can | ||
get up and running with CI right away. | ||
|
||
One note is that the CI runs all `cargo` commands | ||
with `--locked` to ensure it uses the exact same versions as you have locally. This also means | ||
you must have an up-to-date `Cargo.lock` file, which is not auto-generated. | ||
The first time you set up the project (or after adding any dep), you should ensure the | ||
`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by | ||
running `cargo check` or `cargo unit-test`. | ||
|
||
## Using your project | ||
|
||
Once you have your custom repo, you should check out [Developing](./Developing.md) to explain | ||
more on how to run tests and develop code. Or go through the | ||
[online tutorial](https://www.cosmwasm.com/docs/getting-started/intro) to get a better feel | ||
of how to develop. | ||
|
||
[Publishing](./Publishing.md) contains useful information on how to publish your contract | ||
to the world, once you are ready to deploy it on a running blockchain. And | ||
[Importing](./Importing.md) contains information about pulling in other contracts or crates | ||
that have been published. | ||
|
||
Please replace this README file with information about your specific project. You can keep | ||
the `Developing.md` and `Publishing.md` files as useful referenced, but please set some | ||
proper description in the README. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; | ||
|
||
use cw4_group::msg::{CountResponse, HandleMsg, InitMsg, QueryMsg}; | ||
use cw4_group::state::State; | ||
|
||
fn main() { | ||
let mut out_dir = current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
create_dir_all(&out_dir).unwrap(); | ||
remove_schemas(&out_dir).unwrap(); | ||
|
||
export_schema(&schema_for!(InitMsg), &out_dir); | ||
export_schema(&schema_for!(HandleMsg), &out_dir); | ||
export_schema(&schema_for!(QueryMsg), &out_dir); | ||
export_schema(&schema_for!(State), &out_dir); | ||
export_schema(&schema_for!(CountResponse), &out_dir); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "CountResponse", | ||
"type": "object", | ||
"required": [ | ||
"count" | ||
], | ||
"properties": { | ||
"count": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "HandleMsg", | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"increment" | ||
], | ||
"properties": { | ||
"increment": { | ||
"type": "object" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"reset" | ||
], | ||
"properties": { | ||
"reset": { | ||
"type": "object", | ||
"required": [ | ||
"count" | ||
], | ||
"properties": { | ||
"count": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "InitMsg", | ||
"type": "object", | ||
"required": [ | ||
"count" | ||
], | ||
"properties": { | ||
"count": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "QueryMsg", | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"get_count" | ||
], | ||
"properties": { | ||
"get_count": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "State", | ||
"type": "object", | ||
"required": [ | ||
"count", | ||
"owner" | ||
], | ||
"properties": { | ||
"count": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"owner": { | ||
"$ref": "#/definitions/CanonicalAddr" | ||
} | ||
}, | ||
"definitions": { | ||
"Binary": { | ||
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>", | ||
"type": "string" | ||
}, | ||
"CanonicalAddr": { | ||
"$ref": "#/definitions/Binary" | ||
} | ||
} | ||
} |
Oops, something went wrong.