From ce43d827a2b9086287a70d7f4247c24ee23eea08 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 12:38:45 +0800 Subject: [PATCH 01/33] Rename cw-cyb to hub contracts --- Cargo.lock | 220 +++++++++++++++--- contracts/cw-cyb-protocols/Cargo.toml | 53 ----- .../.cargo/config | 0 .../Cargo.toml | 2 +- .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../src/lib.rs | 0 .../src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 .../.cargo/config | 0 .../Cargo.toml | 2 +- .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../src/lib.rs | 0 .../src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 .../.cargo/config | 0 .../Cargo.toml | 2 +- .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../src/lib.rs | 0 .../src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 .../.cargo/config | 0 .../Cargo.toml | 2 +- .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../src/lib.rs | 0 .../src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 .../.cargo/config | 0 .../{cw-cyb-skills => hub-skills}/Cargo.lock | 0 .../{cw-cyb-skills => hub-skills}/Cargo.toml | 2 +- .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../{cw-cyb-skills => hub-skills}/src/lib.rs | 0 .../{cw-cyb-skills => hub-skills}/src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 .../.cargo/config | 0 .../{cw-cyb-tokens => hub-tokens}/Cargo.lock | 0 contracts/hub-tokens/Cargo.toml | 53 +++++ .../examples/schema.rs | 0 .../src/contract.rs | 0 .../src/error.rs | 0 .../{cw-cyb-tokens => hub-tokens}/src/lib.rs | 0 .../{cw-cyb-tokens => hub-tokens}/src/msg.rs | 0 .../src/query.rs | 0 .../src/state.rs | 0 .../src/tests.rs | 0 .../src/validating.rs | 0 70 files changed, 249 insertions(+), 87 deletions(-) delete mode 100644 contracts/cw-cyb-protocols/Cargo.toml rename contracts/{cw-cyb-channels => hub-channels}/.cargo/config (100%) rename contracts/{cw-cyb-tokens => hub-channels}/Cargo.toml (98%) rename contracts/{cw-cyb-channels => hub-channels}/examples/schema.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/contract.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/error.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/lib.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/msg.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/query.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/state.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/tests.rs (100%) rename contracts/{cw-cyb-channels => hub-channels}/src/validating.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/.cargo/config (100%) rename contracts/{cw-cyb-network => hub-contracts}/Cargo.toml (98%) rename contracts/{cw-cyb-contract => hub-contracts}/examples/schema.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/contract.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/error.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/lib.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/msg.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/query.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/state.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/tests.rs (100%) rename contracts/{cw-cyb-contract => hub-contracts}/src/validating.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/.cargo/config (100%) rename contracts/{cw-cyb-channels => hub-networks}/Cargo.toml (98%) rename contracts/{cw-cyb-network => hub-networks}/examples/schema.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/contract.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/error.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/lib.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/msg.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/query.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/state.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/tests.rs (100%) rename contracts/{cw-cyb-network => hub-networks}/src/validating.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/.cargo/config (100%) rename contracts/{cw-cyb-contract => hub-protocols}/Cargo.toml (98%) rename contracts/{cw-cyb-protocols => hub-protocols}/examples/schema.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/contract.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/error.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/lib.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/msg.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/query.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/state.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/tests.rs (100%) rename contracts/{cw-cyb-protocols => hub-protocols}/src/validating.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/.cargo/config (100%) rename contracts/{cw-cyb-skills => hub-skills}/Cargo.lock (100%) rename contracts/{cw-cyb-skills => hub-skills}/Cargo.toml (98%) rename contracts/{cw-cyb-skills => hub-skills}/examples/schema.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/contract.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/error.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/lib.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/msg.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/query.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/state.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/tests.rs (100%) rename contracts/{cw-cyb-skills => hub-skills}/src/validating.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/.cargo/config (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/Cargo.lock (100%) create mode 100644 contracts/hub-tokens/Cargo.toml rename contracts/{cw-cyb-tokens => hub-tokens}/examples/schema.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/contract.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/error.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/lib.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/msg.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/query.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/state.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/tests.rs (100%) rename contracts/{cw-cyb-tokens => hub-tokens}/src/validating.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 1327a77..8f24828 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -508,13 +508,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b81b8c4647f13be38baea7345885fcd97cffe8ad4e0454a43f975be9609127ed" dependencies = [ "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "schemars", "serde", "thiserror", ] +[[package]] +name = "cw-cyb-endpoints" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw-cyb-heroes" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.14.0", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw-multi-test" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f9a8ab7c3c29ec93cb7a39ce4b14a05e053153b4a17ef7cf2246af1b7c087e" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "derivative", + "itertools", + "prost", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw-multi-test" version = "0.14.0" @@ -524,7 +573,7 @@ dependencies = [ "anyhow", "cosmwasm-std", "cosmwasm-storage", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "derivative", "itertools", @@ -534,6 +583,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-storage-plus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + [[package]] name = "cw-storage-plus" version = "0.14.0" @@ -564,7 +624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "414b91f3d7a619bb26c835119d7095804596a1382ddc1d184c33c1d2c17f6c5e" dependencies = [ "cosmwasm-std", - "cw2", + "cw2 0.14.0", "schemars", "semver", "serde", @@ -588,11 +648,11 @@ version = "0.14.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw1", "cw1-whitelist", - "cw2", + "cw2 0.14.0", "cyber-std 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "semver", @@ -608,11 +668,11 @@ dependencies = [ "assert_matches", "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", + "cw-multi-test 0.14.0", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw1", - "cw2", + "cw2 0.14.0", "cyber-std 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "derivative", "schemars", @@ -620,6 +680,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw2" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cf4639517490dd36b333bbd6c4fbd92e325fd0acf4683b41753bc5eb63bfc1" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus 0.13.4", + "schemars", + "serde", +] + [[package]] name = "cw2" version = "0.14.0" @@ -627,7 +699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa74c324af8e3506fd8d50759a265bead3f87402e413c840042af5d2808463d6" dependencies = [ "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "schemars", "serde", ] @@ -651,9 +723,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e39bf97c985a50f2e340833137b3f14999f58708c4ca9928cd8f87d530c4109c" dependencies = [ "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", - "cw2", + "cw2 0.14.0", "cw20", "schemars", "semver", @@ -679,10 +751,10 @@ version = "0.14.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", + "cw-multi-test 0.14.0", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", - "cw2", + "cw2 0.14.0", "cw20", "cw20-base", "cw3", @@ -698,10 +770,10 @@ version = "0.14.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", + "cw-multi-test 0.14.0", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", - "cw2", + "cw2 0.14.0", "cw3", "cw3-fixed-multisig", "cw4", @@ -719,7 +791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95dcc5320bdee5475aadfe7ebce70be5d98040bf91b44b7c22d3acd0c133c329" dependencies = [ "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "schemars", "serde", ] @@ -732,9 +804,9 @@ checksum = "93204a7aa587466636d001b21831c4b4ac87fccd40c7b39f78ad95dee452309e" dependencies = [ "cosmwasm-std", "cw-controllers", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", - "cw2", + "cw2 0.14.0", "cw4", "schemars", "serde", @@ -786,8 +858,8 @@ version = "0.2.2" dependencies = [ "anyhow", "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", + "cw-multi-test 0.14.0", + "cw-storage-plus 0.14.0", "cyber-std 0.2.2", "schemars", "serde", @@ -1030,7 +1102,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw20", "cw20-base", @@ -1046,7 +1118,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw20", "cw20-base", @@ -1062,7 +1134,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw20", "cw20-base", @@ -1078,7 +1150,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-storage-plus", + "cw-storage-plus 0.14.0", "cw-utils 0.14.0", "cw20", "cw20-base", @@ -1221,6 +1293,96 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hub-channels" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "hub-contracts" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "hub-networks" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "hub-protocols" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "hub-skills" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.14.0", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "hub-tokens" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "ibc-reflect" version = "0.0.0" @@ -1229,7 +1391,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cosmwasm-vm", - "cw-multi-test", + "cw-multi-test 0.14.0", "cyber-std 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "serde", @@ -1243,7 +1405,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cosmwasm-vm", - "cw-multi-test", + "cw-multi-test 0.14.0", "cyber-std 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "serde", @@ -1687,7 +1849,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cosmwasm-vm", - "cw-multi-test", + "cw-multi-test 0.14.0", "cyber-std 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "serde", diff --git a/contracts/cw-cyb-protocols/Cargo.toml b/contracts/cw-cyb-protocols/Cargo.toml deleted file mode 100644 index 0fa4f8b..0000000 --- a/contracts/cw-cyb-protocols/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -name = "cw-cyb-protocols" -version = "0.1.0" -authors = ["Bloqhub"] -edition = "2018" - -exclude = [ - # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. - "contract.wasm", - "hash.txt", -] - -# 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] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] -# use library feature to disable all instantiate/execute/query exports -library = [] - -[package.metadata.scripts] -optimize = """docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 -""" - -[dependencies] -cosmwasm-std = { version = "1.0.0", features = ["iterator", "abort"] } -cw-storage-plus = { version = "0.13.4" } -cw2 = { version = "0.13.4" } -schemars = "0.8.10" -serde = { version = "1.0.140", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.31" } -cid = { version = "0.8.0" } - -[dev-dependencies] -cosmwasm-schema = "1.0.0" -cw-multi-test = "0.13.2" diff --git a/contracts/cw-cyb-channels/.cargo/config b/contracts/hub-channels/.cargo/config similarity index 100% rename from contracts/cw-cyb-channels/.cargo/config rename to contracts/hub-channels/.cargo/config diff --git a/contracts/cw-cyb-tokens/Cargo.toml b/contracts/hub-channels/Cargo.toml similarity index 98% rename from contracts/cw-cyb-tokens/Cargo.toml rename to contracts/hub-channels/Cargo.toml index 4081acc..061c6e5 100644 --- a/contracts/cw-cyb-tokens/Cargo.toml +++ b/contracts/hub-channels/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-cyb-tokens" +name = "hub-channels" version = "0.1.0" authors = ["Bloqhub"] edition = "2018" diff --git a/contracts/cw-cyb-channels/examples/schema.rs b/contracts/hub-channels/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-channels/examples/schema.rs rename to contracts/hub-channels/examples/schema.rs diff --git a/contracts/cw-cyb-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs similarity index 100% rename from contracts/cw-cyb-channels/src/contract.rs rename to contracts/hub-channels/src/contract.rs diff --git a/contracts/cw-cyb-channels/src/error.rs b/contracts/hub-channels/src/error.rs similarity index 100% rename from contracts/cw-cyb-channels/src/error.rs rename to contracts/hub-channels/src/error.rs diff --git a/contracts/cw-cyb-channels/src/lib.rs b/contracts/hub-channels/src/lib.rs similarity index 100% rename from contracts/cw-cyb-channels/src/lib.rs rename to contracts/hub-channels/src/lib.rs diff --git a/contracts/cw-cyb-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs similarity index 100% rename from contracts/cw-cyb-channels/src/msg.rs rename to contracts/hub-channels/src/msg.rs diff --git a/contracts/cw-cyb-channels/src/query.rs b/contracts/hub-channels/src/query.rs similarity index 100% rename from contracts/cw-cyb-channels/src/query.rs rename to contracts/hub-channels/src/query.rs diff --git a/contracts/cw-cyb-channels/src/state.rs b/contracts/hub-channels/src/state.rs similarity index 100% rename from contracts/cw-cyb-channels/src/state.rs rename to contracts/hub-channels/src/state.rs diff --git a/contracts/cw-cyb-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs similarity index 100% rename from contracts/cw-cyb-channels/src/tests.rs rename to contracts/hub-channels/src/tests.rs diff --git a/contracts/cw-cyb-channels/src/validating.rs b/contracts/hub-channels/src/validating.rs similarity index 100% rename from contracts/cw-cyb-channels/src/validating.rs rename to contracts/hub-channels/src/validating.rs diff --git a/contracts/cw-cyb-contract/.cargo/config b/contracts/hub-contracts/.cargo/config similarity index 100% rename from contracts/cw-cyb-contract/.cargo/config rename to contracts/hub-contracts/.cargo/config diff --git a/contracts/cw-cyb-network/Cargo.toml b/contracts/hub-contracts/Cargo.toml similarity index 98% rename from contracts/cw-cyb-network/Cargo.toml rename to contracts/hub-contracts/Cargo.toml index 4cc3a14..88caf23 100644 --- a/contracts/cw-cyb-network/Cargo.toml +++ b/contracts/hub-contracts/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-cyb-network" +name = "hub-contracts" version = "0.1.0" authors = ["Bloqhub"] edition = "2018" diff --git a/contracts/cw-cyb-contract/examples/schema.rs b/contracts/hub-contracts/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-contract/examples/schema.rs rename to contracts/hub-contracts/examples/schema.rs diff --git a/contracts/cw-cyb-contract/src/contract.rs b/contracts/hub-contracts/src/contract.rs similarity index 100% rename from contracts/cw-cyb-contract/src/contract.rs rename to contracts/hub-contracts/src/contract.rs diff --git a/contracts/cw-cyb-contract/src/error.rs b/contracts/hub-contracts/src/error.rs similarity index 100% rename from contracts/cw-cyb-contract/src/error.rs rename to contracts/hub-contracts/src/error.rs diff --git a/contracts/cw-cyb-contract/src/lib.rs b/contracts/hub-contracts/src/lib.rs similarity index 100% rename from contracts/cw-cyb-contract/src/lib.rs rename to contracts/hub-contracts/src/lib.rs diff --git a/contracts/cw-cyb-contract/src/msg.rs b/contracts/hub-contracts/src/msg.rs similarity index 100% rename from contracts/cw-cyb-contract/src/msg.rs rename to contracts/hub-contracts/src/msg.rs diff --git a/contracts/cw-cyb-contract/src/query.rs b/contracts/hub-contracts/src/query.rs similarity index 100% rename from contracts/cw-cyb-contract/src/query.rs rename to contracts/hub-contracts/src/query.rs diff --git a/contracts/cw-cyb-contract/src/state.rs b/contracts/hub-contracts/src/state.rs similarity index 100% rename from contracts/cw-cyb-contract/src/state.rs rename to contracts/hub-contracts/src/state.rs diff --git a/contracts/cw-cyb-contract/src/tests.rs b/contracts/hub-contracts/src/tests.rs similarity index 100% rename from contracts/cw-cyb-contract/src/tests.rs rename to contracts/hub-contracts/src/tests.rs diff --git a/contracts/cw-cyb-contract/src/validating.rs b/contracts/hub-contracts/src/validating.rs similarity index 100% rename from contracts/cw-cyb-contract/src/validating.rs rename to contracts/hub-contracts/src/validating.rs diff --git a/contracts/cw-cyb-network/.cargo/config b/contracts/hub-networks/.cargo/config similarity index 100% rename from contracts/cw-cyb-network/.cargo/config rename to contracts/hub-networks/.cargo/config diff --git a/contracts/cw-cyb-channels/Cargo.toml b/contracts/hub-networks/Cargo.toml similarity index 98% rename from contracts/cw-cyb-channels/Cargo.toml rename to contracts/hub-networks/Cargo.toml index 2fc974d..10f8905 100644 --- a/contracts/cw-cyb-channels/Cargo.toml +++ b/contracts/hub-networks/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-cyb-channels" +name = "hub-networks" version = "0.1.0" authors = ["Bloqhub"] edition = "2018" diff --git a/contracts/cw-cyb-network/examples/schema.rs b/contracts/hub-networks/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-network/examples/schema.rs rename to contracts/hub-networks/examples/schema.rs diff --git a/contracts/cw-cyb-network/src/contract.rs b/contracts/hub-networks/src/contract.rs similarity index 100% rename from contracts/cw-cyb-network/src/contract.rs rename to contracts/hub-networks/src/contract.rs diff --git a/contracts/cw-cyb-network/src/error.rs b/contracts/hub-networks/src/error.rs similarity index 100% rename from contracts/cw-cyb-network/src/error.rs rename to contracts/hub-networks/src/error.rs diff --git a/contracts/cw-cyb-network/src/lib.rs b/contracts/hub-networks/src/lib.rs similarity index 100% rename from contracts/cw-cyb-network/src/lib.rs rename to contracts/hub-networks/src/lib.rs diff --git a/contracts/cw-cyb-network/src/msg.rs b/contracts/hub-networks/src/msg.rs similarity index 100% rename from contracts/cw-cyb-network/src/msg.rs rename to contracts/hub-networks/src/msg.rs diff --git a/contracts/cw-cyb-network/src/query.rs b/contracts/hub-networks/src/query.rs similarity index 100% rename from contracts/cw-cyb-network/src/query.rs rename to contracts/hub-networks/src/query.rs diff --git a/contracts/cw-cyb-network/src/state.rs b/contracts/hub-networks/src/state.rs similarity index 100% rename from contracts/cw-cyb-network/src/state.rs rename to contracts/hub-networks/src/state.rs diff --git a/contracts/cw-cyb-network/src/tests.rs b/contracts/hub-networks/src/tests.rs similarity index 100% rename from contracts/cw-cyb-network/src/tests.rs rename to contracts/hub-networks/src/tests.rs diff --git a/contracts/cw-cyb-network/src/validating.rs b/contracts/hub-networks/src/validating.rs similarity index 100% rename from contracts/cw-cyb-network/src/validating.rs rename to contracts/hub-networks/src/validating.rs diff --git a/contracts/cw-cyb-protocols/.cargo/config b/contracts/hub-protocols/.cargo/config similarity index 100% rename from contracts/cw-cyb-protocols/.cargo/config rename to contracts/hub-protocols/.cargo/config diff --git a/contracts/cw-cyb-contract/Cargo.toml b/contracts/hub-protocols/Cargo.toml similarity index 98% rename from contracts/cw-cyb-contract/Cargo.toml rename to contracts/hub-protocols/Cargo.toml index 260a655..fb31c94 100644 --- a/contracts/cw-cyb-contract/Cargo.toml +++ b/contracts/hub-protocols/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-cyb-contract" +name = "hub-protocols" version = "0.1.0" authors = ["Bloqhub"] edition = "2018" diff --git a/contracts/cw-cyb-protocols/examples/schema.rs b/contracts/hub-protocols/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-protocols/examples/schema.rs rename to contracts/hub-protocols/examples/schema.rs diff --git a/contracts/cw-cyb-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/contract.rs rename to contracts/hub-protocols/src/contract.rs diff --git a/contracts/cw-cyb-protocols/src/error.rs b/contracts/hub-protocols/src/error.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/error.rs rename to contracts/hub-protocols/src/error.rs diff --git a/contracts/cw-cyb-protocols/src/lib.rs b/contracts/hub-protocols/src/lib.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/lib.rs rename to contracts/hub-protocols/src/lib.rs diff --git a/contracts/cw-cyb-protocols/src/msg.rs b/contracts/hub-protocols/src/msg.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/msg.rs rename to contracts/hub-protocols/src/msg.rs diff --git a/contracts/cw-cyb-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/query.rs rename to contracts/hub-protocols/src/query.rs diff --git a/contracts/cw-cyb-protocols/src/state.rs b/contracts/hub-protocols/src/state.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/state.rs rename to contracts/hub-protocols/src/state.rs diff --git a/contracts/cw-cyb-protocols/src/tests.rs b/contracts/hub-protocols/src/tests.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/tests.rs rename to contracts/hub-protocols/src/tests.rs diff --git a/contracts/cw-cyb-protocols/src/validating.rs b/contracts/hub-protocols/src/validating.rs similarity index 100% rename from contracts/cw-cyb-protocols/src/validating.rs rename to contracts/hub-protocols/src/validating.rs diff --git a/contracts/cw-cyb-skills/.cargo/config b/contracts/hub-skills/.cargo/config similarity index 100% rename from contracts/cw-cyb-skills/.cargo/config rename to contracts/hub-skills/.cargo/config diff --git a/contracts/cw-cyb-skills/Cargo.lock b/contracts/hub-skills/Cargo.lock similarity index 100% rename from contracts/cw-cyb-skills/Cargo.lock rename to contracts/hub-skills/Cargo.lock diff --git a/contracts/cw-cyb-skills/Cargo.toml b/contracts/hub-skills/Cargo.toml similarity index 98% rename from contracts/cw-cyb-skills/Cargo.toml rename to contracts/hub-skills/Cargo.toml index 9f28037..7eb5120 100644 --- a/contracts/cw-cyb-skills/Cargo.toml +++ b/contracts/hub-skills/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-cyb-skills" +name = "hub-skills" version = "0.1.0" authors = ["Bloqhub"] edition = "2018" diff --git a/contracts/cw-cyb-skills/examples/schema.rs b/contracts/hub-skills/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-skills/examples/schema.rs rename to contracts/hub-skills/examples/schema.rs diff --git a/contracts/cw-cyb-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs similarity index 100% rename from contracts/cw-cyb-skills/src/contract.rs rename to contracts/hub-skills/src/contract.rs diff --git a/contracts/cw-cyb-skills/src/error.rs b/contracts/hub-skills/src/error.rs similarity index 100% rename from contracts/cw-cyb-skills/src/error.rs rename to contracts/hub-skills/src/error.rs diff --git a/contracts/cw-cyb-skills/src/lib.rs b/contracts/hub-skills/src/lib.rs similarity index 100% rename from contracts/cw-cyb-skills/src/lib.rs rename to contracts/hub-skills/src/lib.rs diff --git a/contracts/cw-cyb-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs similarity index 100% rename from contracts/cw-cyb-skills/src/msg.rs rename to contracts/hub-skills/src/msg.rs diff --git a/contracts/cw-cyb-skills/src/query.rs b/contracts/hub-skills/src/query.rs similarity index 100% rename from contracts/cw-cyb-skills/src/query.rs rename to contracts/hub-skills/src/query.rs diff --git a/contracts/cw-cyb-skills/src/state.rs b/contracts/hub-skills/src/state.rs similarity index 100% rename from contracts/cw-cyb-skills/src/state.rs rename to contracts/hub-skills/src/state.rs diff --git a/contracts/cw-cyb-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs similarity index 100% rename from contracts/cw-cyb-skills/src/tests.rs rename to contracts/hub-skills/src/tests.rs diff --git a/contracts/cw-cyb-skills/src/validating.rs b/contracts/hub-skills/src/validating.rs similarity index 100% rename from contracts/cw-cyb-skills/src/validating.rs rename to contracts/hub-skills/src/validating.rs diff --git a/contracts/cw-cyb-tokens/.cargo/config b/contracts/hub-tokens/.cargo/config similarity index 100% rename from contracts/cw-cyb-tokens/.cargo/config rename to contracts/hub-tokens/.cargo/config diff --git a/contracts/cw-cyb-tokens/Cargo.lock b/contracts/hub-tokens/Cargo.lock similarity index 100% rename from contracts/cw-cyb-tokens/Cargo.lock rename to contracts/hub-tokens/Cargo.lock diff --git a/contracts/hub-tokens/Cargo.toml b/contracts/hub-tokens/Cargo.toml new file mode 100644 index 0000000..740277f --- /dev/null +++ b/contracts/hub-tokens/Cargo.toml @@ -0,0 +1,53 @@ +[package] +name = "hub-tokens" +version = "0.1.0" +authors = ["Bloqhub"] +edition = "2018" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# 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] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[package.metadata.scripts] +optimize = """docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.12.6 +""" + +[dependencies] +cosmwasm-std = { version = "1.0.0", features = ["iterator", "abort"] } +cw-storage-plus = { version = "0.13.4" } +cw2 = { version = "0.13.4" } +schemars = "0.8.10" +serde = { version = "1.0.140", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.31" } +cid = { version = "0.8.0" } + +[dev-dependencies] +cosmwasm-schema = "1.0.0" +cw-multi-test = "0.13.2" diff --git a/contracts/cw-cyb-tokens/examples/schema.rs b/contracts/hub-tokens/examples/schema.rs similarity index 100% rename from contracts/cw-cyb-tokens/examples/schema.rs rename to contracts/hub-tokens/examples/schema.rs diff --git a/contracts/cw-cyb-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/contract.rs rename to contracts/hub-tokens/src/contract.rs diff --git a/contracts/cw-cyb-tokens/src/error.rs b/contracts/hub-tokens/src/error.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/error.rs rename to contracts/hub-tokens/src/error.rs diff --git a/contracts/cw-cyb-tokens/src/lib.rs b/contracts/hub-tokens/src/lib.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/lib.rs rename to contracts/hub-tokens/src/lib.rs diff --git a/contracts/cw-cyb-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/msg.rs rename to contracts/hub-tokens/src/msg.rs diff --git a/contracts/cw-cyb-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/query.rs rename to contracts/hub-tokens/src/query.rs diff --git a/contracts/cw-cyb-tokens/src/state.rs b/contracts/hub-tokens/src/state.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/state.rs rename to contracts/hub-tokens/src/state.rs diff --git a/contracts/cw-cyb-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/tests.rs rename to contracts/hub-tokens/src/tests.rs diff --git a/contracts/cw-cyb-tokens/src/validating.rs b/contracts/hub-tokens/src/validating.rs similarity index 100% rename from contracts/cw-cyb-tokens/src/validating.rs rename to contracts/hub-tokens/src/validating.rs From f93f3a3216782a35f6c7d91b30f5f85c1d026c3f Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 12:39:14 +0800 Subject: [PATCH 02/33] Refactoring of versions and networks contracts --- contracts/hub-channels/src/contract.rs | 4 +- contracts/hub-contracts/src/contract.rs | 4 +- contracts/hub-networks/src/contract.rs | 16 ++-- contracts/hub-networks/src/msg.rs | 11 +-- contracts/hub-networks/src/query.rs | 102 +++++++---------------- contracts/hub-networks/src/state.rs | 3 +- contracts/hub-networks/src/tests.rs | 20 ++++- contracts/hub-networks/src/validating.rs | 18 ++++ contracts/hub-protocols/src/contract.rs | 4 +- contracts/hub-skills/src/contract.rs | 2 +- contracts/hub-tokens/src/contract.rs | 4 +- 11 files changed, 91 insertions(+), 97 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index c0e78a5..d1bd8d4 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -13,8 +13,8 @@ use crate::query::{query_list, execute_create_new_item, execute_update_item, exe use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract -const CONTRACT_NAME: &str = "cw-channels"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_NAME: &str = "hub-channels"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 4d598b8..61ae2d1 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -13,8 +13,8 @@ use crate::query::{query_list, execute_create_new_item, execute_update_item, exe use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract -const CONTRACT_NAME: &str = "cw-contract"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_NAME: &str = "hub-contracts"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index c78c1dd..ac02ec9 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -8,13 +8,13 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract -const CONTRACT_NAME: &str = "cw-network"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_NAME: &str = "hub-networks"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -53,22 +53,24 @@ pub fn execute( ExecuteMsg::NewEntry { name, chain_id, + prefix, genesis_hash, protocol, - // unbonding_period, + unbonding_period, logo, particle, - } => execute_create_new_item(deps, info,name,chain_id,genesis_hash, protocol, logo, particle), + } => execute_create_item(deps, info, name, chain_id, prefix, genesis_hash, protocol, unbonding_period, logo, particle), ExecuteMsg::UpdateEntry { id, name, chain_id, + prefix, genesis_hash, protocol, - // unbonding_period, + unbonding_period, logo, particle, - } => execute_update_item(deps, info, id, name,chain_id,genesis_hash,protocol,logo,particle), + } => execute_update_item(deps, info, id, name,chain_id,prefix,genesis_hash,protocol,unbonding_period, logo,particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-networks/src/msg.rs b/contracts/hub-networks/src/msg.rs index 2e8d842..43d1f06 100644 --- a/contracts/hub-networks/src/msg.rs +++ b/contracts/hub-networks/src/msg.rs @@ -1,5 +1,4 @@ use crate::state::{Entry}; -// use cosmwasm_std::{Uint64}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -13,9 +12,10 @@ pub enum ExecuteMsg { NewEntry { name: String, chain_id: String, + prefix: String, genesis_hash: String, protocol: String, - // unbonding_period: String, + unbonding_period: String, logo: String, particle: Option, }, @@ -23,9 +23,10 @@ pub enum ExecuteMsg { id: u64, name: Option, chain_id: Option, + prefix: Option, genesis_hash: Option, protocol: Option, - // unbonding_period: Option, + unbonding_period: Option, logo: Option, particle: Option, }, @@ -43,15 +44,15 @@ pub enum QueryMsg { }, } - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, pub name: String, pub chain_id: String, + pub prefix: String, pub genesis_hash: String, pub protocol: String, - // pub unbonding_period: String, + pub unbonding_period: String, pub logo: String, pub particle: String, } diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index c57ea02..6b418bc 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use cosmwasm_std::{ Deps, DepsMut, MessageInfo, Order, Response, StdResult, }; -use crate::validating::{validate_by_basic_rule,validate_ipfs_cid}; +use crate::validating::{validate_by_basic_rule, validate_period, validate_ipfs_cid}; use cw_storage_plus::Bound; use std::ops::Add; @@ -18,14 +18,15 @@ const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, name: String, chain_id: String, + prefix: String, genesis_hash: String, protocol: String, - // unbonding_period: String, + unbonding_period: String, logo: String, particle: Option, ) -> Result { @@ -45,20 +46,19 @@ pub fn execute_create_new_item( return validate_particle; } } - - + let validate_chainid = validate_by_basic_rule(chain_id.clone(), "chain-id".to_string()); + let validate_prefix = validate_by_basic_rule(prefix.clone(), "prefix".to_string()); let validate_genesishash = validate_by_basic_rule(genesis_hash.clone(), "genesis_hash".to_string()); let validate_name = validate_by_basic_rule(name.clone(), "name".to_string()); let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); - - + let validate_unbonding_period = validate_period(unbonding_period.clone(), "protocol".to_string()); if validate_chainid.is_err() { return validate_chainid; } - if validate_chainid.is_err() { - return validate_chainid; + if validate_prefix.is_err() { + return validate_prefix; } if validate_genesishash.is_err() { return validate_genesishash; @@ -69,24 +69,26 @@ pub fn execute_create_new_item( if validate_protocol.is_err() { return validate_protocol; } - - + if validate_unbonding_period.is_err() { + return validate_protocol; + } let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - //FIXME + let new_entry = Entry { id, name, chain_id, + prefix, genesis_hash, protocol, - // unbonding_period, + unbonding_period, logo, particle: particle.unwrap_or("".to_string()), }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } @@ -96,9 +98,10 @@ pub fn execute_update_item( id: u64, name: Option, chain_id: Option, + prefix: Option, genesis_hash: Option, protocol: Option, - // unbonding_period: Option, + unbonding_period: Option, logo: Option, particle: Option, ) -> Result { @@ -118,14 +121,13 @@ pub fn execute_update_item( return validate_particle; } } - - + let validate_chainid = validate_by_basic_rule(chain_id.as_ref().unwrap().clone(), "chain-id".to_string()); + let validate_prefix = validate_by_basic_rule(prefix.as_ref().unwrap().clone(), "prefix".to_string()); let validate_genesishash = validate_by_basic_rule(genesis_hash.as_ref().unwrap().clone(), "genesis_hash".to_string()); let validate_name = validate_by_basic_rule(name.as_ref().unwrap().clone(), "name".to_string()); let validate_protocol = validate_by_basic_rule(protocol.as_ref().unwrap().clone(), "protocol".to_string()); - - + let validate_unbonding_period = validate_period(unbonding_period.as_ref().unwrap().clone(), "protocol".to_string()); if validate_chainid.is_err() { return validate_chainid; @@ -133,6 +135,9 @@ pub fn execute_update_item( if validate_chainid.is_err() { return validate_chainid; } + if validate_prefix.is_err() { + return validate_prefix; + } if validate_genesishash.is_err() { return validate_genesishash; } @@ -142,65 +147,19 @@ pub fn execute_update_item( if validate_protocol.is_err() { return validate_protocol; } - - //////// - - // if !logo.as_ref().is_none() { - // let particle:Cid; - // let try_particle = Cid::from_str(&logo.as_ref().unwrap().clone()); - // if try_particle.is_ok() { - // particle = try_particle.unwrap(); - // if particle.version() != Version::V0 { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Logo".to_string()}); - // } - // } else { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Logo".to_string()}); - // } - // } - - // for byte in chain_id.as_ref().unwrap().as_bytes().iter() { - // // - && 0-9 && a-z - // if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Chain-id. a-z0-9- allowed".to_string()}); - // } - // } - - // for byte in genesis_hash.as_ref().unwrap().as_bytes().iter() { - // // - && 0-9 && a-z - // if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Genesis_hash. a-z0-9- allowed".to_string()}); - // } - // } - - // for byte in name.as_ref().unwrap().as_bytes().iter() { - // // - && 0-9 && a-z - // if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Name. a-z0-9- allowed".to_string()}); - // } - // } - - // for byte in unbonding_period.as_ref().unwrap().as_bytes().iter() { - // // 0-9 - // if *byte < 48 || *byte > 57 { - // return Err(ContractError::IncorrectInputData {val: "Incorrect Unbonding_period. 0-9 allowed".to_string()}); - // } - // } - - // for byte in particle.as_ref().unwrap().as_bytes().iter() { - // // :/.-_0-9a-zA-Z - // if (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { - // return Err(ContractError::IncorrectInputData {val: "Incorrect particle. Only url allowed".to_string()}); - // } - // } + if validate_unbonding_period.is_err() { + return validate_protocol; + } let entry = LIST.load(deps.storage, id)?; let updated_entry = Entry { id, name: name.unwrap_or(entry.name), chain_id: chain_id.unwrap_or(entry.chain_id), + prefix: prefix.unwrap_or(entry.prefix), genesis_hash: genesis_hash.unwrap_or(entry.genesis_hash), protocol: protocol.unwrap_or(entry.protocol), - // unbonding_period: unbonding_period.unwrap_or(entry.unbonding_period), + unbonding_period: unbonding_period.unwrap_or(entry.unbonding_period), logo: logo.unwrap_or(entry.logo), particle: particle.unwrap_or(entry.particle), }; @@ -226,9 +185,6 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } - - - pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-networks/src/state.rs b/contracts/hub-networks/src/state.rs index dea84c5..544b6b5 100644 --- a/contracts/hub-networks/src/state.rs +++ b/contracts/hub-networks/src/state.rs @@ -15,8 +15,9 @@ pub struct Entry { pub id: u64, pub name: String, pub chain_id: String, + pub prefix: String, pub genesis_hash: String, - + pub unbonding_period: String, pub protocol: String, pub logo: String, pub particle: String, diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index 069c60b..b33edbd 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -63,7 +63,9 @@ mod tests { name: "tst".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -72,7 +74,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); @@ -81,7 +83,9 @@ mod tests { name: "tst2".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -90,7 +94,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); @@ -113,7 +117,9 @@ mod tests { name: "tst".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, @@ -122,7 +128,9 @@ mod tests { name: "tst2".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } @@ -136,7 +144,9 @@ mod tests { name: Some("tstu".to_string()), protocol: Some("tst2".to_string()), chain_id: Some("cyber-1".to_string()), + prefix: Some("cyb".to_string()), genesis_hash: Some("bostrom0x1".to_string()), + unbonding_period: Some("42".to_string()), logo: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -170,7 +180,9 @@ mod tests { name: "tstu".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, @@ -179,7 +191,9 @@ mod tests { name: "tst2".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } @@ -215,7 +229,9 @@ mod tests { name: "tst2".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), + prefix: "cyb".to_string(), genesis_hash: "bostrom0x1".to_string(), + unbonding_period: "42".to_string(), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }]), diff --git a/contracts/hub-networks/src/validating.rs b/contracts/hub-networks/src/validating.rs index 6fb8473..5ff295b 100644 --- a/contracts/hub-networks/src/validating.rs +++ b/contracts/hub-networks/src/validating.rs @@ -23,6 +23,24 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } +/** + * Baseic rule /[0-9]/ + */ +pub fn validate_period( + val: String, + field_name: String, +) -> Result { + + for byte in val.as_bytes().iter() { + // 0-9 + if *byte < 48 || *byte > 57 { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field field {}. Allowed expression /[0-9]/", field_name).to_string()}); + } + } + + Ok(Response::default()) +} + pub fn validate_datatype( val: String ) -> Result { diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 4f6ce51..8530dd5 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -13,8 +13,8 @@ use crate::query::{query_list, execute_create_new_item, execute_update_item, exe use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract -const CONTRACT_NAME: &str = "cw-protocols"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_NAME: &str = "hub-protocols"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index c8e7686..b71e03c 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -14,7 +14,7 @@ use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract const CONTRACT_NAME: &str = "cw-skills"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index fffc4ec..ccb2823 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -13,8 +13,8 @@ use crate::query::{query_list, execute_create_new_item, execute_update_item, exe use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract -const CONTRACT_NAME: &str = "cw-tokens"; -const CONTRACT_VERSION: &str = "1.0.0"; +const CONTRACT_NAME: &str = "hub-tokens"; +const CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( From f04154873e1746b23d360e2233b9a2223739302b Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 13:09:30 +0800 Subject: [PATCH 03/33] Refactoring of tokens and channels contracts --- contracts/hub-channels/src/contract.rs | 8 ++---- contracts/hub-channels/src/msg.rs | 3 --- contracts/hub-channels/src/query.rs | 22 ++--------------- contracts/hub-channels/src/state.rs | 1 - contracts/hub-channels/src/tests.rs | 17 ++----------- contracts/hub-networks/src/contract.rs | 2 -- contracts/hub-networks/src/query.rs | 3 --- contracts/hub-networks/src/state.rs | 1 - contracts/hub-networks/src/tests.rs | 3 --- contracts/hub-tokens/src/contract.rs | 6 +++-- contracts/hub-tokens/src/msg.rs | 9 ++++--- contracts/hub-tokens/src/query.rs | 34 ++++++++++---------------- contracts/hub-tokens/src/state.rs | 4 +-- contracts/hub-tokens/src/tests.rs | 31 +++++++++++++---------- 14 files changed, 49 insertions(+), 95 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index d1bd8d4..0dd0c6f 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -56,10 +56,9 @@ pub fn execute( source_channel_id, destination_channel_id, explorer_url, - token, particle - } => execute_create_new_item(deps, info, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, token, particle), + } => execute_create_new_item(deps, info, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::UpdateEntry { id, source_chain_id, @@ -67,15 +66,12 @@ pub fn execute( source_channel_id, destination_channel_id, explorer_url, - token, particle, - } => execute_update_item(deps, info, id, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, token, particle), + } => execute_update_item(deps, info, id, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index 4abd4a9..3711d25 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -16,7 +16,6 @@ pub enum ExecuteMsg { source_channel_id: String, destination_channel_id: String, explorer_url: String, - token: String, particle: Option, }, UpdateEntry { @@ -26,7 +25,6 @@ pub enum ExecuteMsg { source_channel_id: Option, destination_channel_id: Option, explorer_url: Option, - token: Option, particle: Option, }, DeleteEntry { @@ -52,7 +50,6 @@ pub struct EntryResponse { pub source_channel_id: String, pub destination_channel_id: String, pub explorer_url: String, - pub token: String, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index b2bd432..5608c0a 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -9,7 +9,7 @@ use cw_storage_plus::Bound; use std::ops::Add; -use crate::validating::{validate_by_basic_rule,validate_ipfs_cid,validate_url,validate_by_basic_uppercase_rule}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; use crate::error::ContractError; use crate::msg::{ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; @@ -26,7 +26,6 @@ pub fn execute_create_new_item( source_channel_id: String, destination_channel_id: String, explorer_url: String, - token: String, particle: Option ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; @@ -40,15 +39,12 @@ pub fn execute_create_new_item( return validate_particle; } } - let validate_source_chain_id = validate_by_basic_rule(source_chain_id.clone(), "source_chain_id".to_string()); let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone(), "destination_chain_id".to_string()); let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone(), "source_channel_id".to_string()); let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone(), "destination_channel_id".to_string()); - let validate_explorer_url = validate_url(explorer_url.clone(), "explorer_url".to_string()); - let validate_token = validate_by_basic_uppercase_rule(token.clone(), "token".to_string()); if validate_source_chain_id.is_err() { return validate_source_chain_id; @@ -65,11 +61,6 @@ pub fn execute_create_new_item( if validate_explorer_url.is_err() { return validate_explorer_url; } - if validate_token.is_err() { - return validate_token; - } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; @@ -80,12 +71,11 @@ pub fn execute_create_new_item( source_channel_id, destination_channel_id, explorer_url, - token, particle: particle.unwrap_or("".to_string()), }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } @@ -98,7 +88,6 @@ pub fn execute_update_item( source_channel_id: Option, destination_channel_id: Option, explorer_url: Option, - token: Option, particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; @@ -117,9 +106,7 @@ pub fn execute_update_item( let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone().unwrap(), "destination_chain_id".to_string()); let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone().unwrap(), "source_channel_id".to_string()); let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone().unwrap(), "destination_channel_id".to_string()); - let validate_explorer_url = validate_url(explorer_url.clone().unwrap(), "explorer_url".to_string()); - let validate_token = validate_by_basic_uppercase_rule(token.clone().unwrap(), "token".to_string()); if validate_source_chain_id.is_err() { return validate_source_chain_id; @@ -136,10 +123,6 @@ pub fn execute_update_item( if validate_explorer_url.is_err() { return validate_explorer_url; } - if validate_token.is_err() { - return validate_token; - } - let entry = LIST.load(deps.storage, id)?; let updated_entry = Entry { @@ -149,7 +132,6 @@ pub fn execute_update_item( source_channel_id: source_channel_id.unwrap_or(entry.source_channel_id), destination_channel_id: destination_channel_id.unwrap_or(entry.destination_channel_id), explorer_url: explorer_url.unwrap_or(entry.explorer_url), - token: token.unwrap_or(entry.token), particle: particle.unwrap_or("".to_string()), }; LIST.save(deps.storage, id, &updated_entry)?; diff --git a/contracts/hub-channels/src/state.rs b/contracts/hub-channels/src/state.rs index d179b97..07580ba 100644 --- a/contracts/hub-channels/src/state.rs +++ b/contracts/hub-channels/src/state.rs @@ -18,7 +18,6 @@ pub struct Entry { pub source_channel_id: String, pub destination_channel_id: String, pub explorer_url: String, - pub token: String, pub particle: String, } diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index 0451c84..ae0b7bd 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -2,14 +2,11 @@ #[cfg(test)] mod tests { - // use super::*; - // use cosmwasm_std::{Uint64}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{attr, from_binary, Addr}; use std::vec::Vec; use crate::state::{Entry, CONFIG, Config}; use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; - // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::contract::{query, execute, instantiate}; #[test] @@ -65,7 +62,6 @@ mod tests { source_channel_id: "channel-256".to_string(), destination_channel_id: "channel-1".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -73,7 +69,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); @@ -84,7 +80,6 @@ mod tests { source_channel_id: "channel-2".to_string(), destination_channel_id: "channel-2".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -92,7 +87,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); @@ -117,7 +112,6 @@ mod tests { source_channel_id: "channel-256".to_string(), destination_channel_id: "channel-1".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, Entry { @@ -127,7 +121,6 @@ mod tests { source_channel_id: "channel-2".to_string(), destination_channel_id: "channel-2".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } ]), @@ -142,7 +135,6 @@ mod tests { source_channel_id: Some("channel-256".to_string()), destination_channel_id: Some("channel-1".to_string()), explorer_url: Some("https://explorer.com/{hash}".to_string()), - token: Some("DEM2".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -155,8 +147,6 @@ mod tests { ] ); - - // Query the list of entries let res = query( deps.as_ref(), @@ -177,7 +167,6 @@ mod tests { source_channel_id: "channel-256".to_string(), destination_channel_id: "channel-1".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, Entry { @@ -187,7 +176,6 @@ mod tests { source_channel_id: "channel-2".to_string(), destination_channel_id: "channel-2".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } ]), @@ -224,7 +212,6 @@ mod tests { source_channel_id: "channel-2".to_string(), destination_channel_id: "channel-2".to_string(), explorer_url: "https://explorer.com/{hash}".to_string(), - token: "DEM2".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }]), list.entries diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index ac02ec9..062a7e8 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -75,8 +75,6 @@ pub fn execute( } } - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index 6b418bc..24437e9 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -1,6 +1,3 @@ -use cid::{Cid, Version}; -use std::str::FromStr; - use cosmwasm_std::{ Deps, DepsMut, MessageInfo, Order, Response, StdResult, }; diff --git a/contracts/hub-networks/src/state.rs b/contracts/hub-networks/src/state.rs index 544b6b5..5a964da 100644 --- a/contracts/hub-networks/src/state.rs +++ b/contracts/hub-networks/src/state.rs @@ -24,7 +24,6 @@ pub struct Entry { } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index b33edbd..03bc901 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -2,14 +2,11 @@ #[cfg(test)] mod tests { - // use super::*; - // use cosmwasm_std::{Uint64}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{attr, from_binary, Addr}; use std::vec::Vec; use crate::state::{Entry, CONFIG, Config}; use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; - // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::contract::{query, execute, instantiate}; #[test] diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index ccb2823..4e1817d 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -54,17 +54,19 @@ pub fn execute( ticker, chain_id, denom, + channel, logo, particle, - } => execute_create_new_item(deps, info, ticker, chain_id, denom, logo, particle), + } => execute_create_new_item(deps, info, ticker, chain_id, denom, channel, logo,particle), ExecuteMsg::UpdateEntry { id, ticker, chain_id, denom, + channel, logo, particle, - } => execute_update_item(deps, info, id, ticker, chain_id, denom, logo, particle), + } => execute_update_item(deps, info, id, ticker, chain_id, denom, channel, logo, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index 30b42cd..c3c421b 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -13,7 +13,8 @@ pub enum ExecuteMsg { NewEntry { ticker: String, chain_id: String, - denom: Uint64, + denom: String, + channel: Uint64, logo: String, particle: Option, }, @@ -21,7 +22,8 @@ pub enum ExecuteMsg { id: u64, ticker: Option, chain_id: Option, - denom: Option, + denom: Option, + channel: Option, logo: Option, particle: Option, }, @@ -45,7 +47,8 @@ pub struct EntryResponse { pub id: u64, pub ticker: String, pub chain_id: String, - pub denom: Uint64, + pub denom: String, + pub channel: Uint64, pub logo: String, pub particle: String, } diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index 5355eee..02f9955 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -1,7 +1,4 @@ use cosmwasm_std::{Uint64}; -// use cid::{Cid, Version}; -// use std::str::FromStr; -// use cid::multihash::{Code, MultihashDigest}; use cosmwasm_std::{ Deps, DepsMut, MessageInfo, Order, Response, StdResult, }; @@ -9,7 +6,7 @@ use cosmwasm_std::{ use cw_storage_plus::Bound; use std::ops::Add; -use crate::validating::{validate_by_basic_rule,validate_by_basic_uppercase_rule,validate_ipfs_cid,validate_by_int_range}; +use crate::validating::{validate_by_basic_rule, validate_by_basic_uppercase_rule, validate_ipfs_cid}; use crate::error::ContractError; use crate::msg::{ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; @@ -23,7 +20,8 @@ pub fn execute_create_new_item( info: MessageInfo, ticker: String, chain_id: String, - denom: Uint64, + denom: String, + channel: Uint64, logo: String, particle: Option, ) -> Result { @@ -44,10 +42,8 @@ pub fn execute_create_new_item( } } - let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone(), "ticker".to_string()); let validate_chain_id = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); - let validate_denom = validate_by_int_range(Uint64::from(1u64),Uint64::from(18u64), denom.clone(),"denom".to_string()); if validate_ticker.is_err() { return validate_ticker; @@ -55,11 +51,9 @@ pub fn execute_create_new_item( if validate_chain_id.is_err() { return validate_chain_id; } - if validate_denom.is_err() { - return validate_denom; - } - + // TODO add denom validation + // TODO add channel validation let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; @@ -68,12 +62,13 @@ pub fn execute_create_new_item( ticker, chain_id, denom, + channel, logo, particle: particle.unwrap_or("".to_string()) }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } @@ -83,7 +78,8 @@ pub fn execute_update_item( id: u64, ticker: Option, chain_id: Option, - denom: Option, + denom: Option, + channel: Option, logo: Option, particle: Option, ) -> Result { @@ -107,7 +103,9 @@ pub fn execute_update_item( let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone().unwrap(), "ticker".to_string()); let validate_chain_id = validate_by_basic_rule(chain_id.clone().unwrap(), "chain_id".to_string()); - let validate_denom = validate_by_int_range(Uint64::from(1u64),Uint64::from(18u64), denom.clone().unwrap(),"denom".to_string()); + + // TODO add denom validation + // TODO add channel validation if validate_ticker.is_err() { return validate_ticker; @@ -115,9 +113,6 @@ pub fn execute_update_item( if validate_chain_id.is_err() { return validate_chain_id; } - if validate_denom.is_err() { - return validate_denom; - } let entry = LIST.load(deps.storage, id)?; @@ -126,6 +121,7 @@ pub fn execute_update_item( ticker: ticker.unwrap_or(entry.ticker), denom: denom.unwrap_or(entry.denom), chain_id: chain_id.unwrap_or(entry.chain_id), + channel: channel.unwrap_or(entry.channel), logo: logo.unwrap_or(entry.logo), particle: particle.unwrap_or("".to_string()), }; @@ -151,10 +147,6 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } - - - - pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-tokens/src/state.rs b/contracts/hub-tokens/src/state.rs index 128eb67..b23cb7c 100644 --- a/contracts/hub-tokens/src/state.rs +++ b/contracts/hub-tokens/src/state.rs @@ -15,12 +15,12 @@ pub struct Entry { pub id: u64, pub ticker: String, pub chain_id: String, - pub denom: Uint64, + pub denom: String, + pub channel: Uint64, pub logo: String, pub particle: String, } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index 221b5f1..2665fb7 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -2,14 +2,12 @@ #[cfg(test)] mod tests { - // use super::*; use cosmwasm_std::{Uint64}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{attr, from_binary, Addr}; use std::vec::Vec; use crate::state::{Entry, CONFIG, Config}; use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; - // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::contract::{query, execute, instantiate}; #[test] @@ -62,7 +60,8 @@ mod tests { let msg = ExecuteMsg::NewEntry { chain_id: "testchain-1".to_string(), ticker: "TST".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -71,7 +70,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); @@ -79,7 +78,8 @@ mod tests { let msg = ExecuteMsg::NewEntry { ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -88,7 +88,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); @@ -110,7 +110,8 @@ mod tests { id: 1, chain_id: "testchain-1".to_string(), ticker: "TST".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, @@ -118,7 +119,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } @@ -131,8 +133,8 @@ mod tests { id: 1, ticker: Some("TSTUPDATE".to_string()), chain_id: Some("testchain-1".to_string()), - denom: Some(Uint64::new(8)), - // logo: None, + denom: Some("cyb".to_string()), + channel: Some(Uint64::new(1)), logo: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -165,7 +167,8 @@ mod tests { id: 1, ticker: "TSTUPDATE".to_string(), chain_id: "testchain-1".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }, @@ -173,7 +176,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), } @@ -208,7 +212,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: Uint64::new(8), + denom: "cyb".to_string(), + channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), }]), From d103bbbede26b316d6519ffe4f992c57e1ecd439 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 13:48:20 +0800 Subject: [PATCH 04/33] Added change owner --- contracts/hub-channels/src/contract.rs | 5 +++-- contracts/hub-channels/src/msg.rs | 3 +++ contracts/hub-channels/src/query.rs | 28 +++++++++++++++++++++++--- contracts/hub-channels/src/state.rs | 3 +-- contracts/hub-networks/src/contract.rs | 5 +++-- contracts/hub-networks/src/msg.rs | 3 +++ contracts/hub-networks/src/query.rs | 28 +++++++++++++++++++++++--- contracts/hub-networks/src/state.rs | 2 +- contracts/hub-tokens/src/contract.rs | 7 ++++--- contracts/hub-tokens/src/msg.rs | 3 +++ contracts/hub-tokens/src/query.rs | 26 +++++++++++++++++++++++- contracts/hub-tokens/src/state.rs | 2 +- 12 files changed, 97 insertions(+), 18 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 0dd0c6f..e85dcb8 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { source_chain_id, destination_chain_id, diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index 3711d25..c12f6c8 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -10,6 +10,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, NewEntry { source_chain_id: String, destination_chain_id: String, diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index 5608c0a..55280fa 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -1,9 +1,7 @@ // use regex::Regex; // use cosmwasm_std::{Uint64}; -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; +use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; use cw_storage_plus::Bound; use std::ops::Add; @@ -17,6 +15,30 @@ use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} pub fn execute_create_new_item( deps: DepsMut, diff --git a/contracts/hub-channels/src/state.rs b/contracts/hub-channels/src/state.rs index 07580ba..3ef20b8 100644 --- a/contracts/hub-channels/src/state.rs +++ b/contracts/hub-channels/src/state.rs @@ -7,7 +7,7 @@ use cw_storage_plus::{Item, Map}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -21,7 +21,6 @@ pub struct Entry { pub particle: String, } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index 062a7e8..ad0b88d 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { name, chain_id, diff --git a/contracts/hub-networks/src/msg.rs b/contracts/hub-networks/src/msg.rs index 43d1f06..45eb00a 100644 --- a/contracts/hub-networks/src/msg.rs +++ b/contracts/hub-networks/src/msg.rs @@ -9,6 +9,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, NewEntry { name: String, chain_id: String, diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index 24437e9..f51b7f4 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -1,6 +1,4 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; +use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; use crate::validating::{validate_by_basic_rule, validate_period, validate_ipfs_cid}; use cw_storage_plus::Bound; @@ -14,6 +12,30 @@ use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} pub fn execute_create_item( deps: DepsMut, diff --git a/contracts/hub-networks/src/state.rs b/contracts/hub-networks/src/state.rs index 5a964da..f792de8 100644 --- a/contracts/hub-networks/src/state.rs +++ b/contracts/hub-networks/src/state.rs @@ -7,7 +7,7 @@ use cw_storage_plus::{Item, Map}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 4e1817d..e17f554 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { ticker, chain_id, diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index c3c421b..8dd5951 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -10,6 +10,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, NewEntry { ticker: String, chain_id: String, diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index 02f9955..981eb51 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Uint64}; +use cosmwasm_std::{attr, Env, Uint64}; use cosmwasm_std::{ Deps, DepsMut, MessageInfo, Order, Response, StdResult, }; @@ -14,6 +14,30 @@ use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} pub fn execute_create_new_item( deps: DepsMut, diff --git a/contracts/hub-tokens/src/state.rs b/contracts/hub-tokens/src/state.rs index b23cb7c..7869275 100644 --- a/contracts/hub-tokens/src/state.rs +++ b/contracts/hub-tokens/src/state.rs @@ -7,7 +7,7 @@ use cw_storage_plus::{Item, Map}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From 5c9a386af6c2cfb4978abd7a1977a3f5b3f7158b Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 14:24:33 +0800 Subject: [PATCH 05/33] Deleted endpoints --- contracts/cw-cyb-endpoints/.cargo/config | 4 - contracts/cw-cyb-endpoints/Cargo.toml | 53 ----- contracts/cw-cyb-endpoints/examples/schema.rs | 17 -- contracts/cw-cyb-endpoints/src/contract.rs | 81 ------- contracts/cw-cyb-endpoints/src/error.rs | 17 -- contracts/cw-cyb-endpoints/src/lib.rs | 9 - contracts/cw-cyb-endpoints/src/msg.rs | 55 ----- contracts/cw-cyb-endpoints/src/query.rs | 161 ------------- contracts/cw-cyb-endpoints/src/state.rs | 25 -- contracts/cw-cyb-endpoints/src/tests.rs | 218 ------------------ contracts/cw-cyb-endpoints/src/validating.rs | 79 ------- 11 files changed, 719 deletions(-) delete mode 100644 contracts/cw-cyb-endpoints/.cargo/config delete mode 100644 contracts/cw-cyb-endpoints/Cargo.toml delete mode 100644 contracts/cw-cyb-endpoints/examples/schema.rs delete mode 100644 contracts/cw-cyb-endpoints/src/contract.rs delete mode 100644 contracts/cw-cyb-endpoints/src/error.rs delete mode 100644 contracts/cw-cyb-endpoints/src/lib.rs delete mode 100644 contracts/cw-cyb-endpoints/src/msg.rs delete mode 100644 contracts/cw-cyb-endpoints/src/query.rs delete mode 100644 contracts/cw-cyb-endpoints/src/state.rs delete mode 100644 contracts/cw-cyb-endpoints/src/tests.rs delete mode 100644 contracts/cw-cyb-endpoints/src/validating.rs diff --git a/contracts/cw-cyb-endpoints/.cargo/config b/contracts/cw-cyb-endpoints/.cargo/config deleted file mode 100644 index 336b618..0000000 --- a/contracts/cw-cyb-endpoints/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --example schema" diff --git a/contracts/cw-cyb-endpoints/Cargo.toml b/contracts/cw-cyb-endpoints/Cargo.toml deleted file mode 100644 index 148d075..0000000 --- a/contracts/cw-cyb-endpoints/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -name = "cw-cyb-endpoints" -version = "0.1.0" -authors = ["Bloqhub"] -edition = "2018" - -exclude = [ - # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. - "contract.wasm", - "hash.txt", -] - -# 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] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] -# use library feature to disable all instantiate/execute/query exports -library = [] - -[package.metadata.scripts] -optimize = """docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 -""" - -[dependencies] -cosmwasm-std = { version = "1.0.0", features = ["iterator", "abort"] } -cw-storage-plus = { version = "0.13.4" } -cw2 = { version = "0.13.4" } -schemars = "0.8.10" -serde = { version = "1.0.140", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.31" } -cid = { version = "0.8.0" } - -[dev-dependencies] -cosmwasm-schema = "1.0.0" -cw-multi-test = "0.13.2" diff --git a/contracts/cw-cyb-endpoints/examples/schema.rs b/contracts/cw-cyb-endpoints/examples/schema.rs deleted file mode 100644 index 9942cb2..0000000 --- a/contracts/cw-cyb-endpoints/examples/schema.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::env::current_dir; -use std::fs::create_dir_all; - -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; - -use cw_cyb_endpoints::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - export_schema(&schema_for!(InstantiateMsg), &out_dir); - export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); -} diff --git a/contracts/cw-cyb-endpoints/src/contract.rs b/contracts/cw-cyb-endpoints/src/contract.rs deleted file mode 100644 index 1c1b7ff..0000000 --- a/contracts/cw-cyb-endpoints/src/contract.rs +++ /dev/null @@ -1,81 +0,0 @@ -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, -}; -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; - -use cw2::set_contract_version; - -use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; -// Token constructor -use crate::state::{Config, CONFIG, ENTRY_SEQ}; - -//@TODO git version iteract -const CONTRACT_NAME: &str = "cw-endpoints"; -const CONTRACT_VERSION: &str = "1.0.0"; - -#[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)?; - - let owner = msg - .owner - .and_then(|addr_string| deps.api.addr_validate(addr_string.as_str()).ok()) - .unwrap_or(info.sender); - - let config = Config { - owner: owner.clone(), - }; - CONFIG.save(deps.storage, &config)?; - - ENTRY_SEQ.save(deps.storage, &0u64)?; - - Ok(Response::new() - .add_attribute("method", "instantiate") - .add_attribute("owner", owner)) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - _env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - match msg { - ExecuteMsg::NewEntry { - data_type, - protocol, - chain_id, - url, - particle, - } => execute_create_new_item(deps, info, data_type, protocol, chain_id, url, particle), - ExecuteMsg::UpdateEntry { - id, - data_type, - protocol, - chain_id, - url, - particle, - } => execute_update_item(deps, info, id, data_type, protocol, chain_id, url, particle), - ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), - } -} - - - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::GetItems { start_after, limit } => { - to_binary(&query_list(deps, start_after, limit)?) - } - } -} \ No newline at end of file diff --git a/contracts/cw-cyb-endpoints/src/error.rs b/contracts/cw-cyb-endpoints/src/error.rs deleted file mode 100644 index 4d32a11..0000000 --- a/contracts/cw-cyb-endpoints/src/error.rs +++ /dev/null @@ -1,17 +0,0 @@ -use cosmwasm_std::StdError; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum ContractError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("Unauthorized")] - Unauthorized {}, - - #[error("IncorrectInputData val: {val:?}")] - IncorrectInputData {val: String }, - - #[error("Custom Error val: {val:?}")] - CustomError { val: String }, -} diff --git a/contracts/cw-cyb-endpoints/src/lib.rs b/contracts/cw-cyb-endpoints/src/lib.rs deleted file mode 100644 index b085561..0000000 --- a/contracts/cw-cyb-endpoints/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod contract; -mod error; -pub mod msg; -pub mod query; -pub mod state; -pub mod validating; -mod tests; - -pub use crate::error::ContractError; diff --git a/contracts/cw-cyb-endpoints/src/msg.rs b/contracts/cw-cyb-endpoints/src/msg.rs deleted file mode 100644 index 0b8face..0000000 --- a/contracts/cw-cyb-endpoints/src/msg.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::state::{Entry}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - pub owner: Option, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub enum ExecuteMsg { - NewEntry { - data_type: String, - protocol: String, - chain_id: String, - url: String, - particle: Option, - }, - UpdateEntry { - id: u64, - data_type: String, - protocol: String, - chain_id: String, - url: String, - particle: Option, - }, - DeleteEntry { - id: u64, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - GetItems { - start_after: Option, - limit: Option, - }, -} - -// Tokens -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct EntryResponse { - pub id: u64, - pub data_type: String, - pub protocol: u64, - pub chain_id: String, - pub url: String, - pub particle: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ListResponse { - pub entries: Vec, -} diff --git a/contracts/cw-cyb-endpoints/src/query.rs b/contracts/cw-cyb-endpoints/src/query.rs deleted file mode 100644 index e4548dd..0000000 --- a/contracts/cw-cyb-endpoints/src/query.rs +++ /dev/null @@ -1,161 +0,0 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; - -use cw_storage_plus::Bound; -use std::ops::Add; - - -use crate::error::ContractError; -use crate::msg::{ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; -use crate::validating::{validate_particle,validate_by_basic_rule,validate_url}; - -const MAX_LIMIT: u32 = 30; -const DEFAULT_LIMIT: u32 = 20; - - -pub fn execute_create_new_item( - deps: DepsMut, - info: MessageInfo, - data_type: String, - protocol: String, - chain_id: String, - url: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - - - let validate_url_result = validate_url(url.clone()); - let validate_particle = validate_particle(particle.clone()); - let validate_data_type = validate_by_basic_rule(data_type.clone(), "data-type".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); - let validate_chainid = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); - - if validate_particle.is_err() { - return validate_particle; - } - if validate_data_type.is_err() { - return validate_data_type; - } - if validate_url_result.is_err() { - return validate_url_result; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_chainid.is_err() { - return validate_chainid; - } - - - - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - data_type, - protocol, - chain_id, - url, - particle: particle.unwrap_or("".to_string()).to_string(), - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_new_item") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_item( - deps: DepsMut, - info: MessageInfo, - id: u64, - data_type: String, - protocol: String, - chain_id: String, - url: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let validate_url_result = validate_url(url.clone()); - let validate_particle = validate_particle(particle.clone()); - let validate_data_typer = validate_by_basic_rule(data_type.clone(), "data-type".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); - let validate_chainid = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); - - if validate_particle.is_err() { - return validate_particle; - } - if validate_data_typer.is_err() { - return validate_data_typer; - } - if validate_url_result.is_err() { - return validate_url_result; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_chainid.is_err() { - return validate_chainid; - } - - - - let entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - data_type, - protocol, - chain_id, - url, - particle: particle.unwrap_or("".to_string()).to_string(), - }; - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_item") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - - - - - -pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let start = start_after.map(Bound::exclusive); - let entries: StdResult> = LIST - .range(deps.storage, start, None, Order::Ascending) - .take(limit) - .collect(); - - let result = ListResponse { - entries: entries?.into_iter().map(|l| l.1).collect(), - }; - Ok(result) -} diff --git a/contracts/cw-cyb-endpoints/src/state.rs b/contracts/cw-cyb-endpoints/src/state.rs deleted file mode 100644 index bec6a75..0000000 --- a/contracts/cw-cyb-endpoints/src/state.rs +++ /dev/null @@ -1,25 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use cosmwasm_std::Addr; -use cw_storage_plus::{Item, Map}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct Config { - pub owner: Addr, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct Entry { - pub id: u64, - pub data_type: String, - pub particle: String, - pub protocol: String, - pub chain_id: String, - pub url: String, -} - - -pub const CONFIG: Item = Item::new("config"); -pub const ENTRY_SEQ: Item = Item::new("entry_seq"); -pub const LIST: Map = Map::new("list"); diff --git a/contracts/cw-cyb-endpoints/src/tests.rs b/contracts/cw-cyb-endpoints/src/tests.rs deleted file mode 100644 index 0447121..0000000 --- a/contracts/cw-cyb-endpoints/src/tests.rs +++ /dev/null @@ -1,218 +0,0 @@ - - -#[cfg(test)] -mod tests { - // use super::*; - // use cosmwasm_std::{Uint64}; - use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{attr, from_binary, Addr}; - use std::vec::Vec; - use crate::state::{Entry, CONFIG, Config}; - use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; - // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; - use crate::contract::{query, execute, instantiate}; - - #[test] - fn proper_initialization() { - let mut deps = mock_dependencies(); - //no owner specified in the instantiation message - let msg = InstantiateMsg { owner: None }; - let env = mock_env(); - let info = mock_info("creator", &[]); - - let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let state = CONFIG.load(&deps.storage).unwrap(); - assert_eq!( - state, - Config { - owner: Addr::unchecked("creator".to_string()), - } - ); - //specifying an owner address in the instantiation message - let msg = InstantiateMsg { - owner: Some("specified_owner".to_string()), - }; - - let res = instantiate(deps.as_mut(), env, info, msg).unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let state = CONFIG.load(&deps.storage).unwrap(); - assert_eq!( - state, - Config { - owner: Addr::unchecked("specified_owner".to_string()), - } - ); - } - - #[test] - fn create_update_delete_entry() { - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info("creator", &[]); - let msg = InstantiateMsg { owner: None }; - - let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!(0, res.messages.len()); - - let msg = ExecuteMsg::NewEntry { - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_create_new_item"), - attr("new_entry_id", "1") - ] - ); - - let msg = ExecuteMsg::NewEntry { - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_create_new_item"), - attr("new_entry_id", "2") - ] - ); - - // Query the list of entries - let res = query( - deps.as_ref(), - env.clone(), - QueryMsg::GetItems { - start_after: None, - limit: None, - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([ - Entry { - id: 1, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - }, - Entry { - id: 2, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - } - ]), - list.entries - ); - - // Update entry - let message = ExecuteMsg::UpdateEntry { - id: 1, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - //None - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), message).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_update_item"), - attr("updated_entry_id", "1") - ] - ); - - - - // Query the list of entries - let res = query( - deps.as_ref(), - env.clone(), - QueryMsg::GetItems { - start_after: None, - limit: None, - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([ - Entry { - id: 1, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - }, - Entry { - id: 2, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - } - ]), - list.entries - ); - - //Delete Entry - let message = ExecuteMsg::DeleteEntry { id: 1 }; - - let res = execute(deps.as_mut(), env.clone(), info, message).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_delete_entry"), - attr("deleted_entry_id", "1") - ] - ); - // Query the list of entries - let res = query( - deps.as_ref(), - env, - QueryMsg::GetItems { - start_after: None, - limit: None, - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([Entry { - id: 2, - data_type: "rpc".to_string(), - protocol: "rpc-http-api".to_string(), - chain_id: "test-1".to_string(), - url: "https://cyb.ai".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - }]), - list.entries - ); - } -} diff --git a/contracts/cw-cyb-endpoints/src/validating.rs b/contracts/cw-cyb-endpoints/src/validating.rs deleted file mode 100644 index f12c7fd..0000000 --- a/contracts/cw-cyb-endpoints/src/validating.rs +++ /dev/null @@ -1,79 +0,0 @@ -use cid::{Cid, Version}; -use std::str::FromStr; -use crate::error::ContractError; -use cosmwasm_std::{ - Response, -}; - -/** - * Baseic rule /[a-z0-9-]/ - */ -pub fn validate_by_basic_rule( - val: String, - field_name: String, -) -> Result { - - for byte in val.as_bytes().iter() { - // - && 0-9 && a-z - if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field field {}. Allowed expression /[a-z0-9-]/", field_name).to_string()}); - } - } - - Ok(Response::default()) -} - -pub fn validate_datatype( - val: String -) -> Result { - - for byte in val.as_bytes().iter() { - // - && 0-9 && a-z - if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - return Err(ContractError::IncorrectInputData {val: "Incorrect data-type. a-z0-9- allowed".to_string()}); - } - } - - Ok(Response::default()) -} - -pub fn validate_url( - val: String -) -> Result { - - for byte in val.as_bytes().iter() { - // : / . - _ 0-9 a-z A-Z - if (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { - return Err(ContractError::IncorrectInputData {val: "Incorrect data-type. a-z0-9- allowed".to_string()}); - } - } - - Ok(Response::default()) -} - - -pub fn validate_particle( - particle: Option -) -> Result { - - if !particle.as_ref().is_none() { - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.as_ref().unwrap().clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - - return Err(ContractError::IncorrectInputData {val: "Incorrect particle".to_string()}); - - } - } else { - return Err(ContractError::IncorrectInputData {val: "Incorrect particle".to_string()}); - } - Ok(Response::default()) - } else { - Ok(Response::default()) - } -} - - From a4e4ade3f5428a552be64a212d3e9b1656b6e9a1 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 14:29:12 +0800 Subject: [PATCH 06/33] Deleted heroes --- contracts/cw-cyb-heroes/.cargo/config | 4 - contracts/cw-cyb-heroes/Cargo.lock | 778 --------------------- contracts/cw-cyb-heroes/Cargo.toml | 53 -- contracts/cw-cyb-heroes/examples/schema.rs | 17 - contracts/cw-cyb-heroes/src/contract.rs | 77 -- contracts/cw-cyb-heroes/src/error.rs | 17 - contracts/cw-cyb-heroes/src/lib.rs | 9 - contracts/cw-cyb-heroes/src/msg.rs | 56 -- contracts/cw-cyb-heroes/src/query.rs | 175 ----- contracts/cw-cyb-heroes/src/state.rs | 54 -- contracts/cw-cyb-heroes/src/tests.rs | 214 ------ contracts/cw-cyb-heroes/src/validating.rs | 109 --- 12 files changed, 1563 deletions(-) delete mode 100644 contracts/cw-cyb-heroes/.cargo/config delete mode 100644 contracts/cw-cyb-heroes/Cargo.lock delete mode 100644 contracts/cw-cyb-heroes/Cargo.toml delete mode 100644 contracts/cw-cyb-heroes/examples/schema.rs delete mode 100644 contracts/cw-cyb-heroes/src/contract.rs delete mode 100644 contracts/cw-cyb-heroes/src/error.rs delete mode 100644 contracts/cw-cyb-heroes/src/lib.rs delete mode 100644 contracts/cw-cyb-heroes/src/msg.rs delete mode 100644 contracts/cw-cyb-heroes/src/query.rs delete mode 100644 contracts/cw-cyb-heroes/src/state.rs delete mode 100644 contracts/cw-cyb-heroes/src/tests.rs delete mode 100644 contracts/cw-cyb-heroes/src/validating.rs diff --git a/contracts/cw-cyb-heroes/.cargo/config b/contracts/cw-cyb-heroes/.cargo/config deleted file mode 100644 index 336b618..0000000 --- a/contracts/cw-cyb-heroes/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --example schema" diff --git a/contracts/cw-cyb-heroes/Cargo.lock b/contracts/cw-cyb-heroes/Cargo.lock deleted file mode 100644 index bd9ed11..0000000 --- a/contracts/cw-cyb-heroes/Cargo.lock +++ /dev/null @@ -1,778 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" - -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "base64ct" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bdca834647821e0b13d9539a8634eb62d3501b6b6c2cec1722786ee6671b851" - -[[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 = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" - -[[package]] -name = "cosmwasm-crypto" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eb0afef2325df81aadbf9be1233f522ed8f6e91df870c764bc44cca2b1415bd" -dependencies = [ - "digest", - "ed25519-zebra", - "k256", - "rand_core 0.6.3", - "thiserror", -] - -[[package]] -name = "cosmwasm-derive" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b36e527620a2a3e00e46b6e731ab6c9b68d11069c986f7d7be8eba79ef081a4" -dependencies = [ - "syn", -] - -[[package]] -name = "cosmwasm-schema" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "772e80bbad231a47a2068812b723a1ff81dd4a0d56c9391ac748177bea3a61da" -dependencies = [ - "schemars", - "serde_json", -] - -[[package]] -name = "cosmwasm-std" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875994993c2082a6fcd406937bf0fca21c349e4a624f3810253a14fa83a3a195" -dependencies = [ - "base64", - "cosmwasm-crypto", - "cosmwasm-derive", - "forward_ref", - "schemars", - "serde", - "serde-json-wasm", - "thiserror", - "uint", -] - -[[package]] -name = "cosmwasm-storage" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d18403b07304d15d304dad11040d45bbcaf78d603b4be3fb5e2685c16f9229b5" -dependencies = [ - "cosmwasm-std", - "serde", -] - -[[package]] -name = "cpufeatures" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" -dependencies = [ - "libc", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-bigint" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" -dependencies = [ - "generic-array", - "rand_core 0.6.3", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "curve25519-dalek" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" -dependencies = [ - "byteorder", - "digest", - "rand_core 0.5.1", - "subtle", - "zeroize", -] - -[[package]] -name = "cw-cyb-tokens" -version = "0.1.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-multi-test", - "cw-storage-plus", - "cw2", - "regex", - "schemars", - "semver", - "serde", - "thiserror", -] - -[[package]] -name = "cw-multi-test" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f9a8ab7c3c29ec93cb7a39ce4b14a05e053153b4a17ef7cf2246af1b7c087e" -dependencies = [ - "anyhow", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus", - "cw-utils", - "derivative", - "itertools", - "prost", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "cw-storage-plus" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" -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.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cf4639517490dd36b333bbd6c4fbd92e325fd0acf4683b41753bc5eb63bfc1" -dependencies = [ - "cosmwasm-std", - "cw-storage-plus", - "schemars", - "serde", -] - -[[package]] -name = "der" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" -dependencies = [ - "const-oid", -] - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "dyn-clone" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d07a982d1fb29db01e5a59b1918e03da4df7297eaeee7686ac45542fd4e59c8" - -[[package]] -name = "ecdsa" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" -dependencies = [ - "der", - "elliptic-curve", - "rfc6979", - "signature", -] - -[[package]] -name = "ed25519-zebra" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403ef3e961ab98f0ba902771d29f842058578bb1ce7e3c59dad5a6a93e784c69" -dependencies = [ - "curve25519-dalek", - "hex", - "rand_core 0.6.3", - "serde", - "sha2", - "thiserror", - "zeroize", -] - -[[package]] -name = "either" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" - -[[package]] -name = "elliptic-curve" -version = "0.11.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b477563c2bfed38a3b7a60964c49e058b2510ad3f12ba3483fd8f62c2306d6" -dependencies = [ - "base16ct", - "crypto-bigint", - "der", - "ff", - "generic-array", - "group", - "rand_core 0.6.3", - "sec1", - "subtle", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" -dependencies = [ - "rand_core 0.6.3", - "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.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - -[[package]] -name = "group" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" -dependencies = [ - "ff", - "rand_core 0.6.3", - "subtle", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest", -] - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" - -[[package]] -name = "k256" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "sec1", - "sha2", -] - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "pkcs8" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" -dependencies = [ - "der", - "spki", - "zeroize", -] - -[[package]] -name = "proc-macro2" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "prost" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "quote" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", -] - -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom 0.2.7", -] - -[[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "rfc6979" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" -dependencies = [ - "crypto-bigint", - "hmac", - "zeroize", -] - -[[package]] -name = "ryu" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" - -[[package]] -name = "schemars" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1847b767a3d62d95cbf3d8a9f0e421cf57a0d8aa4f411d4b16525afb0284d4ed" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4d7e1b012cb3d9129567661a63755ea4b8a7386d339dc945ae187e403c6743" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn", -] - -[[package]] -name = "sec1" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" -dependencies = [ - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "semver" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" - -[[package]] -name = "serde" -version = "1.0.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde-json-wasm" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_derive_internals" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" -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", - "cfg-if", - "cpufeatures", - "digest", - "opaque-debug", -] - -[[package]] -name = "signature" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" -dependencies = [ - "digest", - "rand_core 0.6.3", -] - -[[package]] -name = "spki" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" -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.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - -[[package]] -name = "syn" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] -name = "uint" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - -[[package]] -name = "unicode-ident" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" - -[[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.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[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.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" diff --git a/contracts/cw-cyb-heroes/Cargo.toml b/contracts/cw-cyb-heroes/Cargo.toml deleted file mode 100644 index d60ba1b..0000000 --- a/contracts/cw-cyb-heroes/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -name = "cw-cyb-heroes" -version = "0.1.0" -authors = ["Bloqhub"] -edition = "2018" - -exclude = [ - # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. - "contract.wasm", - "hash.txt", -] - -# 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] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] -# use library feature to disable all instantiate/execute/query exports -library = [] - -[package.metadata.scripts] -optimize = """docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 -""" - -[dependencies] -cosmwasm-std = { version = "1.0.0", features = ["iterator", "abort"] } -cw-storage-plus = { version = "0.14.0" } -cw2 = { version = "0.13.4" } -schemars = "0.8.10" -serde = { version = "1.0.140", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.31" } -cid = { version = "0.8.0" } - -[dev-dependencies] -cosmwasm-schema = "1.0.0" -cw-multi-test = "0.13.2" diff --git a/contracts/cw-cyb-heroes/examples/schema.rs b/contracts/cw-cyb-heroes/examples/schema.rs deleted file mode 100644 index d0c03c0..0000000 --- a/contracts/cw-cyb-heroes/examples/schema.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::env::current_dir; -use std::fs::create_dir_all; - -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; - -use cw_cyb_heroes::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - export_schema(&schema_for!(InstantiateMsg), &out_dir); - export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); -} diff --git a/contracts/cw-cyb-heroes/src/contract.rs b/contracts/cw-cyb-heroes/src/contract.rs deleted file mode 100644 index 49063f5..0000000 --- a/contracts/cw-cyb-heroes/src/contract.rs +++ /dev/null @@ -1,77 +0,0 @@ -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, -}; -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; - -use cw2::set_contract_version; - -use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; -// Token constructor -use crate::state::{Config, CONFIG, ENTRY_SEQ}; - -//@TODO git version iteract -const CONTRACT_NAME: &str = "cw-heroes"; -const CONTRACT_VERSION: &str = "1.0.0"; - -#[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)?; - - let owner = msg - .owner - .and_then(|addr_string| deps.api.addr_validate(addr_string.as_str()).ok()) - .unwrap_or(info.sender); - - let config = Config { - owner: owner.clone(), - }; - CONFIG.save(deps.storage, &config)?; - - ENTRY_SEQ.save(deps.storage, &0u64)?; - - Ok(Response::new() - .add_attribute("method", "instantiate") - .add_attribute("owner", owner)) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - _env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - match msg { - ExecuteMsg::NewEntry { - address, - chain_id, - particle, - } => execute_create_new_item(deps, info, address, chain_id,particle), - ExecuteMsg::UpdateEntry { - id, - address, - chain_id, - particle, - } => execute_update_item(deps, info, id, address, chain_id, particle), - ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), - } -} - - - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::GetItems { start_after, limit, id, owner } => { - to_binary(&query_list(deps, start_after, limit, id, owner)?) - } - } -} \ No newline at end of file diff --git a/contracts/cw-cyb-heroes/src/error.rs b/contracts/cw-cyb-heroes/src/error.rs deleted file mode 100644 index 4d32a11..0000000 --- a/contracts/cw-cyb-heroes/src/error.rs +++ /dev/null @@ -1,17 +0,0 @@ -use cosmwasm_std::StdError; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum ContractError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("Unauthorized")] - Unauthorized {}, - - #[error("IncorrectInputData val: {val:?}")] - IncorrectInputData {val: String }, - - #[error("Custom Error val: {val:?}")] - CustomError { val: String }, -} diff --git a/contracts/cw-cyb-heroes/src/lib.rs b/contracts/cw-cyb-heroes/src/lib.rs deleted file mode 100644 index b085561..0000000 --- a/contracts/cw-cyb-heroes/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod contract; -mod error; -pub mod msg; -pub mod query; -pub mod state; -pub mod validating; -mod tests; - -pub use crate::error::ContractError; diff --git a/contracts/cw-cyb-heroes/src/msg.rs b/contracts/cw-cyb-heroes/src/msg.rs deleted file mode 100644 index a155ab3..0000000 --- a/contracts/cw-cyb-heroes/src/msg.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::state::{Entry}; -use cosmwasm_std::{Uint64}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use cosmwasm_std::{ - Addr, -}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - pub owner: Option, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub enum ExecuteMsg { - NewEntry { - address: String, - chain_id: String, - particle: Option, - }, - UpdateEntry { - id: u64, - address: Option, - chain_id: Option, - particle: Option, - }, - DeleteEntry { - id: u64, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - GetItems { - start_after: Option, - owner: Option, - id: Option, - limit: Option, - }, -} - -// Tokens -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct EntryResponse { - pub id: u64, - pub address: String, - pub chain_id: String, - // pub owner: String, - pub particle: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ListResponse { - pub entries: Vec, -} diff --git a/contracts/cw-cyb-heroes/src/query.rs b/contracts/cw-cyb-heroes/src/query.rs deleted file mode 100644 index ee06be5..0000000 --- a/contracts/cw-cyb-heroes/src/query.rs +++ /dev/null @@ -1,175 +0,0 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, Addr, -}; - -// use cw_storage_plus::Bound; -use std::ops::Add; - -use crate::validating::{validate_by_basic_rule,validate_ipfs_cid}; -use crate::error::ContractError; -use crate::msg::{ListResponse}; -use crate::state::{Entry, ENTRY_SEQ, items}; - -const MAX_LIMIT: u32 = 50; -const DEFAULT_LIMIT: u32 = 30; - -pub fn uniq_key_by_owner(owner: Addr, id: u64) -> (Addr, u64) { - (owner.clone(), id.clone()) -} - -pub fn execute_create_new_item( - deps: DepsMut, - info: MessageInfo, - address: String, - chain_id: String, - particle: Option, -) -> Result { - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - - let validate_address = validate_by_basic_rule(address.clone(), "address".to_string()); - let validate_chain_id = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); - - if validate_address.is_err() { - return validate_address; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - - - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - address, - chain_id, - owner: info.sender, - particle: particle.unwrap_or("".to_string()) - }; - - - items().save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_new_item") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_item( - deps: DepsMut, - info: MessageInfo, - id: u64, - address: Option, - chain_id: Option, - particle: Option, -) -> Result { - // let owner = CONFIG.load(deps.storage)?.owner; - // if info.sender != owner { - // return Err(ContractError::Unauthorized {}); - // } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_address = validate_by_basic_rule(address.clone().unwrap(), "address".to_string()); - let validate_chain_id = validate_by_basic_rule(chain_id.clone().unwrap(), "chain_id".to_string()); - - if validate_address.is_err() { - return validate_address; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - - let entry = items().load(deps.storage, id)?; - - if entry.owner != info.sender { - return Err(ContractError::Unauthorized {}); - } - - - let updated_entry = Entry { - id, - address: address.unwrap_or(entry.address), - chain_id: chain_id.unwrap_or(entry.chain_id), - owner: entry.owner, - particle: particle.unwrap_or("".to_string()), - }; - items().save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_item") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - // let owner = CONFIG.load(deps.storage)?.owner; - // if info.sender != owner { - // return Err(ContractError::Unauthorized {}); - // } - - // let key = uniq_key_by_owner(info.sender, id); - let entry = items().load(deps.storage, id)?; - - if entry.owner != info.sender { - return Err(ContractError::Unauthorized {}); - } - - let _result = items().remove(deps.storage, id); - - - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - - - - - -pub fn query_list(deps: Deps, start_after: Option, limit: Option, id: Option, owner: Option) -> StdResult { - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - - - - let entries: StdResult> = items() - .idx - .owner - .prefix(owner.clone().unwrap_or(Addr::unchecked("")).to_string()) - .range( - deps.storage, - None, - // Some(Bound::exclusive(( - // owner.clone().unwrap().to_string(), - // // start_after.unwrap() - // // owner.clone().unwrap().to_string(), - // // start_after.unwrap_or_default(), - // ))), - None, - Order::Ascending, - ) - .take(limit) - .collect(); - - - let result = ListResponse { - entries: entries?.into_iter().map(|l| l.1).collect(), - }; - Ok(result) -} diff --git a/contracts/cw-cyb-heroes/src/state.rs b/contracts/cw-cyb-heroes/src/state.rs deleted file mode 100644 index 4eef657..0000000 --- a/contracts/cw-cyb-heroes/src/state.rs +++ /dev/null @@ -1,54 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use cosmwasm_std::Addr; -use cw_storage_plus::{Item, UniqueIndex, IndexList, IndexedMap, Index, MultiIndex}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct Config { - pub owner: Addr, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct Entry { - pub id: u64, - pub address: String, - pub chain_id: String, - pub owner: Addr, - pub particle: String, -} - - -pub const CONFIG: Item = Item::new("config"); -pub const ENTRY_SEQ: Item = Item::new("entry_seq"); - - - -pub struct EntryIndexes<'a> { - pub id: UniqueIndex<'a, u64, Entry>, - pub owner: MultiIndex<'a, String, Entry, String>, - -} - -impl<'a> IndexList for EntryIndexes<'a> { - fn get_indexes(&'_ self) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.owner, &self.id]; - Box::new(v.into_iter()) - } -} - -pub fn items<'a>() -> IndexedMap<'a, u64, Entry, EntryIndexes<'a>> { - let indexes = EntryIndexes { - owner: MultiIndex::new( - |d| (d.owner.clone().to_string()), - "list", - "list_owner" - ), - id: UniqueIndex::new( - |d| (d.id.clone()), - "list_id" - ), - - }; - IndexedMap::new("list", indexes) -} \ No newline at end of file diff --git a/contracts/cw-cyb-heroes/src/tests.rs b/contracts/cw-cyb-heroes/src/tests.rs deleted file mode 100644 index 8673de9..0000000 --- a/contracts/cw-cyb-heroes/src/tests.rs +++ /dev/null @@ -1,214 +0,0 @@ - - -#[cfg(test)] -mod tests { - // use super::*; - // use cosmwasm_std::{Uint64}; - use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{attr, from_binary, Addr}; - // use std::convert::TryFrom; - use std::vec::Vec; - use crate::state::{Entry, CONFIG, Config}; - use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; - // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; - use crate::contract::{query, execute, instantiate}; - - #[test] - fn proper_initialization() { - let mut deps = mock_dependencies(); - //no owner specified in the instantiation message - let msg = InstantiateMsg { owner: None }; - let env = mock_env(); - let info = mock_info("creator", &[]); - - let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let state = CONFIG.load(&deps.storage).unwrap(); - assert_eq!( - state, - Config { - owner: Addr::unchecked("creator".to_string()), - } - ); - //specifying an owner address in the instantiation message - let msg = InstantiateMsg { - owner: Some("specified_owner".to_string()), - }; - - let res = instantiate(deps.as_mut(), env, info, msg).unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let state = CONFIG.load(&deps.storage).unwrap(); - assert_eq!( - state, - Config { - owner: Addr::unchecked("specified_owner".to_string()), - } - ); - } - - #[test] - fn create_update_delete_entry() { - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info("creator", &[]); - let msg = InstantiateMsg { owner: None }; - - let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!(0, res.messages.len()); - - let msg = ExecuteMsg::NewEntry { - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_create_new_item"), - attr("new_entry_id", "1") - ] - ); - - let msg = ExecuteMsg::NewEntry { - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_create_new_item"), - attr("new_entry_id", "2") - ] - ); - - // Query the list of entries - let res = query( - deps.as_ref(), - env.clone(), - QueryMsg::GetItems { - start_after: None, - limit: None, - id: None, - // owner: None, - owner: Some(Addr::unchecked("creator")), - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([ - Entry { - id: 1, - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - owner: cosmwasm_std::Addr::unchecked("creator"), - }, - Entry { - id: 2, - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - owner: cosmwasm_std::Addr::unchecked("creator"), - } - ]), - list.entries - ); - - // Update entry - let message = ExecuteMsg::UpdateEntry { - id: 1, - address: Some("testchain-1".to_string()), - chain_id: Some("testchain-1".to_string()), - particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), - }; - - let res = execute(deps.as_mut(), env.clone(), info.clone(), message).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_update_item"), - attr("updated_entry_id", "1") - ] - ); - - - - // Query the list of entries - let res = query( - deps.as_ref(), - env.clone(), - QueryMsg::GetItems { - start_after: None, - limit: None, - id: None, - owner: Some(Addr::unchecked("creator")), - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([ - Entry { - id: 1, - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - owner: cosmwasm_std::Addr::unchecked("creator"), - }, - Entry { - id: 2, - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - owner: cosmwasm_std::Addr::unchecked("creator"), - } - ]), - list.entries - ); - - //Delete Entry - let message = ExecuteMsg::DeleteEntry { id: 1 }; - - let res = execute(deps.as_mut(), env.clone(), info, message).unwrap(); - assert_eq!( - res.attributes, - vec![ - attr("method", "execute_delete_entry"), - attr("deleted_entry_id", "1") - ] - ); - // Query the list of entries - let res = query( - deps.as_ref(), - env, - QueryMsg::GetItems { - start_after: None, - id: None, - owner: Some(Addr::unchecked("creator")), - limit: None, - }, - ) - .unwrap(); - let list: ListResponse = from_binary(&res).unwrap(); - assert_eq!( - Vec::from([Entry { - id: 2, - address: "testchain-1".to_string(), - chain_id: "testchain-1".to_string(), - particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), - owner: cosmwasm_std::Addr::unchecked("creator"), - }]), - list.entries - ); - } -} diff --git a/contracts/cw-cyb-heroes/src/validating.rs b/contracts/cw-cyb-heroes/src/validating.rs deleted file mode 100644 index 06a0815..0000000 --- a/contracts/cw-cyb-heroes/src/validating.rs +++ /dev/null @@ -1,109 +0,0 @@ -use cid::{Cid, Version}; -use cosmwasm_std::{Uint64}; -use std::str::FromStr; -use crate::error::ContractError; -use cosmwasm_std::{ - Response, -}; - -/** - * Baseic rule /[a-z0-9-]/ - */ -pub fn validate_by_basic_rule( - val: String, - field_name: String, -) -> Result { - - for byte in val.as_bytes().iter() { - // - && 0-9 && a-z - if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field field {}. Allowed expression /[a-z0-9-]/", field_name).to_string()}); - } - } - - Ok(Response::default()) -} - -/** - * Baseic rule /[A-Z0-9]/ - */ -pub fn validate_by_basic_uppercase_rule( - val: String, - field_name: String, -) -> Result { - - for byte in val.as_bytes().iter() { - // 0-9 && A-Z - if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field field {}. Allowed expression /[a-z0-9-]/", field_name).to_string()}); - } - } - - Ok(Response::default()) -} - -pub fn validate_datatype( - val: String, -) -> Result { - - for byte in val.as_bytes().iter() { - // - && 0-9 && a-z - if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { - return Err(ContractError::IncorrectInputData {val: "Incorrect data-type. a-z0-9- allowed".to_string()}); - } - } - - Ok(Response::default()) -} - -pub fn validate_url( - val: String, - field_name: String, -) -> Result { - - for byte in val.as_bytes().iter() { - // = & } { : / . - _ 0-9 a-z A-Z - if (*byte != 61) && (*byte != 38) && (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only url", field_name).to_string()}); - } - } - - Ok(Response::default()) -} - -pub fn validate_by_int_range( - from: Uint64, - to: Uint64, - field: Uint64, - field_name: String, -) -> Result { - // let intField=Uint64::from(field); - if field < from || field > to { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Out from range", field_name).to_string()}); - } - Ok(Response::default()) -} - - - -pub fn validate_ipfs_cid( - particle: String, - field_name: String, -) -> Result { - - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); - } - } else { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); - } - Ok(Response::default()) - -} - - From 8c3bc1e34643345a12b56e5d841b9b65d599ae03 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 14:30:08 +0800 Subject: [PATCH 07/33] Refactored skills --- contracts/hub-skills/src/contract.rs | 8 +++-- contracts/hub-skills/src/msg.rs | 4 +++ contracts/hub-skills/src/query.rs | 48 ++++++++++------------------ contracts/hub-skills/src/state.rs | 11 ++++--- contracts/hub-skills/src/tests.rs | 12 +++++-- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index b71e03c..b671826 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -53,16 +53,18 @@ pub fn execute( ExecuteMsg::NewEntry { neuron, protocol, + network, endpoint, particle, - } => execute_create_new_item(deps, info, neuron, protocol,endpoint,particle), + } => execute_create_item(deps, info, neuron, network, protocol, endpoint, particle), ExecuteMsg::UpdateEntry { id, neuron, protocol, + network, endpoint, particle, - } => execute_update_item(deps, info, id, neuron, protocol, endpoint, particle), + } => execute_update_item(deps, info, id, neuron, network, protocol, endpoint, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index cc6748b..cd9135b 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -13,8 +13,11 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + // TODO add change owner contract + // TODO add change owner item NewEntry { neuron: String, + network: String, protocol: String, endpoint: String, particle: Option, @@ -22,6 +25,7 @@ pub enum ExecuteMsg { UpdateEntry { id: u64, neuron: Option, + network: Option, protocol: Option, endpoint: Option, particle: Option, diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 5476975..909ab97 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -1,7 +1,6 @@ use cosmwasm_std::{ Deps, DepsMut, MessageInfo, Order, Response, StdResult, Addr, }; -use cw_storage_plus::IndexedMap; // use cw_storage_plus::Bound; use std::ops::Add; @@ -18,10 +17,11 @@ pub fn uniq_key_by_owner(owner: Addr, id: u64) -> (Addr, u64) { (owner.clone(), id.clone()) } -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, neuron: String, + network: String, protocol: String, endpoint: String, particle: Option, @@ -34,14 +34,17 @@ pub fn execute_create_new_item( } } - let validate_neuron = validate_by_basic_rule(neuron.clone(), "neuron".to_string()); + let validate_network = validate_by_basic_rule(network.clone(), "network".to_string()); let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); let validate_endpoint = validate_url(endpoint.clone(), "endpoint".to_string()); if validate_neuron.is_err() { return validate_neuron; } + if validate_network.is_err() { + return validate_network; + } if validate_protocol.is_err() { return validate_protocol; } @@ -49,24 +52,21 @@ pub fn execute_create_new_item( return validate_endpoint; } - - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; let new_entry = Entry { id, neuron, + network, protocol, endpoint, owner: info.sender, particle: particle.unwrap_or("".to_string()) }; - items().save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } @@ -75,15 +75,11 @@ pub fn execute_update_item( info: MessageInfo, id: u64, neuron: Option, + network: Option, protocol: Option, endpoint: Option, particle: Option, ) -> Result { - // let owner = CONFIG.load(deps.storage)?.owner; - // if info.sender != owner { - // return Err(ContractError::Unauthorized {}); - // } - if !particle.as_ref().is_none() { let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); if validate_particle.is_err() { @@ -92,12 +88,16 @@ pub fn execute_update_item( } let validate_neuron = validate_by_basic_rule(neuron.clone().unwrap(), "neuron".to_string()); + let validate_network = validate_by_basic_rule(network.clone().unwrap(), "network".to_string()); let validate_protocol = validate_by_basic_rule(protocol.clone().unwrap(), "protocol".to_string()); let validate_endpoint = validate_url(endpoint.clone().unwrap(), "endpoint".to_string()); if validate_neuron.is_err() { return validate_neuron; } + if validate_network.is_err() { + return validate_network; + } if validate_protocol.is_err() { return validate_protocol; } @@ -111,11 +111,11 @@ pub fn execute_update_item( if entry.owner != info.sender { return Err(ContractError::Unauthorized {}); } - let updated_entry = Entry { id, neuron: neuron.unwrap_or(entry.neuron), + network: network.unwrap_or(entry.network), protocol: protocol.unwrap_or(entry.protocol), endpoint: endpoint.unwrap_or(entry.endpoint), owner: entry.owner, @@ -132,12 +132,6 @@ pub fn execute_delete_entry( info: MessageInfo, id: u64, ) -> Result { - // let owner = CONFIG.load(deps.storage)?.owner; - // if info.sender != owner { - // return Err(ContractError::Unauthorized {}); - // } - - // let key = uniq_key_by_owner(info.sender, id); let entry = items().load(deps.storage, id)?; if entry.owner != info.sender { @@ -146,26 +140,19 @@ pub fn execute_delete_entry( let _result = items().remove(deps.storage, id); - Ok(Response::new() .add_attribute("method", "execute_delete_entry") .add_attribute("deleted_entry_id", id.to_string())) } - - - - -pub fn query_list(deps: Deps, start_after: Option, limit: Option, protocol: Option, owner: Option) -> StdResult { +pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _protocol: Option, owner: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - - // let indexedArr = items(); let indexed_arr = items().idx.owner; + // TODO add start_after and protocol + let entries: StdResult> = indexed_arr - // .idx - // .owner .prefix(owner.clone().unwrap_or(Addr::unchecked("")).to_string()) .range( deps.storage, @@ -176,7 +163,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option, prot .take(limit) .collect(); - let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; diff --git a/contracts/hub-skills/src/state.rs b/contracts/hub-skills/src/state.rs index a75b717..f6abe77 100644 --- a/contracts/hub-skills/src/state.rs +++ b/contracts/hub-skills/src/state.rs @@ -13,23 +13,21 @@ pub struct Config { pub struct Entry { pub id: u64, pub neuron: String, + pub network: String, pub protocol: String, pub endpoint: String, pub owner: Addr, pub particle: String, } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); - - pub struct EntryIndexes<'a> { pub id: UniqueIndex<'a, u64, Entry>, pub owner: MultiIndex<'a, String, Entry, String>, + pub network: MultiIndex<'a, String, Entry, String>, pub protocol: MultiIndex<'a, String, Entry, String>, - } impl<'a> IndexList for EntryIndexes<'a> { @@ -46,6 +44,11 @@ pub fn items<'a>() -> IndexedMap<'a, u64, Entry, EntryIndexes<'a>> { "list", "list_owner" ), + network: MultiIndex::new( + |d| (d.owner.clone().to_string()), + "list", + "list_network" + ), protocol: MultiIndex::new( |d| (d.protocol.clone().to_string()), "list", diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index a18e2ef..6ae9727 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -62,6 +62,7 @@ mod tests { let msg = ExecuteMsg::NewEntry { neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), @@ -71,13 +72,14 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); let msg = ExecuteMsg::NewEntry { neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), @@ -87,7 +89,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); @@ -111,6 +113,7 @@ mod tests { Entry { id: 1, neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -119,6 +122,7 @@ mod tests { Entry { id: 2, neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -132,6 +136,7 @@ mod tests { let message = ExecuteMsg::UpdateEntry { id: 1, neuron: Some("testchain-1".to_string()), + network: Some("cosmos".to_string()), protocol: Some("testchain-1".to_string()), endpoint: Some("https:/abcd.com".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), @@ -166,6 +171,7 @@ mod tests { Entry { id: 1, neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -174,6 +180,7 @@ mod tests { Entry { id: 2, neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -211,6 +218,7 @@ mod tests { Vec::from([Entry { id: 2, neuron: "testchain-1".to_string(), + network: "cosmos".to_string(), protocol: "testchain-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), From 101af37187fa51dc6df515ec6f2e950a359cd167 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 18:47:33 +0800 Subject: [PATCH 08/33] Refactored change owner --- Cargo.lock | 30 -------------- contracts/hub-channels/src/contract.rs | 2 +- contracts/hub-channels/src/query.rs | 15 +++++-- contracts/hub-contracts/src/contract.rs | 7 ++-- contracts/hub-contracts/src/msg.rs | 4 +- contracts/hub-contracts/src/query.rs | 52 ++++++++++++++++++------- contracts/hub-contracts/src/state.rs | 2 +- contracts/hub-networks/src/contract.rs | 2 +- contracts/hub-networks/src/query.rs | 15 +++++-- contracts/hub-protocols/src/contract.rs | 7 ++-- contracts/hub-protocols/src/msg.rs | 3 ++ contracts/hub-protocols/src/query.rs | 50 ++++++++++++++++++------ contracts/hub-protocols/src/state.rs | 2 +- contracts/hub-skills/src/contract.rs | 7 ++-- contracts/hub-skills/src/msg.rs | 4 +- contracts/hub-skills/src/query.rs | 31 +++++++++++++-- contracts/hub-skills/src/state.rs | 2 +- contracts/hub-tokens/src/query.rs | 15 +++++-- 18 files changed, 164 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f24828..ed80611 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,36 +515,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cw-cyb-endpoints" -version = "0.1.0" -dependencies = [ - "cid", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.13.4", - "cw2 0.13.4", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "cw-cyb-heroes" -version = "0.1.0" -dependencies = [ - "cid", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.14.0", - "cw2 0.13.4", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cw-multi-test" version = "0.13.4" diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index e85dcb8..4bb986a 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index 55280fa..dc787cf 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -51,7 +51,10 @@ pub fn execute_create_new_item( particle: Option ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -113,7 +116,10 @@ pub fn execute_update_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -168,7 +174,10 @@ pub fn execute_delete_entry( id: u64, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 61ae2d1..ab280be 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { address, query_cid, diff --git a/contracts/hub-contracts/src/msg.rs b/contracts/hub-contracts/src/msg.rs index 40c1696..046e6bb 100644 --- a/contracts/hub-contracts/src/msg.rs +++ b/contracts/hub-contracts/src/msg.rs @@ -1,5 +1,4 @@ use crate::state::{Entry}; -// use cosmwasm_std::{Uint64}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -10,6 +9,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, NewEntry { address: String, query_cid: String, diff --git a/contracts/hub-contracts/src/query.rs b/contracts/hub-contracts/src/query.rs index 8eb0fff..59eb915 100644 --- a/contracts/hub-contracts/src/query.rs +++ b/contracts/hub-contracts/src/query.rs @@ -1,6 +1,4 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; +use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; use cw_storage_plus::Bound; use std::ops::Add; @@ -13,6 +11,30 @@ use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} pub fn execute_create_new_item( deps: DepsMut, @@ -25,7 +47,10 @@ pub fn execute_create_new_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -35,7 +60,6 @@ pub fn execute_create_new_item( return validate_particle; } } - let validate_address = validate_by_basic_rule(address.clone(), "address".to_string()); let validate_query_cid = validate_ipfs_cid(query_cid.clone(), "query_cid".to_string()); @@ -59,8 +83,6 @@ pub fn execute_create_new_item( return validate_chain_id; } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; let new_entry = Entry { @@ -90,7 +112,10 @@ pub fn execute_update_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -100,7 +125,6 @@ pub fn execute_update_item( return validate_particle; } } - let validate_address = validate_by_basic_rule(address.clone().unwrap(), "address".to_string()); let validate_query_cid = validate_ipfs_cid(query_cid.clone().unwrap(), "query_cid".to_string()); @@ -124,8 +148,6 @@ pub fn execute_update_item( return validate_chain_id; } - - let entry = LIST.load(deps.storage, id)?; let updated_entry = Entry { id, @@ -149,7 +171,10 @@ pub fn execute_delete_entry( id: u64, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -159,9 +184,6 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } - - - pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-contracts/src/state.rs b/contracts/hub-contracts/src/state.rs index 540331e..6a12a0e 100644 --- a/contracts/hub-contracts/src/state.rs +++ b/contracts/hub-contracts/src/state.rs @@ -7,7 +7,7 @@ use cw_storage_plus::{Item, Map}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index ad0b88d..d6d2d4d 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index f51b7f4..8feaa18 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -50,7 +50,10 @@ pub fn execute_create_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -125,7 +128,10 @@ pub fn execute_update_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -194,7 +200,10 @@ pub fn execute_delete_entry( id: u64, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 8530dd5..623cce8 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { data_type, particle, diff --git a/contracts/hub-protocols/src/msg.rs b/contracts/hub-protocols/src/msg.rs index eaa7dce..6c57f97 100644 --- a/contracts/hub-protocols/src/msg.rs +++ b/contracts/hub-protocols/src/msg.rs @@ -9,6 +9,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, NewEntry { data_type: String, particle: Option, diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index c9c6483..8cea630 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -1,6 +1,4 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; +use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; use cw_storage_plus::Bound; use std::ops::Add; @@ -14,6 +12,30 @@ use crate::validating::{validate_particle,validate_datatype}; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} pub fn execute_create_new_item( deps: DepsMut, @@ -22,12 +44,13 @@ pub fn execute_create_new_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } - - let validate_particle = validate_particle(particle.clone()); let validate_data_typer = validate_datatype(data_type.clone()); @@ -61,7 +84,10 @@ pub fn execute_update_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -74,11 +100,8 @@ pub fn execute_update_item( if validate_data_typer.is_err() { return validate_data_typer; } - - - - let entry = LIST.load(deps.storage, id)?; + let _entry = LIST.load(deps.storage, id)?; let updated_entry = Entry { id, data_type: data_type, @@ -96,7 +119,10 @@ pub fn execute_delete_entry( id: u64, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } diff --git a/contracts/hub-protocols/src/state.rs b/contracts/hub-protocols/src/state.rs index 4dcaa9e..3585bcc 100644 --- a/contracts/hub-protocols/src/state.rs +++ b/contracts/hub-protocols/src/state.rs @@ -6,7 +6,7 @@ use cw_storage_plus::{Item, Map}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index b671826..2dc38fb 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -8,7 +8,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; // Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; @@ -31,7 +31,7 @@ pub fn instantiate( .unwrap_or(info.sender); let config = Config { - owner: owner.clone(), + owner: Some(owner.clone()), }; CONFIG.save(deps.storage, &config)?; @@ -45,11 +45,12 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::NewEntry { neuron, protocol, diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index cd9135b..2418cf2 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -13,7 +13,9 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub enum ExecuteMsg { - // TODO add change owner contract + UpdateOwner { + new_owner: Option, + }, // TODO add change owner item NewEntry { neuron: String, diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 909ab97..6dbe3f3 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -1,6 +1,4 @@ -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, Addr, -}; +use cosmwasm_std::{Deps, DepsMut, MessageInfo, Order, Response, StdResult, Addr, Env, attr}; // use cw_storage_plus::Bound; use std::ops::Add; @@ -8,7 +6,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule,validate_ipfs_cid, validate_url}; use crate::error::ContractError; use crate::msg::{ListResponse}; -use crate::state::{Entry, ENTRY_SEQ, items}; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, items}; const MAX_LIMIT: u32 = 50; const DEFAULT_LIMIT: u32 = 30; @@ -17,6 +15,31 @@ pub fn uniq_key_by_owner(owner: Addr, id: u64) -> (Addr, u64) { (owner.clone(), id.clone()) } +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + pub fn execute_create_item( deps: DepsMut, info: MessageInfo, diff --git a/contracts/hub-skills/src/state.rs b/contracts/hub-skills/src/state.rs index f6abe77..be913b1 100644 --- a/contracts/hub-skills/src/state.rs +++ b/contracts/hub-skills/src/state.rs @@ -6,7 +6,7 @@ use cw_storage_plus::{Item, UniqueIndex, IndexList, IndexedMap, Index, MultiInde #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Config { - pub owner: Addr, + pub owner: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index 981eb51..3517fe6 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -50,7 +50,10 @@ pub fn execute_create_new_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -108,7 +111,10 @@ pub fn execute_update_item( particle: Option, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } @@ -161,7 +167,10 @@ pub fn execute_delete_entry( id: u64, ) -> Result { let owner = CONFIG.load(deps.storage)?.owner; - if info.sender != owner { + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { return Err(ContractError::Unauthorized {}); } From 67fee8354fee7636e9f911919c85402515493dad Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 19:07:16 +0800 Subject: [PATCH 09/33] Added simple migrations --- contracts/hub-channels/src/contract.rs | 16 +++++++++++++--- contracts/hub-channels/src/error.rs | 3 +++ contracts/hub-channels/src/msg.rs | 2 ++ contracts/hub-contracts/src/contract.rs | 23 +++++++++++++++-------- contracts/hub-contracts/src/error.rs | 3 +++ contracts/hub-contracts/src/msg.rs | 2 ++ contracts/hub-networks/src/contract.rs | 21 +++++++++++++++------ contracts/hub-networks/src/error.rs | 3 +++ contracts/hub-networks/src/msg.rs | 3 +++ contracts/hub-protocols/src/contract.rs | 23 +++++++++++++++-------- contracts/hub-protocols/src/error.rs | 3 +++ contracts/hub-protocols/src/msg.rs | 3 +++ contracts/hub-skills/src/contract.rs | 25 +++++++++++++++---------- contracts/hub-skills/src/error.rs | 3 +++ contracts/hub-skills/src/msg.rs | 3 +++ contracts/hub-tokens/src/contract.rs | 21 +++++++++++++++------ contracts/hub-tokens/src/error.rs | 3 +++ contracts/hub-tokens/src/msg.rs | 3 +++ 18 files changed, 122 insertions(+), 41 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 4bb986a..eba3664 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -4,12 +4,11 @@ use cosmwasm_std::{ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -80,4 +79,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-channels/src/error.rs b/contracts/hub-channels/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-channels/src/error.rs +++ b/contracts/hub-channels/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index c12f6c8..b852f5d 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -44,6 +44,8 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index ab280be..e43ca0f 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -1,15 +1,13 @@ use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -72,8 +70,6 @@ pub fn execute( } } - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { @@ -81,4 +77,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-contracts/src/error.rs b/contracts/hub-contracts/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-contracts/src/error.rs +++ b/contracts/hub-contracts/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-contracts/src/msg.rs b/contracts/hub-contracts/src/msg.rs index 046e6bb..15939c6 100644 --- a/contracts/hub-contracts/src/msg.rs +++ b/contracts/hub-contracts/src/msg.rs @@ -43,6 +43,8 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index d6d2d4d..de16375 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -1,15 +1,13 @@ use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -83,4 +81,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-networks/src/error.rs b/contracts/hub-networks/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-networks/src/error.rs +++ b/contracts/hub-networks/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-networks/src/msg.rs b/contracts/hub-networks/src/msg.rs index 45eb00a..1569fc8 100644 --- a/contracts/hub-networks/src/msg.rs +++ b/contracts/hub-networks/src/msg.rs @@ -47,6 +47,9 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 623cce8..03c2f77 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -1,15 +1,13 @@ use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -64,8 +62,6 @@ pub fn execute( } } - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { @@ -73,4 +69,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-protocols/src/error.rs b/contracts/hub-protocols/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-protocols/src/error.rs +++ b/contracts/hub-protocols/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-protocols/src/msg.rs b/contracts/hub-protocols/src/msg.rs index 6c57f97..28aab74 100644 --- a/contracts/hub-protocols/src/msg.rs +++ b/contracts/hub-protocols/src/msg.rs @@ -35,6 +35,9 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} + // Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index 2dc38fb..fb4354b 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -1,15 +1,11 @@ -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, -}; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -70,8 +66,6 @@ pub fn execute( } } - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { @@ -79,4 +73,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit, protocol, owner)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-skills/src/error.rs b/contracts/hub-skills/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-skills/src/error.rs +++ b/contracts/hub-skills/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index 2418cf2..808fabd 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -48,6 +48,9 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} + // Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index e17f554..326499f 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -1,15 +1,13 @@ use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; -use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; -// Token constructor +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -81,4 +79,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_list(deps, start_after, limit)?) } } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) } \ No newline at end of file diff --git a/contracts/hub-tokens/src/error.rs b/contracts/hub-tokens/src/error.rs index 4d32a11..863e417 100644 --- a/contracts/hub-tokens/src/error.rs +++ b/contracts/hub-tokens/src/error.rs @@ -14,4 +14,7 @@ pub enum ContractError { #[error("Custom Error val: {val:?}")] CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index 8dd5951..6e11a3f 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -44,6 +44,9 @@ pub enum QueryMsg { }, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} + // Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { From 0fbb820719de6869b691e64c58164760217f7ce8 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 19:11:50 +0800 Subject: [PATCH 10/33] Refactoring --- contracts/hub-channels/src/contract.rs | 4 ++-- contracts/hub-channels/src/query.rs | 5 +---- contracts/hub-channels/src/tests.rs | 4 ++-- contracts/hub-contracts/src/contract.rs | 4 ++-- contracts/hub-contracts/src/query.rs | 4 ++-- contracts/hub-contracts/src/tests.rs | 8 ++++---- contracts/hub-networks/src/tests.rs | 4 ++-- contracts/hub-protocols/src/contract.rs | 4 ++-- contracts/hub-protocols/src/query.rs | 4 ++-- contracts/hub-protocols/src/tests.rs | 8 ++++---- contracts/hub-skills/src/tests.rs | 4 ++-- contracts/hub-tokens/src/contract.rs | 4 ++-- contracts/hub-tokens/src/query.rs | 2 +- contracts/hub-tokens/src/tests.rs | 4 ++-- 14 files changed, 30 insertions(+), 33 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index eba3664..5c1a8c7 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -8,7 +8,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_new_item, execute_update_item, execute_delete_entry, execute_update_owner}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -58,7 +58,7 @@ pub fn execute( explorer_url, particle - } => execute_create_new_item(deps, info, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, particle), + } => execute_create_item(deps, info, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::UpdateEntry { id, source_chain_id, diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index dc787cf..062fc81 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -1,6 +1,3 @@ -// use regex::Regex; -// use cosmwasm_std::{Uint64}; - use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; use cw_storage_plus::Bound; @@ -40,7 +37,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, source_chain_id: String, diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index ae0b7bd..646e2e3 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -25,7 +25,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -41,7 +41,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index e43ca0f..7009335 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -56,7 +56,7 @@ pub fn execute( version, chain_id, particle, - } => execute_create_new_item(deps, info,address,query_cid,execute_cid,version,chain_id, particle), + } => execute_create_item(deps, info, address, query_cid, execute_cid, version, chain_id, particle), ExecuteMsg::UpdateEntry { id, address, diff --git a/contracts/hub-contracts/src/query.rs b/contracts/hub-contracts/src/query.rs index 59eb915..2e19098 100644 --- a/contracts/hub-contracts/src/query.rs +++ b/contracts/hub-contracts/src/query.rs @@ -36,7 +36,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, address: String, @@ -96,7 +96,7 @@ pub fn execute_create_new_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } diff --git a/contracts/hub-contracts/src/tests.rs b/contracts/hub-contracts/src/tests.rs index e5e09a4..f5dcfa7 100644 --- a/contracts/hub-contracts/src/tests.rs +++ b/contracts/hub-contracts/src/tests.rs @@ -28,7 +28,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -44,7 +44,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } @@ -72,7 +72,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); @@ -90,7 +90,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index 03bc901..f75ccb1 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -25,7 +25,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -41,7 +41,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 03c2f77..f9c96b1 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -52,7 +52,7 @@ pub fn execute( ExecuteMsg::NewEntry { data_type, particle, - } => execute_create_new_item(deps, info, data_type, particle), + } => execute_create_item(deps, info, data_type, particle), ExecuteMsg::UpdateEntry { id, data_type, diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index 8cea630..0d72150 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -37,7 +37,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, data_type: String, @@ -72,7 +72,7 @@ pub fn execute_create_new_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_new_item") + .add_attribute("method", "execute_create_item") .add_attribute("new_entry_id", id.to_string())) } diff --git a/contracts/hub-protocols/src/tests.rs b/contracts/hub-protocols/src/tests.rs index f74b71c..6bad543 100644 --- a/contracts/hub-protocols/src/tests.rs +++ b/contracts/hub-protocols/src/tests.rs @@ -28,7 +28,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -44,7 +44,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } @@ -68,7 +68,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "1") ] ); @@ -83,7 +83,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_new_item"), + attr("method", "execute_create_item"), attr("new_entry_id", "2") ] ); diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index 6ae9727..7a8b159 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -29,7 +29,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -45,7 +45,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 326499f..8ff4a35 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_new_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -56,7 +56,7 @@ pub fn execute( channel, logo, particle, - } => execute_create_new_item(deps, info, ticker, chain_id, denom, channel, logo,particle), + } => execute_create_item(deps, info, ticker, chain_id, denom, channel, logo, particle), ExecuteMsg::UpdateEntry { id, ticker, diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index 3517fe6..b90ccf9 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -39,7 +39,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_new_item( +pub fn execute_create_item( deps: DepsMut, info: MessageInfo, ticker: String, diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index 2665fb7..cf0ceac 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -26,7 +26,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("creator".to_string()), + owner: Some(Addr::unchecked("creator".to_string())), } ); //specifying an owner address in the instantiation message @@ -42,7 +42,7 @@ mod tests { assert_eq!( state, Config { - owner: Addr::unchecked("specified_owner".to_string()), + owner: Some(Addr::unchecked("specified_owner".to_string())), } ); } From f5f6dab6ca8f0111346beab1f2577a28a3e8be97 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 19:30:17 +0800 Subject: [PATCH 11/33] Refactored queries --- contracts/hub-channels/src/contract.rs | 7 +++++-- contracts/hub-channels/src/msg.rs | 3 ++- contracts/hub-channels/src/query.rs | 25 ++++++++++++------------- contracts/hub-channels/src/tests.rs | 6 +++--- contracts/hub-contracts/src/contract.rs | 7 +++++-- contracts/hub-contracts/src/msg.rs | 3 ++- contracts/hub-contracts/src/query.rs | 15 ++++++++++++++- contracts/hub-contracts/src/tests.rs | 6 +++--- contracts/hub-networks/src/contract.rs | 7 +++++-- contracts/hub-networks/src/msg.rs | 3 ++- contracts/hub-networks/src/query.rs | 17 ++++++++++++++++- contracts/hub-networks/src/tests.rs | 6 +++--- contracts/hub-protocols/src/contract.rs | 7 +++++-- contracts/hub-protocols/src/msg.rs | 3 ++- contracts/hub-protocols/src/query.rs | 10 +++++++++- contracts/hub-protocols/src/tests.rs | 6 +++--- contracts/hub-skills/src/contract.rs | 7 +++++-- contracts/hub-skills/src/msg.rs | 3 ++- contracts/hub-skills/src/query.rs | 13 ++++++++++++- contracts/hub-skills/src/tests.rs | 6 +++--- contracts/hub-tokens/src/contract.rs | 7 +++++-- contracts/hub-tokens/src/msg.rs | 3 ++- contracts/hub-tokens/src/query.rs | 15 ++++++++++++++- contracts/hub-tokens/src/tests.rs | 6 +++--- 24 files changed, 137 insertions(+), 54 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 5c1a8c7..d7cc3dd 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -8,7 +8,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner}; +use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner, query_entry}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -75,9 +75,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit } => { + QueryMsg::GetEntries { start_after, limit } => { to_binary(&query_list(deps, start_after, limit)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index b852f5d..a021a55 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -38,10 +38,11 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index 062fc81..22a3247 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -6,7 +6,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; @@ -184,18 +184,17 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } - - -// fn query_entry(deps: Deps, id: u64) -> StdResult { -// let entry = LIST.load(deps.storage, id)?; -// Ok(EntryResponse { -// id: entry.id, -// description: entry.description, -// status: entry.status, -// priority: entry.priority, -// }) -// } - +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { + id: entry.id, + source_chain_id: entry.source_chain_id, + destination_chain_id: entry.destination_chain_id, + source_channel_id: entry.source_channel_id, + destination_channel_id: entry.destination_channel_id, + explorer_url: entry.explorer_url + }) +} pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index 646e2e3..38cafe5 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -96,7 +96,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -151,7 +151,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -197,7 +197,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 7009335..e3e8c47 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -73,9 +73,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit } => { + QueryMsg::GetEntries { start_after, limit } => { to_binary(&query_list(deps, start_after, limit)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-contracts/src/msg.rs b/contracts/hub-contracts/src/msg.rs index 15939c6..5088786 100644 --- a/contracts/hub-contracts/src/msg.rs +++ b/contracts/hub-contracts/src/msg.rs @@ -37,10 +37,11 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-contracts/src/query.rs b/contracts/hub-contracts/src/query.rs index 2e19098..241b625 100644 --- a/contracts/hub-contracts/src/query.rs +++ b/contracts/hub-contracts/src/query.rs @@ -5,7 +5,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule,validate_ipfs_cid,validate_url}; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; @@ -184,6 +184,19 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { + id: entry.id, + address: entry.address, + query_cid: entry.query_cid, + execute_cid: entry.execute_cid, + version: entry.version, + chain_id: entry.chain_id, + particle: entry.particle + }) +} + pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-contracts/src/tests.rs b/contracts/hub-contracts/src/tests.rs index f5dcfa7..c1001da 100644 --- a/contracts/hub-contracts/src/tests.rs +++ b/contracts/hub-contracts/src/tests.rs @@ -99,7 +99,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -156,7 +156,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -202,7 +202,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index de16375..a505a05 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -77,9 +77,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit } => { + QueryMsg::GetEntries { start_after, limit } => { to_binary(&query_list(deps, start_after, limit)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-networks/src/msg.rs b/contracts/hub-networks/src/msg.rs index 1569fc8..deca774 100644 --- a/contracts/hub-networks/src/msg.rs +++ b/contracts/hub-networks/src/msg.rs @@ -41,10 +41,11 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index 8feaa18..bd3abd7 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -6,7 +6,7 @@ use std::ops::Add; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; @@ -213,6 +213,21 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { + id, + name: entry.name, + chain_id: entry.chain_id, + prefix: entry.prefix, + genesis_hash: entry.genesis_hash, + protocol: entry.protocol, + unbonding_period: entry.unbonding_period, + logo: entry.logo, + particle: entry.particle + }) +} + pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index f75ccb1..00338a5 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -100,7 +100,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -163,7 +163,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -213,7 +213,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index f9c96b1..3ba1ca8 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -65,9 +65,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit } => { + QueryMsg::GetEntries { start_after, limit } => { to_binary(&query_list(deps, start_after, limit)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-protocols/src/msg.rs b/contracts/hub-protocols/src/msg.rs index 28aab74..7c9db17 100644 --- a/contracts/hub-protocols/src/msg.rs +++ b/contracts/hub-protocols/src/msg.rs @@ -29,10 +29,11 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index 0d72150..30237a7 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -5,7 +5,7 @@ use std::ops::Add; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; use crate::validating::{validate_particle,validate_datatype}; @@ -132,6 +132,14 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { + id, + data_type: entry.data_type, + particle: entry.particle + }) +} pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; diff --git a/contracts/hub-protocols/src/tests.rs b/contracts/hub-protocols/src/tests.rs index 6bad543..a5da6a4 100644 --- a/contracts/hub-protocols/src/tests.rs +++ b/contracts/hub-protocols/src/tests.rs @@ -92,7 +92,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -139,7 +139,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -178,7 +178,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index fb4354b..1b85ead 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -5,7 +5,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -69,9 +69,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit, protocol, owner } => { + QueryMsg::GetEntries { start_after, limit, protocol, owner } => { to_binary(&query_list(deps, start_after, limit, protocol, owner)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index 808fabd..d57b2a2 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -40,12 +40,13 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, owner: Option, protocol: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 6dbe3f3..380e86c 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -5,7 +5,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule,validate_ipfs_cid, validate_url}; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{CONFIG, Entry, ENTRY_SEQ, items}; const MAX_LIMIT: u32 = 50; @@ -168,6 +168,17 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = items().load(deps.storage, id)?; + Ok(EntryResponse { + id, + neuron: entry.neuron, + protocol: entry.protocol, + endpoint: entry.endpoint, + particle: entry.particle + }) +} + pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _protocol: Option, owner: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index 7a8b159..24bcf53 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -98,7 +98,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, protocol: None, @@ -157,7 +157,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, protocol: None, @@ -205,7 +205,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, protocol: None, owner: Some(Addr::unchecked("creator")), diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 8ff4a35..f2a7dc7 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -75,9 +75,12 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetItems { start_after, limit } => { + QueryMsg::GetEntries { start_after, limit } => { to_binary(&query_list(deps, start_after, limit)?) } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } } } diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index 6e11a3f..d1f053b 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -38,10 +38,11 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - GetItems { + GetEntries { start_after: Option, limit: Option, }, + GetEntry { id: u64 } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index b90ccf9..60868e6 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -8,7 +8,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule, validate_by_basic_uppercase_rule, validate_ipfs_cid}; use crate::error::ContractError; -use crate::msg::{ListResponse}; +use crate::msg::{EntryResponse, ListResponse}; use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; const MAX_LIMIT: u32 = 30; @@ -180,6 +180,19 @@ pub fn execute_delete_entry( .add_attribute("deleted_entry_id", id.to_string())) } +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { + id, + ticker: entry.ticker, + chain_id: entry.chain_id, + denom: entry.denom, + channel: entry.channel, + logo: entry.logo, + particle: entry.particle + }) +} + pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index cf0ceac..a6e42ee 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -97,7 +97,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -154,7 +154,7 @@ mod tests { let res = query( deps.as_ref(), env.clone(), - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, @@ -200,7 +200,7 @@ mod tests { let res = query( deps.as_ref(), env, - QueryMsg::GetItems { + QueryMsg::GetEntries { start_after: None, limit: None, }, From 3a6337958b6601d9ec86874d5b8a6d102bf9fdf7 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 19:38:00 +0800 Subject: [PATCH 12/33] Added entry owner to skills contract --- contracts/hub-skills/src/contract.rs | 3 ++- contracts/hub-skills/src/msg.rs | 5 +++- contracts/hub-skills/src/query.rs | 35 ++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index 1b85ead..4f28126 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -5,7 +5,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_item, execute_delete_entry, execute_update_entry_owner, execute_update_item, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -47,6 +47,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), + ExecuteMsg::UpdateEntryOwner { id, new_owner } => execute_update_entry_owner(deps, env, info, id, new_owner), ExecuteMsg::NewEntry { neuron, protocol, diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index d57b2a2..41c7805 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -16,7 +16,10 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - // TODO add change owner item + UpdateEntryOwner { + id: u64, + new_owner: String, + }, NewEntry { neuron: String, network: String, diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 380e86c..4df89ae 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -40,6 +40,36 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } +pub fn execute_update_entry_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + id: u64, + new_owner: String, +) -> Result { + let entry = items().load(deps.storage, id)?; + + if entry.owner != info.sender { + return Err(ContractError::Unauthorized {}); + } + + let updated_entry = Entry { + id, + neuron: entry.neuron, + network: entry.network, + protocol: entry.protocol, + endpoint: entry.endpoint, + owner: deps.api.addr_validate(&new_owner)?, + particle: entry.particle, + }; + + items().save(deps.storage, id, &updated_entry)?; + + Ok(Response::new() + .add_attribute("method", "execute_update_entry_owner") + .add_attribute("updated_entry_id", id.to_string())) +} + pub fn execute_create_item( deps: DepsMut, info: MessageInfo, @@ -49,7 +79,6 @@ pub fn execute_create_item( endpoint: String, particle: Option, ) -> Result { - if !particle.as_ref().is_none() { let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); if validate_particle.is_err() { @@ -127,7 +156,6 @@ pub fn execute_update_item( if validate_endpoint.is_err() { return validate_endpoint; } - let entry = items().load(deps.storage, id)?; @@ -144,7 +172,9 @@ pub fn execute_update_item( owner: entry.owner, particle: particle.unwrap_or("".to_string()), }; + items().save(deps.storage, id, &updated_entry)?; + Ok(Response::new() .add_attribute("method", "execute_update_item") .add_attribute("updated_entry_id", id.to_string())) @@ -200,5 +230,6 @@ pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _pr let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } From 40a746c834dfd0528f675fb80541ffe407eb55fe Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 20:02:12 +0800 Subject: [PATCH 13/33] Refactoring --- contracts/hub-channels/src/contract.rs | 6 +++--- contracts/hub-channels/src/query.rs | 8 +++---- contracts/hub-channels/src/tests.rs | 6 +++--- contracts/hub-contracts/src/contract.rs | 6 +++--- contracts/hub-contracts/src/query.rs | 8 +++---- contracts/hub-contracts/src/state.rs | 1 - contracts/hub-contracts/src/tests.rs | 6 +++--- contracts/hub-networks/src/contract.rs | 6 +++--- contracts/hub-networks/src/query.rs | 8 +++---- contracts/hub-networks/src/tests.rs | 6 +++--- contracts/hub-protocols/src/contract.rs | 6 +++--- contracts/hub-protocols/src/query.rs | 8 +++---- contracts/hub-protocols/src/state.rs | 1 - contracts/hub-protocols/src/tests.rs | 6 +++--- contracts/hub-skills/src/contract.rs | 6 +++--- contracts/hub-skills/src/msg.rs | 1 - contracts/hub-skills/src/query.rs | 28 ++++++++++++------------- contracts/hub-skills/src/state.rs | 4 ++-- contracts/hub-skills/src/tests.rs | 6 +++--- contracts/hub-tokens/src/contract.rs | 6 +++--- contracts/hub-tokens/src/query.rs | 8 +++---- contracts/hub-tokens/src/tests.rs | 6 +++--- 22 files changed, 72 insertions(+), 75 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index d7cc3dd..c4241b3 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -8,7 +8,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_item, execute_update_item, execute_delete_entry, execute_update_owner, query_entry}; +use crate::query::{query_list, execute_create_entry, execute_update_entry, execute_delete_entry, execute_update_owner, query_entry}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -58,7 +58,7 @@ pub fn execute( explorer_url, particle - } => execute_create_item(deps, info, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), + } => execute_create_entry(deps, info, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::UpdateEntry { id, source_chain_id, @@ -67,7 +67,7 @@ pub fn execute( destination_channel_id, explorer_url, particle, - } => execute_update_item(deps, info, id, source_chain_id,destination_chain_id,source_channel_id, destination_channel_id, explorer_url, particle), + } => execute_update_entry(deps, info, id, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index 22a3247..d4f84e9 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -37,7 +37,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, source_chain_id: String, @@ -97,11 +97,11 @@ pub fn execute_create_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -161,7 +161,7 @@ pub fn execute_update_item( }; LIST.save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index 38cafe5..c57dd05 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -69,7 +69,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -87,7 +87,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -142,7 +142,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index e3e8c47..440ff2a 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -56,7 +56,7 @@ pub fn execute( version, chain_id, particle, - } => execute_create_item(deps, info, address, query_cid, execute_cid, version, chain_id, particle), + } => execute_create_entry(deps, info, address, query_cid, execute_cid, version, chain_id, particle), ExecuteMsg::UpdateEntry { id, address, @@ -65,7 +65,7 @@ pub fn execute( version, chain_id, particle, - } => execute_update_item(deps, info, id, address,query_cid,execute_cid,version,chain_id, particle), + } => execute_update_entry(deps, info, id, address, query_cid, execute_cid, version, chain_id, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-contracts/src/query.rs b/contracts/hub-contracts/src/query.rs index 241b625..ab0ae76 100644 --- a/contracts/hub-contracts/src/query.rs +++ b/contracts/hub-contracts/src/query.rs @@ -36,7 +36,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, address: String, @@ -96,11 +96,11 @@ pub fn execute_create_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -161,7 +161,7 @@ pub fn execute_update_item( LIST.save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } diff --git a/contracts/hub-contracts/src/state.rs b/contracts/hub-contracts/src/state.rs index 6a12a0e..2765e3d 100644 --- a/contracts/hub-contracts/src/state.rs +++ b/contracts/hub-contracts/src/state.rs @@ -21,7 +21,6 @@ pub struct Entry { pub particle: String, } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-contracts/src/tests.rs b/contracts/hub-contracts/src/tests.rs index c1001da..69191f7 100644 --- a/contracts/hub-contracts/src/tests.rs +++ b/contracts/hub-contracts/src/tests.rs @@ -72,7 +72,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -90,7 +90,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -145,7 +145,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index a505a05..89bc6fd 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -58,7 +58,7 @@ pub fn execute( unbonding_period, logo, particle, - } => execute_create_item(deps, info, name, chain_id, prefix, genesis_hash, protocol, unbonding_period, logo, particle), + } => execute_create_entry(deps, info, name, chain_id, prefix, genesis_hash, protocol, unbonding_period, logo, particle), ExecuteMsg::UpdateEntry { id, name, @@ -69,7 +69,7 @@ pub fn execute( unbonding_period, logo, particle, - } => execute_update_item(deps, info, id, name,chain_id,prefix,genesis_hash,protocol,unbonding_period, logo,particle), + } => execute_update_entry(deps, info, id, name, chain_id, prefix, genesis_hash, protocol, unbonding_period, logo, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index bd3abd7..6afc72b 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -37,7 +37,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, name: String, @@ -110,11 +110,11 @@ pub fn execute_create_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -190,7 +190,7 @@ pub fn execute_update_item( }; LIST.save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index 00338a5..358ac60 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -71,7 +71,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -91,7 +91,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -152,7 +152,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 3ba1ca8..542c24e 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -52,12 +52,12 @@ pub fn execute( ExecuteMsg::NewEntry { data_type, particle, - } => execute_create_item(deps, info, data_type, particle), + } => execute_create_entry(deps, info, data_type, particle), ExecuteMsg::UpdateEntry { id, data_type, particle, - } => execute_update_item(deps, info, id, data_type, particle), + } => execute_update_entry(deps, info, id, data_type, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index 30237a7..148b1bd 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -37,7 +37,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, data_type: String, @@ -72,11 +72,11 @@ pub fn execute_create_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -109,7 +109,7 @@ pub fn execute_update_item( }; LIST.save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } diff --git a/contracts/hub-protocols/src/state.rs b/contracts/hub-protocols/src/state.rs index 3585bcc..df2df04 100644 --- a/contracts/hub-protocols/src/state.rs +++ b/contracts/hub-protocols/src/state.rs @@ -16,7 +16,6 @@ pub struct Entry { pub particle: String, } - pub const CONFIG: Item = Item::new("config"); pub const ENTRY_SEQ: Item = Item::new("entry_seq"); pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-protocols/src/tests.rs b/contracts/hub-protocols/src/tests.rs index a5da6a4..9a72610 100644 --- a/contracts/hub-protocols/src/tests.rs +++ b/contracts/hub-protocols/src/tests.rs @@ -68,7 +68,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -83,7 +83,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -128,7 +128,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index 4f28126..b7aea51 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -5,7 +5,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_entry_owner, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry_owner, execute_update_entry, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -54,7 +54,7 @@ pub fn execute( network, endpoint, particle, - } => execute_create_item(deps, info, neuron, network, protocol, endpoint, particle), + } => execute_create_entry(deps, info, neuron, network, protocol, endpoint, particle), ExecuteMsg::UpdateEntry { id, neuron, @@ -62,7 +62,7 @@ pub fn execute( network, endpoint, particle, - } => execute_update_item(deps, info, id, neuron, network, protocol, endpoint, particle), + } => execute_update_entry(deps, info, id, neuron, network, protocol, endpoint, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index 41c7805..e026453 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -55,7 +55,6 @@ pub enum QueryMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct MigrateMsg {} -// Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 4df89ae..1959d13 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -6,7 +6,7 @@ use std::ops::Add; use crate::validating::{validate_by_basic_rule,validate_ipfs_cid, validate_url}; use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{CONFIG, Entry, ENTRY_SEQ, items}; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, entries}; const MAX_LIMIT: u32 = 50; const DEFAULT_LIMIT: u32 = 30; @@ -47,7 +47,7 @@ pub fn execute_update_entry_owner( id: u64, new_owner: String, ) -> Result { - let entry = items().load(deps.storage, id)?; + let entry = entries().load(deps.storage, id)?; if entry.owner != info.sender { return Err(ContractError::Unauthorized {}); @@ -63,14 +63,14 @@ pub fn execute_update_entry_owner( particle: entry.particle, }; - items().save(deps.storage, id, &updated_entry)?; + entries().save(deps.storage, id, &updated_entry)?; Ok(Response::new() .add_attribute("method", "execute_update_entry_owner") .add_attribute("updated_entry_id", id.to_string())) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, neuron: String, @@ -116,13 +116,13 @@ pub fn execute_create_item( particle: particle.unwrap_or("".to_string()) }; - items().save(deps.storage, id, &new_entry)?; + entries().save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -157,7 +157,7 @@ pub fn execute_update_item( return validate_endpoint; } - let entry = items().load(deps.storage, id)?; + let entry = entries().load(deps.storage, id)?; if entry.owner != info.sender { return Err(ContractError::Unauthorized {}); @@ -173,10 +173,10 @@ pub fn execute_update_item( particle: particle.unwrap_or("".to_string()), }; - items().save(deps.storage, id, &updated_entry)?; + entries().save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } @@ -185,13 +185,13 @@ pub fn execute_delete_entry( info: MessageInfo, id: u64, ) -> Result { - let entry = items().load(deps.storage, id)?; + let entry = entries().load(deps.storage, id)?; if entry.owner != info.sender { return Err(ContractError::Unauthorized {}); } - let _result = items().remove(deps.storage, id); + let _result = entries().remove(deps.storage, id); Ok(Response::new() .add_attribute("method", "execute_delete_entry") @@ -199,7 +199,7 @@ pub fn execute_delete_entry( } pub fn query_entry(deps: Deps, id: u64) -> StdResult { - let entry = items().load(deps.storage, id)?; + let entry = entries().load(deps.storage, id)?; Ok(EntryResponse { id, neuron: entry.neuron, @@ -212,7 +212,7 @@ pub fn query_entry(deps: Deps, id: u64) -> StdResult { pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _protocol: Option, owner: Option) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let indexed_arr = items().idx.owner; + let indexed_arr = entries().idx.owner; // TODO add start_after and protocol diff --git a/contracts/hub-skills/src/state.rs b/contracts/hub-skills/src/state.rs index be913b1..cc5675d 100644 --- a/contracts/hub-skills/src/state.rs +++ b/contracts/hub-skills/src/state.rs @@ -37,7 +37,7 @@ impl<'a> IndexList for EntryIndexes<'a> { } } -pub fn items<'a>() -> IndexedMap<'a, u64, Entry, EntryIndexes<'a>> { +pub fn entries<'a>() -> IndexedMap<'a, u64, Entry, EntryIndexes<'a>> { let indexes = EntryIndexes { owner: MultiIndex::new( |d| (d.owner.clone().to_string()), @@ -45,7 +45,7 @@ pub fn items<'a>() -> IndexedMap<'a, u64, Entry, EntryIndexes<'a>> { "list_owner" ), network: MultiIndex::new( - |d| (d.owner.clone().to_string()), + |d| (d.network.clone().to_string()), "list", "list_network" ), diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index 24bcf53..2d9d975 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -72,7 +72,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -89,7 +89,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -146,7 +146,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index f2a7dc7..cca7ab5 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -7,7 +7,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_item, execute_delete_entry, execute_update_item, execute_update_owner, query_entry, query_list}; +use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -56,7 +56,7 @@ pub fn execute( channel, logo, particle, - } => execute_create_item(deps, info, ticker, chain_id, denom, channel, logo, particle), + } => execute_create_entry(deps, info, ticker, chain_id, denom, channel, logo, particle), ExecuteMsg::UpdateEntry { id, ticker, @@ -65,7 +65,7 @@ pub fn execute( channel, logo, particle, - } => execute_update_item(deps, info, id, ticker, chain_id, denom, channel, logo, particle), + } => execute_update_entry(deps, info, id, ticker, chain_id, denom, channel, logo, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index 60868e6..f56b8ce 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -39,7 +39,7 @@ pub fn execute_update_owner( Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) } -pub fn execute_create_item( +pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, ticker: String, @@ -95,11 +95,11 @@ pub fn execute_create_item( }; LIST.save(deps.storage, id, &new_entry)?; Ok(Response::new() - .add_attribute("method", "execute_create_item") + .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) } -pub fn execute_update_item( +pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, @@ -157,7 +157,7 @@ pub fn execute_update_item( }; LIST.save(deps.storage, id, &updated_entry)?; Ok(Response::new() - .add_attribute("method", "execute_update_item") + .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) } diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index a6e42ee..a71eb30 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -70,7 +70,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "1") ] ); @@ -88,7 +88,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_create_item"), + attr("method", "execute_create_entry"), attr("new_entry_id", "2") ] ); @@ -143,7 +143,7 @@ mod tests { assert_eq!( res.attributes, vec![ - attr("method", "execute_update_item"), + attr("method", "execute_update_entry"), attr("updated_entry_id", "1") ] ); From c43b2774d1196f77ce471f1fb8115f5d20d49aaa Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 20:03:58 +0800 Subject: [PATCH 14/33] Refactoring --- contracts/hub-channels/src/contract.rs | 2 +- contracts/hub-channels/src/msg.rs | 2 +- contracts/hub-channels/src/tests.rs | 4 ++-- contracts/hub-contracts/src/contract.rs | 2 +- contracts/hub-contracts/src/msg.rs | 2 +- contracts/hub-contracts/src/tests.rs | 4 ++-- contracts/hub-networks/src/contract.rs | 2 +- contracts/hub-networks/src/msg.rs | 2 +- contracts/hub-networks/src/tests.rs | 4 ++-- contracts/hub-protocols/src/contract.rs | 2 +- contracts/hub-protocols/src/msg.rs | 3 +-- contracts/hub-protocols/src/tests.rs | 4 ++-- contracts/hub-skills/src/contract.rs | 2 +- contracts/hub-skills/src/msg.rs | 2 +- contracts/hub-skills/src/tests.rs | 4 ++-- contracts/hub-tokens/src/contract.rs | 2 +- contracts/hub-tokens/src/msg.rs | 3 +-- contracts/hub-tokens/src/tests.rs | 4 ++-- 18 files changed, 24 insertions(+), 26 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index c4241b3..77056d0 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -50,7 +50,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { source_chain_id, destination_chain_id, source_channel_id, diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index a021a55..e1d91f1 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -13,7 +13,7 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - NewEntry { + CreateEntry { source_chain_id: String, destination_chain_id: String, source_channel_id: String, diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index c57dd05..32dbb81 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -56,7 +56,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -74,7 +74,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 440ff2a..20ae9f6 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -49,7 +49,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { address, query_cid, execute_cid, diff --git a/contracts/hub-contracts/src/msg.rs b/contracts/hub-contracts/src/msg.rs index 5088786..0f9d8d6 100644 --- a/contracts/hub-contracts/src/msg.rs +++ b/contracts/hub-contracts/src/msg.rs @@ -12,7 +12,7 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - NewEntry { + CreateEntry { address: String, query_cid: String, execute_cid: String, diff --git a/contracts/hub-contracts/src/tests.rs b/contracts/hub-contracts/src/tests.rs index 69191f7..fea41f6 100644 --- a/contracts/hub-contracts/src/tests.rs +++ b/contracts/hub-contracts/src/tests.rs @@ -59,7 +59,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), query_cid: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), execute_cid: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -77,7 +77,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), query_cid: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), execute_cid: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index 89bc6fd..f53dfc9 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -49,7 +49,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { name, chain_id, prefix, diff --git a/contracts/hub-networks/src/msg.rs b/contracts/hub-networks/src/msg.rs index deca774..119b2dd 100644 --- a/contracts/hub-networks/src/msg.rs +++ b/contracts/hub-networks/src/msg.rs @@ -12,7 +12,7 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - NewEntry { + CreateEntry { name: String, chain_id: String, prefix: String, diff --git a/contracts/hub-networks/src/tests.rs b/contracts/hub-networks/src/tests.rs index 358ac60..5f883d9 100644 --- a/contracts/hub-networks/src/tests.rs +++ b/contracts/hub-networks/src/tests.rs @@ -56,7 +56,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { name: "tst".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), @@ -76,7 +76,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { name: "tst2".to_string(), protocol: "tst2".to_string(), chain_id: "cyber-1".to_string(), diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 542c24e..2df036c 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -49,7 +49,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { data_type, particle, } => execute_create_entry(deps, info, data_type, particle), diff --git a/contracts/hub-protocols/src/msg.rs b/contracts/hub-protocols/src/msg.rs index 7c9db17..9c7ad90 100644 --- a/contracts/hub-protocols/src/msg.rs +++ b/contracts/hub-protocols/src/msg.rs @@ -12,7 +12,7 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - NewEntry { + CreateEntry { data_type: String, particle: Option, }, @@ -39,7 +39,6 @@ pub enum QueryMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct MigrateMsg {} -// Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, diff --git a/contracts/hub-protocols/src/tests.rs b/contracts/hub-protocols/src/tests.rs index 9a72610..06af673 100644 --- a/contracts/hub-protocols/src/tests.rs +++ b/contracts/hub-protocols/src/tests.rs @@ -59,7 +59,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { data_type: "testchain-1".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -73,7 +73,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { data_type: "testchain-1".to_string(), // particle: None, particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index b7aea51..696e906 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -48,7 +48,7 @@ pub fn execute( match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::UpdateEntryOwner { id, new_owner } => execute_update_entry_owner(deps, env, info, id, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { neuron, protocol, network, diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index e026453..4665fb4 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -20,7 +20,7 @@ pub enum ExecuteMsg { id: u64, new_owner: String, }, - NewEntry { + CreateEntry { neuron: String, network: String, protocol: String, diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index 2d9d975..590bd04 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -60,7 +60,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { neuron: "testchain-1".to_string(), network: "cosmos".to_string(), protocol: "testchain-1".to_string(), @@ -77,7 +77,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { neuron: "testchain-1".to_string(), network: "cosmos".to_string(), protocol: "testchain-1".to_string(), diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index cca7ab5..34ac900 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -49,7 +49,7 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), - ExecuteMsg::NewEntry { + ExecuteMsg::CreateEntry { ticker, chain_id, denom, diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index d1f053b..fb97fec 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -13,7 +13,7 @@ pub enum ExecuteMsg { UpdateOwner { new_owner: Option, }, - NewEntry { + CreateEntry { ticker: String, chain_id: String, denom: String, @@ -48,7 +48,6 @@ pub enum QueryMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct MigrateMsg {} -// Tokens #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index a71eb30..bab8a60 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -57,7 +57,7 @@ mod tests { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!(0, res.messages.len()); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { chain_id: "testchain-1".to_string(), ticker: "TST".to_string(), denom: "cyb".to_string(), @@ -75,7 +75,7 @@ mod tests { ] ); - let msg = ExecuteMsg::NewEntry { + let msg = ExecuteMsg::CreateEntry { ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), denom: "cyb".to_string(), From a9dbabcbf37c8eef01f0767ea97a48f96fee2a2e Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 20:17:42 +0800 Subject: [PATCH 15/33] Refactoring --- Cargo.toml | 24 +++++++++++++++++++++++ contracts/hub-channels/Cargo.toml | 11 ----------- contracts/hub-channels/src/validating.rs | 8 ++++---- contracts/hub-contracts/Cargo.toml | 11 ----------- contracts/hub-contracts/src/validating.rs | 8 ++++---- contracts/hub-networks/Cargo.toml | 11 ----------- contracts/hub-networks/src/validating.rs | 8 ++++---- contracts/hub-protocols/Cargo.toml | 11 ----------- contracts/hub-skills/Cargo.toml | 11 ----------- contracts/hub-skills/src/validating.rs | 8 ++++---- contracts/hub-tokens/Cargo.toml | 11 ----------- contracts/hub-tokens/src/validating.rs | 8 ++++---- 12 files changed, 44 insertions(+), 86 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccf8c5f..9d64095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,30 @@ incremental = false codegen-units = 1 incremental = false +[profile.release.package.hub-channels] +codegen-units = 1 +incremental = false + +[profile.release.package.hub-contracts] +codegen-units = 1 +incremental = false + +[profile.release.package.hub-networks] +codegen-units = 1 +incremental = false + +[profile.release.package.hub-protocols] +codegen-units = 1 +incremental = false + +[profile.release.package.hub-skills] +codegen-units = 1 +incremental = false + +[profile.release.package.hub-tokens] +codegen-units = 1 +incremental = false + [profile.release] rpath = false lto = true diff --git a/contracts/hub-channels/Cargo.toml b/contracts/hub-channels/Cargo.toml index 061c6e5..55d79e6 100644 --- a/contracts/hub-channels/Cargo.toml +++ b/contracts/hub-channels/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-channels/src/validating.rs b/contracts/hub-channels/src/validating.rs index f60918f..09a11d3 100644 --- a/contracts/hub-channels/src/validating.rs +++ b/contracts/hub-channels/src/validating.rs @@ -5,8 +5,8 @@ use cosmwasm_std::{ Response, }; -/** - * Baseic rule /[a-z0-9-]/ +/* + * Basic rule /[a-z0-9-]/ */ pub fn validate_by_basic_rule( val: String, @@ -23,8 +23,8 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } -/** - * Baseic rule /[A-Z0-9]/ +/* + * Basic rule /[A-Z0-9]/ */ pub fn validate_by_basic_uppercase_rule( val: String, diff --git a/contracts/hub-contracts/Cargo.toml b/contracts/hub-contracts/Cargo.toml index 88caf23..7b7b91f 100644 --- a/contracts/hub-contracts/Cargo.toml +++ b/contracts/hub-contracts/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-contracts/src/validating.rs b/contracts/hub-contracts/src/validating.rs index f18cd97..bf1c207 100644 --- a/contracts/hub-contracts/src/validating.rs +++ b/contracts/hub-contracts/src/validating.rs @@ -5,8 +5,8 @@ use cosmwasm_std::{ Response, }; -/** - * Baseic rule /[a-z0-9-]/ +/* + * Basic rule /[a-z0-9-]/ */ pub fn validate_by_basic_rule( val: String, @@ -23,8 +23,8 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } -/** - * Baseic rule /[A-Z0-9]/ +/* + * Basic rule /[A-Z0-9]/ */ pub fn validate_by_basic_uppercase_rule( val: String, diff --git a/contracts/hub-networks/Cargo.toml b/contracts/hub-networks/Cargo.toml index 10f8905..dab20bb 100644 --- a/contracts/hub-networks/Cargo.toml +++ b/contracts/hub-networks/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-networks/src/validating.rs b/contracts/hub-networks/src/validating.rs index 5ff295b..fce6f91 100644 --- a/contracts/hub-networks/src/validating.rs +++ b/contracts/hub-networks/src/validating.rs @@ -5,8 +5,8 @@ use cosmwasm_std::{ Response, }; -/** - * Baseic rule /[a-z0-9-]/ +/* + * Basic rule /[a-z0-9-]/ */ pub fn validate_by_basic_rule( val: String, @@ -23,8 +23,8 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } -/** - * Baseic rule /[0-9]/ +/* + * Basic rule /[0-9]/ */ pub fn validate_period( val: String, diff --git a/contracts/hub-protocols/Cargo.toml b/contracts/hub-protocols/Cargo.toml index fb31c94..dcb57e1 100644 --- a/contracts/hub-protocols/Cargo.toml +++ b/contracts/hub-protocols/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-skills/Cargo.toml b/contracts/hub-skills/Cargo.toml index 7eb5120..5577a3c 100644 --- a/contracts/hub-skills/Cargo.toml +++ b/contracts/hub-skills/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-skills/src/validating.rs b/contracts/hub-skills/src/validating.rs index 06a0815..0adbfc7 100644 --- a/contracts/hub-skills/src/validating.rs +++ b/contracts/hub-skills/src/validating.rs @@ -6,8 +6,8 @@ use cosmwasm_std::{ Response, }; -/** - * Baseic rule /[a-z0-9-]/ +/* + * Basic rule /[a-z0-9-]/ */ pub fn validate_by_basic_rule( val: String, @@ -24,8 +24,8 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } -/** - * Baseic rule /[A-Z0-9]/ +/* + * Basic rule /[A-Z0-9]/ */ pub fn validate_by_basic_uppercase_rule( val: String, diff --git a/contracts/hub-tokens/Cargo.toml b/contracts/hub-tokens/Cargo.toml index 740277f..c52f4b2 100644 --- a/contracts/hub-tokens/Cargo.toml +++ b/contracts/hub-tokens/Cargo.toml @@ -15,17 +15,6 @@ exclude = [ [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] # for more explicit tests, cargo test --features=backtraces backtraces = ["cosmwasm-std/backtraces"] diff --git a/contracts/hub-tokens/src/validating.rs b/contracts/hub-tokens/src/validating.rs index 06a0815..0adbfc7 100644 --- a/contracts/hub-tokens/src/validating.rs +++ b/contracts/hub-tokens/src/validating.rs @@ -6,8 +6,8 @@ use cosmwasm_std::{ Response, }; -/** - * Baseic rule /[a-z0-9-]/ +/* + * Basic rule /[a-z0-9-]/ */ pub fn validate_by_basic_rule( val: String, @@ -24,8 +24,8 @@ pub fn validate_by_basic_rule( Ok(Response::default()) } -/** - * Baseic rule /[A-Z0-9]/ +/* + * Basic rule /[A-Z0-9]/ */ pub fn validate_by_basic_uppercase_rule( val: String, From 5ce12d615d768a4d7d3f02d5dd2d3c0151d9dd93 Mon Sep 17 00:00:00 2001 From: C H Date: Wed, 30 Nov 2022 20:33:42 +0800 Subject: [PATCH 16/33] Refactoring --- contracts/hub-channels/src/contract.rs | 6 +- contracts/hub-channels/src/execute.rs | 179 ++++++++++++++++++++ contracts/hub-channels/src/lib.rs | 3 +- contracts/hub-channels/src/query.rs | 183 +------------------- contracts/hub-contracts/src/contract.rs | 3 +- contracts/hub-contracts/src/execute.rs | 180 ++++++++++++++++++++ contracts/hub-contracts/src/lib.rs | 3 +- contracts/hub-contracts/src/query.rs | 183 +------------------- contracts/hub-networks/src/contract.rs | 3 +- contracts/hub-networks/src/execute.rs | 208 +++++++++++++++++++++++ contracts/hub-networks/src/lib.rs | 3 +- contracts/hub-networks/src/query.rs | 212 +----------------------- contracts/hub-protocols/src/contract.rs | 3 +- contracts/hub-protocols/src/execute.rs | 127 ++++++++++++++ contracts/hub-protocols/src/lib.rs | 3 +- contracts/hub-protocols/src/query.rs | 129 +------------- contracts/hub-skills/src/contract.rs | 3 +- contracts/hub-skills/src/execute.rs | 194 ++++++++++++++++++++++ contracts/hub-skills/src/lib.rs | 3 +- contracts/hub-skills/src/query.rs | 201 +--------------------- contracts/hub-tokens/src/contract.rs | 3 +- contracts/hub-tokens/src/execute.rs | 174 +++++++++++++++++++ contracts/hub-tokens/src/lib.rs | 3 +- contracts/hub-tokens/src/query.rs | 179 +------------------- 24 files changed, 1106 insertions(+), 1082 deletions(-) create mode 100644 contracts/hub-channels/src/execute.rs create mode 100644 contracts/hub-contracts/src/execute.rs create mode 100644 contracts/hub-networks/src/execute.rs create mode 100644 contracts/hub-protocols/src/execute.rs create mode 100644 contracts/hub-skills/src/execute.rs create mode 100644 contracts/hub-tokens/src/execute.rs diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 77056d0..916350d 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -1,14 +1,14 @@ use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; - use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{query_list, execute_create_entry, execute_update_entry, execute_delete_entry, execute_update_owner, query_entry}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-channels/src/execute.rs b/contracts/hub-channels/src/execute.rs new file mode 100644 index 0000000..04c8893 --- /dev/null +++ b/contracts/hub-channels/src/execute.rs @@ -0,0 +1,179 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + source_chain_id: String, + destination_chain_id: String, + source_channel_id: String, + destination_channel_id: String, + explorer_url: String, + particle: Option +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_source_chain_id = validate_by_basic_rule(source_chain_id.clone(), "source_chain_id".to_string()); + let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone(), "destination_chain_id".to_string()); + let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone(), "source_channel_id".to_string()); + let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone(), "destination_channel_id".to_string()); + let validate_explorer_url = validate_url(explorer_url.clone(), "explorer_url".to_string()); + + if validate_source_chain_id.is_err() { + return validate_source_chain_id; + } + if validate_destination_chain_id.is_err() { + return validate_destination_chain_id; + } + if validate_source_channel_id.is_err() { + return validate_source_channel_id; + } + if validate_destination_channel_id.is_err() { + return validate_destination_channel_id; + } + if validate_explorer_url.is_err() { + return validate_explorer_url; + } + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + source_chain_id, + destination_chain_id, + source_channel_id, + destination_channel_id, + explorer_url, + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + source_chain_id: Option, + destination_chain_id: Option, + source_channel_id: Option, + destination_channel_id: Option, + explorer_url: Option, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_source_chain_id = validate_by_basic_rule(source_chain_id.clone().unwrap(), "source_chain_id".to_string()); + let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone().unwrap(), "destination_chain_id".to_string()); + let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone().unwrap(), "source_channel_id".to_string()); + let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone().unwrap(), "destination_channel_id".to_string()); + let validate_explorer_url = validate_url(explorer_url.clone().unwrap(), "explorer_url".to_string()); + + if validate_source_chain_id.is_err() { + return validate_source_chain_id; + } + if validate_destination_chain_id.is_err() { + return validate_destination_chain_id; + } + if validate_source_channel_id.is_err() { + return validate_source_channel_id; + } + if validate_destination_channel_id.is_err() { + return validate_destination_channel_id; + } + if validate_explorer_url.is_err() { + return validate_explorer_url; + } + + let entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + source_chain_id: source_chain_id.unwrap_or(entry.source_chain_id), + destination_chain_id: destination_chain_id.unwrap_or(entry.destination_chain_id), + source_channel_id: source_channel_id.unwrap_or(entry.source_channel_id), + destination_channel_id: destination_channel_id.unwrap_or(entry.destination_channel_id), + explorer_url: explorer_url.unwrap_or(entry.explorer_url), + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-channels/src/lib.rs b/contracts/hub-channels/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-channels/src/lib.rs +++ b/contracts/hub-channels/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index d4f84e9..aff1f29 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -1,189 +1,12 @@ -use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; - +use cosmwasm_std::{Deps, Order, StdResult}; use cw_storage_plus::Bound; -use std::ops::Add; - -use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; +use crate::state::LIST; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - source_chain_id: String, - destination_chain_id: String, - source_channel_id: String, - destination_channel_id: String, - explorer_url: String, - particle: Option -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_source_chain_id = validate_by_basic_rule(source_chain_id.clone(), "source_chain_id".to_string()); - let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone(), "destination_chain_id".to_string()); - let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone(), "source_channel_id".to_string()); - let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone(), "destination_channel_id".to_string()); - let validate_explorer_url = validate_url(explorer_url.clone(), "explorer_url".to_string()); - - if validate_source_chain_id.is_err() { - return validate_source_chain_id; - } - if validate_destination_chain_id.is_err() { - return validate_destination_chain_id; - } - if validate_source_channel_id.is_err() { - return validate_source_channel_id; - } - if validate_destination_channel_id.is_err() { - return validate_destination_channel_id; - } - if validate_explorer_url.is_err() { - return validate_explorer_url; - } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - source_chain_id, - destination_chain_id, - source_channel_id, - destination_channel_id, - explorer_url, - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - source_chain_id: Option, - destination_chain_id: Option, - source_channel_id: Option, - destination_channel_id: Option, - explorer_url: Option, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_source_chain_id = validate_by_basic_rule(source_chain_id.clone().unwrap(), "source_chain_id".to_string()); - let validate_destination_chain_id = validate_by_basic_rule(destination_chain_id.clone().unwrap(), "destination_chain_id".to_string()); - let validate_source_channel_id = validate_by_basic_rule(source_channel_id.clone().unwrap(), "source_channel_id".to_string()); - let validate_destination_channel_id = validate_by_basic_rule(destination_channel_id.clone().unwrap(), "destination_channel_id".to_string()); - let validate_explorer_url = validate_url(explorer_url.clone().unwrap(), "explorer_url".to_string()); - - if validate_source_chain_id.is_err() { - return validate_source_chain_id; - } - if validate_destination_chain_id.is_err() { - return validate_destination_chain_id; - } - if validate_source_channel_id.is_err() { - return validate_source_channel_id; - } - if validate_destination_channel_id.is_err() { - return validate_destination_channel_id; - } - if validate_explorer_url.is_err() { - return validate_explorer_url; - } - - let entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - source_chain_id: source_chain_id.unwrap_or(entry.source_chain_id), - destination_chain_id: destination_chain_id.unwrap_or(entry.destination_chain_id), - source_channel_id: source_channel_id.unwrap_or(entry.source_channel_id), - destination_channel_id: destination_channel_id.unwrap_or(entry.destination_channel_id), - explorer_url: explorer_url.unwrap_or(entry.explorer_url), - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; Ok(EntryResponse { @@ -208,4 +31,4 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S entries: entries?.into_iter().map(|l| l.1).collect(), }; Ok(result) -} +} \ No newline at end of file diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 20ae9f6..503cc93 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -6,8 +6,9 @@ use cosmwasm_std::entry_point; use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-contracts/src/execute.rs b/contracts/hub-contracts/src/execute.rs new file mode 100644 index 0000000..0718031 --- /dev/null +++ b/contracts/hub-contracts/src/execute.rs @@ -0,0 +1,180 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + address: String, + query_cid: String, + execute_cid: String, + version: String, + chain_id: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_address = validate_by_basic_rule(address.clone(), "address".to_string()); + let validate_query_cid = validate_ipfs_cid(query_cid.clone(), "query_cid".to_string()); + let validate_execute_cid = validate_ipfs_cid(execute_cid.clone(), "execute_cid".to_string()); + let validate_version = validate_url(version.clone(), "version".to_string()); + let validate_chain_id = validate_url(chain_id.clone(), "chain_id".to_string()); + + if validate_address.is_err() { + return validate_address; + } + if validate_query_cid.is_err() { + return validate_query_cid; + } + if validate_execute_cid.is_err() { + return validate_execute_cid; + } + if validate_version.is_err() { + return validate_version; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + address, + query_cid, + execute_cid, + version, + chain_id, + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + address: Option, + query_cid: Option, + execute_cid: Option, + version: Option, + chain_id: Option, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_address = validate_by_basic_rule(address.clone().unwrap(), "address".to_string()); + let validate_query_cid = validate_ipfs_cid(query_cid.clone().unwrap(), "query_cid".to_string()); + let validate_execute_cid = validate_ipfs_cid(execute_cid.clone().unwrap(), "execute_cid".to_string()); + let validate_version = validate_url(version.clone().unwrap(), "version".to_string()); + let validate_chain_id = validate_url(chain_id.clone().unwrap(), "chain_id".to_string()); + + if validate_address.is_err() { + return validate_address; + } + if validate_query_cid.is_err() { + return validate_query_cid; + } + if validate_execute_cid.is_err() { + return validate_execute_cid; + } + if validate_version.is_err() { + return validate_version; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + let entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + address: address.unwrap_or(entry.address), + query_cid: query_cid.unwrap_or(entry.query_cid), + execute_cid: execute_cid.unwrap_or(entry.execute_cid), + version: version.unwrap_or(entry.version), + chain_id: chain_id.unwrap_or(entry.chain_id), + particle: particle.unwrap_or("".to_string()), + }; + + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-contracts/src/lib.rs b/contracts/hub-contracts/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-contracts/src/lib.rs +++ b/contracts/hub-contracts/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-contracts/src/query.rs b/contracts/hub-contracts/src/query.rs index ab0ae76..c4e2bd0 100644 --- a/contracts/hub-contracts/src/query.rs +++ b/contracts/hub-contracts/src/query.rs @@ -1,189 +1,12 @@ -use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; - +use cosmwasm_std::{Deps, Order, StdResult}; use cw_storage_plus::Bound; -use std::ops::Add; -use crate::validating::{validate_by_basic_rule,validate_ipfs_cid,validate_url}; -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; +use crate::state::LIST; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - address: String, - query_cid: String, - execute_cid: String, - version: String, - chain_id: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_address = validate_by_basic_rule(address.clone(), "address".to_string()); - let validate_query_cid = validate_ipfs_cid(query_cid.clone(), "query_cid".to_string()); - let validate_execute_cid = validate_ipfs_cid(execute_cid.clone(), "execute_cid".to_string()); - let validate_version = validate_url(version.clone(), "version".to_string()); - let validate_chain_id = validate_url(chain_id.clone(), "chain_id".to_string()); - - if validate_address.is_err() { - return validate_address; - } - if validate_query_cid.is_err() { - return validate_query_cid; - } - if validate_execute_cid.is_err() { - return validate_execute_cid; - } - if validate_version.is_err() { - return validate_version; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - address, - query_cid, - execute_cid, - version, - chain_id, - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - address: Option, - query_cid: Option, - execute_cid: Option, - version: Option, - chain_id: Option, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_address = validate_by_basic_rule(address.clone().unwrap(), "address".to_string()); - let validate_query_cid = validate_ipfs_cid(query_cid.clone().unwrap(), "query_cid".to_string()); - let validate_execute_cid = validate_ipfs_cid(execute_cid.clone().unwrap(), "execute_cid".to_string()); - let validate_version = validate_url(version.clone().unwrap(), "version".to_string()); - let validate_chain_id = validate_url(chain_id.clone().unwrap(), "chain_id".to_string()); - - if validate_address.is_err() { - return validate_address; - } - if validate_query_cid.is_err() { - return validate_query_cid; - } - if validate_execute_cid.is_err() { - return validate_execute_cid; - } - if validate_version.is_err() { - return validate_version; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - let entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - address: address.unwrap_or(entry.address), - query_cid: query_cid.unwrap_or(entry.query_cid), - execute_cid: execute_cid.unwrap_or(entry.execute_cid), - version: version.unwrap_or(entry.version), - chain_id: chain_id.unwrap_or(entry.chain_id), - particle: particle.unwrap_or("".to_string()), - }; - - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; Ok(EntryResponse { @@ -209,4 +32,4 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S entries: entries?.into_iter().map(|l| l.1).collect(), }; Ok(result) -} +} \ No newline at end of file diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index f53dfc9..9a2ab1f 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -6,8 +6,9 @@ use cosmwasm_std::entry_point; use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-networks/src/execute.rs b/contracts/hub-networks/src/execute.rs new file mode 100644 index 0000000..27f4803 --- /dev/null +++ b/contracts/hub-networks/src/execute.rs @@ -0,0 +1,208 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_period}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + name: String, + chain_id: String, + prefix: String, + genesis_hash: String, + protocol: String, + unbonding_period: String, + logo: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_logo = validate_ipfs_cid(logo.clone()); + if validate_logo.is_err() { + return validate_logo; + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_chainid = validate_by_basic_rule(chain_id.clone(), "chain-id".to_string()); + let validate_prefix = validate_by_basic_rule(prefix.clone(), "prefix".to_string()); + let validate_genesishash = validate_by_basic_rule(genesis_hash.clone(), "genesis_hash".to_string()); + let validate_name = validate_by_basic_rule(name.clone(), "name".to_string()); + let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); + let validate_unbonding_period = validate_period(unbonding_period.clone(), "protocol".to_string()); + + if validate_chainid.is_err() { + return validate_chainid; + } + if validate_prefix.is_err() { + return validate_prefix; + } + if validate_genesishash.is_err() { + return validate_genesishash; + } + if validate_name.is_err() { + return validate_name; + } + if validate_protocol.is_err() { + return validate_protocol; + } + if validate_unbonding_period.is_err() { + return validate_protocol; + } + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + name, + chain_id, + prefix, + genesis_hash, + protocol, + unbonding_period, + logo, + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + name: Option, + chain_id: Option, + prefix: Option, + genesis_hash: Option, + protocol: Option, + unbonding_period: Option, + logo: Option, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_logo = validate_ipfs_cid(logo.clone().unwrap()); + if validate_logo.is_err() { + return validate_logo; + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_chainid = validate_by_basic_rule(chain_id.as_ref().unwrap().clone(), "chain-id".to_string()); + let validate_prefix = validate_by_basic_rule(prefix.as_ref().unwrap().clone(), "prefix".to_string()); + let validate_genesishash = validate_by_basic_rule(genesis_hash.as_ref().unwrap().clone(), "genesis_hash".to_string()); + let validate_name = validate_by_basic_rule(name.as_ref().unwrap().clone(), "name".to_string()); + let validate_protocol = validate_by_basic_rule(protocol.as_ref().unwrap().clone(), "protocol".to_string()); + let validate_unbonding_period = validate_period(unbonding_period.as_ref().unwrap().clone(), "protocol".to_string()); + + if validate_chainid.is_err() { + return validate_chainid; + } + if validate_chainid.is_err() { + return validate_chainid; + } + if validate_prefix.is_err() { + return validate_prefix; + } + if validate_genesishash.is_err() { + return validate_genesishash; + } + if validate_name.is_err() { + return validate_name; + } + if validate_protocol.is_err() { + return validate_protocol; + } + if validate_unbonding_period.is_err() { + return validate_protocol; + } + + let entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + name: name.unwrap_or(entry.name), + chain_id: chain_id.unwrap_or(entry.chain_id), + prefix: prefix.unwrap_or(entry.prefix), + genesis_hash: genesis_hash.unwrap_or(entry.genesis_hash), + protocol: protocol.unwrap_or(entry.protocol), + unbonding_period: unbonding_period.unwrap_or(entry.unbonding_period), + logo: logo.unwrap_or(entry.logo), + particle: particle.unwrap_or(entry.particle), + }; + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-networks/src/lib.rs b/contracts/hub-networks/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-networks/src/lib.rs +++ b/contracts/hub-networks/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-networks/src/query.rs b/contracts/hub-networks/src/query.rs index 6afc72b..509a743 100644 --- a/contracts/hub-networks/src/query.rs +++ b/contracts/hub-networks/src/query.rs @@ -1,218 +1,12 @@ -use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; -use crate::validating::{validate_by_basic_rule, validate_period, validate_ipfs_cid}; - +use cosmwasm_std::{Deps, Order, StdResult}; use cw_storage_plus::Bound; -use std::ops::Add; - -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; +use crate::state::LIST; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - name: String, - chain_id: String, - prefix: String, - genesis_hash: String, - protocol: String, - unbonding_period: String, - logo: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_logo = validate_ipfs_cid(logo.clone()); - if validate_logo.is_err() { - return validate_logo; - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_chainid = validate_by_basic_rule(chain_id.clone(), "chain-id".to_string()); - let validate_prefix = validate_by_basic_rule(prefix.clone(), "prefix".to_string()); - let validate_genesishash = validate_by_basic_rule(genesis_hash.clone(), "genesis_hash".to_string()); - let validate_name = validate_by_basic_rule(name.clone(), "name".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); - let validate_unbonding_period = validate_period(unbonding_period.clone(), "protocol".to_string()); - - if validate_chainid.is_err() { - return validate_chainid; - } - if validate_prefix.is_err() { - return validate_prefix; - } - if validate_genesishash.is_err() { - return validate_genesishash; - } - if validate_name.is_err() { - return validate_name; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_unbonding_period.is_err() { - return validate_protocol; - } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - name, - chain_id, - prefix, - genesis_hash, - protocol, - unbonding_period, - logo, - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - name: Option, - chain_id: Option, - prefix: Option, - genesis_hash: Option, - protocol: Option, - unbonding_period: Option, - logo: Option, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_logo = validate_ipfs_cid(logo.clone().unwrap()); - if validate_logo.is_err() { - return validate_logo; - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_chainid = validate_by_basic_rule(chain_id.as_ref().unwrap().clone(), "chain-id".to_string()); - let validate_prefix = validate_by_basic_rule(prefix.as_ref().unwrap().clone(), "prefix".to_string()); - let validate_genesishash = validate_by_basic_rule(genesis_hash.as_ref().unwrap().clone(), "genesis_hash".to_string()); - let validate_name = validate_by_basic_rule(name.as_ref().unwrap().clone(), "name".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.as_ref().unwrap().clone(), "protocol".to_string()); - let validate_unbonding_period = validate_period(unbonding_period.as_ref().unwrap().clone(), "protocol".to_string()); - - if validate_chainid.is_err() { - return validate_chainid; - } - if validate_chainid.is_err() { - return validate_chainid; - } - if validate_prefix.is_err() { - return validate_prefix; - } - if validate_genesishash.is_err() { - return validate_genesishash; - } - if validate_name.is_err() { - return validate_name; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_unbonding_period.is_err() { - return validate_protocol; - } - - let entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - name: name.unwrap_or(entry.name), - chain_id: chain_id.unwrap_or(entry.chain_id), - prefix: prefix.unwrap_or(entry.prefix), - genesis_hash: genesis_hash.unwrap_or(entry.genesis_hash), - protocol: protocol.unwrap_or(entry.protocol), - unbonding_period: unbonding_period.unwrap_or(entry.unbonding_period), - logo: logo.unwrap_or(entry.logo), - particle: particle.unwrap_or(entry.particle), - }; - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; Ok(EntryResponse { @@ -240,4 +34,4 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S entries: entries?.into_iter().map(|l| l.1).collect(), }; Ok(result) -} +} \ No newline at end of file diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 2df036c..96ae256 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -6,8 +6,9 @@ use cosmwasm_std::entry_point; use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-protocols/src/execute.rs b/contracts/hub-protocols/src/execute.rs new file mode 100644 index 0000000..b5f72ca --- /dev/null +++ b/contracts/hub-protocols/src/execute.rs @@ -0,0 +1,127 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_datatype, validate_particle}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + data_type: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_particle = validate_particle(particle.clone()); + let validate_data_typer = validate_datatype(data_type.clone()); + + if validate_particle.is_err() { + return validate_particle; + } + if validate_data_typer.is_err() { + return validate_data_typer; + } + + + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + data_type: data_type, + particle: particle.unwrap_or("".to_string()).to_string(), + }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + data_type: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_particle = validate_particle(particle.clone()); + let validate_data_typer = validate_datatype(data_type.clone()); + + if validate_particle.is_err() { + return validate_particle; + } + if validate_data_typer.is_err() { + return validate_data_typer; + } + + let _entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + data_type: data_type, + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} \ No newline at end of file diff --git a/contracts/hub-protocols/src/lib.rs b/contracts/hub-protocols/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-protocols/src/lib.rs +++ b/contracts/hub-protocols/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index 148b1bd..10c28e9 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -1,137 +1,12 @@ -use cosmwasm_std::{attr, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult}; - +use cosmwasm_std::{Deps, Order, StdResult}; use cw_storage_plus::Bound; -use std::ops::Add; - -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; -use crate::validating::{validate_particle,validate_datatype}; +use crate::state::LIST; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - data_type: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_particle = validate_particle(particle.clone()); - let validate_data_typer = validate_datatype(data_type.clone()); - - if validate_particle.is_err() { - return validate_particle; - } - if validate_data_typer.is_err() { - return validate_data_typer; - } - - - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - data_type: data_type, - particle: particle.unwrap_or("".to_string()).to_string(), - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - data_type: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_particle = validate_particle(particle.clone()); - let validate_data_typer = validate_datatype(data_type.clone()); - - if validate_particle.is_err() { - return validate_particle; - } - if validate_data_typer.is_err() { - return validate_data_typer; - } - - let _entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - data_type: data_type, - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; Ok(EntryResponse { diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index 696e906..a7e13a0 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -4,8 +4,9 @@ use cosmwasm_std::entry_point; use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_entry_owner, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry_owner, execute_update_entry, execute_update_owner, query_entry, query_list}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-skills/src/execute.rs b/contracts/hub-skills/src/execute.rs new file mode 100644 index 0000000..0bfb35e --- /dev/null +++ b/contracts/hub-skills/src/execute.rs @@ -0,0 +1,194 @@ +use std::ops::Add; + +use cosmwasm_std::{Addr, attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, entries, Entry, ENTRY_SEQ}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; + +pub fn uniq_key_by_owner(owner: Addr, id: u64) -> (Addr, u64) { + (owner.clone(), id.clone()) +} + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_update_entry_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + id: u64, + new_owner: String, +) -> Result { + let entry = entries().load(deps.storage, id)?; + + if entry.owner != info.sender { + return Err(ContractError::Unauthorized {}); + } + + let updated_entry = Entry { + id, + neuron: entry.neuron, + network: entry.network, + protocol: entry.protocol, + endpoint: entry.endpoint, + owner: deps.api.addr_validate(&new_owner)?, + particle: entry.particle, + }; + + entries().save(deps.storage, id, &updated_entry)?; + + Ok(Response::new() + .add_attribute("method", "execute_update_entry_owner") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + neuron: String, + network: String, + protocol: String, + endpoint: String, + particle: Option, +) -> Result { + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_neuron = validate_by_basic_rule(neuron.clone(), "neuron".to_string()); + let validate_network = validate_by_basic_rule(network.clone(), "network".to_string()); + let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); + let validate_endpoint = validate_url(endpoint.clone(), "endpoint".to_string()); + + if validate_neuron.is_err() { + return validate_neuron; + } + if validate_network.is_err() { + return validate_network; + } + if validate_protocol.is_err() { + return validate_protocol; + } + if validate_endpoint.is_err() { + return validate_endpoint; + } + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + neuron, + network, + protocol, + endpoint, + owner: info.sender, + particle: particle.unwrap_or("".to_string()) + }; + + entries().save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + neuron: Option, + network: Option, + protocol: Option, + endpoint: Option, + particle: Option, +) -> Result { + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_neuron = validate_by_basic_rule(neuron.clone().unwrap(), "neuron".to_string()); + let validate_network = validate_by_basic_rule(network.clone().unwrap(), "network".to_string()); + let validate_protocol = validate_by_basic_rule(protocol.clone().unwrap(), "protocol".to_string()); + let validate_endpoint = validate_url(endpoint.clone().unwrap(), "endpoint".to_string()); + + if validate_neuron.is_err() { + return validate_neuron; + } + if validate_network.is_err() { + return validate_network; + } + if validate_protocol.is_err() { + return validate_protocol; + } + if validate_endpoint.is_err() { + return validate_endpoint; + } + + let entry = entries().load(deps.storage, id)?; + + if entry.owner != info.sender { + return Err(ContractError::Unauthorized {}); + } + + let updated_entry = Entry { + id, + neuron: neuron.unwrap_or(entry.neuron), + network: network.unwrap_or(entry.network), + protocol: protocol.unwrap_or(entry.protocol), + endpoint: endpoint.unwrap_or(entry.endpoint), + owner: entry.owner, + particle: particle.unwrap_or("".to_string()), + }; + + entries().save(deps.storage, id, &updated_entry)?; + + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let entry = entries().load(deps.storage, id)?; + + if entry.owner != info.sender { + return Err(ContractError::Unauthorized {}); + } + + let _result = entries().remove(deps.storage, id); + + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-skills/src/lib.rs b/contracts/hub-skills/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-skills/src/lib.rs +++ b/contracts/hub-skills/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index 1959d13..a405213 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -1,203 +1,12 @@ -use cosmwasm_std::{Deps, DepsMut, MessageInfo, Order, Response, StdResult, Addr, Env, attr}; +use cosmwasm_std::{Addr, Deps, Order, StdResult}; +use cw_storage_plus::Bound; -// use cw_storage_plus::Bound; -use std::ops::Add; - -use crate::validating::{validate_by_basic_rule,validate_ipfs_cid, validate_url}; -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{CONFIG, Entry, ENTRY_SEQ, entries}; +use crate::state::entries; const MAX_LIMIT: u32 = 50; const DEFAULT_LIMIT: u32 = 30; -pub fn uniq_key_by_owner(owner: Addr, id: u64) -> (Addr, u64) { - (owner.clone(), id.clone()) -} - -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_update_entry_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - id: u64, - new_owner: String, -) -> Result { - let entry = entries().load(deps.storage, id)?; - - if entry.owner != info.sender { - return Err(ContractError::Unauthorized {}); - } - - let updated_entry = Entry { - id, - neuron: entry.neuron, - network: entry.network, - protocol: entry.protocol, - endpoint: entry.endpoint, - owner: deps.api.addr_validate(&new_owner)?, - particle: entry.particle, - }; - - entries().save(deps.storage, id, &updated_entry)?; - - Ok(Response::new() - .add_attribute("method", "execute_update_entry_owner") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - neuron: String, - network: String, - protocol: String, - endpoint: String, - particle: Option, -) -> Result { - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_neuron = validate_by_basic_rule(neuron.clone(), "neuron".to_string()); - let validate_network = validate_by_basic_rule(network.clone(), "network".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.clone(), "protocol".to_string()); - let validate_endpoint = validate_url(endpoint.clone(), "endpoint".to_string()); - - if validate_neuron.is_err() { - return validate_neuron; - } - if validate_network.is_err() { - return validate_network; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_endpoint.is_err() { - return validate_endpoint; - } - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - neuron, - network, - protocol, - endpoint, - owner: info.sender, - particle: particle.unwrap_or("".to_string()) - }; - - entries().save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - neuron: Option, - network: Option, - protocol: Option, - endpoint: Option, - particle: Option, -) -> Result { - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_neuron = validate_by_basic_rule(neuron.clone().unwrap(), "neuron".to_string()); - let validate_network = validate_by_basic_rule(network.clone().unwrap(), "network".to_string()); - let validate_protocol = validate_by_basic_rule(protocol.clone().unwrap(), "protocol".to_string()); - let validate_endpoint = validate_url(endpoint.clone().unwrap(), "endpoint".to_string()); - - if validate_neuron.is_err() { - return validate_neuron; - } - if validate_network.is_err() { - return validate_network; - } - if validate_protocol.is_err() { - return validate_protocol; - } - if validate_endpoint.is_err() { - return validate_endpoint; - } - - let entry = entries().load(deps.storage, id)?; - - if entry.owner != info.sender { - return Err(ContractError::Unauthorized {}); - } - - let updated_entry = Entry { - id, - neuron: neuron.unwrap_or(entry.neuron), - network: network.unwrap_or(entry.network), - protocol: protocol.unwrap_or(entry.protocol), - endpoint: endpoint.unwrap_or(entry.endpoint), - owner: entry.owner, - particle: particle.unwrap_or("".to_string()), - }; - - entries().save(deps.storage, id, &updated_entry)?; - - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let entry = entries().load(deps.storage, id)?; - - if entry.owner != info.sender { - return Err(ContractError::Unauthorized {}); - } - - let _result = entries().remove(deps.storage, id); - - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = entries().load(deps.storage, id)?; Ok(EntryResponse { @@ -219,7 +28,7 @@ pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _pr let entries: StdResult> = indexed_arr .prefix(owner.clone().unwrap_or(Addr::unchecked("")).to_string()) .range( - deps.storage, + deps.storage, None, None, Order::Ascending, @@ -232,4 +41,4 @@ pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _pr }; Ok(result) -} +} \ No newline at end of file diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 34ac900..3396f91 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -6,8 +6,9 @@ use cosmwasm_std::entry_point; use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner, query_entry, query_list}; +use crate::query::{query_entry, query_list}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract diff --git a/contracts/hub-tokens/src/execute.rs b/contracts/hub-tokens/src/execute.rs new file mode 100644 index 0000000..e9cfca1 --- /dev/null +++ b/contracts/hub-tokens/src/execute.rs @@ -0,0 +1,174 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, Env, Uint64}; +use cosmwasm_std::{DepsMut, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_by_basic_rule, validate_by_basic_uppercase_rule, validate_ipfs_cid}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + ticker: String, + chain_id: String, + denom: String, + channel: Uint64, + logo: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_logo = validate_ipfs_cid(logo.clone(),"logo".to_string()); + if validate_logo.is_err() { + return validate_logo; + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone(), "ticker".to_string()); + let validate_chain_id = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); + + if validate_ticker.is_err() { + return validate_ticker; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + // TODO add denom validation + // TODO add channel validation + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + ticker, + chain_id, + denom, + channel, + logo, + particle: particle.unwrap_or("".to_string()) + }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + ticker: Option, + chain_id: Option, + denom: Option, + channel: Option, + logo: Option, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + let validate_logo = validate_ipfs_cid(logo.clone().unwrap(),"logo".to_string()); + if validate_logo.is_err() { + return validate_logo; + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + + let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone().unwrap(), "ticker".to_string()); + let validate_chain_id = validate_by_basic_rule(chain_id.clone().unwrap(), "chain_id".to_string()); + + // TODO add denom validation + // TODO add channel validation + + if validate_ticker.is_err() { + return validate_ticker; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + + let entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + ticker: ticker.unwrap_or(entry.ticker), + denom: denom.unwrap_or(entry.denom), + chain_id: chain_id.unwrap_or(entry.chain_id), + channel: channel.unwrap_or(entry.channel), + logo: logo.unwrap_or(entry.logo), + particle: particle.unwrap_or("".to_string()), + }; + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-tokens/src/lib.rs b/contracts/hub-tokens/src/lib.rs index b085561..0a43c7c 100644 --- a/contracts/hub-tokens/src/lib.rs +++ b/contracts/hub-tokens/src/lib.rs @@ -1,9 +1,10 @@ pub mod contract; mod error; pub mod msg; -pub mod query; +pub mod execute; pub mod state; pub mod validating; mod tests; +mod query; pub use crate::error::ContractError; diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index f56b8ce..1d51cb5 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -1,185 +1,12 @@ -use cosmwasm_std::{attr, Env, Uint64}; -use cosmwasm_std::{ - Deps, DepsMut, MessageInfo, Order, Response, StdResult, -}; - +use cosmwasm_std::{Deps, Order, StdResult}; use cw_storage_plus::Bound; -use std::ops::Add; -use crate::validating::{validate_by_basic_rule, validate_by_basic_uppercase_rule, validate_ipfs_cid}; -use crate::error::ContractError; use crate::msg::{EntryResponse, ListResponse}; -use crate::state::{Entry, CONFIG, ENTRY_SEQ, LIST}; +use crate::state::LIST; const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 20; -pub fn execute_update_owner( - deps: DepsMut, - _env: Env, - info: MessageInfo, - new_owner: Option, -) -> Result { - let cfg = CONFIG.load(deps.storage)?; - let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; - if info.sender != owner { - return Err(ContractError::Unauthorized {}); - } - - let mut tmp_owner = None; - if let Some(addr) = new_owner { - tmp_owner = Some(deps.api.addr_validate(&addr)?) - } - - CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { - exists.owner = tmp_owner; - Ok(exists) - })?; - - Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) -} - -pub fn execute_create_entry( - deps: DepsMut, - info: MessageInfo, - ticker: String, - chain_id: String, - denom: String, - channel: Uint64, - logo: String, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_logo = validate_ipfs_cid(logo.clone(),"logo".to_string()); - if validate_logo.is_err() { - return validate_logo; - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone(), "ticker".to_string()); - let validate_chain_id = validate_by_basic_rule(chain_id.clone(), "chain_id".to_string()); - - if validate_ticker.is_err() { - return validate_ticker; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - // TODO add denom validation - // TODO add channel validation - - let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; - - let new_entry = Entry { - id, - ticker, - chain_id, - denom, - channel, - logo, - particle: particle.unwrap_or("".to_string()) - }; - LIST.save(deps.storage, id, &new_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_create_entry") - .add_attribute("new_entry_id", id.to_string())) -} - -pub fn execute_update_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, - ticker: Option, - chain_id: Option, - denom: Option, - channel: Option, - logo: Option, - particle: Option, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - let validate_logo = validate_ipfs_cid(logo.clone().unwrap(),"logo".to_string()); - if validate_logo.is_err() { - return validate_logo; - } - - if !particle.as_ref().is_none() { - let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); - if validate_particle.is_err() { - return validate_particle; - } - } - - - let validate_ticker = validate_by_basic_uppercase_rule(ticker.clone().unwrap(), "ticker".to_string()); - let validate_chain_id = validate_by_basic_rule(chain_id.clone().unwrap(), "chain_id".to_string()); - - // TODO add denom validation - // TODO add channel validation - - if validate_ticker.is_err() { - return validate_ticker; - } - if validate_chain_id.is_err() { - return validate_chain_id; - } - - - let entry = LIST.load(deps.storage, id)?; - let updated_entry = Entry { - id, - ticker: ticker.unwrap_or(entry.ticker), - denom: denom.unwrap_or(entry.denom), - chain_id: chain_id.unwrap_or(entry.chain_id), - channel: channel.unwrap_or(entry.channel), - logo: logo.unwrap_or(entry.logo), - particle: particle.unwrap_or("".to_string()), - }; - LIST.save(deps.storage, id, &updated_entry)?; - Ok(Response::new() - .add_attribute("method", "execute_update_entry") - .add_attribute("updated_entry_id", id.to_string())) -} - -pub fn execute_delete_entry( - deps: DepsMut, - info: MessageInfo, - id: u64, -) -> Result { - let owner = CONFIG.load(deps.storage)?.owner; - - if owner.is_none() { - return Err(ContractError::Unauthorized {}); - } else if info.sender != owner.unwrap() { - return Err(ContractError::Unauthorized {}); - } - - LIST.remove(deps.storage, id); - Ok(Response::new() - .add_attribute("method", "execute_delete_entry") - .add_attribute("deleted_entry_id", id.to_string())) -} - pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; Ok(EntryResponse { @@ -205,4 +32,4 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S entries: entries?.into_iter().map(|l| l.1).collect(), }; Ok(result) -} +} \ No newline at end of file From 5b63216abae466e7d634a0f14ec251c384d32e69 Mon Sep 17 00:00:00 2001 From: C H Date: Thu, 1 Dec 2022 15:30:50 +0800 Subject: [PATCH 17/33] Added queries to skills --- contracts/hub-skills/src/contract.rs | 12 +++- contracts/hub-skills/src/msg.rs | 15 ++++- contracts/hub-skills/src/query.rs | 68 ++++++++++++++++--- contracts/hub-skills/src/state.rs | 2 +- contracts/hub-skills/src/tests.rs | 97 ++++++++++++++++++++++------ 5 files changed, 159 insertions(+), 35 deletions(-) diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index a7e13a0..a1b020a 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -6,7 +6,7 @@ use cw2::{get_contract_version, set_contract_version}; use crate::error::ContractError; use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_entry_owner, execute_update_owner}; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::query::{query_entry, query_list}; +use crate::query::{query_entry, query_list_by_network, query_list_by_owner, query_list_by_protocol}; use crate::state::{Config, CONFIG, ENTRY_SEQ}; //@TODO git version iteract @@ -71,8 +71,14 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetEntries { start_after, limit, protocol, owner } => { - to_binary(&query_list(deps, start_after, limit, protocol, owner)?) + QueryMsg::GetEntries { start_after, limit, owner } => { + to_binary(&query_list_by_owner(deps, start_after, limit, owner)?) + } + QueryMsg::GetEntriesProtocol { start_after, limit, protocol } => { + to_binary(&query_list_by_protocol(deps, start_after, limit, protocol)?) + } + QueryMsg::GetEntriesNetwork { start_after, limit, network } => { + to_binary(&query_list_by_network(deps, start_after, limit, network)?) } QueryMsg::GetEntry { id } => { to_binary(&query_entry(deps, id)?) diff --git a/contracts/hub-skills/src/msg.rs b/contracts/hub-skills/src/msg.rs index 4665fb4..34da06f 100644 --- a/contracts/hub-skills/src/msg.rs +++ b/contracts/hub-skills/src/msg.rs @@ -45,9 +45,18 @@ pub enum ExecuteMsg { pub enum QueryMsg { GetEntries { start_after: Option, - owner: Option, - protocol: Option, limit: Option, + owner: Addr, + }, + GetEntriesProtocol { + start_after: Option, + limit: Option, + protocol: String, + }, + GetEntriesNetwork { + start_after: Option, + limit: Option, + network: String, }, GetEntry { id: u64 } } @@ -59,8 +68,10 @@ pub struct MigrateMsg {} pub struct EntryResponse { pub id: u64, pub neuron: String, + pub network: String, pub protocol: String, pub endpoint: String, + pub owner: String, pub particle: String, } diff --git a/contracts/hub-skills/src/query.rs b/contracts/hub-skills/src/query.rs index a405213..e9f7056 100644 --- a/contracts/hub-skills/src/query.rs +++ b/contracts/hub-skills/src/query.rs @@ -1,39 +1,91 @@ use cosmwasm_std::{Addr, Deps, Order, StdResult}; -use cw_storage_plus::Bound; +// use cw_storage_plus::Bound; use crate::msg::{EntryResponse, ListResponse}; use crate::state::entries; -const MAX_LIMIT: u32 = 50; -const DEFAULT_LIMIT: u32 = 30; +// const MAX_LIMIT: u32 = 50; +// const DEFAULT_LIMIT: u32 = 30; pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = entries().load(deps.storage, id)?; Ok(EntryResponse { id, neuron: entry.neuron, + network: entry.network, protocol: entry.protocol, endpoint: entry.endpoint, + owner: entry.owner.to_string(), particle: entry.particle }) } -pub fn query_list(deps: Deps, _start_after: Option, limit: Option, _protocol: Option, owner: Option) -> StdResult { - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; +pub fn query_list_by_owner(deps: Deps, _start_after: Option, _limit: Option, owner: Addr) -> StdResult { + // TODO + // let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; + // let start = start_after.map(Bound::exclusive); let indexed_arr = entries().idx.owner; - // TODO add start_after and protocol + let entries: StdResult> = indexed_arr + .prefix(owner.clone().to_string()) + .range( + deps.storage, + None, + None, + Order::Ascending, + ) + // .take(limit) + .collect(); + + let result = ListResponse { + entries: entries?.into_iter().map(|l| l.1).collect(), + }; + + Ok(result) +} + +pub fn query_list_by_network(deps: Deps, _start_after: Option, _limit: Option, network: String) -> StdResult { + // TODO + // let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; + // let start = start_after.map(Bound::exclusive); + + let indexed_arr = entries().idx.network; + + let entries: StdResult> = indexed_arr + .prefix(network.clone().to_string()) + .range( + deps.storage, + None, + None, + Order::Ascending, + ) + // .take(limit) + .collect(); + + let result = ListResponse { + entries: entries?.into_iter().map(|l| l.1).collect(), + }; + + Ok(result) +} + +pub fn query_list_by_protocol(deps: Deps, _start_after: Option, _limit: Option, protocol: String) -> StdResult { + // TODO + // let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; + // let start = start_after.map(Bound::exclusive); + + let indexed_arr = entries().idx.protocol; let entries: StdResult> = indexed_arr - .prefix(owner.clone().unwrap_or(Addr::unchecked("")).to_string()) + .prefix(protocol.clone().to_string()) .range( deps.storage, None, None, Order::Ascending, ) - .take(limit) + // .take(limit) .collect(); let result = ListResponse { diff --git a/contracts/hub-skills/src/state.rs b/contracts/hub-skills/src/state.rs index cc5675d..8f56474 100644 --- a/contracts/hub-skills/src/state.rs +++ b/contracts/hub-skills/src/state.rs @@ -32,7 +32,7 @@ pub struct EntryIndexes<'a> { impl<'a> IndexList for EntryIndexes<'a> { fn get_indexes(&'_ self) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.owner, &self.id]; + let v: Vec<&dyn Index> = vec![&self.id, &self.owner, &self.network, &self.protocol]; Box::new(v.into_iter()) } } diff --git a/contracts/hub-skills/src/tests.rs b/contracts/hub-skills/src/tests.rs index 590bd04..0abca05 100644 --- a/contracts/hub-skills/src/tests.rs +++ b/contracts/hub-skills/src/tests.rs @@ -9,7 +9,7 @@ mod tests { // use std::convert::TryFrom; use std::vec::Vec; use crate::state::{Entry, CONFIG, Config}; - use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; + use crate::msg::{ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg, EntryResponse}; // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::contract::{query, execute, instantiate}; @@ -63,7 +63,7 @@ mod tests { let msg = ExecuteMsg::CreateEntry { neuron: "testchain-1".to_string(), network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + protocol: "cosmos-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -79,8 +79,8 @@ mod tests { let msg = ExecuteMsg::CreateEntry { neuron: "testchain-1".to_string(), - network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -101,9 +101,7 @@ mod tests { QueryMsg::GetEntries { start_after: None, limit: None, - protocol: None, - // owner: None, - owner: Some(Addr::unchecked("creator")), + owner: Addr::unchecked("creator"), }, ) .unwrap(); @@ -114,7 +112,7 @@ mod tests { id: 1, neuron: "testchain-1".to_string(), network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + protocol: "cosmos-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), owner: cosmwasm_std::Addr::unchecked("creator"), @@ -122,8 +120,8 @@ mod tests { Entry { id: 2, neuron: "testchain-1".to_string(), - network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), owner: cosmwasm_std::Addr::unchecked("creator"), @@ -137,7 +135,7 @@ mod tests { id: 1, neuron: Some("testchain-1".to_string()), network: Some("cosmos".to_string()), - protocol: Some("testchain-1".to_string()), + protocol: Some("cosmos-1".to_string()), endpoint: Some("https:/abcd.com".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), }; @@ -160,8 +158,7 @@ mod tests { QueryMsg::GetEntries { start_after: None, limit: None, - protocol: None, - owner: Some(Addr::unchecked("creator")), + owner: Addr::unchecked("creator"), }, ) .unwrap(); @@ -172,7 +169,7 @@ mod tests { id: 1, neuron: "testchain-1".to_string(), network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + protocol: "cosmos-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), owner: cosmwasm_std::Addr::unchecked("creator"), @@ -180,8 +177,8 @@ mod tests { Entry { id: 2, neuron: "testchain-1".to_string(), - network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), owner: cosmwasm_std::Addr::unchecked("creator"), @@ -204,11 +201,10 @@ mod tests { // Query the list of entries let res = query( deps.as_ref(), - env, + env.clone(), QueryMsg::GetEntries { start_after: None, - protocol: None, - owner: Some(Addr::unchecked("creator")), + owner: Addr::unchecked("creator"), limit: None, }, ) @@ -218,13 +214,72 @@ mod tests { Vec::from([Entry { id: 2, neuron: "testchain-1".to_string(), - network: "cosmos".to_string(), - protocol: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), + endpoint: "https:/abcd.com".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + owner: cosmwasm_std::Addr::unchecked("creator"), + }]), + list.entries + ); + + let res = query( + deps.as_ref(), + env.clone(), + QueryMsg::GetEntry { + id: 2 + }, + ).unwrap(); + let entry: EntryResponse = from_binary(&res).unwrap(); + assert_eq!( + EntryResponse { + id: 2, + neuron: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), + endpoint: "https:/abcd.com".to_string(), + owner: cosmwasm_std::Addr::unchecked("creator").to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + }, + entry + ); + + let res = query( + deps.as_ref(), + env.clone(), + QueryMsg::GetEntriesProtocol { + start_after: None, + limit: None, + protocol: "bostrom-1".to_string() + }, + ).unwrap(); + let list: ListResponse = from_binary(&res).unwrap(); + assert_eq!( + Vec::from([Entry { + id: 2, + neuron: "testchain-1".to_string(), + network: "bostrom".to_string(), + protocol: "bostrom-1".to_string(), endpoint: "https:/abcd.com".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), owner: cosmwasm_std::Addr::unchecked("creator"), }]), list.entries ); + + let res = query( + deps.as_ref(), + env.clone(), + QueryMsg::GetEntriesNetwork { + start_after: None, + limit: None, + network: "cosmos".to_string() + }, + ).unwrap(); + let list: ListResponse = from_binary(&res).unwrap(); + assert_eq!( + 0, + list.entries.len() + ); } } From bb50cba3df1bdf74a3fde643068962f390c754c8 Mon Sep 17 00:00:00 2001 From: C H Date: Thu, 1 Dec 2022 15:36:26 +0800 Subject: [PATCH 18/33] Updated schemas --- contracts/hub-channels/examples/schema.rs | 2 +- contracts/hub-contracts/examples/schema.rs | 2 +- contracts/hub-networks/examples/schema.rs | 2 +- contracts/hub-protocols/examples/schema.rs | 2 +- contracts/hub-skills/examples/schema.rs | 2 +- contracts/hub-tokens/examples/schema.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/hub-channels/examples/schema.rs b/contracts/hub-channels/examples/schema.rs index 237e888..d5ad876 100644 --- a/contracts/hub-channels/examples/schema.rs +++ b/contracts/hub-channels/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_channels::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_channels::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/hub-contracts/examples/schema.rs b/contracts/hub-contracts/examples/schema.rs index 1522f1b..eef2b64 100644 --- a/contracts/hub-contracts/examples/schema.rs +++ b/contracts/hub-contracts/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_contract::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_contracts::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/hub-networks/examples/schema.rs b/contracts/hub-networks/examples/schema.rs index 119ffd0..8910958 100644 --- a/contracts/hub-networks/examples/schema.rs +++ b/contracts/hub-networks/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_network::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_networks::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/hub-protocols/examples/schema.rs b/contracts/hub-protocols/examples/schema.rs index 81fbbe9..d96e492 100644 --- a/contracts/hub-protocols/examples/schema.rs +++ b/contracts/hub-protocols/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_protocols::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_protocols::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/hub-skills/examples/schema.rs b/contracts/hub-skills/examples/schema.rs index 8917677..4b03d9a 100644 --- a/contracts/hub-skills/examples/schema.rs +++ b/contracts/hub-skills/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_skills::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_skills::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/hub-tokens/examples/schema.rs b/contracts/hub-tokens/examples/schema.rs index ed93f31..f28a3c9 100644 --- a/contracts/hub-tokens/examples/schema.rs +++ b/contracts/hub-tokens/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw_cyb_tokens::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use hub_tokens::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); From 88a915e002d02fd707eeb994ef7ded05d93fb52c Mon Sep 17 00:00:00 2001 From: C H Date: Thu, 1 Dec 2022 16:15:11 +0800 Subject: [PATCH 19/33] Refactoring --- contracts/hub-channels/src/contract.rs | 1 + contracts/hub-channels/src/execute.rs | 5 +++ contracts/hub-channels/src/query.rs | 2 + contracts/hub-channels/src/validating.rs | 26 +++++------- contracts/hub-contracts/src/contract.rs | 1 + contracts/hub-contracts/src/execute.rs | 4 ++ contracts/hub-contracts/src/query.rs | 2 + contracts/hub-contracts/src/validating.rs | 23 +++++------ contracts/hub-networks/src/contract.rs | 1 + contracts/hub-networks/src/execute.rs | 3 ++ contracts/hub-networks/src/query.rs | 2 + contracts/hub-networks/src/validating.rs | 49 +++++------------------ contracts/hub-protocols/src/contract.rs | 1 + contracts/hub-protocols/src/execute.rs | 7 +++- contracts/hub-protocols/src/query.rs | 2 + contracts/hub-protocols/src/validating.rs | 2 - contracts/hub-skills/src/contract.rs | 2 + contracts/hub-skills/src/validating.rs | 25 +++++------- contracts/hub-tokens/src/contract.rs | 2 + contracts/hub-tokens/src/execute.rs | 6 ++- contracts/hub-tokens/src/query.rs | 2 + contracts/hub-tokens/src/validating.rs | 26 +++++------- 22 files changed, 86 insertions(+), 108 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 916350d..0c2011e 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -92,5 +92,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result StdResult { let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { id: entry.id, source_chain_id: entry.source_chain_id, @@ -30,5 +31,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } \ No newline at end of file diff --git a/contracts/hub-channels/src/validating.rs b/contracts/hub-channels/src/validating.rs index 09a11d3..f62fd80 100644 --- a/contracts/hub-channels/src/validating.rs +++ b/contracts/hub-channels/src/validating.rs @@ -12,7 +12,6 @@ pub fn validate_by_basic_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -30,7 +29,6 @@ pub fn validate_by_basic_uppercase_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // 0-9 && A-Z if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { @@ -44,7 +42,6 @@ pub fn validate_by_basic_uppercase_rule( pub fn validate_datatype( val: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -59,7 +56,6 @@ pub fn validate_url( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // } { : / . - _ 0-9 a-z A-Z if (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { @@ -76,22 +72,20 @@ pub fn validate_url( pub fn validate_ipfs_cid( particle: String ) -> Result { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { + if particle_value.version() != Version::V0 { - return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); - - } - } else { return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); - } - Ok(Response::default()) + } + } else { + return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); + } + Ok(Response::default()) } diff --git a/contracts/hub-contracts/src/contract.rs b/contracts/hub-contracts/src/contract.rs index 503cc93..110f41c 100644 --- a/contracts/hub-contracts/src/contract.rs +++ b/contracts/hub-contracts/src/contract.rs @@ -91,5 +91,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result StdResult { let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { id: entry.id, address: entry.address, @@ -31,5 +32,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } \ No newline at end of file diff --git a/contracts/hub-contracts/src/validating.rs b/contracts/hub-contracts/src/validating.rs index bf1c207..85f4207 100644 --- a/contracts/hub-contracts/src/validating.rs +++ b/contracts/hub-contracts/src/validating.rs @@ -12,7 +12,6 @@ pub fn validate_by_basic_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -30,7 +29,6 @@ pub fn validate_by_basic_uppercase_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // 0-9 && A-Z if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { @@ -44,7 +42,6 @@ pub fn validate_by_basic_uppercase_rule( pub fn validate_datatype( val: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -59,7 +56,6 @@ pub fn validate_url( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // = & } { : / . - _ 0-9 a-z A-Z if (*byte != 61) && (*byte != 38) && (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { @@ -77,20 +73,19 @@ pub fn validate_ipfs_cid( particle: String, field_name: String, ) -> Result { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); - } - } else { + if particle_value.version() != Version::V0 { return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); } - Ok(Response::default()) + } else { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); + } + Ok(Response::default()) } diff --git a/contracts/hub-networks/src/contract.rs b/contracts/hub-networks/src/contract.rs index 9a2ab1f..17aa1fb 100644 --- a/contracts/hub-networks/src/contract.rs +++ b/contracts/hub-networks/src/contract.rs @@ -95,5 +95,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result StdResult { let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { id, name: entry.name, @@ -33,5 +34,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } \ No newline at end of file diff --git a/contracts/hub-networks/src/validating.rs b/contracts/hub-networks/src/validating.rs index fce6f91..1f9c592 100644 --- a/contracts/hub-networks/src/validating.rs +++ b/contracts/hub-networks/src/validating.rs @@ -12,7 +12,6 @@ pub fn validate_by_basic_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -30,7 +29,6 @@ pub fn validate_period( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // 0-9 if *byte < 48 || *byte > 57 { @@ -44,7 +42,6 @@ pub fn validate_period( pub fn validate_datatype( val: String ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -58,7 +55,6 @@ pub fn validate_datatype( pub fn validate_url( val: String ) -> Result { - for byte in val.as_bytes().iter() { // : / . - _ 0-9 a-z A-Z if (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { @@ -69,48 +65,21 @@ pub fn validate_url( Ok(Response::default()) } - -// pub fn validate_particle( -// particle: Option -// ) -> Result { -// // let defaultValue=""; - -// return validate_ipfs_cid(particle.unwrap()) -// // let particle_value:Cid; -// // let try_particle = Cid::from_str(&particle.unwrap().clone()); -// // if try_particle.is_ok() { -// // particle_value = try_particle.unwrap(); - -// // if particle_value.version() != Version::V0 { - -// // return Err(ContractError::IncorrectInputData {val: "Incorrect particle".to_string()}); - -// // } -// // } else { -// // return Err(ContractError::IncorrectInputData {val: "Incorrect particle".to_string()}); -// // } -// // Ok(Response::default()) -// } - pub fn validate_ipfs_cid( particle: String ) -> Result { - - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - - return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); - - } - } else { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); + if particle_value.version() != Version::V0 { return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); } - Ok(Response::default()) + } else { + return Err(ContractError::IncorrectInputData {val: "Incorrect cid".to_string()}); + } + Ok(Response::default()) } diff --git a/contracts/hub-protocols/src/contract.rs b/contracts/hub-protocols/src/contract.rs index 96ae256..2cb405f 100644 --- a/contracts/hub-protocols/src/contract.rs +++ b/contracts/hub-protocols/src/contract.rs @@ -83,5 +83,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result(deps.storage, |id| Ok(id.add(1)))?; let new_entry = Entry { @@ -64,7 +62,9 @@ pub fn execute_create_entry( data_type: data_type, particle: particle.unwrap_or("".to_string()).to_string(), }; + LIST.save(deps.storage, id, &new_entry)?; + Ok(Response::new() .add_attribute("method", "execute_create_entry") .add_attribute("new_entry_id", id.to_string())) @@ -101,7 +101,9 @@ pub fn execute_update_entry( data_type: data_type, particle: particle.unwrap_or("".to_string()), }; + LIST.save(deps.storage, id, &updated_entry)?; + Ok(Response::new() .add_attribute("method", "execute_update_entry") .add_attribute("updated_entry_id", id.to_string())) @@ -121,6 +123,7 @@ pub fn execute_delete_entry( } LIST.remove(deps.storage, id); + Ok(Response::new() .add_attribute("method", "execute_delete_entry") .add_attribute("deleted_entry_id", id.to_string())) diff --git a/contracts/hub-protocols/src/query.rs b/contracts/hub-protocols/src/query.rs index 10c28e9..e92a87e 100644 --- a/contracts/hub-protocols/src/query.rs +++ b/contracts/hub-protocols/src/query.rs @@ -9,6 +9,7 @@ const DEFAULT_LIMIT: u32 = 20; pub fn query_entry(deps: Deps, id: u64) -> StdResult { let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { id, data_type: entry.data_type, @@ -27,5 +28,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } diff --git a/contracts/hub-protocols/src/validating.rs b/contracts/hub-protocols/src/validating.rs index f9c3ea7..f3b17be 100644 --- a/contracts/hub-protocols/src/validating.rs +++ b/contracts/hub-protocols/src/validating.rs @@ -8,7 +8,6 @@ use cosmwasm_std::{ pub fn validate_datatype( val: String ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -23,7 +22,6 @@ pub fn validate_datatype( pub fn validate_particle( particle: Option ) -> Result { - if !particle.as_ref().is_none() { let particle_value:Cid; let try_particle = Cid::from_str(&particle.as_ref().unwrap().clone()); diff --git a/contracts/hub-skills/src/contract.rs b/contracts/hub-skills/src/contract.rs index a1b020a..47e9128 100644 --- a/contracts/hub-skills/src/contract.rs +++ b/contracts/hub-skills/src/contract.rs @@ -30,6 +30,7 @@ pub fn instantiate( let config = Config { owner: Some(owner.clone()), }; + CONFIG.save(deps.storage, &config)?; ENTRY_SEQ.save(deps.storage, &0u64)?; @@ -94,5 +95,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -31,7 +30,6 @@ pub fn validate_by_basic_uppercase_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // 0-9 && A-Z if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { @@ -45,7 +43,6 @@ pub fn validate_by_basic_uppercase_rule( pub fn validate_datatype( val: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -60,7 +57,6 @@ pub fn validate_url( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // = & } { : / . - _ 0-9 a-z A-Z if (*byte != 61) && (*byte != 38) && (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { @@ -77,10 +73,10 @@ pub fn validate_by_int_range( field: Uint64, field_name: String, ) -> Result { - // let intField=Uint64::from(field); if field < from || field > to { return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Out from range", field_name).to_string()}); } + Ok(Response::default()) } @@ -90,20 +86,19 @@ pub fn validate_ipfs_cid( particle: String, field_name: String, ) -> Result { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); - } - } else { + if particle_value.version() != Version::V0 { return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); } - Ok(Response::default()) + } else { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); + } + Ok(Response::default()) } diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 3396f91..6c8505d 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -32,6 +32,7 @@ pub fn instantiate( let config = Config { owner: Some(owner.clone()), }; + CONFIG.save(deps.storage, &config)?; ENTRY_SEQ.save(deps.storage, &0u64)?; @@ -93,5 +94,6 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result StdResult { let entry = LIST.load(deps.storage, id)?; + Ok(EntryResponse { id, ticker: entry.ticker, @@ -31,5 +32,6 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S let result = ListResponse { entries: entries?.into_iter().map(|l| l.1).collect(), }; + Ok(result) } \ No newline at end of file diff --git a/contracts/hub-tokens/src/validating.rs b/contracts/hub-tokens/src/validating.rs index 0adbfc7..6575339 100644 --- a/contracts/hub-tokens/src/validating.rs +++ b/contracts/hub-tokens/src/validating.rs @@ -13,7 +13,6 @@ pub fn validate_by_basic_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -31,7 +30,6 @@ pub fn validate_by_basic_uppercase_rule( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // 0-9 && A-Z if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { @@ -45,7 +43,6 @@ pub fn validate_by_basic_uppercase_rule( pub fn validate_datatype( val: String, ) -> Result { - for byte in val.as_bytes().iter() { // - && 0-9 && a-z if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { @@ -60,7 +57,6 @@ pub fn validate_url( val: String, field_name: String, ) -> Result { - for byte in val.as_bytes().iter() { // = & } { : / . - _ 0-9 a-z A-Z if (*byte != 61) && (*byte != 38) && (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { @@ -77,33 +73,29 @@ pub fn validate_by_int_range( field: Uint64, field_name: String, ) -> Result { - // let intField=Uint64::from(field); if field < from || field > to { return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Out from range", field_name).to_string()}); } Ok(Response::default()) } - - pub fn validate_ipfs_cid( particle: String, field_name: String, ) -> Result { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); - let particle_value:Cid; - let try_particle = Cid::from_str(&particle.clone()); - if try_particle.is_ok() { - particle_value = try_particle.unwrap(); - - if particle_value.version() != Version::V0 { - return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); - } - } else { + if particle_value.version() != Version::V0 { return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); } - Ok(Response::default()) + } else { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); + } + Ok(Response::default()) } From a2dbeef0ad8defcbd373ec4437303464d5341f68 Mon Sep 17 00:00:00 2001 From: master Date: Wed, 14 Dec 2022 11:54:04 +0000 Subject: [PATCH 20/33] Update contract.rs --- contracts/hub-tokens/src/contract.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 6c8505d..4ea31bb 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -54,7 +54,8 @@ pub fn execute( ExecuteMsg::CreateEntry { ticker, chain_id, - denom, + contract, + decimals, channel, logo, particle, @@ -63,7 +64,8 @@ pub fn execute( id, ticker, chain_id, - denom, + contract, + decimals, channel, logo, particle, @@ -96,4 +98,4 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result Date: Wed, 14 Dec 2022 11:54:56 +0000 Subject: [PATCH 21/33] Update query.rs --- contracts/hub-tokens/src/query.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/hub-tokens/src/query.rs b/contracts/hub-tokens/src/query.rs index c803a71..dc56caa 100644 --- a/contracts/hub-tokens/src/query.rs +++ b/contracts/hub-tokens/src/query.rs @@ -14,7 +14,8 @@ pub fn query_entry(deps: Deps, id: u64) -> StdResult { id, ticker: entry.ticker, chain_id: entry.chain_id, - denom: entry.denom, + contract: entry.contract, + decimals: entry.decimals, channel: entry.channel, logo: entry.logo, particle: entry.particle @@ -34,4 +35,4 @@ pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> S }; Ok(result) -} \ No newline at end of file +} From 8c34df4f2cd7f9076e6c318070229900007afcfc Mon Sep 17 00:00:00 2001 From: master Date: Wed, 14 Dec 2022 11:55:40 +0000 Subject: [PATCH 22/33] Update state.rs --- contracts/hub-tokens/src/state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/hub-tokens/src/state.rs b/contracts/hub-tokens/src/state.rs index 7869275..d2acc5d 100644 --- a/contracts/hub-tokens/src/state.rs +++ b/contracts/hub-tokens/src/state.rs @@ -15,7 +15,8 @@ pub struct Entry { pub id: u64, pub ticker: String, pub chain_id: String, - pub denom: String, + pub contract: String, + pub decimals: Uint64, pub channel: Uint64, pub logo: String, pub particle: String, From 834cedd11c16255c9a3c2e1defd331a3ae92d041 Mon Sep 17 00:00:00 2001 From: master Date: Wed, 14 Dec 2022 11:57:04 +0000 Subject: [PATCH 23/33] Update msg.rs --- contracts/hub-tokens/src/msg.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/hub-tokens/src/msg.rs b/contracts/hub-tokens/src/msg.rs index fb97fec..094e491 100644 --- a/contracts/hub-tokens/src/msg.rs +++ b/contracts/hub-tokens/src/msg.rs @@ -16,7 +16,8 @@ pub enum ExecuteMsg { CreateEntry { ticker: String, chain_id: String, - denom: String, + contract: String, + decimals: Uint64, channel: Uint64, logo: String, particle: Option, @@ -25,7 +26,8 @@ pub enum ExecuteMsg { id: u64, ticker: Option, chain_id: Option, - denom: Option, + contract: Option, + decimals: Option, channel: Option, logo: Option, particle: Option, @@ -53,7 +55,8 @@ pub struct EntryResponse { pub id: u64, pub ticker: String, pub chain_id: String, - pub denom: String, + pub contract: String, + pub decimals: Uint64, pub channel: Uint64, pub logo: String, pub particle: String, From 4c56b82d960f81bd19cefc867bbd5befd4ade22e Mon Sep 17 00:00:00 2001 From: master Date: Wed, 14 Dec 2022 11:58:27 +0000 Subject: [PATCH 24/33] Update tests.rs --- contracts/hub-tokens/src/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index bab8a60..6d9d24e 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -60,7 +60,8 @@ mod tests { let msg = ExecuteMsg::CreateEntry { chain_id: "testchain-1".to_string(), ticker: "TST".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), From 13466f49b3461be89e1044cfdfabf57d84b8f6c5 Mon Sep 17 00:00:00 2001 From: master Date: Wed, 14 Dec 2022 12:00:18 +0000 Subject: [PATCH 25/33] Update tests.rs --- contracts/hub-tokens/src/tests.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index 6d9d24e..6c8cc2b 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -79,7 +79,8 @@ mod tests { let msg = ExecuteMsg::CreateEntry { ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), @@ -111,7 +112,8 @@ mod tests { id: 1, chain_id: "testchain-1".to_string(), ticker: "TST".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -120,7 +122,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -134,7 +137,8 @@ mod tests { id: 1, ticker: Some("TSTUPDATE".to_string()), chain_id: Some("testchain-1".to_string()), - denom: Some("cyb".to_string()), + contract: Some("cyb".to_string()), + decimals: Uint64::new(6), channel: Some(Uint64::new(1)), logo: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), @@ -168,7 +172,8 @@ mod tests { id: 1, ticker: "TSTUPDATE".to_string(), chain_id: "testchain-1".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -177,7 +182,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -213,7 +219,8 @@ mod tests { id: 2, ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), - denom: "cyb".to_string(), + contract: "cyb".to_string(), + decimals: Uint64::new(6), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), From 23973b8a648ed3ce64349449bedafafb89f49831 Mon Sep 17 00:00:00 2001 From: master Date: Tue, 27 Dec 2022 03:02:03 +0000 Subject: [PATCH 26/33] fix hub-tokens --- contracts/hub-tokens/src/contract.rs | 4 ++-- contracts/hub-tokens/src/execute.rs | 12 ++++++++---- contracts/hub-tokens/src/tests.rs | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/contracts/hub-tokens/src/contract.rs b/contracts/hub-tokens/src/contract.rs index 4ea31bb..6f580da 100644 --- a/contracts/hub-tokens/src/contract.rs +++ b/contracts/hub-tokens/src/contract.rs @@ -59,7 +59,7 @@ pub fn execute( channel, logo, particle, - } => execute_create_entry(deps, info, ticker, chain_id, denom, channel, logo, particle), + } => execute_create_entry(deps, info, ticker, chain_id, contract, decimals, channel, logo, particle), ExecuteMsg::UpdateEntry { id, ticker, @@ -69,7 +69,7 @@ pub fn execute( channel, logo, particle, - } => execute_update_entry(deps, info, id, ticker, chain_id, denom, channel, logo, particle), + } => execute_update_entry(deps, info, id, ticker, chain_id, contract, decimals, channel, logo, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-tokens/src/execute.rs b/contracts/hub-tokens/src/execute.rs index 6f83e89..db756b4 100644 --- a/contracts/hub-tokens/src/execute.rs +++ b/contracts/hub-tokens/src/execute.rs @@ -37,7 +37,8 @@ pub fn execute_create_entry( info: MessageInfo, ticker: String, chain_id: String, - denom: String, + contract: String, + decimals: Uint64, channel: Uint64, logo: String, particle: Option, @@ -81,7 +82,8 @@ pub fn execute_create_entry( id, ticker, chain_id, - denom, + contract, + decimals, channel, logo, particle: particle.unwrap_or("".to_string()) @@ -100,7 +102,8 @@ pub fn execute_update_entry( id: u64, ticker: Option, chain_id: Option, - denom: Option, + contract: Option, + decimals: Option, channel: Option, logo: Option, particle: Option, @@ -142,7 +145,8 @@ pub fn execute_update_entry( let updated_entry = Entry { id, ticker: ticker.unwrap_or(entry.ticker), - denom: denom.unwrap_or(entry.denom), + contract: contract.unwrap_or(entry.contract), + decimals: decimals.unwrap_or(entry.decimals), chain_id: chain_id.unwrap_or(entry.chain_id), channel: channel.unwrap_or(entry.channel), logo: logo.unwrap_or(entry.logo), diff --git a/contracts/hub-tokens/src/tests.rs b/contracts/hub-tokens/src/tests.rs index 6c8cc2b..bf3053f 100644 --- a/contracts/hub-tokens/src/tests.rs +++ b/contracts/hub-tokens/src/tests.rs @@ -123,7 +123,7 @@ mod tests { ticker: "TST2".to_string(), chain_id: "testchain-1".to_string(), contract: "cyb".to_string(), - decimals: Uint64::new(6), + decimals: Uint64::new(8), channel: Uint64::new(1), logo: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), @@ -138,7 +138,7 @@ mod tests { ticker: Some("TSTUPDATE".to_string()), chain_id: Some("testchain-1".to_string()), contract: Some("cyb".to_string()), - decimals: Uint64::new(6), + decimals: Some(Uint64::new(7)), channel: Some(Uint64::new(1)), logo: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), From 327e6dffdff27e4af5ecb3a8564fd1dee9078939 Mon Sep 17 00:00:00 2001 From: master Date: Fri, 6 Jan 2023 07:12:08 +0000 Subject: [PATCH 27/33] add active field to channels --- contracts/hub-channels/src/contract.rs | 4 +++- contracts/hub-channels/src/execute.rs | 3 +++ contracts/hub-channels/src/msg.rs | 3 +++ contracts/hub-channels/src/query.rs | 1 + contracts/hub-channels/src/state.rs | 2 ++ contracts/hub-channels/src/tests.rs | 8 ++++++++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 0c2011e..393c45f 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -51,6 +51,7 @@ pub fn execute( match msg { ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), ExecuteMsg::CreateEntry { + active, source_chain_id, destination_chain_id, source_channel_id, @@ -58,9 +59,10 @@ pub fn execute( explorer_url, particle - } => execute_create_entry(deps, info, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), + } => execute_create_entry(deps, info, active, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::UpdateEntry { id, + active, source_chain_id, destination_chain_id, source_channel_id, diff --git a/contracts/hub-channels/src/execute.rs b/contracts/hub-channels/src/execute.rs index 6d42a60..7207312 100644 --- a/contracts/hub-channels/src/execute.rs +++ b/contracts/hub-channels/src/execute.rs @@ -34,6 +34,7 @@ pub fn execute_update_owner( pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, + active: bool, source_chain_id: String, destination_chain_id: String, source_channel_id: String, @@ -82,6 +83,7 @@ pub fn execute_create_entry( let new_entry = Entry { id, + active, source_chain_id, destination_chain_id, source_channel_id, @@ -101,6 +103,7 @@ pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, + active: bool, source_chain_id: Option, destination_chain_id: Option, source_channel_id: Option, diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index e1d91f1..4d8aba9 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -14,6 +14,7 @@ pub enum ExecuteMsg { new_owner: Option, }, CreateEntry { + active: bool, source_chain_id: String, destination_chain_id: String, source_channel_id: String, @@ -23,6 +24,7 @@ pub enum ExecuteMsg { }, UpdateEntry { id: u64, + active: bool, source_chain_id: Option, destination_chain_id: Option, source_channel_id: Option, @@ -51,6 +53,7 @@ pub struct MigrateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, + pub active: bool, pub source_chain_id: String, pub destination_chain_id: String, pub source_channel_id: String, diff --git a/contracts/hub-channels/src/query.rs b/contracts/hub-channels/src/query.rs index 002ae3f..24c7301 100644 --- a/contracts/hub-channels/src/query.rs +++ b/contracts/hub-channels/src/query.rs @@ -12,6 +12,7 @@ pub fn query_entry(deps: Deps, id: u64) -> StdResult { Ok(EntryResponse { id: entry.id, + active: entry.active, source_chain_id: entry.source_chain_id, destination_chain_id: entry.destination_chain_id, source_channel_id: entry.source_channel_id, diff --git a/contracts/hub-channels/src/state.rs b/contracts/hub-channels/src/state.rs index 3ef20b8..2a5f0ef 100644 --- a/contracts/hub-channels/src/state.rs +++ b/contracts/hub-channels/src/state.rs @@ -13,12 +13,14 @@ pub struct Config { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Entry { pub id: u64, + pub active: bool, pub source_chain_id: String, pub destination_chain_id: String, pub source_channel_id: String, pub destination_channel_id: String, pub explorer_url: String, pub particle: String, + pub(crate) active: bool, } pub const CONFIG: Item = Item::new("config"); diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index 32dbb81..b60676d 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -57,6 +57,7 @@ mod tests { assert_eq!(0, res.messages.len()); let msg = ExecuteMsg::CreateEntry { + active: true, source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -75,6 +76,7 @@ mod tests { ); let msg = ExecuteMsg::CreateEntry { + active: true, source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -107,6 +109,7 @@ mod tests { Vec::from([ Entry { id: 1, + active: true, source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -116,6 +119,7 @@ mod tests { }, Entry { id: 2, + active: true, source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -130,6 +134,7 @@ mod tests { // Update entry let message = ExecuteMsg::UpdateEntry { id: 1, + active: false, source_chain_id: Some("bostrom-1".to_string()), destination_chain_id: Some("cosmos-1".to_string()), source_channel_id: Some("channel-256".to_string()), @@ -162,6 +167,7 @@ mod tests { Vec::from([ Entry { id: 1, + active: true, source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -171,6 +177,7 @@ mod tests { }, Entry { id: 2, + active: false, source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -207,6 +214,7 @@ mod tests { assert_eq!( Vec::from([Entry { id: 2, + active: false, source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), From 4096fa4c3470736ba32a60373fc8d13a6047e270 Mon Sep 17 00:00:00 2001 From: master Date: Fri, 6 Jan 2023 07:15:13 +0000 Subject: [PATCH 28/33] add protocols schema --- .../hub-protocols/src/schema/execute_msg.json | 106 ++++++++++++++++++ .../src/schema/instantiate_msg.json | 3 + .../hub-protocols/src/schema/query_msg.json | 58 ++++++++++ 3 files changed, 167 insertions(+) create mode 100644 contracts/hub-protocols/src/schema/execute_msg.json create mode 100644 contracts/hub-protocols/src/schema/instantiate_msg.json create mode 100644 contracts/hub-protocols/src/schema/query_msg.json diff --git a/contracts/hub-protocols/src/schema/execute_msg.json b/contracts/hub-protocols/src/schema/execute_msg.json new file mode 100644 index 0000000..3098769 --- /dev/null +++ b/contracts/hub-protocols/src/schema/execute_msg.json @@ -0,0 +1,106 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "data_type" + ], + "properties": { + "data_type": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "data_type", + "id" + ], + "properties": { + "data_type": { + "type": "string" + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "particle": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-protocols/src/schema/instantiate_msg.json b/contracts/hub-protocols/src/schema/instantiate_msg.json new file mode 100644 index 0000000..2f38907 --- /dev/null +++ b/contracts/hub-protocols/src/schema/instantiate_msg.json @@ -0,0 +1,3 @@ +{ + "owner": "bostrom1d8754xqa9245pctlfcyv8eah468neqzn3a0y0t" +} \ No newline at end of file diff --git a/contracts/hub-protocols/src/schema/query_msg.json b/contracts/hub-protocols/src/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-protocols/src/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} From 16e4ba972c111be01b1ec6eafd09b9198d8ee68c Mon Sep 17 00:00:00 2001 From: master Date: Fri, 6 Jan 2023 08:05:42 +0000 Subject: [PATCH 29/33] fix active field --- contracts/hub-channels/src/contract.rs | 2 +- contracts/hub-channels/src/execute.rs | 5 +++-- contracts/hub-channels/src/msg.rs | 6 +++--- contracts/hub-channels/src/state.rs | 3 +-- contracts/hub-channels/src/tests.rs | 16 ++++++++-------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/contracts/hub-channels/src/contract.rs b/contracts/hub-channels/src/contract.rs index 393c45f..1faff6b 100644 --- a/contracts/hub-channels/src/contract.rs +++ b/contracts/hub-channels/src/contract.rs @@ -69,7 +69,7 @@ pub fn execute( destination_channel_id, explorer_url, particle, - } => execute_update_entry(deps, info, id, source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), + } => execute_update_entry(deps, info, id, Some(active), source_chain_id, destination_chain_id, source_channel_id, destination_channel_id, explorer_url, particle), ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), } } diff --git a/contracts/hub-channels/src/execute.rs b/contracts/hub-channels/src/execute.rs index 7207312..56d0976 100644 --- a/contracts/hub-channels/src/execute.rs +++ b/contracts/hub-channels/src/execute.rs @@ -34,7 +34,7 @@ pub fn execute_update_owner( pub fn execute_create_entry( deps: DepsMut, info: MessageInfo, - active: bool, + active: String, source_chain_id: String, destination_chain_id: String, source_channel_id: String, @@ -103,7 +103,7 @@ pub fn execute_update_entry( deps: DepsMut, info: MessageInfo, id: u64, - active: bool, + active: Option, source_chain_id: Option, destination_chain_id: Option, source_channel_id: Option, @@ -151,6 +151,7 @@ pub fn execute_update_entry( let entry = LIST.load(deps.storage, id)?; let updated_entry = Entry { id, + active: active.unwrap_or(entry.active), source_chain_id: source_chain_id.unwrap_or(entry.source_chain_id), destination_chain_id: destination_chain_id.unwrap_or(entry.destination_chain_id), source_channel_id: source_channel_id.unwrap_or(entry.source_channel_id), diff --git a/contracts/hub-channels/src/msg.rs b/contracts/hub-channels/src/msg.rs index 4d8aba9..39a0e67 100644 --- a/contracts/hub-channels/src/msg.rs +++ b/contracts/hub-channels/src/msg.rs @@ -14,7 +14,7 @@ pub enum ExecuteMsg { new_owner: Option, }, CreateEntry { - active: bool, + active: String, source_chain_id: String, destination_chain_id: String, source_channel_id: String, @@ -24,7 +24,7 @@ pub enum ExecuteMsg { }, UpdateEntry { id: u64, - active: bool, + active: String, source_chain_id: Option, destination_chain_id: Option, source_channel_id: Option, @@ -53,7 +53,7 @@ pub struct MigrateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct EntryResponse { pub id: u64, - pub active: bool, + pub active: String, pub source_chain_id: String, pub destination_chain_id: String, pub source_channel_id: String, diff --git a/contracts/hub-channels/src/state.rs b/contracts/hub-channels/src/state.rs index 2a5f0ef..3452140 100644 --- a/contracts/hub-channels/src/state.rs +++ b/contracts/hub-channels/src/state.rs @@ -13,14 +13,13 @@ pub struct Config { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct Entry { pub id: u64, - pub active: bool, + pub active: String, pub source_chain_id: String, pub destination_chain_id: String, pub source_channel_id: String, pub destination_channel_id: String, pub explorer_url: String, pub particle: String, - pub(crate) active: bool, } pub const CONFIG: Item = Item::new("config"); diff --git a/contracts/hub-channels/src/tests.rs b/contracts/hub-channels/src/tests.rs index b60676d..7d9aed0 100644 --- a/contracts/hub-channels/src/tests.rs +++ b/contracts/hub-channels/src/tests.rs @@ -57,7 +57,7 @@ mod tests { assert_eq!(0, res.messages.len()); let msg = ExecuteMsg::CreateEntry { - active: true, + active: "active".to_string(), source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -76,7 +76,7 @@ mod tests { ); let msg = ExecuteMsg::CreateEntry { - active: true, + active: "active".to_string(), source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -109,7 +109,7 @@ mod tests { Vec::from([ Entry { id: 1, - active: true, + active: "active".to_string(), source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -119,7 +119,7 @@ mod tests { }, Entry { id: 2, - active: true, + active: "active".to_string(), source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -134,7 +134,7 @@ mod tests { // Update entry let message = ExecuteMsg::UpdateEntry { id: 1, - active: false, + active: "active".to_string(), source_chain_id: Some("bostrom-1".to_string()), destination_chain_id: Some("cosmos-1".to_string()), source_channel_id: Some("channel-256".to_string()), @@ -167,7 +167,7 @@ mod tests { Vec::from([ Entry { id: 1, - active: true, + active: "active".to_string(), source_chain_id: "bostrom-1".to_string(), destination_chain_id: "cosmos-1".to_string(), source_channel_id: "channel-256".to_string(), @@ -177,7 +177,7 @@ mod tests { }, Entry { id: 2, - active: false, + active: "active".to_string(), source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), @@ -214,7 +214,7 @@ mod tests { assert_eq!( Vec::from([Entry { id: 2, - active: false, + active: "active".to_string(), source_chain_id: "bostrom-2".to_string(), destination_chain_id: "cosmos-2".to_string(), source_channel_id: "channel-2".to_string(), From e0ea67aa28567d45515dfa48fd4b1d767e927456 Mon Sep 17 00:00:00 2001 From: master Date: Fri, 6 Jan 2023 08:06:06 +0000 Subject: [PATCH 30/33] remove schema gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 48b3822..b83f62d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ target/ artifacts packages/*/schema -contracts/*/schema From 529c32d0fea0727d26d64e925be468c5186f2bac Mon Sep 17 00:00:00 2001 From: master Date: Fri, 6 Jan 2023 08:06:25 +0000 Subject: [PATCH 31/33] hub schemas --- .../hub-channels/schema/execute_msg.json | 156 ++++++++++++++++ .../hub-channels/schema/instantiate_msg.json | 13 ++ contracts/hub-channels/schema/query_msg.json | 58 ++++++ .../hub-contracts/schema/execute_msg.json | 148 +++++++++++++++ .../hub-contracts/schema/instantiate_msg.json | 13 ++ contracts/hub-contracts/schema/query_msg.json | 58 ++++++ .../hub-networks/schema/execute_msg.json | 168 +++++++++++++++++ .../hub-networks/schema/instantiate_msg.json | 13 ++ contracts/hub-networks/schema/query_msg.json | 58 ++++++ contracts/hub-skills/schema/execute_msg.json | 164 +++++++++++++++++ .../hub-skills/schema/instantiate_msg.json | 13 ++ contracts/hub-skills/schema/query_msg.json | 142 +++++++++++++++ contracts/hub-tokens/schema/execute_msg.json | 172 ++++++++++++++++++ .../hub-tokens/schema/instantiate_msg.json | 13 ++ contracts/hub-tokens/schema/query_msg.json | 58 ++++++ 15 files changed, 1247 insertions(+) create mode 100644 contracts/hub-channels/schema/execute_msg.json create mode 100644 contracts/hub-channels/schema/instantiate_msg.json create mode 100644 contracts/hub-channels/schema/query_msg.json create mode 100644 contracts/hub-contracts/schema/execute_msg.json create mode 100644 contracts/hub-contracts/schema/instantiate_msg.json create mode 100644 contracts/hub-contracts/schema/query_msg.json create mode 100644 contracts/hub-networks/schema/execute_msg.json create mode 100644 contracts/hub-networks/schema/instantiate_msg.json create mode 100644 contracts/hub-networks/schema/query_msg.json create mode 100644 contracts/hub-skills/schema/execute_msg.json create mode 100644 contracts/hub-skills/schema/instantiate_msg.json create mode 100644 contracts/hub-skills/schema/query_msg.json create mode 100644 contracts/hub-tokens/schema/execute_msg.json create mode 100644 contracts/hub-tokens/schema/instantiate_msg.json create mode 100644 contracts/hub-tokens/schema/query_msg.json diff --git a/contracts/hub-channels/schema/execute_msg.json b/contracts/hub-channels/schema/execute_msg.json new file mode 100644 index 0000000..0a86b8e --- /dev/null +++ b/contracts/hub-channels/schema/execute_msg.json @@ -0,0 +1,156 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "active", + "destination_chain_id", + "destination_channel_id", + "explorer_url", + "source_chain_id", + "source_channel_id" + ], + "properties": { + "active": { + "type": "string" + }, + "destination_chain_id": { + "type": "string" + }, + "destination_channel_id": { + "type": "string" + }, + "explorer_url": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "source_chain_id": { + "type": "string" + }, + "source_channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "active", + "id" + ], + "properties": { + "active": { + "type": "string" + }, + "destination_chain_id": { + "type": [ + "string", + "null" + ] + }, + "destination_channel_id": { + "type": [ + "string", + "null" + ] + }, + "explorer_url": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "source_chain_id": { + "type": [ + "string", + "null" + ] + }, + "source_channel_id": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-channels/schema/instantiate_msg.json b/contracts/hub-channels/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-channels/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-channels/schema/query_msg.json b/contracts/hub-channels/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-channels/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-contracts/schema/execute_msg.json b/contracts/hub-contracts/schema/execute_msg.json new file mode 100644 index 0000000..5e6d165 --- /dev/null +++ b/contracts/hub-contracts/schema/execute_msg.json @@ -0,0 +1,148 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "address", + "chain_id", + "execute_cid", + "query_cid", + "version" + ], + "properties": { + "address": { + "type": "string" + }, + "chain_id": { + "type": "string" + }, + "execute_cid": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "query_cid": { + "type": "string" + }, + "version": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "address": { + "type": [ + "string", + "null" + ] + }, + "chain_id": { + "type": [ + "string", + "null" + ] + }, + "execute_cid": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "query_cid": { + "type": [ + "string", + "null" + ] + }, + "version": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-contracts/schema/instantiate_msg.json b/contracts/hub-contracts/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-contracts/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-contracts/schema/query_msg.json b/contracts/hub-contracts/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-contracts/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-networks/schema/execute_msg.json b/contracts/hub-networks/schema/execute_msg.json new file mode 100644 index 0000000..f3974cc --- /dev/null +++ b/contracts/hub-networks/schema/execute_msg.json @@ -0,0 +1,168 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "chain_id", + "genesis_hash", + "logo", + "name", + "prefix", + "protocol", + "unbonding_period" + ], + "properties": { + "chain_id": { + "type": "string" + }, + "genesis_hash": { + "type": "string" + }, + "logo": { + "type": "string" + }, + "name": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "prefix": { + "type": "string" + }, + "protocol": { + "type": "string" + }, + "unbonding_period": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "chain_id": { + "type": [ + "string", + "null" + ] + }, + "genesis_hash": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "logo": { + "type": [ + "string", + "null" + ] + }, + "name": { + "type": [ + "string", + "null" + ] + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "prefix": { + "type": [ + "string", + "null" + ] + }, + "protocol": { + "type": [ + "string", + "null" + ] + }, + "unbonding_period": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-networks/schema/instantiate_msg.json b/contracts/hub-networks/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-networks/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-networks/schema/query_msg.json b/contracts/hub-networks/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-networks/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-skills/schema/execute_msg.json b/contracts/hub-skills/schema/execute_msg.json new file mode 100644 index 0000000..034fe97 --- /dev/null +++ b/contracts/hub-skills/schema/execute_msg.json @@ -0,0 +1,164 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntryOwner" + ], + "properties": { + "UpdateEntryOwner": { + "type": "object", + "required": [ + "id", + "new_owner" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "new_owner": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "endpoint", + "network", + "neuron", + "protocol" + ], + "properties": { + "endpoint": { + "type": "string" + }, + "network": { + "type": "string" + }, + "neuron": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "protocol": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "endpoint": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "network": { + "type": [ + "string", + "null" + ] + }, + "neuron": { + "type": [ + "string", + "null" + ] + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "protocol": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-skills/schema/instantiate_msg.json b/contracts/hub-skills/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-skills/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-skills/schema/query_msg.json b/contracts/hub-skills/schema/query_msg.json new file mode 100644 index 0000000..ab97d17 --- /dev/null +++ b/contracts/hub-skills/schema/query_msg.json @@ -0,0 +1,142 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "required": [ + "owner" + ], + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "owner": { + "$ref": "#/definitions/Addr" + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entries_protocol" + ], + "properties": { + "get_entries_protocol": { + "type": "object", + "required": [ + "protocol" + ], + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "protocol": { + "type": "string" + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entries_network" + ], + "properties": { + "get_entries_network": { + "type": "object", + "required": [ + "network" + ], + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "network": { + "type": "string" + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ], + "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/contracts/hub-tokens/schema/execute_msg.json b/contracts/hub-tokens/schema/execute_msg.json new file mode 100644 index 0000000..2758170 --- /dev/null +++ b/contracts/hub-tokens/schema/execute_msg.json @@ -0,0 +1,172 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "chain_id", + "channel", + "contract", + "decimals", + "logo", + "ticker" + ], + "properties": { + "chain_id": { + "type": "string" + }, + "channel": { + "$ref": "#/definitions/Uint64" + }, + "contract": { + "type": "string" + }, + "decimals": { + "$ref": "#/definitions/Uint64" + }, + "logo": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "ticker": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "chain_id": { + "type": [ + "string", + "null" + ] + }, + "channel": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, + "contract": { + "type": [ + "string", + "null" + ] + }, + "decimals": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "logo": { + "type": [ + "string", + "null" + ] + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "ticker": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/hub-tokens/schema/instantiate_msg.json b/contracts/hub-tokens/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-tokens/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-tokens/schema/query_msg.json b/contracts/hub-tokens/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-tokens/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} From ed614a0d89aa77276f7ed4769770a330fdc9b651 Mon Sep 17 00:00:00 2001 From: master Date: Sat, 7 Jan 2023 08:02:34 +0000 Subject: [PATCH 32/33] add libs registry --- Cargo.lock | 15 ++ contracts/hub-libs/.cargo/config | 4 + contracts/hub-libs/Cargo.toml | 42 ++++ contracts/hub-libs/examples/schema.rs | 17 ++ contracts/hub-libs/schema/execute_msg.json | 136 +++++++++++ .../hub-libs/schema/instantiate_msg.json | 13 ++ contracts/hub-libs/schema/query_msg.json | 58 +++++ contracts/hub-libs/src/contract.rs | 94 ++++++++ contracts/hub-libs/src/error.rs | 20 ++ contracts/hub-libs/src/execute.rs | 172 ++++++++++++++ contracts/hub-libs/src/lib.rs | 10 + contracts/hub-libs/src/msg.rs | 61 +++++ contracts/hub-libs/src/query.rs | 36 +++ contracts/hub-libs/src/state.rs | 25 ++ contracts/hub-libs/src/tests.rs | 217 ++++++++++++++++++ contracts/hub-libs/src/validating.rs | 91 ++++++++ 16 files changed, 1011 insertions(+) create mode 100644 contracts/hub-libs/.cargo/config create mode 100644 contracts/hub-libs/Cargo.toml create mode 100644 contracts/hub-libs/examples/schema.rs create mode 100644 contracts/hub-libs/schema/execute_msg.json create mode 100644 contracts/hub-libs/schema/instantiate_msg.json create mode 100644 contracts/hub-libs/schema/query_msg.json create mode 100644 contracts/hub-libs/src/contract.rs create mode 100644 contracts/hub-libs/src/error.rs create mode 100644 contracts/hub-libs/src/execute.rs create mode 100644 contracts/hub-libs/src/lib.rs create mode 100644 contracts/hub-libs/src/msg.rs create mode 100644 contracts/hub-libs/src/query.rs create mode 100644 contracts/hub-libs/src/state.rs create mode 100644 contracts/hub-libs/src/tests.rs create mode 100644 contracts/hub-libs/src/validating.rs diff --git a/Cargo.lock b/Cargo.lock index ed80611..2e420fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1293,6 +1293,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "hub-libs" +version = "0.1.0" +dependencies = [ + "cid", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "hub-networks" version = "0.1.0" diff --git a/contracts/hub-libs/.cargo/config b/contracts/hub-libs/.cargo/config new file mode 100644 index 0000000..336b618 --- /dev/null +++ b/contracts/hub-libs/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" diff --git a/contracts/hub-libs/Cargo.toml b/contracts/hub-libs/Cargo.toml new file mode 100644 index 0000000..1b4cdcb --- /dev/null +++ b/contracts/hub-libs/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "hub-libs" +version = "0.1.0" +authors = ["master"] +edition = "2018" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[package.metadata.scripts] +optimize = """docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.12.6 +""" + +[dependencies] +cosmwasm-std = { version = "1.0.0", features = ["iterator", "abort"] } +cw-storage-plus = { version = "0.13.4" } +cw2 = { version = "0.13.4" } +schemars = "0.8.10" +serde = { version = "1.0.140", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.31" } +cid = { version = "0.8.0" } + +[dev-dependencies] +cosmwasm-schema = "1.0.0" +cw-multi-test = "0.13.2" diff --git a/contracts/hub-libs/examples/schema.rs b/contracts/hub-libs/examples/schema.rs new file mode 100644 index 0000000..0e6f579 --- /dev/null +++ b/contracts/hub-libs/examples/schema.rs @@ -0,0 +1,17 @@ +use std::env::current_dir; +use std::fs::create_dir_all; + +use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; + +use hub_libs::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); +} diff --git a/contracts/hub-libs/schema/execute_msg.json b/contracts/hub-libs/schema/execute_msg.json new file mode 100644 index 0000000..6f8a5c2 --- /dev/null +++ b/contracts/hub-libs/schema/execute_msg.json @@ -0,0 +1,136 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "address", + "chain_id", + "init_particle", + "version" + ], + "properties": { + "address": { + "type": "string" + }, + "chain_id": { + "type": "string" + }, + "init_particle": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "version": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "address", + "id" + ], + "properties": { + "address": { + "type": "string" + }, + "chain_id": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "init_particle": { + "type": [ + "string", + "null" + ] + }, + "particle": { + "type": [ + "string", + "null" + ] + }, + "version": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-libs/schema/instantiate_msg.json b/contracts/hub-libs/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-libs/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-libs/schema/query_msg.json b/contracts/hub-libs/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-libs/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-libs/src/contract.rs b/contracts/hub-libs/src/contract.rs new file mode 100644 index 0000000..f416c48 --- /dev/null +++ b/contracts/hub-libs/src/contract.rs @@ -0,0 +1,94 @@ +use cosmwasm_std::{ + Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, to_binary, +}; +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cw2::{get_contract_version, set_contract_version}; + +use crate::error::ContractError; +use crate::execute::{execute_create_entry, execute_delete_entry, execute_update_entry, execute_update_owner}; +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::query::{query_entry, query_list}; +use crate::state::{Config, CONFIG, ENTRY_SEQ}; + +//@TODO git version iteract +const CONTRACT_NAME: &str = "hub-libs"; +const CONTRACT_VERSION: &str = "0.1.0"; + +#[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)?; + + let owner = msg + .owner + .and_then(|addr_string| deps.api.addr_validate(addr_string.as_str()).ok()) + .unwrap_or(info.sender); + + let config = Config { + owner: Some(owner.clone()), + }; + CONFIG.save(deps.storage, &config)?; + + ENTRY_SEQ.save(deps.storage, &0u64)?; + + Ok(Response::new() + .add_attribute("method", "instantiate") + .add_attribute("owner", owner)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + ExecuteMsg::UpdateOwner { new_owner } => execute_update_owner(deps, env, info, new_owner), + ExecuteMsg::CreateEntry { + address, + init_particle, + version, + chain_id, + particle, + } => execute_create_entry(deps, info, address, init_particle, version, chain_id, particle), + ExecuteMsg::UpdateEntry { + id, + address, + init_particle, + version, + chain_id, + particle, + } => execute_update_entry(deps, info, id, Some(address), init_particle, version, chain_id, particle), + ExecuteMsg::DeleteEntry { id } => execute_delete_entry(deps, info, id), + } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::GetEntries { start_after, limit } => { + to_binary(&query_list(deps, start_after, limit)?) + } + QueryMsg::GetEntry { id } => { + to_binary(&query_entry(deps, id)?) + } + } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + + Ok(Response::default()) +} \ No newline at end of file diff --git a/contracts/hub-libs/src/error.rs b/contracts/hub-libs/src/error.rs new file mode 100644 index 0000000..863e417 --- /dev/null +++ b/contracts/hub-libs/src/error.rs @@ -0,0 +1,20 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, + + #[error("IncorrectInputData val: {val:?}")] + IncorrectInputData {val: String }, + + #[error("Custom Error val: {val:?}")] + CustomError { val: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, +} diff --git a/contracts/hub-libs/src/execute.rs b/contracts/hub-libs/src/execute.rs new file mode 100644 index 0000000..93dba09 --- /dev/null +++ b/contracts/hub-libs/src/execute.rs @@ -0,0 +1,172 @@ +use std::ops::Add; + +use cosmwasm_std::{attr, DepsMut, Env, MessageInfo, Response, StdResult}; + +use crate::error::ContractError; +use crate::state::{CONFIG, Entry, ENTRY_SEQ, LIST}; +use crate::validating::{validate_by_basic_rule, validate_ipfs_cid, validate_url}; + +pub fn execute_update_owner( + deps: DepsMut, + _env: Env, + info: MessageInfo, + new_owner: Option, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + let owner = cfg.owner.ok_or(ContractError::Unauthorized {})?; + if info.sender != owner { + return Err(ContractError::Unauthorized {}); + } + + let mut tmp_owner = None; + if let Some(addr) = new_owner { + tmp_owner = Some(deps.api.addr_validate(&addr)?) + } + + CONFIG.update(deps.storage, |mut exists| -> StdResult<_> { + exists.owner = tmp_owner; + Ok(exists) + })?; + + Ok(Response::new().add_attributes(vec![attr("action", "update_owner")])) +} + +pub fn execute_create_entry( + deps: DepsMut, + info: MessageInfo, + address: String, + init_particle: String, + version: String, + chain_id: String, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_address = validate_by_basic_rule(address.clone(), "address".to_string()); + let validate_init_particle = validate_ipfs_cid(init_particle.clone(), "init_particle".to_string()); + let validate_version = validate_url(version.clone(), "version".to_string()); + let validate_chain_id = validate_url(chain_id.clone(), "chain_id".to_string()); + + if validate_address.is_err() { + return validate_address; + } + if validate_init_particle.is_err() { + return validate_init_particle; + } + if validate_version.is_err() { + return validate_version; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + let id = ENTRY_SEQ.update::<_, cosmwasm_std::StdError>(deps.storage, |id| Ok(id.add(1)))?; + + let new_entry = Entry { + id, + address, + init_particle, + version, + chain_id, + particle: particle.unwrap_or("".to_string()), + }; + + LIST.save(deps.storage, id, &new_entry)?; + + Ok(Response::new() + .add_attribute("method", "execute_create_entry") + .add_attribute("new_entry_id", id.to_string())) +} + +pub fn execute_update_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, + address: Option, + init_particle: Option, + version: Option, + chain_id: Option, + particle: Option, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + if !particle.as_ref().is_none() { + let validate_particle = validate_ipfs_cid(particle.clone().unwrap(),"particle".to_string()); + if validate_particle.is_err() { + return validate_particle; + } + } + + let validate_address = validate_by_basic_rule(address.clone().unwrap(), "address".to_string()); + let validate_init_particle = validate_ipfs_cid(init_particle.clone().unwrap(), "init_particle".to_string()); + let validate_version = validate_url(version.clone().unwrap(), "version".to_string()); + let validate_chain_id = validate_url(chain_id.clone().unwrap(), "chain_id".to_string()); + + if validate_address.is_err() { + return validate_address; + } + if validate_init_particle.is_err() { + return validate_init_particle; + } + if validate_version.is_err() { + return validate_version; + } + if validate_chain_id.is_err() { + return validate_chain_id; + } + + let entry = LIST.load(deps.storage, id)?; + let updated_entry = Entry { + id, + address: address.unwrap_or(entry.address), + init_particle: init_particle.unwrap_or(entry.init_particle), + version: version.unwrap_or(entry.version), + chain_id: chain_id.unwrap_or(entry.chain_id), + particle: particle.unwrap_or("".to_string()), + }; + + LIST.save(deps.storage, id, &updated_entry)?; + + Ok(Response::new() + .add_attribute("method", "execute_update_entry") + .add_attribute("updated_entry_id", id.to_string())) +} + +pub fn execute_delete_entry( + deps: DepsMut, + info: MessageInfo, + id: u64, +) -> Result { + let owner = CONFIG.load(deps.storage)?.owner; + + if owner.is_none() { + return Err(ContractError::Unauthorized {}); + } else if info.sender != owner.unwrap() { + return Err(ContractError::Unauthorized {}); + } + + LIST.remove(deps.storage, id); + + Ok(Response::new() + .add_attribute("method", "execute_delete_entry") + .add_attribute("deleted_entry_id", id.to_string())) +} diff --git a/contracts/hub-libs/src/lib.rs b/contracts/hub-libs/src/lib.rs new file mode 100644 index 0000000..0a43c7c --- /dev/null +++ b/contracts/hub-libs/src/lib.rs @@ -0,0 +1,10 @@ +pub mod contract; +mod error; +pub mod msg; +pub mod execute; +pub mod state; +pub mod validating; +mod tests; +mod query; + +pub use crate::error::ContractError; diff --git a/contracts/hub-libs/src/msg.rs b/contracts/hub-libs/src/msg.rs new file mode 100644 index 0000000..dc27d41 --- /dev/null +++ b/contracts/hub-libs/src/msg.rs @@ -0,0 +1,61 @@ +use crate::state::{Entry}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct InstantiateMsg { + pub owner: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub enum ExecuteMsg { + UpdateOwner { + new_owner: Option, + }, + CreateEntry { + address: String, + init_particle: String, + version: String, + chain_id: String, + particle: Option, + }, + UpdateEntry { + id: u64, + address: String, + init_particle: Option, + version: Option, + chain_id: Option, + particle: Option, + }, + DeleteEntry { + id: u64, + }, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + GetEntries { + start_after: Option, + limit: Option, + }, + GetEntry { id: u64 } +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct MigrateMsg {} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct EntryResponse { + pub id: u64, + pub address: String, + pub init_particle: String, + pub version: String, + pub chain_id: String, + pub particle: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct ListResponse { + pub entries: Vec, +} diff --git a/contracts/hub-libs/src/query.rs b/contracts/hub-libs/src/query.rs new file mode 100644 index 0000000..8f2e414 --- /dev/null +++ b/contracts/hub-libs/src/query.rs @@ -0,0 +1,36 @@ +use cosmwasm_std::{Deps, Order, StdResult}; +use cw_storage_plus::Bound; + +use crate::msg::{EntryResponse, ListResponse}; +use crate::state::LIST; + +const MAX_LIMIT: u32 = 30; +const DEFAULT_LIMIT: u32 = 20; + +pub fn query_entry(deps: Deps, id: u64) -> StdResult { + let entry = LIST.load(deps.storage, id)?; + + Ok(EntryResponse { + id: entry.id, + address: entry.address, + init_particle: entry.init_particle, + version: entry.version, + chain_id: entry.chain_id, + particle: entry.particle + }) +} + +pub fn query_list(deps: Deps, start_after: Option, limit: Option) -> StdResult { + let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; + let start = start_after.map(Bound::exclusive); + let entries: StdResult> = LIST + .range(deps.storage, start, None, Order::Ascending) + .take(limit) + .collect(); + + let result = ListResponse { + entries: entries?.into_iter().map(|l| l.1).collect(), + }; + + Ok(result) +} \ No newline at end of file diff --git a/contracts/hub-libs/src/state.rs b/contracts/hub-libs/src/state.rs new file mode 100644 index 0000000..2d88b79 --- /dev/null +++ b/contracts/hub-libs/src/state.rs @@ -0,0 +1,25 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +// use cosmwasm_std::{Uint64}; + +use cosmwasm_std::Addr; +use cw_storage_plus::{Item, Map}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct Config { + pub owner: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct Entry { + pub id: u64, + pub address: String, + pub init_particle: String, + pub version: String, + pub chain_id: String, + pub particle: String, +} + +pub const CONFIG: Item = Item::new("config"); +pub const ENTRY_SEQ: Item = Item::new("entry_seq"); +pub const LIST: Map = Map::new("list"); diff --git a/contracts/hub-libs/src/tests.rs b/contracts/hub-libs/src/tests.rs new file mode 100644 index 0000000..c9910da --- /dev/null +++ b/contracts/hub-libs/src/tests.rs @@ -0,0 +1,217 @@ + + +#[cfg(test)] +mod tests { + // use super::*; + // use cosmwasm_std::{Uint64}; + use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; + use cosmwasm_std::{attr, from_binary, Addr}; + use std::vec::Vec; + use crate::state::{Entry, CONFIG, Config}; + use crate::msg::{ ListResponse, QueryMsg, InstantiateMsg, ExecuteMsg}; + // use crate::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg}; + use crate::contract::{query, execute, instantiate}; + + #[test] + fn proper_initialization() { + let mut deps = mock_dependencies(); + //no owner specified in the instantiation message + let msg = InstantiateMsg { owner: None }; + let env = mock_env(); + let info = mock_info("creator", &[]); + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + assert_eq!(0, res.messages.len()); + + // it worked, let's query the state + let state = CONFIG.load(&deps.storage).unwrap(); + assert_eq!( + state, + Config { + owner: Some(Addr::unchecked("creator".to_string())), + } + ); + //specifying an owner address in the instantiation message + let msg = InstantiateMsg { + owner: Some("specified_owner".to_string()), + }; + + let res = instantiate(deps.as_mut(), env, info, msg).unwrap(); + assert_eq!(0, res.messages.len()); + + // it worked, let's query the state + let state = CONFIG.load(&deps.storage).unwrap(); + assert_eq!( + state, + Config { + owner: Some(Addr::unchecked("specified_owner".to_string())), + } + ); + } + + #[test] + fn create_update_delete_entry() { + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info("creator", &[]); + let msg = InstantiateMsg { owner: None }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + assert_eq!(0, res.messages.len()); + + let msg = ExecuteMsg::CreateEntry { + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()) + }; + + let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + assert_eq!( + res.attributes, + vec![ + attr("method", "execute_create_entry"), + attr("new_entry_id", "1") + ] + ); + + let msg = ExecuteMsg::CreateEntry { + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()) + }; + + let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + assert_eq!( + res.attributes, + vec![ + attr("method", "execute_create_entry"), + attr("new_entry_id", "2") + ] + ); + + // Query the list of entries + let res = query( + deps.as_ref(), + env.clone(), + QueryMsg::GetEntries { + start_after: None, + limit: None, + }, + ) + .unwrap(); + let list: ListResponse = from_binary(&res).unwrap(); + assert_eq!( + Vec::from([ + Entry { + id: 1, + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string() + }, + Entry { + id: 2, + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string() + } + ]), + list.entries + ); + + // Update entry + let message = ExecuteMsg::UpdateEntry { + id: 1, + address: Some("bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z3".to_string()), + init_particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()), + version: Some("v=1&s=2&j=3".to_string()), + chain_id: Some("test-1".to_string()), + particle: Some("QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string()) + }; + + let res = execute(deps.as_mut(), env.clone(), info.clone(), message).unwrap(); + assert_eq!( + res.attributes, + vec![ + attr("method", "execute_update_entry"), + attr("updated_entry_id", "1") + ] + ); + + + + // Query the list of entries + let res = query( + deps.as_ref(), + env.clone(), + QueryMsg::GetEntries { + start_after: None, + limit: None, + }, + ) + .unwrap(); + let list: ListResponse = from_binary(&res).unwrap(); + assert_eq!( + Vec::from([ + Entry { + id: 1, + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z3".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string() + }, + Entry { + id: 2, + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string() + } + ]), + list.entries + ); + + //Delete Entry + let message = ExecuteMsg::DeleteEntry { id: 1 }; + + let res = execute(deps.as_mut(), env.clone(), info, message).unwrap(); + assert_eq!( + res.attributes, + vec![ + attr("method", "execute_delete_entry"), + attr("deleted_entry_id", "1") + ] + ); + // Query the list of entries + let res = query( + deps.as_ref(), + env, + QueryMsg::GetEntries { + start_after: None, + limit: None, + }, + ) + .unwrap(); + let list: ListResponse = from_binary(&res).unwrap(); + assert_eq!( + Vec::from([Entry { + id: 2, + address: "bostrom1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq7ha2z2".to_string(), + init_particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string(), + version: "v=1&s=2&j=3".to_string(), + chain_id: "test-1".to_string(), + particle: "QmYpTB36duejmy1szbdL1D2EzC5fgRL4dyhSFsHkMYPtny".to_string() + }]), + list.entries + ); + } +} diff --git a/contracts/hub-libs/src/validating.rs b/contracts/hub-libs/src/validating.rs new file mode 100644 index 0000000..85f4207 --- /dev/null +++ b/contracts/hub-libs/src/validating.rs @@ -0,0 +1,91 @@ +use cid::{Cid, Version}; +use std::str::FromStr; +use crate::error::ContractError; +use cosmwasm_std::{ + Response, +}; + +/* + * Basic rule /[a-z0-9-]/ + */ +pub fn validate_by_basic_rule( + val: String, + field_name: String, +) -> Result { + for byte in val.as_bytes().iter() { + // - && 0-9 && a-z + if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field field {}. Allowed expression /[a-z0-9-]/", field_name).to_string()}); + } + } + + Ok(Response::default()) +} + +/* + * Basic rule /[A-Z0-9]/ + */ +pub fn validate_by_basic_uppercase_rule( + val: String, + field_name: String, +) -> Result { + for byte in val.as_bytes().iter() { + // 0-9 && A-Z + if (*byte < 48 || *byte > 57) && (*byte < 65 || *byte > 90) { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed expression /[a-z0-9-]/", field_name).to_string()}); + } + } + + Ok(Response::default()) +} + +pub fn validate_datatype( + val: String, +) -> Result { + for byte in val.as_bytes().iter() { + // - && 0-9 && a-z + if (*byte != 45) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) { + return Err(ContractError::IncorrectInputData {val: "Incorrect data-type. a-z0-9- allowed".to_string()}); + } + } + + Ok(Response::default()) +} + +pub fn validate_url( + val: String, + field_name: String, +) -> Result { + for byte in val.as_bytes().iter() { + // = & } { : / . - _ 0-9 a-z A-Z + if (*byte != 61) && (*byte != 38) && (*byte != 125) && (*byte != 123) && (*byte != 58) && (*byte != 95) && (*byte != 45) && (*byte != 47) && (*byte != 46) && (*byte < 48 || *byte > 57) && (*byte < 97 || *byte > 122) && (*byte < 65 || *byte > 90) { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only url", field_name).to_string()}); + } + } + + Ok(Response::default()) +} + + + + +pub fn validate_ipfs_cid( + particle: String, + field_name: String, +) -> Result { + let particle_value:Cid; + let try_particle = Cid::from_str(&particle.clone()); + if try_particle.is_ok() { + particle_value = try_particle.unwrap(); + + if particle_value.version() != Version::V0 { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); + } + } else { + return Err(ContractError::IncorrectInputData {val: format!("Incorrect value for field {}. Allowed only Ipfs hash", field_name).to_string()}); + } + + Ok(Response::default()) +} + + From e170aa43f53b93a22e1ae50b8f3d5fb4980a248e Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 13 May 2023 13:39:30 +0800 Subject: [PATCH 33/33] - add contracts schemas --- .../schema/admin_list_response.json | 20 + .../schema/all_allowances_response.json | 120 ++ contracts/cw1-subkeys/schema/allowance.json | 102 ++ contracts/cw1-subkeys/schema/execute_msg.json | 700 +++++++++ .../cw1-subkeys/schema/instantiate_msg.json | 20 + contracts/cw1-subkeys/schema/query_msg.json | 602 +++++++ .../schema/admin_list_response.json | 20 + .../cw1-whitelist/schema/execute_msg.json | 525 +++++++ .../cw1-whitelist/schema/instantiate_msg.json | 20 + contracts/cw1-whitelist/schema/query_msg.json | 502 ++++++ .../schema/execute_msg.json | 642 ++++++++ .../schema/instantiate_msg.json | 155 ++ .../cw3-fixed-multisig/schema/query_msg.json | 218 +++ .../cw3-flex-multisig/schema/execute_msg.json | 698 +++++++++ .../schema/instantiate_msg.json | 173 +++ .../cw3-flex-multisig/schema/query_msg.json | 218 +++ .../hub-protocols/schema/execute_msg.json | 106 ++ .../hub-protocols/schema/instantiate_msg.json | 13 + contracts/hub-protocols/schema/query_msg.json | 58 + .../schema/account_response.json | 65 + .../schema/admin_response.json | 13 + .../schema/cyber_msg_wrapper.json | 569 +++++++ .../ibc-reflect-send/schema/execute_msg.json | 1355 ++++++++++++++++ .../schema/instantiate_msg.json | 6 + .../schema/list_accounts_response.json | 83 + .../ibc-reflect-send/schema/packet_msg.json | 1308 ++++++++++++++++ .../ibc-reflect-send/schema/query_msg.json | 50 + .../schema/acknowledgement_msg_balances.json | 72 + .../schema/acknowledgement_msg_dispatch.json | 32 + .../schema/acknowledgement_msg_who_am_i.json | 46 + .../ibc-reflect/schema/cyber_msg_wrapper.json | 569 +++++++ .../ibc-reflect/schema/instantiate_msg.json | 16 + contracts/ibc-reflect/schema/packet_msg.json | 1307 ++++++++++++++++ contracts/ibc-reflect/schema/query_msg.json | 40 + contracts/reflect/schema/chain_response.json | 19 + .../reflect/schema/cyber_msg_wrapper.json | 569 +++++++ contracts/reflect/schema/execute_msg.json | 1367 ++++++++++++++++ contracts/reflect/schema/instantiate_msg.json | 5 + contracts/reflect/schema/owner_response.json | 13 + contracts/reflect/schema/query_msg.json | 873 +++++++++++ contracts/reflect/schema/raw_response.json | 24 + .../response_for__cyber_msg_wrapper.json | 1377 +++++++++++++++++ contracts/reflect/schema/state.json | 19 + 43 files changed, 14709 insertions(+) create mode 100644 contracts/cw1-subkeys/schema/admin_list_response.json create mode 100644 contracts/cw1-subkeys/schema/all_allowances_response.json create mode 100644 contracts/cw1-subkeys/schema/allowance.json create mode 100644 contracts/cw1-subkeys/schema/execute_msg.json create mode 100644 contracts/cw1-subkeys/schema/instantiate_msg.json create mode 100644 contracts/cw1-subkeys/schema/query_msg.json create mode 100644 contracts/cw1-whitelist/schema/admin_list_response.json create mode 100644 contracts/cw1-whitelist/schema/execute_msg.json create mode 100644 contracts/cw1-whitelist/schema/instantiate_msg.json create mode 100644 contracts/cw1-whitelist/schema/query_msg.json create mode 100644 contracts/cw3-fixed-multisig/schema/execute_msg.json create mode 100644 contracts/cw3-fixed-multisig/schema/instantiate_msg.json create mode 100644 contracts/cw3-fixed-multisig/schema/query_msg.json create mode 100644 contracts/cw3-flex-multisig/schema/execute_msg.json create mode 100644 contracts/cw3-flex-multisig/schema/instantiate_msg.json create mode 100644 contracts/cw3-flex-multisig/schema/query_msg.json create mode 100644 contracts/hub-protocols/schema/execute_msg.json create mode 100644 contracts/hub-protocols/schema/instantiate_msg.json create mode 100644 contracts/hub-protocols/schema/query_msg.json create mode 100644 contracts/ibc-reflect-send/schema/account_response.json create mode 100644 contracts/ibc-reflect-send/schema/admin_response.json create mode 100644 contracts/ibc-reflect-send/schema/cyber_msg_wrapper.json create mode 100644 contracts/ibc-reflect-send/schema/execute_msg.json create mode 100644 contracts/ibc-reflect-send/schema/instantiate_msg.json create mode 100644 contracts/ibc-reflect-send/schema/list_accounts_response.json create mode 100644 contracts/ibc-reflect-send/schema/packet_msg.json create mode 100644 contracts/ibc-reflect-send/schema/query_msg.json create mode 100644 contracts/ibc-reflect/schema/acknowledgement_msg_balances.json create mode 100644 contracts/ibc-reflect/schema/acknowledgement_msg_dispatch.json create mode 100644 contracts/ibc-reflect/schema/acknowledgement_msg_who_am_i.json create mode 100644 contracts/ibc-reflect/schema/cyber_msg_wrapper.json create mode 100644 contracts/ibc-reflect/schema/instantiate_msg.json create mode 100644 contracts/ibc-reflect/schema/packet_msg.json create mode 100644 contracts/ibc-reflect/schema/query_msg.json create mode 100644 contracts/reflect/schema/chain_response.json create mode 100644 contracts/reflect/schema/cyber_msg_wrapper.json create mode 100644 contracts/reflect/schema/execute_msg.json create mode 100644 contracts/reflect/schema/instantiate_msg.json create mode 100644 contracts/reflect/schema/owner_response.json create mode 100644 contracts/reflect/schema/query_msg.json create mode 100644 contracts/reflect/schema/raw_response.json create mode 100644 contracts/reflect/schema/response_for__cyber_msg_wrapper.json create mode 100644 contracts/reflect/schema/state.json diff --git a/contracts/cw1-subkeys/schema/admin_list_response.json b/contracts/cw1-subkeys/schema/admin_list_response.json new file mode 100644 index 0000000..bc20467 --- /dev/null +++ b/contracts/cw1-subkeys/schema/admin_list_response.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AdminListResponse", + "type": "object", + "required": [ + "admins", + "mutable" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + }, + "mutable": { + "type": "boolean" + } + } +} diff --git a/contracts/cw1-subkeys/schema/all_allowances_response.json b/contracts/cw1-subkeys/schema/all_allowances_response.json new file mode 100644 index 0000000..287b750 --- /dev/null +++ b/contracts/cw1-subkeys/schema/all_allowances_response.json @@ -0,0 +1,120 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AllAllowancesResponse", + "type": "object", + "required": [ + "allowances" + ], + "properties": { + "allowances": { + "type": "array", + "items": { + "$ref": "#/definitions/AllowanceInfo" + } + } + }, + "definitions": { + "AllowanceInfo": { + "type": "object", + "required": [ + "balance", + "expires", + "spender" + ], + "properties": { + "balance": { + "$ref": "#/definitions/NativeBalance" + }, + "expires": { + "$ref": "#/definitions/Expiration" + }, + "spender": { + "type": "string" + } + } + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object" + } + }, + "additionalProperties": false + } + ] + }, + "NativeBalance": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/cw1-subkeys/schema/allowance.json b/contracts/cw1-subkeys/schema/allowance.json new file mode 100644 index 0000000..2a8fb26 --- /dev/null +++ b/contracts/cw1-subkeys/schema/allowance.json @@ -0,0 +1,102 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Allowance", + "type": "object", + "required": [ + "balance", + "expires" + ], + "properties": { + "balance": { + "$ref": "#/definitions/NativeBalance" + }, + "expires": { + "$ref": "#/definitions/Expiration" + } + }, + "definitions": { + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object" + } + }, + "additionalProperties": false + } + ] + }, + "NativeBalance": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/cw1-subkeys/schema/execute_msg.json b/contracts/cw1-subkeys/schema/execute_msg.json new file mode 100644 index 0000000..d1f8872 --- /dev/null +++ b/contracts/cw1-subkeys/schema/execute_msg.json @@ -0,0 +1,700 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "description": "Execute requests the contract to re-dispatch all these messages with the contract's address as sender. Every implementation has it's own logic to determine in", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Freeze will make a mutable contract immutable, must be called by an admin", + "type": "object", + "required": [ + "freeze" + ], + "properties": { + "freeze": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "UpdateAdmins will change the admin set of the contract, must be called by an existing admin, and only works if the contract is mutable", + "type": "object", + "required": [ + "update_admins" + ], + "properties": { + "update_admins": { + "type": "object", + "required": [ + "admins" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Add an allowance to a given subkey (subkey must not be admin)", + "type": "object", + "required": [ + "increase_allowance" + ], + "properties": { + "increase_allowance": { + "type": "object", + "required": [ + "amount", + "spender" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "expires": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "spender": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Decreases an allowance for a given subkey (subkey must not be admin)", + "type": "object", + "required": [ + "decrease_allowance" + ], + "properties": { + "decrease_allowance": { + "type": "object", + "required": [ + "amount", + "spender" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "expires": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "spender": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "set_permissions" + ], + "properties": { + "set_permissions": { + "type": "object", + "required": [ + "permissions", + "spender" + ], + "properties": { + "permissions": { + "$ref": "#/definitions/Permissions" + }, + "spender": { + "type": "string" + } + } + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object" + } + }, + "additionalProperties": false + } + ] + }, + "Permissions": { + "type": "object", + "required": [ + "delegate", + "redelegate", + "undelegate", + "withdraw" + ], + "properties": { + "delegate": { + "type": "boolean" + }, + "redelegate": { + "type": "boolean" + }, + "undelegate": { + "type": "boolean" + }, + "withdraw": { + "type": "boolean" + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw1-subkeys/schema/instantiate_msg.json b/contracts/cw1-subkeys/schema/instantiate_msg.json new file mode 100644 index 0000000..fdcd684 --- /dev/null +++ b/contracts/cw1-subkeys/schema/instantiate_msg.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "admins", + "mutable" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + }, + "mutable": { + "type": "boolean" + } + } +} diff --git a/contracts/cw1-subkeys/schema/query_msg.json b/contracts/cw1-subkeys/schema/query_msg.json new file mode 100644 index 0000000..1fc41ea --- /dev/null +++ b/contracts/cw1-subkeys/schema/query_msg.json @@ -0,0 +1,602 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "description": "Shows all admins and whether or not it is mutable Returns cw1-whitelist::AdminListResponse", + "type": "object", + "required": [ + "admin_list" + ], + "properties": { + "admin_list": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Get the current allowance for the given subkey (how much it can spend) Returns crate::state::Allowance", + "type": "object", + "required": [ + "allowance" + ], + "properties": { + "allowance": { + "type": "object", + "required": [ + "spender" + ], + "properties": { + "spender": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Get the current permissions for the given subkey (how much it can spend) Returns PermissionsInfo", + "type": "object", + "required": [ + "permissions" + ], + "properties": { + "permissions": { + "type": "object", + "required": [ + "spender" + ], + "properties": { + "spender": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Checks permissions of the caller on this proxy. If CanExecute returns true then a call to `Execute` with the same message, before any further state changes, should also succeed.", + "type": "object", + "required": [ + "can_execute" + ], + "properties": { + "can_execute": { + "type": "object", + "required": [ + "msg", + "sender" + ], + "properties": { + "msg": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + }, + "sender": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Gets all Allowances for this contract Returns AllAllowancesResponse", + "type": "object", + "required": [ + "all_allowances" + ], + "properties": { + "all_allowances": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Gets all Permissions for this contract Returns AllPermissionsResponse", + "type": "object", + "required": [ + "all_permissions" + ], + "properties": { + "all_permissions": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw1-whitelist/schema/admin_list_response.json b/contracts/cw1-whitelist/schema/admin_list_response.json new file mode 100644 index 0000000..bc20467 --- /dev/null +++ b/contracts/cw1-whitelist/schema/admin_list_response.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AdminListResponse", + "type": "object", + "required": [ + "admins", + "mutable" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + }, + "mutable": { + "type": "boolean" + } + } +} diff --git a/contracts/cw1-whitelist/schema/execute_msg.json b/contracts/cw1-whitelist/schema/execute_msg.json new file mode 100644 index 0000000..50ca31e --- /dev/null +++ b/contracts/cw1-whitelist/schema/execute_msg.json @@ -0,0 +1,525 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "description": "Execute requests the contract to re-dispatch all these messages with the contract's address as sender. Every implementation has it's own logic to determine in", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Freeze will make a mutable contract immutable, must be called by an admin", + "type": "object", + "required": [ + "freeze" + ], + "properties": { + "freeze": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "UpdateAdmins will change the admin set of the contract, must be called by an existing admin, and only works if the contract is mutable", + "type": "object", + "required": [ + "update_admins" + ], + "properties": { + "update_admins": { + "type": "object", + "required": [ + "admins" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw1-whitelist/schema/instantiate_msg.json b/contracts/cw1-whitelist/schema/instantiate_msg.json new file mode 100644 index 0000000..fdcd684 --- /dev/null +++ b/contracts/cw1-whitelist/schema/instantiate_msg.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "admins", + "mutable" + ], + "properties": { + "admins": { + "type": "array", + "items": { + "type": "string" + } + }, + "mutable": { + "type": "boolean" + } + } +} diff --git a/contracts/cw1-whitelist/schema/query_msg.json b/contracts/cw1-whitelist/schema/query_msg.json new file mode 100644 index 0000000..7ce7782 --- /dev/null +++ b/contracts/cw1-whitelist/schema/query_msg.json @@ -0,0 +1,502 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "description": "Shows all admins and whether or not it is mutable", + "type": "object", + "required": [ + "admin_list" + ], + "properties": { + "admin_list": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Checks permissions of the caller on this proxy. If CanExecute returns true then a call to `Execute` with the same message, before any further state changes, should also succeed.", + "type": "object", + "required": [ + "can_execute" + ], + "properties": { + "can_execute": { + "type": "object", + "required": [ + "msg", + "sender" + ], + "properties": { + "msg": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + }, + "sender": { + "type": "string" + } + } + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw3-fixed-multisig/schema/execute_msg.json b/contracts/cw3-fixed-multisig/schema/execute_msg.json new file mode 100644 index 0000000..3c29a4f --- /dev/null +++ b/contracts/cw3-fixed-multisig/schema/execute_msg.json @@ -0,0 +1,642 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "propose" + ], + "properties": { + "propose": { + "type": "object", + "required": [ + "description", + "msgs", + "title" + ], + "properties": { + "description": { + "type": "string" + }, + "latest": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + }, + "title": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/Vote" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "close" + ], + "properties": { + "close": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object" + } + }, + "additionalProperties": false + } + ] + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "Vote": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw3-fixed-multisig/schema/instantiate_msg.json b/contracts/cw3-fixed-multisig/schema/instantiate_msg.json new file mode 100644 index 0000000..6525213 --- /dev/null +++ b/contracts/cw3-fixed-multisig/schema/instantiate_msg.json @@ -0,0 +1,155 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "max_voting_period", + "threshold", + "voters" + ], + "properties": { + "max_voting_period": { + "$ref": "#/definitions/Duration" + }, + "threshold": { + "$ref": "#/definitions/Threshold" + }, + "voters": { + "type": "array", + "items": { + "$ref": "#/definitions/Voter" + } + } + }, + "definitions": { + "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" + }, + "Duration": { + "description": "Duration is a delta of time. You can add it to a BlockInfo or Expiration to move that further in the future. Note that an height-based Duration and a time-based Expiration cannot be combined", + "oneOf": [ + { + "type": "object", + "required": [ + "height" + ], + "properties": { + "height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "Time in seconds", + "type": "object", + "required": [ + "time" + ], + "properties": { + "time": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "Threshold": { + "description": "This defines the different ways tallies can happen.\n\nThe total_weight used for calculating success as well as the weights of each individual voter used in tallying should be snapshotted at the beginning of the block at which the proposal starts (this is likely the responsibility of a correct cw4 implementation). See also `ThresholdResponse` in the cw3 spec.", + "oneOf": [ + { + "description": "Declares that a fixed weight of Yes votes is needed to pass. See `ThresholdResponse.AbsoluteCount` in the cw3 spec for details.", + "type": "object", + "required": [ + "absolute_count" + ], + "properties": { + "absolute_count": { + "type": "object", + "required": [ + "weight" + ], + "properties": { + "weight": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Declares a percentage of the total weight that must cast Yes votes in order for a proposal to pass. See `ThresholdResponse.AbsolutePercentage` in the cw3 spec for details.", + "type": "object", + "required": [ + "absolute_percentage" + ], + "properties": { + "absolute_percentage": { + "type": "object", + "required": [ + "percentage" + ], + "properties": { + "percentage": { + "$ref": "#/definitions/Decimal" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Declares a `quorum` of the total votes that must participate in the election in order for the vote to be considered at all. See `ThresholdResponse.ThresholdQuorum` in the cw3 spec for details.", + "type": "object", + "required": [ + "threshold_quorum" + ], + "properties": { + "threshold_quorum": { + "type": "object", + "required": [ + "quorum", + "threshold" + ], + "properties": { + "quorum": { + "$ref": "#/definitions/Decimal" + }, + "threshold": { + "$ref": "#/definitions/Decimal" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Voter": { + "type": "object", + "required": [ + "addr", + "weight" + ], + "properties": { + "addr": { + "type": "string" + }, + "weight": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } +} diff --git a/contracts/cw3-fixed-multisig/schema/query_msg.json b/contracts/cw3-fixed-multisig/schema/query_msg.json new file mode 100644 index 0000000..42aea71 --- /dev/null +++ b/contracts/cw3-fixed-multisig/schema/query_msg.json @@ -0,0 +1,218 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "description": "Return ThresholdResponse", + "type": "object", + "required": [ + "threshold" + ], + "properties": { + "threshold": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalResponse", + "type": "object", + "required": [ + "proposal" + ], + "properties": { + "proposal": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalListResponse", + "type": "object", + "required": [ + "list_proposals" + ], + "properties": { + "list_proposals": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalListResponse", + "type": "object", + "required": [ + "reverse_proposals" + ], + "properties": { + "reverse_proposals": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_before": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoteResponse", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "voter" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "voter": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoteListResponse", + "type": "object", + "required": [ + "list_votes" + ], + "properties": { + "list_votes": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoterInfo", + "type": "object", + "required": [ + "voter" + ], + "properties": { + "voter": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoterListResponse", + "type": "object", + "required": [ + "list_voters" + ], + "properties": { + "list_voters": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/cw3-flex-multisig/schema/execute_msg.json b/contracts/cw3-flex-multisig/schema/execute_msg.json new file mode 100644 index 0000000..62a3118 --- /dev/null +++ b/contracts/cw3-flex-multisig/schema/execute_msg.json @@ -0,0 +1,698 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "propose" + ], + "properties": { + "propose": { + "type": "object", + "required": [ + "description", + "msgs", + "title" + ], + "properties": { + "description": { + "type": "string" + }, + "latest": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + }, + "title": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/Vote" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "close" + ], + "properties": { + "close": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Handles update hook messages from the group contract", + "type": "object", + "required": [ + "member_changed_hook" + ], + "properties": { + "member_changed_hook": { + "$ref": "#/definitions/MemberChangedHookMsg" + } + }, + "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", + "type": "string" + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object" + } + }, + "additionalProperties": false + } + ] + }, + "MemberChangedHookMsg": { + "description": "MemberChangedHookMsg should be de/serialized under `MemberChangedHook()` variant in a ExecuteMsg. This contains a list of all diffs on the given transaction.", + "type": "object", + "required": [ + "diffs" + ], + "properties": { + "diffs": { + "type": "array", + "items": { + "$ref": "#/definitions/MemberDiff" + } + } + } + }, + "MemberDiff": { + "description": "MemberDiff shows the old and new states for a given cw4 member They cannot both be None. old = None, new = Some -> Insert old = Some, new = Some -> Update old = Some, new = None -> Delete", + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + }, + "new": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "old": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "Vote": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/cw3-flex-multisig/schema/instantiate_msg.json b/contracts/cw3-flex-multisig/schema/instantiate_msg.json new file mode 100644 index 0000000..f28f601 --- /dev/null +++ b/contracts/cw3-flex-multisig/schema/instantiate_msg.json @@ -0,0 +1,173 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "group_addr", + "max_voting_period", + "threshold" + ], + "properties": { + "executor": { + "anyOf": [ + { + "$ref": "#/definitions/Executor" + }, + { + "type": "null" + } + ] + }, + "group_addr": { + "type": "string" + }, + "max_voting_period": { + "$ref": "#/definitions/Duration" + }, + "threshold": { + "$ref": "#/definitions/Threshold" + } + }, + "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" + }, + "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" + }, + "Duration": { + "description": "Duration is a delta of time. You can add it to a BlockInfo or Expiration to move that further in the future. Note that an height-based Duration and a time-based Expiration cannot be combined", + "oneOf": [ + { + "type": "object", + "required": [ + "height" + ], + "properties": { + "height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "Time in seconds", + "type": "object", + "required": [ + "time" + ], + "properties": { + "time": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "Executor": { + "description": "Defines who is able to execute proposals once passed", + "oneOf": [ + { + "type": "string", + "enum": [ + "Member" + ] + }, + { + "description": "Only the given address", + "type": "object", + "required": [ + "Only" + ], + "properties": { + "Only": { + "$ref": "#/definitions/Addr" + } + }, + "additionalProperties": false + } + ] + }, + "Threshold": { + "description": "This defines the different ways tallies can happen.\n\nThe total_weight used for calculating success as well as the weights of each individual voter used in tallying should be snapshotted at the beginning of the block at which the proposal starts (this is likely the responsibility of a correct cw4 implementation). See also `ThresholdResponse` in the cw3 spec.", + "oneOf": [ + { + "description": "Declares that a fixed weight of Yes votes is needed to pass. See `ThresholdResponse.AbsoluteCount` in the cw3 spec for details.", + "type": "object", + "required": [ + "absolute_count" + ], + "properties": { + "absolute_count": { + "type": "object", + "required": [ + "weight" + ], + "properties": { + "weight": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Declares a percentage of the total weight that must cast Yes votes in order for a proposal to pass. See `ThresholdResponse.AbsolutePercentage` in the cw3 spec for details.", + "type": "object", + "required": [ + "absolute_percentage" + ], + "properties": { + "absolute_percentage": { + "type": "object", + "required": [ + "percentage" + ], + "properties": { + "percentage": { + "$ref": "#/definitions/Decimal" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Declares a `quorum` of the total votes that must participate in the election in order for the vote to be considered at all. See `ThresholdResponse.ThresholdQuorum` in the cw3 spec for details.", + "type": "object", + "required": [ + "threshold_quorum" + ], + "properties": { + "threshold_quorum": { + "type": "object", + "required": [ + "quorum", + "threshold" + ], + "properties": { + "quorum": { + "$ref": "#/definitions/Decimal" + }, + "threshold": { + "$ref": "#/definitions/Decimal" + } + } + } + }, + "additionalProperties": false + } + ] + } + } +} diff --git a/contracts/cw3-flex-multisig/schema/query_msg.json b/contracts/cw3-flex-multisig/schema/query_msg.json new file mode 100644 index 0000000..42aea71 --- /dev/null +++ b/contracts/cw3-flex-multisig/schema/query_msg.json @@ -0,0 +1,218 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "description": "Return ThresholdResponse", + "type": "object", + "required": [ + "threshold" + ], + "properties": { + "threshold": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalResponse", + "type": "object", + "required": [ + "proposal" + ], + "properties": { + "proposal": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalListResponse", + "type": "object", + "required": [ + "list_proposals" + ], + "properties": { + "list_proposals": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns ProposalListResponse", + "type": "object", + "required": [ + "reverse_proposals" + ], + "properties": { + "reverse_proposals": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_before": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoteResponse", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "voter" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "voter": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoteListResponse", + "type": "object", + "required": [ + "list_votes" + ], + "properties": { + "list_votes": { + "type": "object", + "required": [ + "proposal_id" + ], + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoterInfo", + "type": "object", + "required": [ + "voter" + ], + "properties": { + "voter": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns VoterListResponse", + "type": "object", + "required": [ + "list_voters" + ], + "properties": { + "list_voters": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-protocols/schema/execute_msg.json b/contracts/hub-protocols/schema/execute_msg.json new file mode 100644 index 0000000..3098769 --- /dev/null +++ b/contracts/hub-protocols/schema/execute_msg.json @@ -0,0 +1,106 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "UpdateOwner" + ], + "properties": { + "UpdateOwner": { + "type": "object", + "properties": { + "new_owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "CreateEntry" + ], + "properties": { + "CreateEntry": { + "type": "object", + "required": [ + "data_type" + ], + "properties": { + "data_type": { + "type": "string" + }, + "particle": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "UpdateEntry" + ], + "properties": { + "UpdateEntry": { + "type": "object", + "required": [ + "data_type", + "id" + ], + "properties": { + "data_type": { + "type": "string" + }, + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "particle": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "DeleteEntry" + ], + "properties": { + "DeleteEntry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/hub-protocols/schema/instantiate_msg.json b/contracts/hub-protocols/schema/instantiate_msg.json new file mode 100644 index 0000000..fc5f000 --- /dev/null +++ b/contracts/hub-protocols/schema/instantiate_msg.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "properties": { + "owner": { + "type": [ + "string", + "null" + ] + } + } +} diff --git a/contracts/hub-protocols/schema/query_msg.json b/contracts/hub-protocols/schema/query_msg.json new file mode 100644 index 0000000..f3d8cbe --- /dev/null +++ b/contracts/hub-protocols/schema/query_msg.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_entries" + ], + "properties": { + "get_entries": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_entry" + ], + "properties": { + "get_entry": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-reflect-send/schema/account_response.json b/contracts/ibc-reflect-send/schema/account_response.json new file mode 100644 index 0000000..d6e05cc --- /dev/null +++ b/contracts/ibc-reflect-send/schema/account_response.json @@ -0,0 +1,65 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AccountResponse", + "type": "object", + "required": [ + "last_update_time", + "remote_balance" + ], + "properties": { + "last_update_time": { + "description": "last block balance was updated (0 is never)", + "allOf": [ + { + "$ref": "#/definitions/Timestamp" + } + ] + }, + "remote_addr": { + "description": "in normal cases, it should be set, but there is a delay between binding the channel and making a query and in that time it is empty", + "type": [ + "string", + "null" + ] + }, + "remote_balance": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + }, + "definitions": { + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/ibc-reflect-send/schema/admin_response.json b/contracts/ibc-reflect-send/schema/admin_response.json new file mode 100644 index 0000000..b0d3272 --- /dev/null +++ b/contracts/ibc-reflect-send/schema/admin_response.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AdminResponse", + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + } +} diff --git a/contracts/ibc-reflect-send/schema/cyber_msg_wrapper.json b/contracts/ibc-reflect-send/schema/cyber_msg_wrapper.json new file mode 100644 index 0000000..ae0cc6f --- /dev/null +++ b/contracts/ibc-reflect-send/schema/cyber_msg_wrapper.json @@ -0,0 +1,569 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "CyberMsgWrapper", + "type": "object", + "required": [ + "msg_data", + "route" + ], + "properties": { + "msg_data": { + "$ref": "#/definitions/CyberMsg" + }, + "route": { + "$ref": "#/definitions/CyberRoute" + } + }, + "definitions": { + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "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 + } + ] + }, + "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" + } + } + }, + "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" + } + } +} diff --git a/contracts/ibc-reflect-send/schema/execute_msg.json b/contracts/ibc-reflect-send/schema/execute_msg.json new file mode 100644 index 0000000..1ca38fe --- /dev/null +++ b/contracts/ibc-reflect-send/schema/execute_msg.json @@ -0,0 +1,1355 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "description": "Changes the admin", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "send_msgs" + ], + "properties": { + "send_msgs": { + "type": "object", + "required": [ + "channel_id", + "msgs" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "check_remote_balance" + ], + "properties": { + "check_remote_balance": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "If you sent funds to this contract, it will attempt to ibc transfer them to the account on the remote side of this channel. If we don't have the address yet, this fails.", + "type": "object", + "required": [ + "send_funds" + ], + "properties": { + "send_funds": { + "type": "object", + "required": [ + "reflect_channel_id", + "transfer_channel_id" + ], + "properties": { + "reflect_channel_id": { + "description": "The channel id we use above to talk with the reflect contract", + "type": "string" + }, + "transfer_channel_id": { + "description": "The channel to use for ibctransfer. This is bound to a different port and handled by a different module. It should connect to the same chain as the reflect_channel_id does", + "type": "string" + } + } + } + }, + "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", + "type": "string" + }, + "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": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "GovMsg": { + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "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" + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/ibc-reflect-send/schema/instantiate_msg.json b/contracts/ibc-reflect-send/schema/instantiate_msg.json new file mode 100644 index 0000000..149ba9c --- /dev/null +++ b/contracts/ibc-reflect-send/schema/instantiate_msg.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "description": "This needs no info. Owner of the contract is whoever signed the InstantiateMsg.", + "type": "object" +} diff --git a/contracts/ibc-reflect-send/schema/list_accounts_response.json b/contracts/ibc-reflect-send/schema/list_accounts_response.json new file mode 100644 index 0000000..7c63981 --- /dev/null +++ b/contracts/ibc-reflect-send/schema/list_accounts_response.json @@ -0,0 +1,83 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ListAccountsResponse", + "type": "object", + "required": [ + "accounts" + ], + "properties": { + "accounts": { + "type": "array", + "items": { + "$ref": "#/definitions/AccountInfo" + } + } + }, + "definitions": { + "AccountInfo": { + "type": "object", + "required": [ + "channel_id", + "last_update_time", + "remote_balance" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "last_update_time": { + "description": "last block balance was updated (0 is never)", + "allOf": [ + { + "$ref": "#/definitions/Timestamp" + } + ] + }, + "remote_addr": { + "description": "in normal cases, it should be set, but there is a delay between binding the channel and making a query and in that time it is empty", + "type": [ + "string", + "null" + ] + }, + "remote_balance": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/ibc-reflect-send/schema/packet_msg.json b/contracts/ibc-reflect-send/schema/packet_msg.json new file mode 100644 index 0000000..651e0be --- /dev/null +++ b/contracts/ibc-reflect-send/schema/packet_msg.json @@ -0,0 +1,1308 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PacketMsg", + "description": "This is the message we send over the IBC channel", + "oneOf": [ + { + "type": "object", + "required": [ + "dispatch" + ], + "properties": { + "dispatch": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "who_am_i" + ], + "properties": { + "who_am_i": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "balances" + ], + "properties": { + "balances": { + "type": "object" + } + }, + "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", + "type": "string" + }, + "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": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "GovMsg": { + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "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" + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/ibc-reflect-send/schema/query_msg.json b/contracts/ibc-reflect-send/schema/query_msg.json new file mode 100644 index 0000000..17d10a2 --- /dev/null +++ b/contracts/ibc-reflect-send/schema/query_msg.json @@ -0,0 +1,50 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "list_accounts" + ], + "properties": { + "list_accounts": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account" + ], + "properties": { + "account": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-reflect/schema/acknowledgement_msg_balances.json b/contracts/ibc-reflect/schema/acknowledgement_msg_balances.json new file mode 100644 index 0000000..cf09b7c --- /dev/null +++ b/contracts/ibc-reflect/schema/acknowledgement_msg_balances.json @@ -0,0 +1,72 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AcknowledgementMsgBalances", + "description": "This is the final result type that is created and serialized in a contract for every init/execute/migrate call. The VM then deserializes this type to distinguish between successful and failed executions.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let response: Response = Response::default(); let result: ContractResult = ContractResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"messages\":[],\"attributes\":[],\"events\":[],\"data\":null}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result: ContractResult = ContractResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```", + "oneOf": [ + { + "type": "object", + "required": [ + "ok" + ], + "properties": { + "ok": { + "$ref": "#/definitions/BalancesResponse" + } + }, + "additionalProperties": false + }, + { + "description": "An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.", + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "string" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "BalancesResponse": { + "description": "This is the success response we send on ack for PacketMsg::Balance. Just acknowledge success or error", + "type": "object", + "required": [ + "account", + "balances" + ], + "properties": { + "account": { + "type": "string" + }, + "balances": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "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" + } + } +} diff --git a/contracts/ibc-reflect/schema/acknowledgement_msg_dispatch.json b/contracts/ibc-reflect/schema/acknowledgement_msg_dispatch.json new file mode 100644 index 0000000..e89f54b --- /dev/null +++ b/contracts/ibc-reflect/schema/acknowledgement_msg_dispatch.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AcknowledgementMsgDispatch", + "description": "This is the final result type that is created and serialized in a contract for every init/execute/migrate call. The VM then deserializes this type to distinguish between successful and failed executions.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let response: Response = Response::default(); let result: ContractResult = ContractResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"messages\":[],\"attributes\":[],\"events\":[],\"data\":null}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result: ContractResult = ContractResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```", + "oneOf": [ + { + "type": "object", + "required": [ + "ok" + ], + "properties": { + "ok": { + "type": "null" + } + }, + "additionalProperties": false + }, + { + "description": "An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.", + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "string" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-reflect/schema/acknowledgement_msg_who_am_i.json b/contracts/ibc-reflect/schema/acknowledgement_msg_who_am_i.json new file mode 100644 index 0000000..bfbabf6 --- /dev/null +++ b/contracts/ibc-reflect/schema/acknowledgement_msg_who_am_i.json @@ -0,0 +1,46 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AcknowledgementMsgWhoAmI", + "description": "This is the final result type that is created and serialized in a contract for every init/execute/migrate call. The VM then deserializes this type to distinguish between successful and failed executions.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let response: Response = Response::default(); let result: ContractResult = ContractResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"messages\":[],\"attributes\":[],\"events\":[],\"data\":null}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, ContractResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result: ContractResult = ContractResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```", + "oneOf": [ + { + "type": "object", + "required": [ + "ok" + ], + "properties": { + "ok": { + "$ref": "#/definitions/WhoAmIResponse" + } + }, + "additionalProperties": false + }, + { + "description": "An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.", + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "string" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "WhoAmIResponse": { + "description": "This is the success response we send on ack for PacketMsg::WhoAmI. Return the caller's account address on the remote chain", + "type": "object", + "required": [ + "account" + ], + "properties": { + "account": { + "type": "string" + } + } + } + } +} diff --git a/contracts/ibc-reflect/schema/cyber_msg_wrapper.json b/contracts/ibc-reflect/schema/cyber_msg_wrapper.json new file mode 100644 index 0000000..ae0cc6f --- /dev/null +++ b/contracts/ibc-reflect/schema/cyber_msg_wrapper.json @@ -0,0 +1,569 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "CyberMsgWrapper", + "type": "object", + "required": [ + "msg_data", + "route" + ], + "properties": { + "msg_data": { + "$ref": "#/definitions/CyberMsg" + }, + "route": { + "$ref": "#/definitions/CyberRoute" + } + }, + "definitions": { + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "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 + } + ] + }, + "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" + } + } + }, + "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" + } + } +} diff --git a/contracts/ibc-reflect/schema/instantiate_msg.json b/contracts/ibc-reflect/schema/instantiate_msg.json new file mode 100644 index 0000000..9bcdcf2 --- /dev/null +++ b/contracts/ibc-reflect/schema/instantiate_msg.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "description": "Just needs to know the code_id of a reflect contract to spawn sub-accounts", + "type": "object", + "required": [ + "reflect_code_id" + ], + "properties": { + "reflect_code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } +} diff --git a/contracts/ibc-reflect/schema/packet_msg.json b/contracts/ibc-reflect/schema/packet_msg.json new file mode 100644 index 0000000..d7887c3 --- /dev/null +++ b/contracts/ibc-reflect/schema/packet_msg.json @@ -0,0 +1,1307 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PacketMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "dispatch" + ], + "properties": { + "dispatch": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "who_am_i" + ], + "properties": { + "who_am_i": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "balances" + ], + "properties": { + "balances": { + "type": "object" + } + }, + "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", + "type": "string" + }, + "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": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "GovMsg": { + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "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" + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/ibc-reflect/schema/query_msg.json b/contracts/ibc-reflect/schema/query_msg.json new file mode 100644 index 0000000..9a89af3 --- /dev/null +++ b/contracts/ibc-reflect/schema/query_msg.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "description": "Returns (reflect) account that is attached to this channel, or none.", + "type": "object", + "required": [ + "account" + ], + "properties": { + "account": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns all (channel, reflect_account) pairs. No pagination - this is a test contract", + "type": "object", + "required": [ + "list_accounts" + ], + "properties": { + "list_accounts": { + "type": "object" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/reflect/schema/chain_response.json b/contracts/reflect/schema/chain_response.json new file mode 100644 index 0000000..a836c62 --- /dev/null +++ b/contracts/reflect/schema/chain_response.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ChainResponse", + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/definitions/Binary" + } + }, + "definitions": { + "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", + "type": "string" + } + } +} diff --git a/contracts/reflect/schema/cyber_msg_wrapper.json b/contracts/reflect/schema/cyber_msg_wrapper.json new file mode 100644 index 0000000..ae0cc6f --- /dev/null +++ b/contracts/reflect/schema/cyber_msg_wrapper.json @@ -0,0 +1,569 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "CyberMsgWrapper", + "type": "object", + "required": [ + "msg_data", + "route" + ], + "properties": { + "msg_data": { + "$ref": "#/definitions/CyberMsg" + }, + "route": { + "$ref": "#/definitions/CyberRoute" + } + }, + "definitions": { + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "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 + } + ] + }, + "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" + } + } + }, + "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" + } + } +} diff --git a/contracts/reflect/schema/execute_msg.json b/contracts/reflect/schema/execute_msg.json new file mode 100644 index 0000000..c4b11ad --- /dev/null +++ b/contracts/reflect/schema/execute_msg.json @@ -0,0 +1,1367 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "reflect_msg" + ], + "properties": { + "reflect_msg": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + } + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "reflect_sub_msg" + ], + "properties": { + "reflect_sub_msg": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/SubMsg_for_CyberMsgWrapper" + } + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "change_owner" + ], + "properties": { + "change_owner": { + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "string" + } + } + } + }, + "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", + "type": "string" + }, + "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": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "GovMsg": { + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "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" + } + } + }, + "ReplyOn": { + "description": "Use this to define when the contract gets a response callback. If you only need it for errors or success you can select just those in order to save gas.", + "type": "string", + "enum": [ + "always", + "error", + "success", + "never" + ] + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "SubMsg_for_CyberMsgWrapper": { + "description": "A submessage that will guarantee a `reply` call on success or error, depending on the `reply_on` setting. If you do not need to process the result, use regular messages instead.\n\nNote: On error the submessage execution will revert any partial state changes due to this message, but not revert any state changes in the calling contract. If this is required, it must be done manually in the `reply` entry point.", + "type": "object", + "required": [ + "id", + "msg", + "reply_on" + ], + "properties": { + "gas_limit": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "id": { + "description": "An arbitrary ID chosen by the contract. This is typically used to match `Reply`s in the `reply` entry point to the submessage.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "msg": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + }, + "reply_on": { + "$ref": "#/definitions/ReplyOn" + } + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/reflect/schema/instantiate_msg.json b/contracts/reflect/schema/instantiate_msg.json new file mode 100644 index 0000000..44588cf --- /dev/null +++ b/contracts/reflect/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/reflect/schema/owner_response.json b/contracts/reflect/schema/owner_response.json new file mode 100644 index 0000000..0ec6409 --- /dev/null +++ b/contracts/reflect/schema/owner_response.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OwnerResponse", + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "string" + } + } +} diff --git a/contracts/reflect/schema/query_msg.json b/contracts/reflect/schema/query_msg.json new file mode 100644 index 0000000..9cd8238 --- /dev/null +++ b/contracts/reflect/schema/query_msg.json @@ -0,0 +1,873 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Queries the blockchain and returns the result untouched", + "type": "object", + "required": [ + "chain" + ], + "properties": { + "chain": { + "type": "object", + "required": [ + "request" + ], + "properties": { + "request": { + "$ref": "#/definitions/QueryRequest_for_CyberQueryWrapper" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Queries another contract and returns the data", + "type": "object", + "required": [ + "raw" + ], + "properties": { + "raw": { + "type": "object", + "required": [ + "contract", + "key" + ], + "properties": { + "contract": { + "type": "string" + }, + "key": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "If there was a previous ReflectSubMsg with this ID, returns cosmwasm_std::Reply", + "type": "object", + "required": [ + "sub_msg_result" + ], + "properties": { + "sub_msg_result": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "BankQuery": { + "oneOf": [ + { + "description": "This calls into the native bank module for one denomination Return value is BalanceResponse", + "type": "object", + "required": [ + "balance" + ], + "properties": { + "balance": { + "type": "object", + "required": [ + "address", + "denom" + ], + "properties": { + "address": { + "type": "string" + }, + "denom": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This calls into the native bank module for all denominations. Note that this may be much more expensive than Balance and should be avoided if possible. Return value is AllBalanceResponse.", + "type": "object", + "required": [ + "all_balances" + ], + "properties": { + "all_balances": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + } + } + }, + "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", + "type": "string" + }, + "CyberQuery": { + "oneOf": [ + { + "type": "object", + "required": [ + "particle_rank" + ], + "properties": { + "particle_rank": { + "type": "object", + "required": [ + "particle" + ], + "properties": { + "particle": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "particles_amount" + ], + "properties": { + "particles_amount": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "cyberlinks_amount" + ], + "properties": { + "cyberlinks_amount": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "thought" + ], + "properties": { + "thought": { + "type": "object", + "required": [ + "name", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "thought_stats" + ], + "properties": { + "thought_stats": { + "type": "object", + "required": [ + "name", + "program" + ], + "properties": { + "name": { + "type": "string" + }, + "program": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "thought_lowest_fee" + ], + "properties": { + "thought_lowest_fee": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "source_routes" + ], + "properties": { + "source_routes": { + "type": "object", + "required": [ + "source" + ], + "properties": { + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "source_routed_energy" + ], + "properties": { + "source_routed_energy": { + "type": "object", + "required": [ + "source" + ], + "properties": { + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "destination_routed_energy" + ], + "properties": { + "destination_routed_energy": { + "type": "object", + "required": [ + "destination" + ], + "properties": { + "destination": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "route" + ], + "properties": { + "route": { + "type": "object", + "required": [ + "destination", + "source" + ], + "properties": { + "destination": { + "type": "string" + }, + "source": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bandwidth_price" + ], + "properties": { + "bandwidth_price": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bandwidth_load" + ], + "properties": { + "bandwidth_load": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bandwidth_total" + ], + "properties": { + "bandwidth_total": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "neuron_bandwidth" + ], + "properties": { + "neuron_bandwidth": { + "type": "object", + "required": [ + "neuron" + ], + "properties": { + "neuron": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pool_params" + ], + "properties": { + "pool_params": { + "type": "object", + "required": [ + "pool_id" + ], + "properties": { + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pool_liquidity" + ], + "properties": { + "pool_liquidity": { + "type": "object", + "required": [ + "pool_id" + ], + "properties": { + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pool_supply" + ], + "properties": { + "pool_supply": { + "type": "object", + "required": [ + "pool_id" + ], + "properties": { + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pool_price" + ], + "properties": { + "pool_price": { + "type": "object", + "required": [ + "pool_id" + ], + "properties": { + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pool_address" + ], + "properties": { + "pool_address": { + "type": "object", + "required": [ + "pool_id" + ], + "properties": { + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] + }, + "CyberQueryWrapper": { + "type": "object", + "required": [ + "query_data", + "route" + ], + "properties": { + "query_data": { + "$ref": "#/definitions/CyberQuery" + }, + "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" + ] + }, + "IbcQuery": { + "description": "These are queries to the various IBC modules to see the state of the contract's IBC connection. These will return errors if the contract is not \"ibc enabled\"", + "oneOf": [ + { + "description": "Gets the Port ID the current contract is bound to.\n\nReturns a `PortIdResponse`.", + "type": "object", + "required": [ + "port_id" + ], + "properties": { + "port_id": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Lists all channels that are bound to a given port. If `port_id` is omitted, this list all channels bound to the contract's port.\n\nReturns a `ListChannelsResponse`.", + "type": "object", + "required": [ + "list_channels" + ], + "properties": { + "list_channels": { + "type": "object", + "properties": { + "port_id": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Lists all information for a (portID, channelID) pair. If port_id is omitted, it will default to the contract's own channel. (To save a PortId{} call)\n\nReturns a `ChannelResponse`.", + "type": "object", + "required": [ + "channel" + ], + "properties": { + "channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "port_id": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + } + ] + }, + "QueryRequest_for_CyberQueryWrapper": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankQuery" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/CyberQueryWrapper" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingQuery" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate query is encoded the same way as abci_query, with path and protobuf encoded request data. The format is defined in [ADR-21](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-021-protobuf-query-encoding.md). The response is protobuf encoded data directly without a JSON response wrapper. The caller is responsible for compiling the proper protobuf definitions for both requests and responses.", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "data", + "path" + ], + "properties": { + "data": { + "description": "this is the expected protobuf message type (not any), binary encoded", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "path": { + "description": "this is the fully qualified service path used for routing, eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcQuery" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmQuery" + } + }, + "additionalProperties": false + } + ] + }, + "StakingQuery": { + "oneOf": [ + { + "description": "Returns the denomination that can be bonded (if there are multiple native tokens on the chain)", + "type": "object", + "required": [ + "bonded_denom" + ], + "properties": { + "bonded_denom": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "AllDelegations will return all delegations by the delegator", + "type": "object", + "required": [ + "all_delegations" + ], + "properties": { + "all_delegations": { + "type": "object", + "required": [ + "delegator" + ], + "properties": { + "delegator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Delegation will return more detailed info on a particular delegation, defined by delegator/validator pair", + "type": "object", + "required": [ + "delegation" + ], + "properties": { + "delegation": { + "type": "object", + "required": [ + "delegator", + "validator" + ], + "properties": { + "delegator": { + "type": "string" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Returns all validators in the currently active validator set.\n\nThe query response type is `AllValidatorsResponse`.", + "type": "object", + "required": [ + "all_validators" + ], + "properties": { + "all_validators": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "description": "Returns the validator at the given address. Returns None if the validator is not part of the currently active validator set.\n\nThe query response type is `ValidatorResponse`.", + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The validator's address (e.g. (e.g. cosmosvaloper1...))", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "WasmQuery": { + "oneOf": [ + { + "description": "this queries the public API of another contract at a known address (with known ABI) Return value is whatever the contract returns (caller should know), wrapped in a ContractResult that is JSON encoded.", + "type": "object", + "required": [ + "smart" + ], + "properties": { + "smart": { + "type": "object", + "required": [ + "contract_addr", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded QueryMsg struct", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "this queries the raw kv-store of the contract. returns the raw, unparsed data stored at that key, which may be an empty vector if not present", + "type": "object", + "required": [ + "raw" + ], + "properties": { + "raw": { + "type": "object", + "required": [ + "contract_addr", + "key" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "key": { + "description": "Key is the raw key used in the contracts Storage", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "returns a ContractInfoResponse with metadata on the contract from the runtime", + "type": "object", + "required": [ + "contract_info" + ], + "properties": { + "contract_info": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + } + } +} diff --git a/contracts/reflect/schema/raw_response.json b/contracts/reflect/schema/raw_response.json new file mode 100644 index 0000000..06d1400 --- /dev/null +++ b/contracts/reflect/schema/raw_response.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "RawResponse", + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "description": "The returned value of the raw query. Empty data can be the result of a non-existent key or an empty value. We cannot differentiate those two cases in cross contract queries.", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + }, + "definitions": { + "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", + "type": "string" + } + } +} diff --git a/contracts/reflect/schema/response_for__cyber_msg_wrapper.json b/contracts/reflect/schema/response_for__cyber_msg_wrapper.json new file mode 100644 index 0000000..918f5e9 --- /dev/null +++ b/contracts/reflect/schema/response_for__cyber_msg_wrapper.json @@ -0,0 +1,1377 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Response_for_CyberMsgWrapper", + "description": "A response of a contract entry point, such as `instantiate`, `execute` or `migrate`.\n\nThis type can be constructed directly at the end of the call. Alternatively a mutable response instance can be created early in the contract's logic and incrementally be updated.\n\n## Examples\n\nDirect:\n\n``` # use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo}; # type InstantiateMsg = (); # use cosmwasm_std::{attr, Response, StdResult};\n\npub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, msg: InstantiateMsg, ) -> StdResult { // ...\n\nOk(Response::new().add_attribute(\"action\", \"instantiate\")) } ```\n\nMutating:\n\n``` # use cosmwasm_std::{coins, BankMsg, Binary, DepsMut, Env, MessageInfo, SubMsg}; # type InstantiateMsg = (); # type MyError = (); # use cosmwasm_std::Response;\n\npub fn instantiate( deps: DepsMut, _env: Env, info: MessageInfo, msg: InstantiateMsg, ) -> Result { let mut response = Response::new() .add_attribute(\"Let the\", \"hacking begin\") .add_message(BankMsg::Send { to_address: String::from(\"recipient\"), amount: coins(128, \"uint\"), }) .add_attribute(\"foo\", \"bar\") .set_data(b\"the result data\"); Ok(response) } ```", + "type": "object", + "required": [ + "attributes", + "events", + "messages" + ], + "properties": { + "attributes": { + "description": "The attributes that will be emitted as part of a \"wasm\" event.\n\nMore info about events (and their attributes) can be found in [*Cosmos SDK* docs].\n\n[*Cosmos SDK* docs]: https://docs.cosmos.network/master/core/events.html", + "type": "array", + "items": { + "$ref": "#/definitions/Attribute" + } + }, + "data": { + "description": "The binary payload to include in the response.", + "anyOf": [ + { + "$ref": "#/definitions/Binary" + }, + { + "type": "null" + } + ] + }, + "events": { + "description": "Extra, custom events separate from the main `wasm` one. These will have `wasm-` prepended to the type.\n\nMore info about events can be found in [*Cosmos SDK* docs].\n\n[*Cosmos SDK* docs]: https://docs.cosmos.network/master/core/events.html", + "type": "array", + "items": { + "$ref": "#/definitions/Event" + } + }, + "messages": { + "description": "Optional list of messages to pass. These will be executed in order. If the ReplyOn variant matches the result (Always, Success on Ok, Error on Err), the runtime will invoke this contract's `reply` entry point after execution. Otherwise, they act like \"fire and forget\". Use `SubMsg::new` to create messages with the older \"fire and forget\" semantics.", + "type": "array", + "items": { + "$ref": "#/definitions/SubMsg_for_CyberMsgWrapper" + } + } + }, + "definitions": { + "Attribute": { + "description": "An key value pair that is used in the context of event attributes in logs", + "type": "object", + "required": [ + "key", + "value" + ], + "properties": { + "key": { + "type": "string" + }, + "value": { + "type": "string" + } + } + }, + "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", + "type": "string" + }, + "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": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Event": { + "description": "A full [*Cosmos SDK* event].\n\nThis version uses string attributes (similar to [*Cosmos SDK* StringEvent]), which then get magically converted to bytes for Tendermint somewhere between the Rust-Go interface, JSON deserialization and the `NewEvent` call in Cosmos SDK.\n\n[*Cosmos SDK* event]: https://docs.cosmos.network/master/core/events.html [*Cosmos SDK* StringEvent]: https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/base/abci/v1beta1/abci.proto#L56-L70", + "type": "object", + "required": [ + "attributes", + "type" + ], + "properties": { + "attributes": { + "description": "The attributes to be included in the event.\n\nYou can learn more about these from [*Cosmos SDK* docs].\n\n[*Cosmos SDK* docs]: https://docs.cosmos.network/master/core/events.html", + "type": "array", + "items": { + "$ref": "#/definitions/Attribute" + } + }, + "type": { + "description": "The event type. This is renamed to \"ty\" because \"type\" is reserved in Rust. This sucks, we know.", + "type": "string" + } + } + }, + "GovMsg": { + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "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" + } + } + }, + "ReplyOn": { + "description": "Use this to define when the contract gets a response callback. If you only need it for errors or success you can select just those in order to save gas.", + "type": "string", + "enum": [ + "always", + "error", + "success", + "never" + ] + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "SubMsg_for_CyberMsgWrapper": { + "description": "A submessage that will guarantee a `reply` call on success or error, depending on the `reply_on` setting. If you do not need to process the result, use regular messages instead.\n\nNote: On error the submessage execution will revert any partial state changes due to this message, but not revert any state changes in the calling contract. If this is required, it must be done manually in the `reply` entry point.", + "type": "object", + "required": [ + "id", + "msg", + "reply_on" + ], + "properties": { + "gas_limit": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "id": { + "description": "An arbitrary ID chosen by the contract. This is typically used to match `Reply`s in the `reply` entry point to the submessage.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "msg": { + "$ref": "#/definitions/CosmosMsg_for_CyberMsgWrapper" + }, + "reply_on": { + "$ref": "#/definitions/ReplyOn" + } + } + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "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\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `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-readbale label for the contract", + "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/contracts/reflect/schema/state.json b/contracts/reflect/schema/state.json new file mode 100644 index 0000000..1c10ba4 --- /dev/null +++ b/contracts/reflect/schema/state.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "State", + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "$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" + } + } +}