From 9ff194a50ad29bd747e7bb58fecf835496b3eca9 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 29 May 2024 04:26:34 +0800 Subject: [PATCH 1/2] demo ton connect wasm --- contract/.cargo/config | 4 + contract/.editorconfig | 11 + contract/.gitignore | 17 + contract/Cargo.lock | 1003 +++++++++++++ contract/Cargo.toml | 38 + contract/README.md | 16 + contract/schema/contract.json | 1297 +++++++++++++++++ contract/schema/raw/execute.json | 991 +++++++++++++ contract/schema/raw/instantiate.json | 6 + contract/schema/raw/query.json | 173 +++ .../schema/raw/response_to_check_proof.json | 5 + contract/schema/raw/response_to_config.json | 19 + .../raw/response_to_get_debug_state.json | 62 + .../schema/raw/response_to_get_nickname.json | 5 + .../schema/raw/response_to_get_posts.json | 27 + contract/src/bin/schema.rs | 11 + contract/src/contract.rs | 323 ++++ contract/src/error.rs | 43 + contract/src/lib.rs | 7 + contract/src/msg.rs | 64 + contract/src/state.rs | 15 + contract/src/ton.rs | 105 ++ 22 files changed, 4242 insertions(+) create mode 100644 contract/.cargo/config create mode 100644 contract/.editorconfig create mode 100644 contract/.gitignore create mode 100644 contract/Cargo.lock create mode 100644 contract/Cargo.toml create mode 100644 contract/README.md create mode 100644 contract/schema/contract.json create mode 100644 contract/schema/raw/execute.json create mode 100644 contract/schema/raw/instantiate.json create mode 100644 contract/schema/raw/query.json create mode 100644 contract/schema/raw/response_to_check_proof.json create mode 100644 contract/schema/raw/response_to_config.json create mode 100644 contract/schema/raw/response_to_get_debug_state.json create mode 100644 contract/schema/raw/response_to_get_nickname.json create mode 100644 contract/schema/raw/response_to_get_posts.json create mode 100644 contract/src/bin/schema.rs create mode 100644 contract/src/contract.rs create mode 100644 contract/src/error.rs create mode 100644 contract/src/lib.rs create mode 100644 contract/src/msg.rs create mode 100644 contract/src/state.rs create mode 100644 contract/src/ton.rs diff --git a/contract/.cargo/config b/contract/.cargo/config new file mode 100644 index 00000000..af5698e5 --- /dev/null +++ b/contract/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --lib --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --bin schema" diff --git a/contract/.editorconfig b/contract/.editorconfig new file mode 100644 index 00000000..3d36f20b --- /dev/null +++ b/contract/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.rs] +indent_size = 4 diff --git a/contract/.gitignore b/contract/.gitignore new file mode 100644 index 00000000..21a3a582 --- /dev/null +++ b/contract/.gitignore @@ -0,0 +1,17 @@ +# Build results +/target +/schema +/artifacts + +# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) +.cargo-ok + +# Text file backups +**/*.rs.bk + +# macOS +.DS_Store + +# IDEs +*.iml +.idea diff --git a/contract/Cargo.lock b/contract/Cargo.lock new file mode 100644 index 00000000..da0b0332 --- /dev/null +++ b/contract/Cargo.lock @@ -0,0 +1,1003 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "blake2s_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94230421e395b9920d23df13ea5d77a20e1725331f90fbbf6df6040b33f756ae" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "blake3" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bnum" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cid" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ed9c8b2d17acb8110c46f1da5bf4a696d745e1474a16db0cd2b49cd0249bf2" +dependencies = [ + "core2", + "multibase", + "multihash", + "serde", + "unsigned-varint", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + +[[package]] +name = "cosmwasm-crypto" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6aa9f904de106fa16443ad14ec2abe75e94ba003bb61c681c0e43d4c58d2a" +dependencies = [ + "digest 0.10.7", + "ecdsa", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "242e98e7a231c122e08f300d9db3262d1007b51758a8732cd6210b3e9faa4f3a" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7879036156092ad1c22fe0d7316efc5a5eceec2bc3906462a2560215f2a2f929" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb57855fbfc83327f8445ae0d413b1a05ac0d68c396ab4d122b2abd7bb82cb6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" +dependencies = [ + "base64", + "bech32", + "bnum", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.8", + "static_assertions", + "thiserror", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-storage-plus" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b6f91c0b94481a3e9ef1ceb183c37d00764f8751e39b45fc09f4d9b970d469" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "cw-utils" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dbaecb78c8e8abfd6b4258c7f4fbeb5c49a5e45ee4d910d3240ee8e1d714e1b" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw2" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91398113b806f4d2a8d5f8d05684704a20ffd5968bf87e3473e1973710b884ad" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "schemars", + "serde", +] + +[[package]] +name = "cw721" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "035818368a74c07dd9ed5c5a93340199ba251530162010b9f34c3809e3b97df1" +dependencies = [ + "cosmwasm-std", + "cw-utils", + "schemars", + "serde", +] + +[[package]] +name = "cyber-std" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ac2ed72d2a819bb1c3f9acb68b73d70ec5503206f80d289a24e7c15548f439d" +dependencies = [ + "cid", + "cosmwasm-std", + "cw721", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "data-encoding-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8", + "signature", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" +dependencies = [ + "blake2b_simd", + "blake2s_simd", + "blake3", + "core2", + "digest 0.10.7", + "multihash-derive", + "sha2 0.10.8", + "sha3", + "unsigned-varint", +] + +[[package]] +name = "multihash-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" +dependencies = [ + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro-crate" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.66", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "ton-connect-wasm" +version = "0.1.0" +dependencies = [ + "base64", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "cw2", + "cyber-std", + "hex", + "schemars", + "serde", + "serde_json", + "sha2 0.9.9", + "thiserror", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "unsigned-varint" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/contract/Cargo.toml b/contract/Cargo.toml new file mode 100644 index 00000000..5b528472 --- /dev/null +++ b/contract/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "ton-connect-wasm" +version = "0.1.0" +authors = ["C H "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[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] +library = [] + +[dependencies] +cosmwasm-schema = "1.0.1" +cosmwasm-std = { version = "1.0.1" } +cw-storage-plus = "0.16.0" +cw2 = "0.16.0" +schemars = "0.8.16" +serde = { version = "1.0.197", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.58" } +hex = "0.4.3" +cyber-std = { version = "0.2.1" } +sha2 = { version = "0.9.5", default-features = false } +base64 = "0.21.7" +serde_json = "1.0.117" diff --git a/contract/README.md b/contract/README.md new file mode 100644 index 00000000..b54c0ee9 --- /dev/null +++ b/contract/README.md @@ -0,0 +1,16 @@ +# ton-connect-wasm + +```bash +RUSTFLAGS="-C link-arg=-s" cargo build --release --target=wasm32-unknown-unknown --lib +``` + +```bash +docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.14.0 +``` + +```bash +cargo cw-optimizoor . +``` diff --git a/contract/schema/contract.json b/contract/schema/contract.json new file mode 100644 index 00000000..71971b33 --- /dev/null +++ b/contract/schema/contract.json @@ -0,0 +1,1297 @@ +{ + "contract_name": "contract", + "contract_version": "0.1.0", + "idl_version": "1.0.0", + "instantiate": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "additionalProperties": false + }, + "execute": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "relay_ton_msg" + ], + "properties": { + "relay_ton_msg": { + "type": "object", + "required": [ + "proof", + "pubkey" + ], + "properties": { + "proof": { + "$ref": "#/definitions/CheckProofPayload" + }, + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "debug_execute" + ], + "properties": { + "debug_execute": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "BankMsg": { + "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", + "oneOf": [ + { + "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "send" + ], + "properties": { + "send": { + "type": "object", + "required": [ + "amount", + "to_address" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "to_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", + "type": "object", + "required": [ + "burn" + ], + "properties": { + "burn": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Binary": { + "description": "Binary is a wrapper around Vec 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. See also .", + "type": "string" + }, + "CheckProofPayload": { + "type": "object", + "required": [ + "address", + "network", + "proof" + ], + "properties": { + "address": { + "type": "string" + }, + "network": { + "$ref": "#/definitions/TonNetwork" + }, + "proof": { + "$ref": "#/definitions/TonProof" + } + } + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_CyberMsgWrapper": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/CyberMsgWrapper" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "CyberMsg": { + "oneOf": [ + { + "type": "object", + "required": [ + "cyberlink" + ], + "properties": { + "cyberlink": { + "type": "object", + "required": [ + "links", + "neuron" + ], + "properties": { + "links": { + "type": "array", + "items": { + "$ref": "#/definitions/Link" + } + }, + "neuron": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "investmint" + ], + "properties": { + "investmint": { + "type": "object", + "required": [ + "amount", + "length", + "neuron", + "resource" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "length": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "neuron": { + "type": "string" + }, + "resource": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_energy_route" + ], + "properties": { + "create_energy_route": { + "type": "object", + "required": [ + "destination", + "name", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "name": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "edit_energy_route" + ], + "properties": { + "edit_energy_route": { + "type": "object", + "required": [ + "destination", + "source", + "value" + ], + "properties": { + "destination": { + "type": "string" + }, + "source": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Coin" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "edit_energy_route_name" + ], + "properties": { + "edit_energy_route_name": { + "type": "object", + "required": [ + "destination", + "name", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "name": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "delete_energy_route" + ], + "properties": { + "delete_energy_route": { + "type": "object", + "required": [ + "destination", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_thought" + ], + "properties": { + "create_thought": { + "type": "object", + "required": [ + "load", + "name", + "particle", + "program", + "trigger" + ], + "properties": { + "load": { + "$ref": "#/definitions/Load" + }, + "name": { + "type": "string" + }, + "particle": { + "type": "string" + }, + "program": { + "type": "string" + }, + "trigger": { + "$ref": "#/definitions/Trigger" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "forget_thought" + ], + "properties": { + "forget_thought": { + "type": "object", + "required": [ + "name", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_input" + ], + "properties": { + "change_thought_input": { + "type": "object", + "required": [ + "input", + "name", + "program" + ], + "properties": { + "input": { + "type": "string" + }, + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_period" + ], + "properties": { + "change_thought_period": { + "type": "object", + "required": [ + "name", + "period", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_block" + ], + "properties": { + "change_thought_block": { + "type": "object", + "required": [ + "block", + "name", + "program" + ], + "properties": { + "block": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_pool" + ], + "properties": { + "create_pool": { + "type": "object", + "required": [ + "deposit_coins", + "pool_creator_address", + "pool_type_id" + ], + "properties": { + "deposit_coins": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "pool_creator_address": { + "type": "string" + }, + "pool_type_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "deposit_within_batch" + ], + "properties": { + "deposit_within_batch": { + "type": "object", + "required": [ + "deposit_coins", + "depositor_address", + "pool_id" + ], + "properties": { + "deposit_coins": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "depositor_address": { + "type": "string" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "withdraw_within_batch" + ], + "properties": { + "withdraw_within_batch": { + "type": "object", + "required": [ + "pool_coin", + "pool_id", + "withdrawer_address" + ], + "properties": { + "pool_coin": { + "$ref": "#/definitions/Coin" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "withdrawer_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "swap_within_batch" + ], + "properties": { + "swap_within_batch": { + "type": "object", + "required": [ + "demand_coin_denom", + "offer_coin", + "offer_coin_fee", + "order_price", + "pool_id", + "swap_requester_address", + "swap_type_id" + ], + "properties": { + "demand_coin_denom": { + "type": "string" + }, + "offer_coin": { + "$ref": "#/definitions/Coin" + }, + "offer_coin_fee": { + "$ref": "#/definitions/Coin" + }, + "order_price": { + "$ref": "#/definitions/Decimal" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "swap_requester_address": { + "type": "string" + }, + "swap_type_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] + }, + "CyberMsgWrapper": { + "type": "object", + "required": [ + "msg_data", + "route" + ], + "properties": { + "msg_data": { + "$ref": "#/definitions/CyberMsg" + }, + "route": { + "$ref": "#/definitions/CyberRoute" + } + } + }, + "CyberRoute": { + "description": "CyberRoute is enum type to represent cyber query route path", + "type": "string", + "enum": [ + "rank", + "graph", + "resources", + "grid", + "dmn", + "bandwidth", + "liquidity" + ] + }, + "Decimal": { + "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", + "type": "string" + }, + "Link": { + "type": "object", + "required": [ + "from", + "to" + ], + "properties": { + "from": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, + "Load": { + "type": "object", + "required": [ + "gas_price", + "input" + ], + "properties": { + "gas_price": { + "$ref": "#/definitions/Coin" + }, + "input": { + "type": "string" + } + } + }, + "TonDomain": { + "type": "object", + "required": [ + "lengthBytes", + "value" + ], + "properties": { + "lengthBytes": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "value": { + "type": "string" + } + } + }, + "TonNetwork": { + "type": "string", + "enum": [ + "-239", + "-3" + ] + }, + "TonProof": { + "type": "object", + "required": [ + "domain", + "payload", + "signature", + "state_init", + "timestamp" + ], + "properties": { + "domain": { + "$ref": "#/definitions/TonDomain" + }, + "payload": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "state_init": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "Trigger": { + "type": "object", + "required": [ + "block", + "period" + ], + "properties": { + "block": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + }, + "WasmMsg": { + "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", + "oneOf": [ + { + "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "contract_addr", + "funds", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "msg": { + "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "instantiate" + ], + "properties": { + "instantiate": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readable label for the contract.\n\nValid values should: - not be empty - not be bigger than 128 bytes (or some chain-specific limit) - not start / end with whitespace", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin", + "contract_addr" + ], + "properties": { + "admin": { + "type": "string" + }, + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "clear_admin" + ], + "properties": { + "clear_admin": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + } + } + }, + "query": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_nickname" + ], + "properties": { + "get_nickname": { + "type": "object", + "required": [ + "pubkey" + ], + "properties": { + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_posts" + ], + "properties": { + "get_posts": { + "type": "object", + "required": [ + "pubkey" + ], + "properties": { + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "check_proof" + ], + "properties": { + "check_proof": { + "type": "object", + "required": [ + "proof", + "pubkey" + ], + "properties": { + "proof": { + "$ref": "#/definitions/CheckProofPayload" + }, + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_debug_state" + ], + "properties": { + "get_debug_state": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "CheckProofPayload": { + "type": "object", + "required": [ + "address", + "network", + "proof" + ], + "properties": { + "address": { + "type": "string" + }, + "network": { + "$ref": "#/definitions/TonNetwork" + }, + "proof": { + "$ref": "#/definitions/TonProof" + } + } + }, + "TonDomain": { + "type": "object", + "required": [ + "lengthBytes", + "value" + ], + "properties": { + "lengthBytes": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "value": { + "type": "string" + } + } + }, + "TonNetwork": { + "type": "string", + "enum": [ + "-239", + "-3" + ] + }, + "TonProof": { + "type": "object", + "required": [ + "domain", + "payload", + "signature", + "state_init", + "timestamp" + ], + "properties": { + "domain": { + "$ref": "#/definitions/TonDomain" + }, + "payload": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "state_init": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } + }, + "migrate": null, + "sudo": null, + "responses": { + "check_proof": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Boolean", + "type": "boolean" + }, + "config": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "$ref": "#/definitions/Addr" + } + }, + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + } + } + }, + "get_debug_state": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "State", + "type": "object", + "required": [ + "nicknames", + "posts" + ], + "properties": { + "nicknames": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + } + ], + "maxItems": 2, + "minItems": 2 + } + }, + "posts": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/Post" + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "definitions": { + "Post": { + "type": "object", + "required": [ + "post", + "timestamp" + ], + "properties": { + "post": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } + }, + "get_nickname": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "String", + "type": "string" + }, + "get_posts": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Array_of_Post", + "type": "array", + "items": { + "$ref": "#/definitions/Post" + }, + "definitions": { + "Post": { + "type": "object", + "required": [ + "post", + "timestamp" + ], + "properties": { + "post": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } + } + } +} diff --git a/contract/schema/raw/execute.json b/contract/schema/raw/execute.json new file mode 100644 index 00000000..9e379b71 --- /dev/null +++ b/contract/schema/raw/execute.json @@ -0,0 +1,991 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "relay_ton_msg" + ], + "properties": { + "relay_ton_msg": { + "type": "object", + "required": [ + "proof", + "pubkey" + ], + "properties": { + "proof": { + "$ref": "#/definitions/CheckProofPayload" + }, + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "debug_execute" + ], + "properties": { + "debug_execute": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "BankMsg": { + "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", + "oneOf": [ + { + "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "send" + ], + "properties": { + "send": { + "type": "object", + "required": [ + "amount", + "to_address" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "to_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", + "type": "object", + "required": [ + "burn" + ], + "properties": { + "burn": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Binary": { + "description": "Binary is a wrapper around Vec 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. See also .", + "type": "string" + }, + "CheckProofPayload": { + "type": "object", + "required": [ + "address", + "network", + "proof" + ], + "properties": { + "address": { + "type": "string" + }, + "network": { + "$ref": "#/definitions/TonNetwork" + }, + "proof": { + "$ref": "#/definitions/TonProof" + } + } + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_CyberMsgWrapper": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/CyberMsgWrapper" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "CyberMsg": { + "oneOf": [ + { + "type": "object", + "required": [ + "cyberlink" + ], + "properties": { + "cyberlink": { + "type": "object", + "required": [ + "links", + "neuron" + ], + "properties": { + "links": { + "type": "array", + "items": { + "$ref": "#/definitions/Link" + } + }, + "neuron": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "investmint" + ], + "properties": { + "investmint": { + "type": "object", + "required": [ + "amount", + "length", + "neuron", + "resource" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "length": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "neuron": { + "type": "string" + }, + "resource": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_energy_route" + ], + "properties": { + "create_energy_route": { + "type": "object", + "required": [ + "destination", + "name", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "name": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "edit_energy_route" + ], + "properties": { + "edit_energy_route": { + "type": "object", + "required": [ + "destination", + "source", + "value" + ], + "properties": { + "destination": { + "type": "string" + }, + "source": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Coin" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "edit_energy_route_name" + ], + "properties": { + "edit_energy_route_name": { + "type": "object", + "required": [ + "destination", + "name", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "name": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "delete_energy_route" + ], + "properties": { + "delete_energy_route": { + "type": "object", + "required": [ + "destination", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_thought" + ], + "properties": { + "create_thought": { + "type": "object", + "required": [ + "load", + "name", + "particle", + "program", + "trigger" + ], + "properties": { + "load": { + "$ref": "#/definitions/Load" + }, + "name": { + "type": "string" + }, + "particle": { + "type": "string" + }, + "program": { + "type": "string" + }, + "trigger": { + "$ref": "#/definitions/Trigger" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "forget_thought" + ], + "properties": { + "forget_thought": { + "type": "object", + "required": [ + "name", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_input" + ], + "properties": { + "change_thought_input": { + "type": "object", + "required": [ + "input", + "name", + "program" + ], + "properties": { + "input": { + "type": "string" + }, + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_period" + ], + "properties": { + "change_thought_period": { + "type": "object", + "required": [ + "name", + "period", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_thought_block" + ], + "properties": { + "change_thought_block": { + "type": "object", + "required": [ + "block", + "name", + "program" + ], + "properties": { + "block": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "create_pool" + ], + "properties": { + "create_pool": { + "type": "object", + "required": [ + "deposit_coins", + "pool_creator_address", + "pool_type_id" + ], + "properties": { + "deposit_coins": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "pool_creator_address": { + "type": "string" + }, + "pool_type_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "deposit_within_batch" + ], + "properties": { + "deposit_within_batch": { + "type": "object", + "required": [ + "deposit_coins", + "depositor_address", + "pool_id" + ], + "properties": { + "deposit_coins": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "depositor_address": { + "type": "string" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "withdraw_within_batch" + ], + "properties": { + "withdraw_within_batch": { + "type": "object", + "required": [ + "pool_coin", + "pool_id", + "withdrawer_address" + ], + "properties": { + "pool_coin": { + "$ref": "#/definitions/Coin" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "withdrawer_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "swap_within_batch" + ], + "properties": { + "swap_within_batch": { + "type": "object", + "required": [ + "demand_coin_denom", + "offer_coin", + "offer_coin_fee", + "order_price", + "pool_id", + "swap_requester_address", + "swap_type_id" + ], + "properties": { + "demand_coin_denom": { + "type": "string" + }, + "offer_coin": { + "$ref": "#/definitions/Coin" + }, + "offer_coin_fee": { + "$ref": "#/definitions/Coin" + }, + "order_price": { + "$ref": "#/definitions/Decimal" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "swap_requester_address": { + "type": "string" + }, + "swap_type_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] + }, + "CyberMsgWrapper": { + "type": "object", + "required": [ + "msg_data", + "route" + ], + "properties": { + "msg_data": { + "$ref": "#/definitions/CyberMsg" + }, + "route": { + "$ref": "#/definitions/CyberRoute" + } + } + }, + "CyberRoute": { + "description": "CyberRoute is enum type to represent cyber query route path", + "type": "string", + "enum": [ + "rank", + "graph", + "resources", + "grid", + "dmn", + "bandwidth", + "liquidity" + ] + }, + "Decimal": { + "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", + "type": "string" + }, + "Link": { + "type": "object", + "required": [ + "from", + "to" + ], + "properties": { + "from": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, + "Load": { + "type": "object", + "required": [ + "gas_price", + "input" + ], + "properties": { + "gas_price": { + "$ref": "#/definitions/Coin" + }, + "input": { + "type": "string" + } + } + }, + "TonDomain": { + "type": "object", + "required": [ + "lengthBytes", + "value" + ], + "properties": { + "lengthBytes": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "value": { + "type": "string" + } + } + }, + "TonNetwork": { + "type": "string", + "enum": [ + "-239", + "-3" + ] + }, + "TonProof": { + "type": "object", + "required": [ + "domain", + "payload", + "signature", + "state_init", + "timestamp" + ], + "properties": { + "domain": { + "$ref": "#/definitions/TonDomain" + }, + "payload": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "state_init": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "Trigger": { + "type": "object", + "required": [ + "block", + "period" + ], + "properties": { + "block": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + }, + "WasmMsg": { + "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", + "oneOf": [ + { + "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "contract_addr", + "funds", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "msg": { + "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "instantiate" + ], + "properties": { + "instantiate": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readable label for the contract.\n\nValid values should: - not be empty - not be bigger than 128 bytes (or some chain-specific limit) - not start / end with whitespace", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin", + "contract_addr" + ], + "properties": { + "admin": { + "type": "string" + }, + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "clear_admin" + ], + "properties": { + "clear_admin": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + } + } +} diff --git a/contract/schema/raw/instantiate.json b/contract/schema/raw/instantiate.json new file mode 100644 index 00000000..1352613d --- /dev/null +++ b/contract/schema/raw/instantiate.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "additionalProperties": false +} diff --git a/contract/schema/raw/query.json b/contract/schema/raw/query.json new file mode 100644 index 00000000..94f87325 --- /dev/null +++ b/contract/schema/raw/query.json @@ -0,0 +1,173 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_nickname" + ], + "properties": { + "get_nickname": { + "type": "object", + "required": [ + "pubkey" + ], + "properties": { + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_posts" + ], + "properties": { + "get_posts": { + "type": "object", + "required": [ + "pubkey" + ], + "properties": { + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "check_proof" + ], + "properties": { + "check_proof": { + "type": "object", + "required": [ + "proof", + "pubkey" + ], + "properties": { + "proof": { + "$ref": "#/definitions/CheckProofPayload" + }, + "pubkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_debug_state" + ], + "properties": { + "get_debug_state": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "CheckProofPayload": { + "type": "object", + "required": [ + "address", + "network", + "proof" + ], + "properties": { + "address": { + "type": "string" + }, + "network": { + "$ref": "#/definitions/TonNetwork" + }, + "proof": { + "$ref": "#/definitions/TonProof" + } + } + }, + "TonDomain": { + "type": "object", + "required": [ + "lengthBytes", + "value" + ], + "properties": { + "lengthBytes": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "value": { + "type": "string" + } + } + }, + "TonNetwork": { + "type": "string", + "enum": [ + "-239", + "-3" + ] + }, + "TonProof": { + "type": "object", + "required": [ + "domain", + "payload", + "signature", + "state_init", + "timestamp" + ], + "properties": { + "domain": { + "$ref": "#/definitions/TonDomain" + }, + "payload": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "state_init": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } +} diff --git a/contract/schema/raw/response_to_check_proof.json b/contract/schema/raw/response_to_check_proof.json new file mode 100644 index 00000000..a7fe2bfe --- /dev/null +++ b/contract/schema/raw/response_to_check_proof.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Boolean", + "type": "boolean" +} diff --git a/contract/schema/raw/response_to_config.json b/contract/schema/raw/response_to_config.json new file mode 100644 index 00000000..730edcde --- /dev/null +++ b/contract/schema/raw/response_to_config.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "$ref": "#/definitions/Addr" + } + }, + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + } + } +} diff --git a/contract/schema/raw/response_to_get_debug_state.json b/contract/schema/raw/response_to_get_debug_state.json new file mode 100644 index 00000000..fb14547a --- /dev/null +++ b/contract/schema/raw/response_to_get_debug_state.json @@ -0,0 +1,62 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "State", + "type": "object", + "required": [ + "nicknames", + "posts" + ], + "properties": { + "nicknames": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + } + ], + "maxItems": 2, + "minItems": 2 + } + }, + "posts": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/Post" + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "definitions": { + "Post": { + "type": "object", + "required": [ + "post", + "timestamp" + ], + "properties": { + "post": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } +} diff --git a/contract/schema/raw/response_to_get_nickname.json b/contract/schema/raw/response_to_get_nickname.json new file mode 100644 index 00000000..f689aceb --- /dev/null +++ b/contract/schema/raw/response_to_get_nickname.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "String", + "type": "string" +} diff --git a/contract/schema/raw/response_to_get_posts.json b/contract/schema/raw/response_to_get_posts.json new file mode 100644 index 00000000..c3160b23 --- /dev/null +++ b/contract/schema/raw/response_to_get_posts.json @@ -0,0 +1,27 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Array_of_Post", + "type": "array", + "items": { + "$ref": "#/definitions/Post" + }, + "definitions": { + "Post": { + "type": "object", + "required": [ + "post", + "timestamp" + ], + "properties": { + "post": { + "type": "string" + }, + "timestamp": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } +} diff --git a/contract/src/bin/schema.rs b/contract/src/bin/schema.rs new file mode 100644 index 00000000..06f13cd2 --- /dev/null +++ b/contract/src/bin/schema.rs @@ -0,0 +1,11 @@ +use cosmwasm_schema::write_api; + +use contract::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } +} diff --git a/contract/src/contract.rs b/contract/src/contract.rs new file mode 100644 index 00000000..b67172b3 --- /dev/null +++ b/contract/src/contract.rs @@ -0,0 +1,323 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{Addr, attr, Binary, CosmosMsg, Deps, DepsMut, Empty, ensure, Env, MessageInfo, Order, StdError, StdResult, Storage, to_json_binary}; +use cosmwasm_std::Order::Ascending; +use cw2::{ContractVersion, get_contract_version, set_contract_version}; +use cyber_std::{create_cyberlink_msg, CyberMsgWrapper, Link}; +use cyber_std::particle::prepare_particle; +use sha2::{Digest, Sha256}; + +use crate::error::ContractError; +use crate::msg::{ExecuteMsg, InstantiateMsg, Payload, Post, QueryMsg, State}; +use crate::state::{CONFIG, Config, NICKNAMES, POSTS}; +use crate::ton::{CheckProofPayload, TonAddress}; + +type Response = cosmwasm_std::Response; +const CONTRACT_NAME: &str = "crates.io:contract"; +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +pub fn ensure_root(store: &dyn Storage, address: &Addr) -> Result<(), ContractError> { + let config = CONFIG.load(store)?; + ensure!(config.admin == address, ContractError::Unauthorized {}); + Ok(()) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + CONFIG.save(deps.storage, &Config{ admin: info.sender})?; + + Ok(Response::default()) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + ExecuteMsg::RelayTonMsg { pubkey, proof } => do_relay_ton_msg(deps, env, info, pubkey, proof), + ExecuteMsg::UpdateAdmin { admin } => do_update_admin(deps, env, info, admin), + ExecuteMsg::DebugExecute { msgs } => do_debug_execute(deps, env, info, msgs), + } +} + +pub fn do_relay_ton_msg( + deps: DepsMut, + env: Env, + info: MessageInfo, + pubkey: String, + proof_payload: CheckProofPayload, +) -> Result { + // TODO enable later + // ensure_root(deps.storage, &info.sender)?; + + ensure!( + check_proof(deps.as_ref(), pubkey.clone(), proof_payload.clone())? == true, + ContractError::Unauthorized {} + ); + + let payload: Payload = serde_json::from_str(&proof_payload.proof.payload) + .map_err(|_| ContractError::PayloadError {})?; + + if payload.msg_type == "map_nickname" { + NICKNAMES.save(deps.storage, pubkey.clone(), &payload.msg_data)?; + } + + if payload.msg_type == "add_post" { + ensure!( + NICKNAMES.has(deps.storage, pubkey.clone()), + ContractError::Unauthorized {} + ); + POSTS.save(deps.storage, (pubkey.clone(), env.block.time.seconds()), &payload.msg_data)?; + let link = Link { + from: prepare_particle(pubkey)?.to_string(), + to: prepare_particle(payload.msg_data)?.to_string(), + }; + let msg = create_cyberlink_msg(env.contract.address.to_string(), vec![link]); + return Ok(Response::new() + .add_attribute("action", "relay_msg") + .add_message(msg) + ) + } + + Ok(Response::new() + .add_attributes(vec![ + attr("action", "relay_msg"), + // attr("result", rst.to_string()), + ])) +} + +pub fn do_update_admin( + deps: DepsMut, + _env: Env, + info: MessageInfo, + admin: String, +) -> Result { + ensure_root(deps.storage, &info.sender)?; + + CONFIG.save(deps.storage, &Config{ admin: deps.api.addr_validate(&admin)?})?; + + Ok(Response::new() + .add_attribute("action", "update_admin") + ) +} + +pub fn do_debug_execute( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msgs: Vec>, +) -> Result { + ensure_root(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_messages(msgs) + .add_attribute("action", "execute") + ) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query( + deps: Deps, + _env: Env, + msg: QueryMsg +) -> StdResult { + match msg { + QueryMsg::Config { } => to_json_binary(&get_config(deps.storage)?), + QueryMsg::GetNickname { pubkey } => to_json_binary(&get_nickname(deps.storage, pubkey)?), + QueryMsg::GetPosts { pubkey } => to_json_binary(&get_posts(deps.storage, pubkey)?), + QueryMsg::CheckProof { pubkey, proof } => to_json_binary(&check_proof(deps, pubkey, proof)?), + QueryMsg::GetDebugState { } => to_json_binary(&get_debug_state(deps.storage)?), + } +} + +pub fn get_config(store: &dyn Storage) -> StdResult { + let config = CONFIG.load(store)?; + + return Ok(config) +} + +pub fn get_nickname(store: &dyn Storage, address: String) -> StdResult { + let nickname = NICKNAMES.load(store, address)?; + + return Ok(nickname) +} + +pub fn check_proof( + deps: Deps, + pubkey: String, + proof_payload: CheckProofPayload +) -> StdResult { + const TON_PROOF_PREFIX: &'static str = "ton-proof-item-v2/"; + + let ton_address = TonAddress::from_hex_str(&proof_payload.address) + .map_err(|err| StdError::generic_err(err.to_string()))?; + + let mut msg: Vec = Vec::new(); + msg.extend_from_slice(TON_PROOF_PREFIX.as_bytes()); + msg.extend_from_slice(&ton_address.workchain.to_be_bytes()); + msg.extend_from_slice(&ton_address.hash_part); // should it be big endian? + msg.extend_from_slice(&(proof_payload.proof.domain.length_bytes as u32).to_le_bytes()); + msg.extend_from_slice(proof_payload.proof.domain.value.as_bytes()); + msg.extend_from_slice(&proof_payload.proof.timestamp.to_le_bytes()); + msg.extend_from_slice(proof_payload.proof.payload.as_bytes()); + + let mut hasher = Sha256::new(); + hasher.update(msg); + let msg_hash = hasher.finalize(); + + const TON_CONNECT_PREFIX: &'static str = "ton-connect"; + + let mut full_msg: Vec = vec![0xff, 0xff]; + full_msg.extend_from_slice(TON_CONNECT_PREFIX.as_bytes()); + full_msg.extend_from_slice(&msg_hash); + + let mut hasher = Sha256::new(); + hasher.update(full_msg); + let full_msg_hash = hasher.finalize(); + + + // let pubkey = VerifyingKey::from_bytes(&pubkey_bytes)?; + let signature_bytes: [u8; 64] = BASE64_STANDARD + .decode(&proof_payload.proof.signature) + // .map_err(|e| ContractError::VerificationFailed { msg: "sig bytes error".to_string() })? + .map_err(|err| StdError::generic_err(err.to_string()))? + .try_into() + // .map_err(|_| ContractError::VerificationFailed { msg: "expected 64 bit long signature".to_string() })?; + .map_err(|_| StdError::generic_err("expected 64 bit long signature".to_string()))?; + // let signature = Signature::from_bytes(&signature_bytes); + // pubkey + // .verify(&full_msg_hash, &signature) + // .map_err(|e| AppError::BadRequest(e.into()))?; + + + // let public_key_hex = "db642e022c80911fe61f19eb4f22d7fb95c1ea0b589c0f74ecf0cbf6db746c13".as_bytes(); + let public_key_hex = pubkey.as_bytes(); + + let binding = hex::decode(public_key_hex).unwrap(); + let public_key = binding.as_slice(); + + let result = deps + .api + .ed25519_verify( + full_msg_hash.as_slice(), + &signature_bytes.as_slice(), + public_key, + ) + // .map_err(|err| ContractError::VerificationFailed { + // msg: err.to_string(), + // }); + .map_err(|err| StdError::generic_err(err.to_string()))?; + + + Ok(result) +} + +pub fn get_posts(store: &dyn Storage, address: String) -> StdResult> { + let posts = POSTS + .prefix(address) + .range(store, None, None, Order::Ascending) + .map(|post| { + let p: (u64, String) = post.unwrap(); + Post{post: p.1, timestamp: p.0} + }) + .collect::>(); + + return Ok(posts) +} + +pub fn get_debug_state(store: &dyn Storage) -> StdResult { + let nicknames = NICKNAMES + .range(store, None, None, Ascending) + .collect::>>() + .unwrap(); + let posts = POSTS + .range(store, None, None, Ascending) + .map(|item| { + let ((addr,timestamp), post) = item.unwrap(); + (addr, Post{post,timestamp}) + }) + .collect::>(); + // .unwrap(); + + let state = State { + nicknames, + posts, + }; + + return Ok(state) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate( + _deps: DepsMut, + _env: Env, + _msg: Empty, +) -> Result { + // let storage_version: ContractVersion = get_contract_version(deps.storage)?; + // + // if storage_version.version.as_str() < CONTRACT_VERSION { + // set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // } else { + // return Err(ContractError::MigrationError {}) + // } + + Ok(Response::new().add_attribute("action", "migrate")) +} + +#[cfg(test)] +mod tests { + use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; + use crate::contract::{check_proof, instantiate, query}; + use crate::msg::InstantiateMsg; + use crate::ton::{CheckProofPayload, TonDomain, TonNetwork, TonProof}; + + #[test] + fn test_proof() { + let mut deps = mock_dependencies(); + + let admin = "admin"; + let instantiate_msg = InstantiateMsg {}; + + instantiate( + deps.as_mut(), + mock_env(), + mock_info(&admin, &[]), + instantiate_msg + ).unwrap(); + + let proof = CheckProofPayload { + address: "0:f63660ff947e5fe6ed4a8f729f1b24ef859497d0483aaa9d9ae48414297c4e1b".to_string(), + network: TonNetwork::Mainnet, + proof: TonProof { + domain: TonDomain { + length_bytes: 21, + value: "ton-connect.github.io".to_string() + }, + payload: "E5B4ARS6CdOI2b5e1jz0jnS-x-a3DgfNXprrg_3pec0=".to_string(), + signature: "28tWSg8RDB3P/iIYupySINq1o3F5xLodndzNFHOtdi16Z+MuII8LAPnHLT3E6WTB27//qY4psU5Rf5/aJaIIAA==".to_string(), + state_init: "".to_string(), + timestamp: 1668094767, + }, + }; + + let result = check_proof( + deps.as_ref(), + "db642e022c80911fe61f19eb4f22d7fb95c1ea0b589c0f74ecf0cbf6db746c13".to_string(), + proof, + ); + + assert_eq!(result.is_ok(), true); + } +} diff --git a/contract/src/error.rs b/contract/src/error.rs new file mode 100644 index 00000000..20615be1 --- /dev/null +++ b/contract/src/error.rs @@ -0,0 +1,43 @@ +use cosmwasm_std::StdError; +use cyber_std::particle::ParticleError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, + + #[error("Ton parse error: {sender}, {message}")] + TonAddressParseError { sender: String, message: String }, + + #[error("Verification failed")] + VerificationFailed { msg: String }, + + #[error("Contract have issue during migration")] + MigrationError {}, + + #[error("Payload type and data error")] + PayloadError {}, + + #[error("Invalid data for the particle")] + InvalidParticleData {}, + + #[error("Invalid particle")] + InvalidParticle {}, + + #[error("Invalid particle version")] + InvalidParticleVersion {}, +} + +impl From for ContractError { + fn from(msg: ParticleError) -> ContractError { + match msg { + ParticleError::InvalidParticleData {} => ContractError::InvalidParticleData {}, + ParticleError::InvalidParticle {} => ContractError::InvalidParticle {}, + ParticleError::InvalidParticleVersion {} => ContractError::InvalidParticleVersion {} + } + } +} diff --git a/contract/src/lib.rs b/contract/src/lib.rs new file mode 100644 index 00000000..679bfbec --- /dev/null +++ b/contract/src/lib.rs @@ -0,0 +1,7 @@ +pub mod contract; +mod error; +pub mod msg; +pub mod state; +mod ton; + +pub use crate::error::ContractError; diff --git a/contract/src/msg.rs b/contract/src/msg.rs new file mode 100644 index 00000000..36816c4a --- /dev/null +++ b/contract/src/msg.rs @@ -0,0 +1,64 @@ +use crate::state::Config; +use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_std::{CosmosMsg}; +use cyber_std::CyberMsgWrapper; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use crate::ton::CheckProofPayload; + +#[cw_serde] +pub struct InstantiateMsg {} + +#[cw_serde] +pub enum ExecuteMsg { + RelayTonMsg { + pubkey: String, + proof: CheckProofPayload, + }, + UpdateAdmin { + admin: String, + }, + DebugExecute { + msgs: Vec>, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Config)] + Config {}, + #[returns(String)] + GetNickname { pubkey: String }, + #[returns(Vec)] + GetPosts { pubkey: String }, + #[returns(bool)] + CheckProof { + pubkey: String, + proof: CheckProofPayload, + }, + #[returns(State)] + GetDebugState {}, +} + +#[cw_serde] +pub struct MigrateMsg {} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct Payload { + pub msg_type: String, + pub msg_data: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct Post { + pub post: String, + // pub particle: String, + pub timestamp: u64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct State { + pub nicknames: Vec<(String, String)>, + pub posts: Vec<(String, Post)>, +} diff --git a/contract/src/state.rs b/contract/src/state.rs new file mode 100644 index 00000000..44058209 --- /dev/null +++ b/contract/src/state.rs @@ -0,0 +1,15 @@ +use cosmwasm_std::{Addr, Timestamp}; +use cw_storage_plus::{Item, Map}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct Config { + pub admin: Addr, +} + +pub const CONFIG: Item = Item::new("config"); + +pub const NICKNAMES: Map = Map::new("nicknames"); + +pub const POSTS: Map<(String, u64), String> = Map::new("posts"); \ No newline at end of file diff --git a/contract/src/ton.rs b/contract/src/ton.rs new file mode 100644 index 00000000..dee3b622 --- /dev/null +++ b/contract/src/ton.rs @@ -0,0 +1,105 @@ +use crate::ContractError; +use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct TonAddress { + pub workchain: i32, + pub hash_part: [u8; 32], +} +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct CheckProofPayload { + // pub address: TonAddress, + pub address: String, + pub network: TonNetwork, + pub proof: TonProof, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub enum TonNetwork { + #[serde(rename = "-239")] + Mainnet, + #[serde(rename = "-3")] + Testnet, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct TonProof { + pub domain: TonDomain, + pub payload: String, + pub signature: String, + pub state_init: String, + pub timestamp: u64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct TonDomain { + #[serde(rename = "lengthBytes")] + pub length_bytes: u64, + pub value: String, +} + +impl TonAddress { + pub const NULL: TonAddress = TonAddress { + workchain: 0, + hash_part: [0; 32], + }; + + pub fn new(workchain: i32, hash_part: &[u8; 32]) -> TonAddress { + TonAddress { + workchain, + hash_part: hash_part.clone(), + } + } + + pub fn null() -> TonAddress { + TonAddress::NULL.clone() + } + + pub fn from_hex_str(s: &str) -> Result { + let parts: Vec<&str> = s.split(":").collect(); + + if parts.len() != 2 { + return Err(ContractError::TonAddressParseError{ + sender: s.to_string(), + message: "Invalid hex address string: wrong address format".to_string(), + }); + } + + let maybe_wc = i32::from_str_radix(parts[0], 10); + let wc = match maybe_wc { + Ok(wc) => wc, + Err(_) => { + return Err(ContractError::TonAddressParseError{ + sender: s.to_string(), + message: "Invalid hex address string: parse int error".to_string(), + }) + } + }; + + let maybe_decoded_hash_part = hex::decode(parts[1]); + let decoded_hash_part = match maybe_decoded_hash_part { + Ok(decoded_hash_part) => decoded_hash_part, + Err(_) => { + return Err(ContractError::TonAddressParseError{ + sender: s.to_string(), + message: "Invalid hex address string: base64 decode error".to_string(), + }) + } + }; + + let maybe_hash_part = decoded_hash_part.as_slice().try_into(); + let hash_part = match maybe_hash_part { + Ok(hash_part) => hash_part, + Err(_) => { + return Err(ContractError::TonAddressParseError{ + sender: s.to_string(), + message: "Invalid hex address string: unexpected error".to_string(), + }) + } + }; + + let addr = TonAddress::new(wc, &hash_part); + Ok(addr) + } +} \ No newline at end of file From 476deeafda1ed1cfbffcd19b2b37e6c6c0e92669 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 29 May 2024 04:31:48 +0800 Subject: [PATCH 2/2] Refactoring --- contract/src/contract.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/contract/src/contract.rs b/contract/src/contract.rs index b67172b3..f54c2185 100644 --- a/contract/src/contract.rs +++ b/contract/src/contract.rs @@ -33,7 +33,7 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - CONFIG.save(deps.storage, &Config{ admin: info.sender})?; + CONFIG.save(deps.storage, &Config{ admin: info.sender })?; Ok(Response::default()) } @@ -148,8 +148,8 @@ pub fn get_config(store: &dyn Storage) -> StdResult { return Ok(config) } -pub fn get_nickname(store: &dyn Storage, address: String) -> StdResult { - let nickname = NICKNAMES.load(store, address)?; +pub fn get_nickname(store: &dyn Storage, pubkey: String) -> StdResult { + let nickname = NICKNAMES.load(store, pubkey)?; return Ok(nickname) } @@ -224,9 +224,9 @@ pub fn check_proof( Ok(result) } -pub fn get_posts(store: &dyn Storage, address: String) -> StdResult> { +pub fn get_posts(store: &dyn Storage, pubkey: String) -> StdResult> { let posts = POSTS - .prefix(address) + .prefix(pubkey) .range(store, None, None, Order::Ascending) .map(|post| { let p: (u64, String) = post.unwrap(); @@ -249,14 +249,11 @@ pub fn get_debug_state(store: &dyn Storage) -> StdResult { (addr, Post{post,timestamp}) }) .collect::>(); - // .unwrap(); - let state = State { + return Ok(State { nicknames, posts, - }; - - return Ok(state) + }) } #[cfg_attr(not(feature = "library"), entry_point)]