From 337a7b1acc7bd46ea2244d4577e46c8182b33051 Mon Sep 17 00:00:00 2001 From: Mikael Lindlof Date: Sun, 27 Sep 2020 20:17:35 +0100 Subject: [PATCH] Initial commit --- .cargo/config | 3 + .gitignore | 2 + Cargo.lock | 252 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 33 ++++++ LICENSE | 21 ++++ README.md | 34 ++++++ docker-compose.yaml | 11 ++ docker-optimize.yaml | 6 ++ src/contract.rs | 46 ++++++++ src/lib.rs | 36 +++++++ src/msg.rs | 14 +++ 11 files changed, 458 insertions(+) create mode 100644 .cargo/config create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docker-compose.yaml create mode 100644 docker-optimize.yaml create mode 100644 src/contract.rs create mode 100644 src/lib.rs create mode 100644 src/msg.rs diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..80a5bdb --- /dev/null +++ b/.cargo/config @@ -0,0 +1,3 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib --features backtraces" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd5af78 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +contract.wasm.gz diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..04b42ec --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,252 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "backtrace" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cosmwasm-std" +version = "0.10.0" +source = "git+https://github.com/enigmampc/SecretNetwork?tag=v1.0.0#490fba9243e6cb291462e9d3c1bcbd1975c0df1e" +dependencies = [ + "base64", + "schemars", + "serde", + "serde-json-wasm", + "snafu", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "libc" +version = "0.2.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" + +[[package]] +name = "miniz_oxide" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" + +[[package]] +name = "proc-macro2" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "schemars" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be77ed66abed6954aabf6a3e31a84706bedbf93750d267e92ef4a6d90bbd6a61" +dependencies = [ + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11af7a475c9ee266cfaa9e303a47c830ebe072bf3101ab907a7b7b9d816fa01d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "secret_rock_paper_scissors" +version = "0.1.0" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "serde" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7294d94d390f1d2334697c065ea591d7074c676e2d20aa6f1df752fced29823f" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "snafu" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c4e6046e4691afe918fd1b603fd6e515bcda5388a1092a9edbada307d159f09" +dependencies = [ + "backtrace", + "doc-comment", + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7073448732a89f2f3e6581989106067f403d378faeafb4a50812eb814170d3e5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9425a74 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "secret_rock_paper_scissors" +version = "0.1.0" +authors = ["Mikael Lindlof "] +edition = "2018" + +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] +default = [] +backtraces = ["cosmwasm-std/backtraces"] + +[dependencies] +cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.0" } +schemars = "0.7" +serde = { version = "1.0.103", default-features = false, features = ["derive"] } diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c0dab1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Mikael Lindlof + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c19ceb1 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Secret Rock Paper Scissors + +Rock paper scissors game secret contract for Secret Network. + +## Testing + +Compile: +``` +cargo wasm +``` + +Unit tests: +``` +cargo unit-test +``` + +## Dev deployment + +Compile optimized contract: +``` +docker-compose -f docker-optimize.yaml up +``` + +Run dev node: +``` +docker-compose up +``` + +Deploy contract: +``` +docker exec -it srps_dev /bin/bash +secretcli tx compute store code/contract.wasm.gz --from a --gas auto --gas-adjustment 2 -y --keyring-backend test +secretcli tx compute instantiate 1 "{}" --from a --label "srps" -y --keyring-backend test +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ab6ef67 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: "3.8" +services: + secretdev: + container_name: srps_dev + ports: + - '26657:26657' + - '26656:26656' + - '1317:1317' + volumes: + - '.:/root/code' + image: 'enigmampc/secret-network-sw-dev:v1.0.0' diff --git a/docker-optimize.yaml b/docker-optimize.yaml new file mode 100644 index 0000000..a759960 --- /dev/null +++ b/docker-optimize.yaml @@ -0,0 +1,6 @@ +version: '3.8' +services: + secret-contract-optimizer: + volumes: + - '.:/contract' + image: 'enigmampc/secret-contract-optimizer:1.0.3' diff --git a/src/contract.rs b/src/contract.rs new file mode 100644 index 0000000..94919eb --- /dev/null +++ b/src/contract.rs @@ -0,0 +1,46 @@ +use cosmwasm_std::{ + Api, Env, Extern, HandleResponse, InitResponse, QueryResponse, Querier, + StdResult, Storage, +}; + +use crate::msg::{InitMsg, HandleMsg, QueryMsg}; + +pub fn init( + _deps: &mut Extern, + _env: Env, + _msg: InitMsg, +) -> StdResult { + Ok(InitResponse::default()) +} + +pub fn handle( + _deps: &mut Extern, + _env: Env, + _msg: HandleMsg, +) -> StdResult { + Ok(HandleResponse::default()) +} + +pub fn query( + _deps: &Extern, + _msg: QueryMsg, +) -> StdResult { + Ok(QueryResponse::default()) +} + +#[cfg(test)] +mod tests { + use super::*; + use cosmwasm_std::testing::{mock_dependencies, mock_env}; + use cosmwasm_std::{coins}; + + #[test] + fn proper_initialization() { + let mut deps = mock_dependencies(20, &[]); + let env = mock_env("creator", &coins(1000, "earth")); + let msg = InitMsg{}; + + let res = init(&mut deps, env, msg).unwrap(); + assert_eq!(0, res.messages.len()); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ef91153 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,36 @@ +pub mod contract; +pub mod msg; + +#[cfg(target_arch = "wasm32")] +mod wasm { + use super::contract; + use cosmwasm_std::{ + do_handle, do_init, do_query, ExternalApi, ExternalQuerier, ExternalStorage, + }; + + #[no_mangle] + extern "C" fn init(env_ptr: u32, msg_ptr: u32) -> u32 { + do_init( + &contract::init::, + env_ptr, + msg_ptr, + ) + } + + #[no_mangle] + extern "C" fn handle(env_ptr: u32, msg_ptr: u32) -> u32 { + do_handle( + &contract::handle::, + env_ptr, + msg_ptr, + ) + } + + #[no_mangle] + extern "C" fn query(msg_ptr: u32) -> u32 { + do_query( + &contract::query::, + msg_ptr, + ) + } +} diff --git a/src/msg.rs b/src/msg.rs new file mode 100644 index 0000000..e37da65 --- /dev/null +++ b/src/msg.rs @@ -0,0 +1,14 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct InitMsg {} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct HandleMsg {} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct QueryMsg {}