diff --git a/Cargo.lock b/Cargo.lock index 6a89d4f..efe06e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2230,7 +2230,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", ] @@ -2253,7 +2253,7 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-support-procedural", @@ -2278,7 +2278,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "array-bytes 6.2.2", @@ -2326,7 +2326,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -2356,7 +2356,7 @@ dependencies = [ [[package]] name = "frame-remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "indicatif", @@ -2377,7 +2377,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "aquamarine", "array-bytes 6.2.2", @@ -2418,7 +2418,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "cfg-expr", @@ -2437,7 +2437,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate 3.1.0", @@ -2449,7 +2449,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro2", "quote", @@ -2459,7 +2459,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "cfg-if", "docify", @@ -2479,7 +2479,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -2494,7 +2494,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-api", @@ -2503,7 +2503,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "parity-scale-codec", @@ -4081,24 +4081,6 @@ dependencies = [ "keystream", ] -[[package]] -name = "lite-json" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0e787ffe1153141a0f6f6d759fdf1cc34b1226e088444523812fd412a5cca2" -dependencies = [ - "lite-parser", -] - -[[package]] -name = "lite-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d5f9dc37c52d889a21fd701983d02bb6a84f852c5140a6c80ef4557f7dc29e" -dependencies = [ - "paste", -] - [[package]] name = "lock_api" version = "0.4.11" @@ -4585,7 +4567,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-core", "sp-runtime", @@ -4602,6 +4584,7 @@ dependencies = [ "futures", "jsonrpsee", "node-template-runtime", + "pallet-skip-feeless-payment", "pallet-transaction-payment", "pallet-transaction-payment-rpc", "sc-basic-authorship", @@ -4655,6 +4638,7 @@ dependencies = [ "pallet-grandpa", "pallet-insecure-randomness-collective-flip", "pallet-nfts", + "pallet-skip-feeless-payment", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -4862,7 +4846,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallet-aura" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4879,7 +4863,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4893,7 +4877,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -4913,8 +4897,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "lite-json", - "log", "pallet-balances", "pallet-insecure-randomness-collective-flip", "pallet-nfts", @@ -4931,7 +4913,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -4954,7 +4936,7 @@ dependencies = [ [[package]] name = "pallet-insecure-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4968,7 +4950,7 @@ dependencies = [ [[package]] name = "pallet-nfts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "enumflags2", "frame-benchmarking", @@ -4986,7 +4968,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -5005,10 +4987,23 @@ dependencies = [ "sp-trie", ] +[[package]] +name = "pallet-skip-feeless-payment" +version = "1.0.0-dev" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std 8.0.0", +] + [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "frame-benchmarking", @@ -5024,7 +5019,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "frame-benchmarking", @@ -5044,7 +5039,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -5060,7 +5055,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5076,7 +5071,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5108,9 +5103,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec", "bitvec", @@ -5123,11 +5118,11 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 1.0.109", @@ -5532,15 +5527,6 @@ dependencies = [ "toml 0.5.11", ] -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.7", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -6259,7 +6245,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "sp-core", @@ -6270,7 +6256,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "futures-timer", @@ -6292,7 +6278,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-api", @@ -6307,7 +6293,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "docify", @@ -6332,7 +6318,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -6343,7 +6329,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bip39", @@ -6384,7 +6370,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "fnv", "futures", @@ -6411,7 +6397,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "kvdb", @@ -6437,7 +6423,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6462,7 +6448,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6491,7 +6477,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "array-bytes 6.2.2", @@ -6533,7 +6519,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6556,7 +6542,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", @@ -6578,7 +6564,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sc-allocator", "sp-maybe-compressed-blob", @@ -6590,7 +6576,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "anyhow", "cfg-if", @@ -6608,7 +6594,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "futures", @@ -6625,7 +6611,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "parking_lot 0.12.1", @@ -6639,7 +6625,7 @@ dependencies = [ [[package]] name = "sc-mixnet" version = "0.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 4.2.0", "arrayvec", @@ -6668,7 +6654,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6711,7 +6697,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-channel", "cid", @@ -6731,7 +6717,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -6748,7 +6734,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "futures", @@ -6767,7 +6753,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6788,7 +6774,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6824,7 +6810,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "futures", @@ -6843,7 +6829,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bytes", @@ -6877,7 +6863,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -6886,7 +6872,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "jsonrpsee", @@ -6918,7 +6904,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -6938,7 +6924,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "http", "jsonrpsee", @@ -6953,7 +6939,7 @@ dependencies = [ [[package]] name = "sc-rpc-spec-v2" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "futures", @@ -6982,7 +6968,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "directories", @@ -7045,7 +7031,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "parity-scale-codec", @@ -7056,7 +7042,7 @@ dependencies = [ [[package]] name = "sc-statement-store" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "parity-db", @@ -7075,7 +7061,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "derive_more", "futures", @@ -7095,7 +7081,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "chrono", "futures", @@ -7114,7 +7100,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "chrono", @@ -7144,7 +7130,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -7155,7 +7141,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7181,7 +7167,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7197,7 +7183,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-channel", "futures", @@ -7631,7 +7617,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "log", @@ -7652,7 +7638,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "blake2 0.10.6", @@ -7666,7 +7652,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "23.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -7679,7 +7665,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "integer-sqrt", "num-traits", @@ -7711,7 +7697,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-inherents", @@ -7722,7 +7708,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "log", @@ -7740,7 +7726,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7755,7 +7741,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -7772,7 +7758,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -7791,7 +7777,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "finality-grandpa", "log", @@ -7809,7 +7795,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -7821,7 +7807,7 @@ dependencies = [ [[package]] name = "sp-core" version = "21.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bandersnatch_vrfs", @@ -7867,7 +7853,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "9.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "blake2b_simd", "byteorder", @@ -7880,7 +7866,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "9.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "quote", "sp-core-hashing", @@ -7890,7 +7876,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -7910,7 +7896,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -7919,7 +7905,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro2", "quote", @@ -7929,7 +7915,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "proc-macro2", "quote", @@ -7939,7 +7925,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.19.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "environmental", "parity-scale-codec", @@ -7950,7 +7936,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "environmental", "parity-scale-codec", @@ -7960,7 +7946,7 @@ dependencies = [ [[package]] name = "sp-genesis-builder" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "serde_json", "sp-api", @@ -7971,7 +7957,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -7985,7 +7971,7 @@ dependencies = [ [[package]] name = "sp-io" version = "23.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bytes", "ed25519-dalek", @@ -8009,7 +7995,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-core", "sp-runtime", @@ -8019,7 +8005,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.27.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", @@ -8031,7 +8017,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "thiserror", "zstd 0.12.4", @@ -8040,7 +8026,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -8051,7 +8037,7 @@ dependencies = [ [[package]] name = "sp-mixnet" version = "0.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -8063,7 +8049,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-core", @@ -8073,7 +8059,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "backtrace", "lazy_static", @@ -8083,7 +8069,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "rustc-hash", "serde", @@ -8093,7 +8079,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "either", @@ -8117,7 +8103,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8135,7 +8121,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8154,7 +8140,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "11.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "expander", @@ -8167,7 +8153,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "Inflector", "expander", @@ -8180,7 +8166,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -8195,7 +8181,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -8209,7 +8195,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.28.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "log", @@ -8230,7 +8216,7 @@ dependencies = [ [[package]] name = "sp-statement-store" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "aes-gcm", "curve25519-dalek 4.1.2", @@ -8254,17 +8240,17 @@ dependencies = [ [[package]] name = "sp-std" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" [[package]] name = "sp-storage" version = "13.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8277,7 +8263,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8289,7 +8275,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -8302,7 +8288,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "10.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-std 8.0.0", @@ -8314,7 +8300,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "parity-scale-codec", "tracing", @@ -8325,7 +8311,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-runtime", @@ -8334,7 +8320,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -8349,7 +8335,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "22.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "hash-db", @@ -8373,7 +8359,7 @@ dependencies = [ [[package]] name = "sp-version" version = "22.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8390,7 +8376,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8401,7 +8387,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -8414,7 +8400,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "impl-trait-for-tuples", "log", @@ -8424,7 +8410,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bounded-collections", "parity-scale-codec", @@ -8587,12 +8573,12 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -8611,7 +8597,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hyper", "log", @@ -8623,7 +8609,7 @@ dependencies = [ [[package]] name = "substrate-rpc-client" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "jsonrpsee", @@ -8636,7 +8622,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "build-helper", @@ -8985,17 +8971,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.20.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" -dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.21.1" @@ -9254,7 +9229,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "clap", diff --git a/node/Cargo.toml b/node/Cargo.toml index 45c8b62..8215dec 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -18,55 +18,56 @@ name = "node-template" [dependencies] clap = { version = "4.4.2", features = ["derive"] } -futures = { version = "0.3.21", features = ["thread-pool"]} +futures = { version = "0.3.21", features = ["thread-pool"] } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-statement-store = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-keystore = {git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-statement-store = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # These dependencies are used for the node template's RPCs jsonrpsee = { version = "0.16.2", features = ["server"] } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # These dependencies are used for runtime benchmarking -frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # Local Dependencies node-template-runtime = { version = "4.0.0-dev", path = "../runtime" } # CLI-specific dependencies -try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } [features] default = [] @@ -78,4 +79,7 @@ runtime-benchmarks = [ ] # Enable features that allow the runtime to be tried and debugged. Name might be subject to change # in the near future. -try-runtime = ["node-template-runtime/try-runtime", "try-runtime-cli/try-runtime"] \ No newline at end of file +try-runtime = [ + "node-template-runtime/try-runtime", + "try-runtime-cli/try-runtime", +] diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 6e29ad1..7c0b8cb 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -120,7 +120,9 @@ pub fn create_benchmark_extrinsic( )), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(0), + pallet_skip_feeless_payment::SkipCheckIfFeeless::from( + pallet_transaction_payment::ChargeTransactionPayment::::from(0), + ), ); let raw_payload = runtime::SignedPayload::from_raw( diff --git a/node/src/service.rs b/node/src/service.rs index df88269..c4a2b2f 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -66,23 +66,6 @@ pub fn new_partial( )?; let client = Arc::new(client); - let keystore = keystore_container.keystore(); - if config.offchain_worker.enabled { - // Initialize seed for signing transaction using off-chain workers. This is a convenience - // so learners can see the transactions submitted simply running the node. - // Typically these keys should be inserted with RPC calls to `author_insertKey`. - - // For pallet-ocw - sp_keystore::Keystore::sr25519_generate_new( - &*keystore, - node_template_runtime::pallet_game::KEY_TYPE, - Some("//Alice"), - ) - .expect("Creating key with account Alice should succeed."); - - // For pallet-example-offchain-worker - } - let telemetry = telemetry.map(|(worker, telemetry)| { task_manager.spawn_handle().spawn("telemetry", None, worker.run()); telemetry diff --git a/pallets/game/Cargo.toml b/pallets/game/Cargo.toml index 5031ff8..cfa0157 100644 --- a/pallets/game/Cargo.toml +++ b/pallets/game/Cargo.toml @@ -17,25 +17,25 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = [ + "derive", +] } serde = { version = "1.0.197", features = ["derive"], optional = true } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-std = { version = "8.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-std = { version = "8.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } -pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } enumflags2 = { version = "0.7.7" } -log = { version = "0.4.21", default-features = false } -lite-json = { version = "0.2.0", default-features = false } - [dev-dependencies] -pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } +sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } +sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } + +pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } [features] default = ["std"] @@ -49,8 +49,6 @@ std = [ "pallet-nfts/std", "pallet-balances/std", "sp-std/std", - "log/std", - "lite-json/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] -try-runtime = ["frame-support/try-runtime"] \ No newline at end of file +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index cd436d5..d096d49 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -13,8 +13,10 @@ use frame_system::RawOrigin; fn create_setup() -> T::AccountId { let caller: T::AccountId = whitelisted_caller(); + let admin: T::AccountId = account("admin", 0, 0); assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); - assert_ok!(GameModule::::register_user(RawOrigin::Root.into(), caller.clone())); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), admin.clone())); + assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller.clone())); caller } @@ -28,6 +30,13 @@ fn practise_round(caller: T::AccountId, game_id: u32) { 20, game_id )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 20, + game_id, + 20, + "test".as_bytes().to_vec().try_into().unwrap(), + )); } #[benchmarks] @@ -42,17 +51,23 @@ mod benchmarks { #[benchmark] fn register_user() { - let caller: T::AccountId = whitelisted_caller(); + let caller: T::AccountId = account("caller", 0, 0); assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), admin.clone())); #[extrinsic_call] - register_user(RawOrigin::Root, caller); + register_user(RawOrigin::Signed(admin), caller.clone()); + + assert!(GameModule::::users(caller).is_some()); } #[benchmark] fn give_points() { let caller = create_setup::(); #[extrinsic_call] - give_points(RawOrigin::Root, caller); + give_points(RawOrigin::Root, caller.clone(), 100); + + assert_eq!(GameModule::::users(caller).unwrap().points, 150); } #[benchmark] @@ -61,7 +76,9 @@ mod benchmarks { current_block::(30u32.into()); practise_round::(caller.clone(), 0); #[extrinsic_call] - play_game(RawOrigin::Signed(caller), crate::DifficultyLevel::Player); + play_game(RawOrigin::Signed(caller.clone()), crate::DifficultyLevel::Player); + + assert_eq!(GameModule::::game_info(1).unwrap().player, caller); } #[benchmark] @@ -74,7 +91,42 @@ mod benchmarks { crate::DifficultyLevel::Player )); #[extrinsic_call] - submit_answer(RawOrigin::Signed(caller), 200000, 1); + submit_answer(RawOrigin::Signed(caller.clone()), 220000, 1); + + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); + assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); + } + + #[benchmark] + fn check_result() { + let caller = create_setup::(); + current_block::(30u32.into()); + practise_round::(caller.clone(), 0); + assert_ok!(GameModule::::play_game( + RawOrigin::Signed(caller.clone()).into(), + crate::DifficultyLevel::Player + )); + assert_ok!(GameModule::::submit_answer( + RawOrigin::Signed(caller.clone()).into(), + 220000, + 1 + )); + #[extrinsic_call] + check_result( + RawOrigin::Root, + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + ); + + assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); } #[benchmark] @@ -91,8 +143,17 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); #[extrinsic_call] - list_nft(RawOrigin::Signed(caller), 0.into(), 0.into()); + list_nft(RawOrigin::Signed(caller.clone()), 0.into(), 0.into()); + + assert_eq!(GameModule::::listings(0).unwrap().owner, caller); } #[benchmark] @@ -109,6 +170,13 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), @@ -116,6 +184,8 @@ mod benchmarks { )); #[extrinsic_call] delist_nft(RawOrigin::Signed(caller), 0); + + assert!(GameModule::::listings(0).is_none()); } #[benchmark] @@ -132,24 +202,45 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), 0.into() )); - let caller2 = create_setup::(); + let caller2: T::AccountId = account("caller2", 0, 0); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::register_user( + RawOrigin::Signed(admin).into(), + caller2.clone() + )); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( - RawOrigin::Signed(caller.clone()).into(), + RawOrigin::Signed(caller2.clone()).into(), crate::DifficultyLevel::Player )); assert_ok!(GameModule::::submit_answer( - RawOrigin::Signed(caller.clone()).into(), + RawOrigin::Signed(caller2.clone()).into(), 220000, 3 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 3, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); #[extrinsic_call] - make_offer(RawOrigin::Signed(caller2), 0, 0.into(), 1.into()); + make_offer(RawOrigin::Signed(caller2.clone()), 0, 0.into(), 1.into()); + + assert_eq!(GameModule::::offers(0).unwrap().owner, caller2); } #[benchmark] @@ -166,12 +257,24 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), 0.into() )); - let caller2 = create_setup::(); + let caller2: T::AccountId = account("caller2", 0, 0); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::register_user( + RawOrigin::Signed(admin).into(), + caller2.clone() + )); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( RawOrigin::Signed(caller2.clone()).into(), @@ -182,6 +285,13 @@ mod benchmarks { 220000, 3 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 3, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_eq!( GameModule::::users::>(caller2.clone()).unwrap().nfts.xorange, 1 @@ -194,7 +304,59 @@ mod benchmarks { )); #[extrinsic_call] - handle_offer(RawOrigin::Signed(caller2), 0, crate::Offer::Accept); + handle_offer(RawOrigin::Signed(caller), 0, crate::Offer::Accept); + + assert_eq!(GameModule::::offers(0).is_none(), true); + assert_eq!(GameModule::::listings(0).is_none(), true); + } + + #[benchmark] + fn add_property() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_property = PropertyInfoData { + id: 147031382, + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), + }; + #[extrinsic_call] + add_property(RawOrigin::Root, new_property); + + assert_eq!(GameModule::::game_properties().len(), 5); + } + + #[benchmark] + fn remove_property() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + #[extrinsic_call] + remove_property(RawOrigin::Root, 146480642); + + assert_eq!(GameModule::::game_properties().len(), 3); + } + + #[benchmark] + fn add_to_admins() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_admin: T::AccountId = account("new_admin", 1, 0); + #[extrinsic_call] + add_to_admins(RawOrigin::Root, new_admin); + } + + #[benchmark] + fn remove_from_admins() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_admin: T::AccountId = account("new_admin", 0, 0); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), new_admin.clone())); + #[extrinsic_call] + remove_from_admins(RawOrigin::Root, new_admin); + } + + #[benchmark] + fn request_token() { + let caller = create_setup::(); + current_block::(30u32.into()); + current_block::(100801u32.into()); + #[extrinsic_call] + request_token(RawOrigin::Signed(caller)); } impl_benchmark_test_suite!(GameModule, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs new file mode 100644 index 0000000..40782e9 --- /dev/null +++ b/pallets/game/src/functions.rs @@ -0,0 +1,407 @@ +use crate::*; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +impl Pallet { + /// Get the account id of the pallet + pub fn account_id() -> AccountIdOf { + ::PalletId::get().into_account_truncating() + } + + /// checks if the signer has enough points to start a game. + pub fn check_enough_points( + signer: AccountIdOf, + game_type: DifficultyLevel, + ) -> DispatchResult { + if game_type == DifficultyLevel::Pro { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, + Error::::NotEnoughPoints + ); + } else if game_type == DifficultyLevel::Player { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, + Error::::NotEnoughPoints + ); + } else { + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, + Error::::TooManyPractise + ); + } + Ok(()) + } + + /// checks the answer and distributes the rewards accordingly. + pub fn do_check_result(difference: u16, game_id: u32, secret: BoundedVec::StringLimit> ) -> DispatchResult { + let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; + ensure!(game_info.guess.is_some(), Error::::NoGuess); + if game_info.difficulty == DifficultyLevel::Pro { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = random_number.into(); + let next_item_id = NextColorId::::get(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = + user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + Self::deposit_event(Event::::ResultChecked { game_id, secret, points, won: true }); + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: true }); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: true }); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: true }); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: false }); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 40, won: false }); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: false }); + }, + } + } else if game_info.difficulty == DifficultyLevel::Player { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = random_number.into(); + let next_item_id = NextColorId::::get(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = + user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + Self::deposit_event(Event::::ResultChecked { game_id, secret, points, won: true }); + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: true }); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: true }); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: true }); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: false }); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: false }); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: false }); + }, + } + } else { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + user.practise_rounds = + user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: true }); + } + let user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + Self::update_leaderboard(game_info.player, user.points)?; + Ok(()) + } + + pub fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { + let mut leaderboard = Self::leaderboard(); + let leaderboard_size = leaderboard.len(); + + if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { + *user_points = new_points; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); + return Ok(()); + } + if new_points > 0 && + (leaderboard_size < 10 || + new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) + { + if leaderboard.len() >= 10 { + leaderboard.pop(); + } + leaderboard + .try_push((user_id, new_points)) + .map_err(|_| Error::::InvalidIndex)?; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); + } + Ok(()) + } + + pub fn swap_user_points( + nft_holder: AccountIdOf, + collection_id_add: CollectionId, + collection_id_sub: CollectionId, + ) -> DispatchResult { + let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; + let color_add = + Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; + let color_sub = + Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color_add.clone())?; + let points = user.calculate_points(color_add); + user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.sub_nft_color(color_sub.clone())?; + let points = user.subtracting_calculate_points(color_sub); + user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(nft_holder.clone(), user.clone()); + Self::update_leaderboard(nft_holder.clone(), user.points)?; + if user.has_four_of_all_colors() { + Self::end_game(nft_holder)?; + } + Ok(()) + } + + /// Handles the case if the player did not answer on time. + pub fn no_answer_result(game_info: GameData, game_id: u32) -> DispatchResult { + if game_info.difficulty == DifficultyLevel::Pro { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::NoAnswer { game_id, points: 50 }); + } else if game_info.difficulty == DifficultyLevel::Player { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::NoAnswer { game_id, points: 25 }); + } + Ok(()) + } + + pub fn end_game(winner: AccountIdOf) -> DispatchResult { + RoundActive::::put(false); + RoundChampion::::insert(Self::current_round(), winner); + Ok(()) + } + + /// Set the default collection configuration for creating a collection. + pub fn default_collection_config( + ) -> CollectionConfig, BlockNumberFor, ::CollectionId> + { + Self::collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) + } + + pub fn collection_config_from_disabled_settings( + settings: BitFlags, + ) -> CollectionConfig, BlockNumberFor, ::CollectionId> + { + CollectionConfig { + settings: CollectionSettings::from_disabled(settings), + max_supply: None, + mint_settings: MintSettings::default(), + } + } + + /// Set the default item configuration for minting a nft. + pub fn default_item_config() -> ItemConfig { + ItemConfig { settings: ItemSettings::all_enabled() } + } +} diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index ef19d7e..95e5485 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -15,8 +15,9 @@ mod tests; mod benchmarking; pub mod weights; pub use weights::*; -pub mod offchain_function; +pub mod functions; pub mod properties; +pub mod types; type AccountIdOf = ::AccountId; type BalanceOf = <::Currency as Currency< @@ -24,7 +25,7 @@ type BalanceOf = <::Currency as Currency< >>::Balance; use frame_support::{ - traits::{Currency, Incrementable}, + traits::{Currency, Incrementable, ReservableCurrency}, PalletId, }; @@ -43,58 +44,7 @@ use enumflags2::BitFlags; use frame_support::traits::Randomness; -use codec::{Decode, Encode}; -use frame_support::traits::Get; -use frame_system::{ - self as system, - offchain::{ - AppCrypto, CreateSignedTransaction, SendSignedTransaction, - Signer, - }, - pallet_prelude::BlockNumberFor, -}; -use lite_json::json::JsonValue; -use scale_info::prelude::string::String; -use sp_core::crypto::KeyTypeId; - -use sp_runtime::{ - offchain::{ - http, - Duration, - }, - BoundedVec, RuntimeDebug, -}; -use sp_std::vec::Vec; - -pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"btc!"); - -pub mod crypto { - use super::KEY_TYPE; - use sp_core::sr25519::Signature as Sr25519Signature; - use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, - MultiSignature, MultiSigner, - }; - app_crypto!(sr25519, KEY_TYPE); - - pub struct TestAuthId; - - impl frame_system::offchain::AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } - - // implemented for mock runtime in test - impl frame_system::offchain::AppCrypto<::Signer, Sr25519Signature> - for TestAuthId - { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } -} +pub use types::*; #[frame_support::pallet] pub mod pallet { @@ -105,332 +55,14 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); - /// Difficulty level of game enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum DifficultyLevel { - Practice, - Player, - Pro, - } - - /// Offer enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum Offer { - Accept, - Reject, - } - - /// Nft color enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum NftColor { - Xorange, - Xpink, - Xblue, - Xcyan, - Xcoral, - Xpurple, - Xleafgreen, - Xgreen, - } - - impl NftColor { - pub fn from_index(index: usize) -> Option { - match index { - 0 => Some(NftColor::Xorange), - 1 => Some(NftColor::Xpink), - 2 => Some(NftColor::Xblue), - 3 => Some(NftColor::Xcyan), - 4 => Some(NftColor::Xcoral), - 5 => Some(NftColor::Xpurple), - 6 => Some(NftColor::Xleafgreen), - 7 => Some(NftColor::Xgreen), - _ => None, - } - } - } - - /// AccountId storage. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub struct PalletIdStorage { - pallet_id: AccountIdOf, - } - - /// Game Data. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct GameData { - pub difficulty: DifficultyLevel, - pub player: AccountIdOf, - pub property: PropertyInfoData, - } - - /// Listing infos of a NFT. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct ListingInfo { - pub owner: AccountIdOf, - pub collection_id: CollectionId, - pub item_id: ItemId, - } - - /// Offer infos of a listing. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct OfferInfo { - pub owner: AccountIdOf, - pub listing_id: u32, - pub collection_id: CollectionId, - pub item_id: ItemId, - } - - /// Struct to store the property data for a game. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, - Decode, - Clone, - PartialEq, - Eq, - MaxEncodedLen, - frame_support::pallet_prelude::RuntimeDebugNoBound, - TypeInfo, - )] - #[scale_info(skip_type_params(T))] - pub struct PropertyInfoData { - pub id: u32, - pub bedrooms: u32, - pub bathrooms: u32, - pub summary: BoundedVec::StringLimit>, - pub property_sub_type: BoundedVec::StringLimit>, - pub first_visible_date: BoundedVec::StringLimit>, - pub display_size: BoundedVec::StringLimit>, - pub display_address: BoundedVec::StringLimit>, - pub property_images1: BoundedVec::StringLimit>, - } - - /// Struct for the user datas. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct User { - pub points: u32, - pub wins: u32, - pub losses: u32, - pub practise_rounds: u8, - pub last_played_round: u32, - pub nfts: CollectedColors, - } - - impl User { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.add_nft_color(color)?; - Ok(()) - } - - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.sub_nft_color(color)?; - Ok(()) - } - - pub fn has_four_of_all_colors(&self) -> bool { - self.nfts.has_four_of_all_colors() - } - - pub fn calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 1 => 100, - NftColor::Xorange if self.nfts.xorange == 2 => 120, - NftColor::Xorange if self.nfts.xorange == 3 => 220, - NftColor::Xorange if self.nfts.xorange == 4 => 340, - NftColor::Xpink if self.nfts.xpink == 1 => 100, - NftColor::Xpink if self.nfts.xpink == 2 => 120, - NftColor::Xpink if self.nfts.xpink == 3 => 220, - NftColor::Xpink if self.nfts.xpink == 4 => 340, - NftColor::Xblue if self.nfts.xblue == 1 => 100, - NftColor::Xblue if self.nfts.xblue == 2 => 120, - NftColor::Xblue if self.nfts.xblue == 3 => 220, - NftColor::Xblue if self.nfts.xblue == 4 => 340, - NftColor::Xcyan if self.nfts.xcyan == 1 => 100, - NftColor::Xcyan if self.nfts.xcyan == 2 => 120, - NftColor::Xcyan if self.nfts.xcyan == 3 => 220, - NftColor::Xcyan if self.nfts.xcyan == 4 => 340, - NftColor::Xcoral if self.nfts.xcoral == 1 => 100, - NftColor::Xcoral if self.nfts.xcoral == 2 => 120, - NftColor::Xcoral if self.nfts.xcoral == 3 => 220, - NftColor::Xcoral if self.nfts.xcoral == 4 => 340, - NftColor::Xpurple if self.nfts.xpurple == 1 => 100, - NftColor::Xpurple if self.nfts.xpurple == 2 => 120, - NftColor::Xpurple if self.nfts.xpurple == 3 => 220, - NftColor::Xpurple if self.nfts.xpurple == 4 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, - NftColor::Xgreen if self.nfts.xgreen == 1 => 100, - NftColor::Xgreen if self.nfts.xgreen == 2 => 120, - NftColor::Xgreen if self.nfts.xgreen == 3 => 220, - NftColor::Xgreen if self.nfts.xgreen == 4 => 340, - _ => 0, - } - } - - pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 0 => 100, - NftColor::Xorange if self.nfts.xorange == 1 => 120, - NftColor::Xorange if self.nfts.xorange == 2 => 220, - NftColor::Xorange if self.nfts.xorange == 3 => 340, - NftColor::Xpink if self.nfts.xpink == 0 => 100, - NftColor::Xpink if self.nfts.xpink == 1 => 120, - NftColor::Xpink if self.nfts.xpink == 2 => 220, - NftColor::Xpink if self.nfts.xpink == 3 => 340, - NftColor::Xblue if self.nfts.xblue == 0 => 100, - NftColor::Xblue if self.nfts.xblue == 1 => 120, - NftColor::Xblue if self.nfts.xblue == 2 => 220, - NftColor::Xblue if self.nfts.xblue == 3 => 340, - NftColor::Xcyan if self.nfts.xcyan == 0 => 100, - NftColor::Xcyan if self.nfts.xcyan == 1 => 120, - NftColor::Xcyan if self.nfts.xcyan == 2 => 220, - NftColor::Xcyan if self.nfts.xcyan == 3 => 340, - NftColor::Xcoral if self.nfts.xcoral == 0 => 100, - NftColor::Xcoral if self.nfts.xcoral == 1 => 120, - NftColor::Xcoral if self.nfts.xcoral == 2 => 220, - NftColor::Xcoral if self.nfts.xcoral == 3 => 340, - NftColor::Xpurple if self.nfts.xpurple == 0 => 100, - NftColor::Xpurple if self.nfts.xpurple == 1 => 120, - NftColor::Xpurple if self.nfts.xpurple == 2 => 220, - NftColor::Xpurple if self.nfts.xpurple == 3 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, - NftColor::Xgreen if self.nfts.xgreen == 0 => 100, - NftColor::Xgreen if self.nfts.xgreen == 1 => 120, - NftColor::Xgreen if self.nfts.xgreen == 2 => 220, - NftColor::Xgreen if self.nfts.xgreen == 3 => 340, - _ => 0, - } - } - } - - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default, - )] - #[scale_info(skip_type_params(T))] - pub struct CollectedColors { - pub xorange: u32, - pub xpink: u32, - pub xblue: u32, - pub xcyan: u32, - pub xcoral: u32, - pub xpurple: u32, - pub xleafgreen: u32, - pub xgreen: u32, - } - - impl CollectedColors { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - } - } - - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - } - } - - pub fn has_four_of_all_colors(&self) -> bool { - self.xorange >= 4 && - self.xpink >= 4 && self.xblue >= 4 && - self.xcyan >= 4 && self.xcoral >= 4 && - self.xpurple >= 4 && - self.xleafgreen >= 4 && - self.xgreen >= 4 - } - } - /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: - frame_system::Config + pallet_nfts::Config - //+ pallet_babe::Config + pub trait Config: frame_system::Config + pallet_nfts::Config //+ pallet_babe::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The currency type. + type Currency: Currency> + ReservableCurrency>; /// Type representing the weight of this pallet type WeightInfo: WeightInfo; /// Origin who can create a new game. @@ -468,6 +100,10 @@ pub mod pallet { /// The maximum length of leaderboard. #[pallet::constant] type LeaderboardLimit: Get; + #[pallet::constant] + type MaxAdmins: Get; + /// The amount of time until player can request more token. + type RequestLimit: Get>; } pub type CollectionId = ::CollectionId; @@ -491,7 +127,6 @@ pub mod pallet { /// The next item id in a collection. #[pallet::storage] - #[pallet::getter(fn next_color_id)] pub(super) type NextColorId = StorageMap<_, Blake2_128Concat, ::CollectionId, u32, ValueQuery>; @@ -503,7 +138,6 @@ pub mod pallet { /// The next id of listings. #[pallet::storage] - #[pallet::getter(fn next_lising_id)] pub(super) type NextListingId = StorageValue<_, u32, ValueQuery>; /// The next id of offers. @@ -528,7 +162,7 @@ pub mod pallet { /// Mapping of an account id to the user data of the account. #[pallet::storage] #[pallet::getter(fn users)] - pub type Users = StorageMap<_, Blake2_128Concat, AccountIdOf, User, OptionQuery>; + pub type Users = StorageMap<_, Blake2_128Concat, AccountIdOf, User, OptionQuery>; /// Mapping of game id to the game info. #[pallet::storage] @@ -569,14 +203,15 @@ pub mod pallet { /// A List of test properties #[pallet::storage] - #[pallet::getter(fn test_properties)] - pub type TestProperties = + #[pallet::getter(fn game_properties)] + pub type GameProperties = StorageValue<_, BoundedVec, T::MaxProperty>, ValueQuery>; - /// Test for properties + /// Vector of admins who can register users. #[pallet::storage] - #[pallet::getter(fn test_prices)] - pub type TestPrices = StorageMap<_, Blake2_128Concat, u32, u32, OptionQuery>; + #[pallet::getter(fn admins)] + pub type Admins = + StorageValue<_, BoundedVec, T::MaxAdmins>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -584,9 +219,13 @@ pub mod pallet { /// A user has received points. PointsReceived { receiver: AccountIdOf, amount: u32 }, /// A game has started. - GameStarted { player: AccountIdOf, game_id: u32 }, + GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor }, /// An answer has been submitted. - AnswerSubmitted { player: AccountIdOf, game_id: u32 }, + AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, + /// The result has been checked. + ResultChecked { game_id: u32, secret: BoundedVec::StringLimit>, points: u32, won: bool }, + /// No Answer has been submitted. + NoAnswer { game_id: u32, points: u32 }, /// A nft has been listed. NftListed { owner: AccountIdOf, collection_id: CollectionId, item_id: ItemId }, /// A nft has been delisted. @@ -602,8 +241,14 @@ pub mod pallet { OfferWithdrawn { owner: AccountIdOf, offer_id: u32 }, /// An offer has been handled. OfferHandeld { offer_id: u32, offer: Offer }, - /// A new player has been registered + /// A new player has been registered. NewPlayerRegistered { player: AccountIdOf }, + /// A new admins has been added. + NewAdminAdded { new_admin: AccountIdOf }, + /// An admin has been removed. + AdminRemoved { admin: AccountIdOf }, + /// The user received token. + TokenReceived { player: AccountIdOf }, } // Errors inform users that something went wrong. @@ -644,6 +289,16 @@ pub mod pallet { NoActiveRound, /// The player is already registered. PlayerAlreadyRegistered, + /// The account is already an admin. + AccountAlreadyAdmin, + /// This account is not an admin. + NotAdmin, + /// There are already enough admins. + TooManyAdmins, + /// The user has to wait to request token. + CantRequestToken, + /// There has been no guess from the player. + NoGuess, } #[pallet::hooks] @@ -657,19 +312,15 @@ pub mod pallet { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); let game_info = >::take(index); if let Some(game_info) = game_info { - let _ = Self::no_answer_result(game_info); + if game_info.guess.is_none() { + let _ = Self::no_answer_result(game_info, *index); + } else { + GameInfo::::insert(index, game_info); + } } }); weight } - - fn offchain_worker(block_number: BlockNumberFor) { - log::info!("Hello World from offchain workers!"); - - let parent_hash = >::block_hash(block_number - 1u32.into()); - log::debug!("Current block: {:?} (parent hash: {:?})", block_number, parent_hash); - - } } #[pallet::call] @@ -708,8 +359,8 @@ pub mod pallet { let color = NftColor::from_index(x).ok_or(Error::::InvalidIndex)?; CollectionColor::::insert(collection_id, color); } - Self::create_test_properties()?; - let mut round = Self::current_round(); + Self::create_game_properties()?; + let mut round = CurrentRound::::get(); round = round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; CurrentRound::::put(round); RoundActive::::put(true); @@ -727,17 +378,27 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::register_user())] pub fn register_user(origin: OriginFor, player: AccountIdOf) -> DispatchResult { - T::GameOrigin::ensure_origin(origin)?; - ensure!(Self::users(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); + let signer = ensure_signed(origin)?; + ensure!(Admins::::get().contains(&signer), Error::::NoPermission); + ensure!(Users::::get(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); + let current_block_number = >::block_number(); + let next_request = + current_block_number.saturating_add(::RequestLimit::get()); let user = User { points: 50, wins: Default::default(), losses: Default::default(), practise_rounds: Default::default(), last_played_round: Default::default(), + next_token_request: next_request, nfts: CollectedColors::default(), }; + ::Currency::make_free_balance_be( + &player, + 10u32.try_into().map_err(|_| Error::::ConversionError)?, + ); Users::::insert(player.clone(), user); + frame_system::Pallet::::inc_providers(&player); Self::deposit_event(Event::::NewPlayerRegistered { player }); Ok(()) } @@ -752,10 +413,15 @@ pub mod pallet { /// Emits `LocationCreated` event when succesfful. #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::give_points())] - pub fn give_points(origin: OriginFor, receiver: AccountIdOf) -> DispatchResult { + pub fn give_points( + origin: OriginFor, + receiver: AccountIdOf, + amount: u32, + ) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - let mut user = Self::users(receiver.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_add(100).ok_or(Error::::ArithmeticOverflow)?; + let mut user = + Users::::get(receiver.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_add(amount).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(receiver.clone(), user); Self::deposit_event(Event::::PointsReceived { receiver, amount: 100 }); Ok(()) @@ -771,55 +437,74 @@ pub mod pallet { /// Emits `GameStarted` event when succesfful. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::play_game())] + #[pallet::feeless_if(|origin: &OriginFor, game_type: &DifficultyLevel| -> bool { + if let Ok(signer) = ensure_signed(origin.clone()) { + match game_type { + DifficultyLevel::Pro => { + if let Some(user) = Users::::get(&signer) { + if user.points >= 50 { + return true; + } + } + }, + DifficultyLevel::Player => { + if let Some(user) = Users::::get(&signer) { + if user.points >= 25 { + return true; + } + } + }, + DifficultyLevel::Practice => { + return true; + } + } + } + false + })] pub fn play_game(origin: OriginFor, game_type: DifficultyLevel) -> DispatchResult { let signer = ensure_signed(origin)?; Self::check_enough_points(signer.clone(), game_type.clone())?; - ensure!(Self::round_active(), Error::::NoActiveRound); - let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; - if Self::current_round() != user.last_played_round { - user.nfts == Default::default(); - user.last_played_round = user.last_played_round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + ensure!(RoundActive::::get(), Error::::NoActiveRound); + let mut user = Users::::get(signer.clone()).ok_or(Error::::UserNotRegistered)?; + let current_round = CurrentRound::::get(); + if current_round != user.last_played_round { + user.nfts = Default::default(); + user.last_played_round = current_round; Users::::insert(signer.clone(), user); } - let game_id = Self::game_id(); - if game_type == DifficultyLevel::Player { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(8u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; + let game_id = GameId::::get(); + let current_block_number = >::block_number(); + + // Determine expiry block based on game type + let expiry_block = if game_type == DifficultyLevel::Player { + current_block_number.saturating_add(8u32.into()) } else if game_type == DifficultyLevel::Pro { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(5u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; + current_block_number.saturating_add(5u32.into()) } else { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(10u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; - } + current_block_number.saturating_add(10u32.into()) + }; + + GamesExpiring::::try_mutate(expiry_block, |keys| { + keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; + Ok::<(), DispatchError>(()) + })?; + let (hashi, _) = T::GameRandomness::random(&[(game_id % 256) as u8]); let u32_value = u32::from_le_bytes( hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, ); - let random_number = u32_value as usize % - Self::test_properties() - .len(); - let property = Self::test_properties()[random_number].clone(); - let game_datas = GameData { difficulty: game_type, player: signer.clone(), property }; + let mut game_properties = GameProperties::::take(); + let random_number = u32_value as usize % game_properties.len(); + let property = game_properties[random_number].clone(); + let game_datas = + GameData { difficulty: game_type, player: signer.clone(), property: property, guess: None }; + game_properties.retain(|property| property.id as usize != random_number); + GameProperties::::put(game_properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); - Self::deposit_event(Event::::GameStarted { player: signer, game_id }); + // Submit the encrypted property data and delete the price + Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block }); Ok(()) } @@ -834,22 +519,60 @@ pub mod pallet { /// Emits `AnswerSubmitted` event when succesfful. #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::submit_answer())] + #[pallet::feeless_if(|origin: &OriginFor, guess: &u32, game_id: &u32| -> bool { + if let Ok(signer) = ensure_signed(origin.clone()) { + if let Some(game_info) = GameInfo::::get(*game_id) { + if signer == game_info.player { + return true; + } + } + } + false + })] pub fn submit_answer(origin: OriginFor, guess: u32, game_id: u32) -> DispatchResult { let signer = ensure_signed(origin)?; - let game_info = Self::game_info(game_id).ok_or(Error::::NoActiveGame)?; + let mut game_info = GameInfo::::get(game_id).ok_or(Error::::NoActiveGame)?; ensure!(signer == game_info.player, Error::::NoThePlayer); - let property_id = game_info.property.id; - let result: u32 = Self::test_prices(property_id).ok_or(Error::::NoProperty)?; - let difference_value = ((result as i32) + game_info.guess = Some(guess); + GameInfo::::insert(game_id, game_info); + Self::deposit_event(Event::::AnswerSubmitted { player: signer, game_id, guess }); + Ok(()) + } + + /// Checks the answer of the player and handles rewards accordingly. + /// + /// The origin must be root. + /// + /// Parameters: + /// - `guess`: The answer of the player. + /// - `game_id`: The id of the game that the result should be compared to. + /// - `price`: The price of the property. + /// - `secret`: The secret to decrypt the price and property data. + /// + /// Emits `ResultChecked` event when succesfful. + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::check_result())] + pub fn check_result( + origin: OriginFor, + guess: u32, + game_id: u32, + price: u32, + secret: BoundedVec::StringLimit>, + ) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + let difference_value = ((price as i32) .checked_sub(guess as i32) .ok_or(Error::::ArithmeticUnderflow)?) .checked_mul(1000) .ok_or(Error::::MultiplyError)? - .checked_div(result as i32) + .checked_div(price as i32) .ok_or(Error::::DivisionError)? .abs(); - Self::check_result(difference_value.try_into().unwrap(), game_id)?; - Self::deposit_event(Event::::AnswerSubmitted { player: signer, game_id }); + Self::do_check_result( + difference_value.try_into().map_err(|_| Error::::ConversionError)?, + game_id, + secret, + )?; Ok(()) } @@ -862,7 +585,7 @@ pub mod pallet { /// - `item_id`: The item id of the nft that will be listed. /// /// Emits `NftListed` event when succesfful. - #[pallet::call_index(5)] + #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::list_nft())] pub fn list_nft( origin: OriginFor, @@ -889,7 +612,7 @@ pub mod pallet { pallet_lookup, )?; let listing_info = ListingInfo { owner: signer.clone(), collection_id, item_id }; - let mut listing_id = Self::next_lising_id(); + let mut listing_id = NextListingId::::get(); Listings::::insert(listing_id, listing_info); listing_id = listing_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; NextListingId::::put(listing_id); @@ -905,7 +628,7 @@ pub mod pallet { /// - `listing_id`: The listing id of the listing. /// /// Emits `NftDelisted` event when succesfful. - #[pallet::call_index(6)] + #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::delist_nft())] pub fn delist_nft(origin: OriginFor, listing_id: u32) -> DispatchResult { let signer = ensure_signed(origin.clone())?; @@ -942,7 +665,7 @@ pub mod pallet { /// - `item_id`: The item id of the nft that will be offered. /// /// Emits `OfferMade` event when succesfful. - #[pallet::call_index(7)] + #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::make_offer())] pub fn make_offer( origin: OriginFor, @@ -951,7 +674,7 @@ pub mod pallet { item_id: ItemId, ) -> DispatchResult { let signer = ensure_signed(origin.clone())?; - ensure!(Self::listings(listing_id).is_some(), Error::::ListingDoesNotExist); + ensure!(Listings::::get(listing_id).is_some(), Error::::ListingDoesNotExist); let pallet_lookup = ::unlookup(Self::account_id()); let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); pallet_nfts::Pallet::::unlock_item_transfer( @@ -967,7 +690,7 @@ pub mod pallet { )?; let offer_info = OfferInfo { owner: signer.clone(), listing_id, collection_id, item_id }; - let offer_id = Self::next_offer_id(); + let offer_id = NextOfferId::::get(); Offers::::insert(offer_id, offer_info); let offer_id = offer_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; NextOfferId::::put(offer_id); @@ -988,11 +711,11 @@ pub mod pallet { /// - `offer_id`: The id of the offer. /// /// Emits `OfferWithdrawn` event when succesfful. - #[pallet::call_index(8)] + #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::make_offer())] pub fn withdraw_offer(origin: OriginFor, offer_id: u32) -> DispatchResult { let signer = ensure_signed(origin.clone())?; - let offer_details = Self::offers(offer_id).ok_or(Error::::OfferDoesNotExist)?; + let offer_details = Offers::::get(offer_id).ok_or(Error::::OfferDoesNotExist)?; ensure!(offer_details.owner == signer, Error::::NoPermission); pallet_nfts::Pallet::::do_transfer( offer_details.collection_id.into(), @@ -1020,13 +743,13 @@ pub mod pallet { /// - `offer`: Must be either Accept or Reject. /// /// Emits `OfferHandeld` event when succesfful. - #[pallet::call_index(9)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::call_index(10)] + #[pallet::weight(::WeightInfo::handle_offer())] pub fn handle_offer(origin: OriginFor, offer_id: u32, offer: Offer) -> DispatchResult { let signer = ensure_signed(origin.clone())?; let offer_details = Offers::::take(offer_id).ok_or(Error::::OfferDoesNotExist)?; - let listing_details = - Self::listings(offer_details.listing_id).ok_or(Error::::ListingDoesNotExist)?; + let listing_details = Listings::::get(offer_details.listing_id) + .ok_or(Error::::ListingDoesNotExist)?; ensure!(listing_details.owner == signer, Error::::NoPermission); let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); if offer == Offer::Accept { @@ -1089,12 +812,12 @@ pub mod pallet { /// Parameters: /// - `property`: The new property that will be added. /// - `price`: The price of the property that will be added. - #[pallet::call_index(10)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] - pub fn add_property(origin: OriginFor, property: PropertyInfoData, price: u32) -> DispatchResult { + #[pallet::call_index(11)] + #[pallet::weight(::WeightInfo::add_property())] + pub fn add_property(origin: OriginFor, property: PropertyInfoData) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - TestProperties::::try_append(property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(property.id, price); + GameProperties::::try_append(property.clone()) + .map_err(|_| Error::::TooManyTest)?; Ok(()) } @@ -1104,398 +827,77 @@ pub mod pallet { /// /// Parameters: /// - `id`: The id of the property that should be removed. - #[pallet::call_index(11)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::call_index(12)] + #[pallet::weight(::WeightInfo::remove_property())] pub fn remove_property(origin: OriginFor, id: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - let mut properties = TestProperties::::take(); + let mut properties = GameProperties::::take(); properties.retain(|property| property.id != id); - TestProperties::::put(properties); - TestPrices::::take(id); - Ok(()) - } - } - - impl Pallet { - /// Get the account id of the pallet - pub fn account_id() -> AccountIdOf { - ::PalletId::get().into_account_truncating() - } - - /// checks if the signer has enough points to start a game. - fn check_enough_points( - signer: AccountIdOf, - game_type: DifficultyLevel, - ) -> DispatchResult { - if game_type == DifficultyLevel::Pro { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, - Error::::NotEnoughPoints - ); - } else if game_type == DifficultyLevel::Player { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, - Error::::NotEnoughPoints - ); - } else { - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, - Error::::TooManyPractise - ); - } + GameProperties::::put(properties); Ok(()) } - /// checks the answer and distributes the rewards accordingly. - fn check_result(difference: u16, game_id: u32) -> DispatchResult { - let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; - if game_info.difficulty == DifficultyLevel::Pro { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else if game_info.difficulty == DifficultyLevel::Player { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - user.practise_rounds = - user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } - let user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - Self::update_leaderboard(game_info.player, user.points)?; - Ok(()) - } - - fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { - let mut leaderboard = Self::leaderboard(); - let leaderboard_size = leaderboard.len(); - - if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { - *user_points = new_points; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - return Ok(()); - } - if new_points > 0 && - (leaderboard_size < 10 || - new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) - { - if leaderboard.len() >= 10 { - leaderboard.pop(); - } - leaderboard - .try_push((user_id, new_points)) - .map_err(|_| Error::::InvalidIndex)?; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - } - Ok(()) - } - - fn swap_user_points( - nft_holder: AccountIdOf, - collection_id_add: CollectionId, - collection_id_sub: CollectionId, - ) -> DispatchResult { - let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; - let color_add = - Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; - let color_sub = - Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color_add.clone())?; - let points = user.calculate_points(color_add); - user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; - user.sub_nft_color(color_sub.clone())?; - let points = user.subtracting_calculate_points(color_sub); - user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(nft_holder.clone(), user.clone()); - Self::update_leaderboard(nft_holder.clone(), user.points)?; - if user.has_four_of_all_colors() { - Self::end_game(nft_holder)?; - } + /// Adds an account to the admins. + /// + /// The origin must be the sudo. + /// + /// Parameters: + /// - `new_admin`: The address of the new account added to the list. + /// + /// Emits `NewAdminAdded` event when succesfful + #[pallet::call_index(13)] + #[pallet::weight(::WeightInfo::add_to_admins())] + pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + ensure!(!Admins::::get().contains(&new_admin), Error::::AccountAlreadyAdmin,); + Admins::::try_append(new_admin.clone()).map_err(|_| Error::::TooManyAdmins)?; + Self::deposit_event(Event::::NewAdminAdded { new_admin }); Ok(()) } - /// Handles the case if the player did not answer on time. - fn no_answer_result(game_info: GameData) -> DispatchResult { - if game_info.difficulty == DifficultyLevel::Pro { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } else if game_info.difficulty == DifficultyLevel::Player { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } else { - } + /// Removes an account from the admins. + /// + /// The origin must be the sudo. + /// + /// Parameters: + /// - `admin`: The address of the admin removed from the admins. + /// + /// Emits `UserRemoved` event when succesfful + #[pallet::call_index(14)] + #[pallet::weight(::WeightInfo::remove_from_admins())] + pub fn remove_from_admins(origin: OriginFor, admin: AccountIdOf) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + ensure!(Admins::::get().contains(&admin), Error::::NotAdmin); + let mut admins = Admins::::get(); + let index = admins.iter().position(|x| *x == admin).ok_or(Error::::InvalidIndex)?; + admins.remove(index); + Admins::::put(admins); + Self::deposit_event(Event::::AdminRemoved { admin }); Ok(()) } - fn end_game(winner: AccountIdOf) -> DispatchResult { - RoundActive::::put(false); - RoundChampion::::insert(Self::current_round(), winner); + /// Lets the player request token to play. + /// + /// The origin must be Signed and the sender must have sufficient funds free. + /// + /// Emits `TokenReceived` event when succesfful. + #[pallet::call_index(15)] + #[pallet::weight(::WeightInfo::request_token())] + pub fn request_token(origin: OriginFor) -> DispatchResult { + let signer = ensure_signed(origin)?; + let current_block_number = >::block_number(); + let mut user = Users::::get(signer.clone()).ok_or(Error::::UserNotRegistered)?; + ensure!(user.next_token_request < current_block_number, Error::::CantRequestToken); + let next_request = + current_block_number.saturating_add(::RequestLimit::get()); + user.next_token_request = next_request; + ::Currency::make_free_balance_be( + &signer, + 10u32.try_into().map_err(|_| Error::::ConversionError)?, + ); + Users::::insert(signer.clone(), user); + Self::deposit_event(Event::::TokenReceived { player: signer }); Ok(()) } - - /// Set the default collection configuration for creating a collection. - fn default_collection_config() -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - Self::collection_config_from_disabled_settings( - CollectionSetting::DepositRequired.into(), - ) - } - - fn collection_config_from_disabled_settings( - settings: BitFlags, - ) -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - CollectionConfig { - settings: CollectionSettings::from_disabled(settings), - max_supply: None, - mint_settings: MintSettings::default(), - } - } - - /// Set the default item configuration for minting a nft. - fn default_item_config() -> ItemConfig { - ItemConfig { settings: ItemSettings::all_enabled() } - } } } diff --git a/pallets/game/src/mock.rs b/pallets/game/src/mock.rs index b06cfe7..265fe33 100644 --- a/pallets/game/src/mock.rs +++ b/pallets/game/src/mock.rs @@ -131,11 +131,14 @@ parameter_types! { pub const GamePalletId: PalletId = PalletId(*b"py/rlxdl"); pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; + pub const MaxAdmin: u32 = 10; + pub const RequestLimits: BlockNumber = 180; } /// Configure the pallet-game in pallets/game. impl pallet_game::Config for Test { type RuntimeEvent = RuntimeEvent; + type Currency = Balances; type WeightInfo = pallet_game::weights::SubstrateWeight; type GameOrigin = EnsureRoot; type CollectionId = u32; @@ -146,6 +149,8 @@ impl pallet_game::Config for Test { type GameRandomness = RandomnessCollectiveFlip; type StringLimit = ConstU32<5000>; type LeaderboardLimit = LeaderLimit; + type MaxAdmins = MaxAdmin; + type RequestLimit = RequestLimits; } // Build genesis storage according to the mock runtime. @@ -153,13 +158,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut test = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { - balances: vec![ - ([0; 32].into(), 1_000_000), - ([1; 32].into(), 1_000_000), - ([2; 32].into(), 1_000_000), - ([3; 32].into(), 1_000_000), - (GameModule::account_id(), 1_000_000), - ], + balances: vec![(GameModule::account_id(), 1_000_000)], } .assimilate_storage(&mut test) .unwrap(); diff --git a/pallets/game/src/offchain_function.rs b/pallets/game/src/offchain_function.rs deleted file mode 100644 index 705d788..0000000 --- a/pallets/game/src/offchain_function.rs +++ /dev/null @@ -1,399 +0,0 @@ -use crate::*; -use frame_support::pallet_prelude::*; - -impl Pallet { - /// Fetch current price and return the result in cents. - pub fn fetch_property() -> Result, http::Error> { - // We want to keep the offchain worker execution time reasonable, so we set a hard-coded - // deadline to 2s to complete the external call. - // You can also wait indefinitely for the response, however you may still get a timeout - // coming from the host machine. - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(2_000)); - // Initiate an external HTTP GET request. - // This is using high-level wrappers from `sp_runtime`, for the low-level calls that - // you can find in `sp_io`. The API is trying to be similar to `request`, but - // since we are running in a custom WASM execution environment we can't simply - // import the library here. - - let request = http::Request::get( - "https://ipfs.io/ipfs/QmZ3Dn5B2UMuv9PFr1Ba3NGSKft2rwToBKCPaCTCmSab4k?filename=testing_data.json" - ); - - // We set the deadline for sending of the request, note that awaiting response can - // have a separate deadline. Next we send the request, before that it's also possible - // to alter request headers or stream body content in case of non-GET requests. - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - - // The request is already being processed by the host, we are free to do anything - // else in the worker (we can send multiple concurrent requests too). - // At some point however we probably want to check the response though, - // so we can block current thread and wait for it to finish. - // Note that since the request is being driven by the host, we don't have to wait - // for the request to have it complete, we will just not read the response. - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - // Let's check the status code before we proceed to reading the response. - if response.code != 200 { - log::warn!("Unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - - // Next we want to fully read the response body and collect it to a vector of bytes. - // Note that the return object allows you to read the body in chunks as well - // with a way to control the deadline. - let body = response.body().collect::>(); - - // Create a str slice from the body. - let body_str = sp_std::str::from_utf8(&body).map_err(|_| { - log::warn!("No UTF8 body"); - http::Error::Unknown - })?; - - let property = match Self::parse_property(body_str) { - Some(property) => Ok(property), - None => { - log::warn!("Unable to extract price from the response: {:?}", body_str); - Err(http::Error::Unknown) - }, - }?; - - // log::warn!("Got property: {:?} cents", price); - - Ok(property) - } - - /// Parse the price from the given JSON string using `lite-json`. - /// - /// Returns `None` when parsing failed or `Some(price in cents)` when parsing is successful. - pub fn parse_property(property_str: &str) -> Option> { - let val = lite_json::parse_json(property_str); - let id = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'id' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("id".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - let val = lite_json::parse_json(property_str); - let bedrooms = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'bedrooms' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("bedrooms".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - let val = lite_json::parse_json(property_str); - let bathrooms = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'bathrooms' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("bathrooms".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let summary = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'summary' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("summary".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let property_sub_type = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'propertySubType' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("propertySubType".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let first_visible_date = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'firstVisibleDate' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("firstVisibleDate".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let display_size = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'displaySize' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("displaySize".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let display_address = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'displayAddress' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("displayAddress".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let property_images = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'propertyImages' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("propertyImages".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let id = id.integer as u32; - let bedrooms = bedrooms.integer as u32; - let bathrooms = bathrooms.integer as u32; - let summary: &str = &summary.iter().collect::(); - let property_sub_type: &str = &property_sub_type.iter().collect::(); - let first_visible_date: &str = &first_visible_date.iter().collect::(); - let display_size: &str = &display_size.iter().collect::(); - let display_address: &str = &display_address.iter().collect::(); - let property_images: &str = &property_images.iter().collect::(); - - let property = PropertyInfoData { - id, - bedrooms, - bathrooms, - summary: summary.as_bytes().to_vec().try_into().unwrap(), - property_sub_type: property_sub_type.as_bytes().to_vec().try_into().unwrap(), - first_visible_date: first_visible_date.as_bytes().to_vec().try_into().unwrap(), - display_size: display_size.as_bytes().to_vec().try_into().unwrap(), - display_address: display_address.as_bytes().to_vec().try_into().unwrap(), - property_images1: property_images.as_bytes().to_vec().try_into().unwrap(), - }; - - Some(property) - - // Some(price.integer as u32 * 100 + (price.fraction / 10_u64.pow(exp)) as u32) - } - - /* pub fn fetch_property_and_send_signed() -> DispatchResult { - let signer = Signer::::all_accounts(); - if !signer.can_sign() { - return Err( - "No local accounts available. Consider adding one via `author_insertKey` RPC.", - ) - } - // Make an external HTTP request to fetch the current price. - // Note this call will block until response is received. - let property = Self::fetch_property().map_err(|_| "Failed to fetch price")?; - - // Using `send_signed_transaction` associated type we create and submit a transaction - // representing the call, we've just created. - // Submit signed will return a vector of results for all accounts that were found in the - // local keystore with expected `KEY_TYPE`. - let results = signer.send_signed_transaction(|_account| { - // Received price is wrapped into a call to `submit_price` public function of this - // pallet. This means that the transaction, when executed, will simply call that - // function passing `price` as an argument. - //Call::submit_price { property: property.clone() } - }); - - for (acc, res) in &results { - match res { - Ok(()) => log::info!("[{:?}] Submitted price of {:?} cents", acc.id, property), - Err(e) => log::error!("[{:?}] Failed to submit transaction: {:?}", acc.id, e), - } - } - - Ok(()) - } */ -} diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index a65aa02..d85acac 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -2,59 +2,31 @@ use crate::*; use frame_support::pallet_prelude::*; impl Pallet { - pub(crate) fn create_test_properties() -> DispatchResult { + pub(crate) fn create_game_properties() -> DispatchResult { let new_property = PropertyInfoData { id: 147229391, - bedrooms: 2, - bathrooms: 1, - summary: "Superb 2 double bedroom ground floor purpose-built apartment with sole use of garden. Directly opposite Hackney Downs Park, within walking distance of Clapton, Hackney Downs & Rectory Rd Stations. Benefitting from; 2 double bedrooms, fitted kitchen/diner, modern shower/WC, separate lounge with di...".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "St Peters Street, Islington".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/56k/55489/146480642/55489_2291824_IMG_00_0000_max_476x317.jpeg".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 220000); + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + }; + GameProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 146480642, - bedrooms: 2, - bathrooms: 1, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 650000); + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + }; + GameProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, - bedrooms: 3, - bathrooms: 2, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 525000); + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + }; + GameProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, - bedrooms: 3, - bathrooms: 2, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 525000); + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + }; + GameProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; Ok(()) - } + } } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index cc5034a..3cd1415 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -1,16 +1,37 @@ -use crate::{mock::*, Error}; -use frame_support::{assert_noop, assert_ok}; +use crate::{mock::*, Error, Event, PropertyInfoData}; +use frame_support::{ + assert_noop, assert_ok, + traits::{OnFinalize, OnInitialize}, +}; use sp_runtime::{traits::BadOrigin, DispatchError, ModuleError}; -use crate::PropertyInfoData; fn practise_round(player: AccountId, game_id: u32) { assert_ok!(GameModule::play_game( RuntimeOrigin::signed(player.clone()), crate::DifficultyLevel::Practice, )); - assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed(player), 220000, game_id)); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed(player.clone()), 220000, game_id)); + System::assert_last_event(Event::AnswerSubmitted { player, game_id, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + game_id, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); +} + +fn run_to_block(n: u64) { + while System::block_number() < n { + GameModule::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + GameModule::on_initialize(System::block_number()); + } } + #[test] fn setup_game_works() { new_test_ext().execute_with(|| { @@ -27,14 +48,73 @@ fn setup_game_fails() { }); } +#[test] +fn add_to_admins_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + }); +} + +#[test] +fn add_to_admins_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_noop!( + GameModule::add_to_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), + BadOrigin + ); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_noop!( + GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into()), + Error::::AccountAlreadyAdmin + ); + }); +} + +#[test] +fn remove_admins_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_ok!(GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 0); + }); +} + +#[test] +fn remove_admins_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_noop!( + GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into()), + Error::::NotAdmin + ); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_noop!( + GameModule::remove_from_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), + BadOrigin + ); + }); +} + #[test] fn play_game_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_eq!(Balances::free_balance(&([0; 32].into())), 10); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -49,7 +129,7 @@ fn play_game_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_noop!( GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -64,7 +144,11 @@ fn play_game_fails() { fn play_game_fails_no_active_round() { new_test_ext().execute_with(|| { System::set_block_number(1); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); assert_noop!( GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -80,8 +164,12 @@ fn play_game_fails_not_enough_points() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -100,14 +188,29 @@ fn submit_answer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 223_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 223_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + System::assert_last_event(Event::ResultChecked { game_id: 1, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 25, won: true }.into()); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 80); assert_ok!(GameModule::play_game( @@ -115,10 +218,82 @@ fn submit_answer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 2)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 2, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + System::assert_last_event(Event::ResultChecked { game_id: 2, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 100, won: true }.into()); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 180); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 1); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 0, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 0 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 0, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); + }); +} + +#[test] +fn game_expires_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + practise_round([0; 32].into(), 0); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + run_to_block(20); + System::assert_last_event(Event::NoAnswer { game_id: 1, points: 25 }.into()); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 30); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 2)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 2, + 223_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 55); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Pro, + )); + run_to_block(30); + System::assert_last_event(Event::NoAnswer { game_id: 3, points: 50 }.into()); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 5); }); } @@ -127,10 +302,20 @@ fn leaderboard_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [2; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [2; 32].into() + )); practise_round([0; 32].into(), 0); practise_round([1; 32].into(), 1); practise_round([2; 32].into(), 2); @@ -139,21 +324,57 @@ fn leaderboard_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 230_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 230_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 230_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + System::assert_last_event(Event::ResultChecked { game_id: 3, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 15, won: true }.into()); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([1; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 225_000, 4)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 4, guess: 225_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 225_000, + 4, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([2; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([2; 32].into()), 220_000, 5)); + System::assert_last_event( + Event::AnswerSubmitted { player: [2; 32].into(), game_id: 5, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 5, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([2; 32].into()).unwrap().points, 155); assert_eq!(GameModule::users::([1; 32].into()).unwrap().points, 80); + assert_eq!(GameModule::users::([1; 32].into()).unwrap().wins, 1); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 70); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 1); assert_eq!(GameModule::leaderboard().len(), 3); + assert_eq!(GameModule::leaderboard()[0], ([2; 32].into(), 155)); + assert_eq!(GameModule::leaderboard()[1], ([1; 32].into(), 80)); + assert_eq!(GameModule::leaderboard()[2], ([0; 32].into(), 70)); }); } @@ -162,7 +383,7 @@ fn submit_answer_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_noop!( GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 223_000, 0), Error::::NoActiveGame @@ -175,15 +396,29 @@ fn transfer_of_nft_does_not_work() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); assert_noop!( @@ -207,14 +442,28 @@ fn list_nft_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -229,14 +478,28 @@ fn list_nft_doesnt_work() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -252,14 +515,28 @@ fn delist_nft_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -288,14 +565,28 @@ fn delist_nft_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -314,15 +605,32 @@ fn make_offer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -332,6 +640,16 @@ fn make_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -346,9 +664,13 @@ fn make_offer_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -367,17 +689,35 @@ fn withdraw_offer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 1); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); practise_round([1; 32].into(), 2); assert_ok!(GameModule::play_game( @@ -385,6 +725,16 @@ fn withdraw_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -401,15 +751,32 @@ fn withdraw_offer_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -419,6 +786,16 @@ fn withdraw_offer_fails() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -441,15 +818,32 @@ fn handle_offer_accept_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -459,17 +853,47 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 4)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 4, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 4, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 275); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 5)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 5, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 5, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 495); assert_eq!(GameModule::users::([1; 32].into()).unwrap().nfts.xorange, 1); @@ -518,6 +942,18 @@ fn handle_offer_accept_works() { message: Some("ItemLocked") }) ); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + System::assert_last_event( + Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9 }.into(), + ); + run_to_block(20); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 470); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 3); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().losses, 1); }); } @@ -526,15 +962,32 @@ fn handle_offer_reject_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -544,6 +997,16 @@ fn handle_offer_reject_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -579,15 +1042,32 @@ fn handle_offer_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -597,6 +1077,16 @@ fn handle_offer_doesnt_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -617,8 +1107,12 @@ fn play_multiple_rounds_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); for x in 1..=20 { assert_ok!(GameModule::play_game( @@ -630,6 +1124,17 @@ fn play_multiple_rounds_works() { 217_000, x )); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: x, guess: 217_000 } + .into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 217_000, + x, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); } assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -646,18 +1151,11 @@ fn add_property_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); let new_property = PropertyInfoData { - id: 146480642, - bedrooms: 2, - bathrooms: 1, - summary: "Spacious apartment in the heart of New York City with a balcony and garden.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Apartment".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-05-06T12:00:00Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "1000 sq ft".as_bytes().to_vec().try_into().unwrap(), - display_address: "New York City, NY".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://example.com/image1.jpg".as_bytes().to_vec().try_into().unwrap(), + id: 147031382, + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), }; - assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property, 122565)); - assert_eq!(GameModule::test_properties().len(), 5); + assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); + assert_eq!(GameModule::game_properties().len(), 5); }); } @@ -667,6 +1165,92 @@ fn remove_property_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_ok!(GameModule::remove_property(RuntimeOrigin::root(), 146480642)); - assert_eq!(GameModule::test_properties().len(), 3); + assert_eq!(GameModule::game_properties().len(), 3); + }); +} + +#[test] +fn request_token_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + System::set_block_number(100802); + assert_ok!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into()))); + assert_eq!(Balances::free_balance(&([0; 32].into())), 10); + }); +} + +#[test] +fn request_token_doesnt_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_noop!( + GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), + Error::::UserNotRegistered + ); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_noop!( + GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), + Error::::CantRequestToken + ); + }); +} + +#[test] +fn check_result_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + practise_round([0; 32].into(), 0); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 0, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoActiveGame + ); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoActiveGame + ); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoGuess + ); }); } diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs new file mode 100644 index 0000000..5a514ff --- /dev/null +++ b/pallets/game/src/types.rs @@ -0,0 +1,314 @@ +use crate::*; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +/// Difficulty level of game enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum DifficultyLevel { + Practice, + Player, + Pro, +} + +/// Offer enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum Offer { + Accept, + Reject, +} + +/// Nft color enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum NftColor { + Xorange, + Xpink, + Xblue, + Xcyan, + Xcoral, + Xpurple, + Xleafgreen, + Xgreen, +} + +impl NftColor { + pub fn from_index(index: usize) -> Option { + match index { + 0 => Some(NftColor::Xorange), + 1 => Some(NftColor::Xpink), + 2 => Some(NftColor::Xblue), + 3 => Some(NftColor::Xcyan), + 4 => Some(NftColor::Xcoral), + 5 => Some(NftColor::Xpurple), + 6 => Some(NftColor::Xleafgreen), + 7 => Some(NftColor::Xgreen), + _ => None, + } + } +} + +/// AccountId storage. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub struct PalletIdStorage { + pallet_id: AccountIdOf, +} + +/// Game Data. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct GameData { + pub difficulty: DifficultyLevel, + pub player: AccountIdOf, + pub property: PropertyInfoData, + pub guess: Option, +} + +/// Listing infos of a NFT. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct ListingInfo { + pub owner: AccountIdOf, + pub collection_id: CollectionId, + pub item_id: ItemId, +} + +/// Offer infos of a listing. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct OfferInfo { + pub owner: AccountIdOf, + pub listing_id: u32, + pub collection_id: CollectionId, + pub item_id: ItemId, +} + +/// Struct to store the property data for a game. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Encode, + Decode, + Clone, + PartialEq, + Eq, + MaxEncodedLen, + frame_support::pallet_prelude::RuntimeDebugNoBound, + TypeInfo, +)] +#[scale_info(skip_type_params(T))] +pub struct PropertyInfoData { + pub id: u32, + pub data: BoundedVec::StringLimit>, +} + +/// Struct for the user datas. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct User { + pub points: u32, + pub wins: u32, + pub losses: u32, + pub practise_rounds: u8, + pub last_played_round: u32, + pub next_token_request: BlockNumberFor, + pub nfts: CollectedColors, +} + +impl User { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.add_nft_color(color)?; + Ok(()) + } + + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.sub_nft_color(color)?; + Ok(()) + } + + pub fn has_four_of_all_colors(&self) -> bool { + self.nfts.has_four_of_all_colors() + } + + pub fn calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 1 => 100, + NftColor::Xorange if self.nfts.xorange == 2 => 120, + NftColor::Xorange if self.nfts.xorange == 3 => 220, + NftColor::Xorange if self.nfts.xorange == 4 => 340, + NftColor::Xpink if self.nfts.xpink == 1 => 100, + NftColor::Xpink if self.nfts.xpink == 2 => 120, + NftColor::Xpink if self.nfts.xpink == 3 => 220, + NftColor::Xpink if self.nfts.xpink == 4 => 340, + NftColor::Xblue if self.nfts.xblue == 1 => 100, + NftColor::Xblue if self.nfts.xblue == 2 => 120, + NftColor::Xblue if self.nfts.xblue == 3 => 220, + NftColor::Xblue if self.nfts.xblue == 4 => 340, + NftColor::Xcyan if self.nfts.xcyan == 1 => 100, + NftColor::Xcyan if self.nfts.xcyan == 2 => 120, + NftColor::Xcyan if self.nfts.xcyan == 3 => 220, + NftColor::Xcyan if self.nfts.xcyan == 4 => 340, + NftColor::Xcoral if self.nfts.xcoral == 1 => 100, + NftColor::Xcoral if self.nfts.xcoral == 2 => 120, + NftColor::Xcoral if self.nfts.xcoral == 3 => 220, + NftColor::Xcoral if self.nfts.xcoral == 4 => 340, + NftColor::Xpurple if self.nfts.xpurple == 1 => 100, + NftColor::Xpurple if self.nfts.xpurple == 2 => 120, + NftColor::Xpurple if self.nfts.xpurple == 3 => 220, + NftColor::Xpurple if self.nfts.xpurple == 4 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, + NftColor::Xgreen if self.nfts.xgreen == 1 => 100, + NftColor::Xgreen if self.nfts.xgreen == 2 => 120, + NftColor::Xgreen if self.nfts.xgreen == 3 => 220, + NftColor::Xgreen if self.nfts.xgreen == 4 => 340, + _ => 0, + } + } + + pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 0 => 100, + NftColor::Xorange if self.nfts.xorange == 1 => 120, + NftColor::Xorange if self.nfts.xorange == 2 => 220, + NftColor::Xorange if self.nfts.xorange == 3 => 340, + NftColor::Xpink if self.nfts.xpink == 0 => 100, + NftColor::Xpink if self.nfts.xpink == 1 => 120, + NftColor::Xpink if self.nfts.xpink == 2 => 220, + NftColor::Xpink if self.nfts.xpink == 3 => 340, + NftColor::Xblue if self.nfts.xblue == 0 => 100, + NftColor::Xblue if self.nfts.xblue == 1 => 120, + NftColor::Xblue if self.nfts.xblue == 2 => 220, + NftColor::Xblue if self.nfts.xblue == 3 => 340, + NftColor::Xcyan if self.nfts.xcyan == 0 => 100, + NftColor::Xcyan if self.nfts.xcyan == 1 => 120, + NftColor::Xcyan if self.nfts.xcyan == 2 => 220, + NftColor::Xcyan if self.nfts.xcyan == 3 => 340, + NftColor::Xcoral if self.nfts.xcoral == 0 => 100, + NftColor::Xcoral if self.nfts.xcoral == 1 => 120, + NftColor::Xcoral if self.nfts.xcoral == 2 => 220, + NftColor::Xcoral if self.nfts.xcoral == 3 => 340, + NftColor::Xpurple if self.nfts.xpurple == 0 => 100, + NftColor::Xpurple if self.nfts.xpurple == 1 => 120, + NftColor::Xpurple if self.nfts.xpurple == 2 => 220, + NftColor::Xpurple if self.nfts.xpurple == 3 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, + NftColor::Xgreen if self.nfts.xgreen == 0 => 100, + NftColor::Xgreen if self.nfts.xgreen == 1 => 120, + NftColor::Xgreen if self.nfts.xgreen == 2 => 220, + NftColor::Xgreen if self.nfts.xgreen == 3 => 340, + _ => 0, + } + } +} + +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default)] +#[scale_info(skip_type_params(T))] +pub struct CollectedColors { + pub xorange: u32, + pub xpink: u32, + pub xblue: u32, + pub xcyan: u32, + pub xcoral: u32, + pub xpurple: u32, + pub xleafgreen: u32, + pub xgreen: u32, +} + +impl CollectedColors { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + } + } + + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + } + } + + pub fn has_four_of_all_colors(&self) -> bool { + self.xorange >= 4 && + self.xpink >= 4 && + self.xblue >= 4 && + self.xcyan >= 4 && + self.xcoral >= 4 && + self.xpurple >= 4 && + self.xleafgreen >= 4 && + self.xgreen >= 4 + } +} diff --git a/pallets/game/src/weights.rs b/pallets/game/src/weights.rs index 2f31c37..ad54e6d 100644 --- a/pallets/game/src/weights.rs +++ b/pallets/game/src/weights.rs @@ -2,9 +2,9 @@ //! Autogenerated weights for `pallet_game` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-05-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `LAPTOP-DFFNONK6`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` +//! HOSTNAME: `recrafter-Legion-5-16IRX9`, CPU: `Intel(R) Core(TM) i7-14650HX` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -39,10 +39,16 @@ pub trait WeightInfo { fn give_points() -> Weight; fn play_game() -> Weight; fn submit_answer() -> Weight; + fn check_result() -> Weight; fn list_nft() -> Weight; fn delist_nft() -> Weight; fn make_offer() -> Weight; fn handle_offer() -> Weight; + fn add_property() -> Weight; + fn remove_property() -> Weight; + fn add_to_admins() -> Weight; + fn remove_from_admins() -> Weight; + fn request_token() -> Weight; } /// Weight functions for `pallet_game`. @@ -54,10 +60,14 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::Collection` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestProperties` (r:1 w:1) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(2002002), added: 2002497, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:0 w:4) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:1) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::RoundActive` (r:0 w:1) + /// Proof: `GameModule::RoundActive` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:0 w:8) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:0 w:8) /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionConfigOf` (r:0 w:8) @@ -67,75 +77,114 @@ impl WeightInfo for SubstrateWeight { fn setup_game() -> Weight { // Proof Size summary in bytes: // Measured: `166` - // Estimated: `2003487` - // Minimum execution time: 282_362_000 picoseconds. - Weight::from_parts(348_148_000, 0) - .saturating_add(Weight::from_parts(0, 2003487)) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(39)) + // Estimated: `102287` + // Minimum execution time: 203_338_000 picoseconds. + Weight::from_parts(207_008_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(45)) } - /// Storage: `GameModule::Users` (r:0 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Admins` (r:1 w:0) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn register_user() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 10_548_000 picoseconds. - Weight::from_parts(12_842_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `159` + // Estimated: `3593` + // Minimum execution time: 23_973_000 picoseconds. + Weight::from_parts(25_287_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `GameModule::Users` (r:1 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) fn give_points() -> Weight { // Proof Size summary in bytes: - // Measured: `159` - // Estimated: `3526` - // Minimum execution time: 22_795_000 picoseconds. - Weight::from_parts(35_614_000, 0) - .saturating_add(Weight::from_parts(0, 3526)) + // Measured: `224` + // Estimated: `3566` + // Minimum execution time: 13_927_000 picoseconds. + Weight::from_parts(14_546_000, 0) + .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `GameModule::Users` (r:1 w:0) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::RoundActive` (r:1 w:0) + /// Proof: `GameModule::RoundActive` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:0) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `GameModule::GameId` (r:1 w:1) /// Proof: `GameModule::GameId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `GameModule::GamesExpiring` (r:1 w:1) /// Proof: `GameModule::GamesExpiring` (`max_values`: None, `max_size`: Some(822), added: 3297, mode: `MaxEncodedLen`) /// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0) /// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestProperties` (r:1 w:0) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(2002002), added: 2002497, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) /// Storage: `GameModule::GameInfo` (r:0 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(20073), added: 22548, mode: `MaxEncodedLen`) - /// Storage: `GameModule::StoredHash` (r:0 w:1) - /// Proof: `GameModule::StoredHash` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) fn play_game() -> Weight { // Proof Size summary in bytes: - // Measured: `596` - // Estimated: `2003487` - // Minimum execution time: 38_152_000 picoseconds. - Weight::from_parts(53_722_000, 0) - .saturating_add(Weight::from_parts(0, 2003487)) - .saturating_add(T::DbWeight::get().reads(5)) + // Measured: `616` + // Estimated: `102287` + // Minimum execution time: 33_772_000 picoseconds. + Weight::from_parts(35_079_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) + .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `GameModule::GameInfo` (r:1 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(20073), added: 22548, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:1 w:0) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) - /// Storage: `GameModule::Users` (r:1 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) fn submit_answer() -> Weight { // Proof Size summary in bytes: - // Measured: `489` - // Estimated: `23538` - // Minimum execution time: 32_358_000 picoseconds. - Weight::from_parts(44_190_000, 0) - .saturating_add(Weight::from_parts(0, 23538)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `359` + // Estimated: `4531` + // Minimum execution time: 14_305_000 picoseconds. + Weight::from_parts(15_213_000, 0) + .saturating_add(Weight::from_parts(0, 4531)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::GameInfo` (r:1 w:1) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) + /// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0) + /// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:0) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::NextColorId` (r:1 w:1) + /// Proof: `GameModule::NextColorId` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Nfts::Item` (r:1 w:1) + /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) + /// Storage: `Nfts::Collection` (r:1 w:1) + /// Proof: `Nfts::Collection` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + /// Storage: `Nfts::CollectionConfigOf` (r:1 w:0) + /// Proof: `Nfts::CollectionConfigOf` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `Nfts::ItemConfigOf` (r:1 w:1) + /// Proof: `Nfts::ItemConfigOf` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Nfts::CollectionRoleOf` (r:1 w:0) + /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:1 w:0) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Leaderboard` (r:1 w:1) + /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) + /// Storage: `Nfts::Account` (r:0 w:1) + /// Proof: `Nfts::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + fn check_result() -> Weight { + // Proof Size summary in bytes: + // Measured: `1697` + // Estimated: `4531` + // Minimum execution time: 83_106_000 picoseconds. + Weight::from_parts(85_634_000, 0) + .saturating_add(Weight::from_parts(0, 4531)) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Nfts::Item` (r:1 w:1) /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) @@ -161,10 +210,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn list_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1290` + // Measured: `1336` // Estimated: `4326` - // Minimum execution time: 84_211_000 picoseconds. - Weight::from_parts(106_018_000, 0) + // Minimum execution time: 74_512_000 picoseconds. + Weight::from_parts(77_636_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(8)) @@ -191,10 +240,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn delist_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1396` + // Measured: `1433` // Estimated: `4326` - // Minimum execution time: 75_643_000 picoseconds. - Weight::from_parts(87_909_000, 0) + // Minimum execution time: 69_764_000 picoseconds. + Weight::from_parts(71_311_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(7)) @@ -225,10 +274,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn make_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `1968` + // Measured: `1507` // Estimated: `4326` - // Minimum execution time: 87_841_000 picoseconds. - Weight::from_parts(97_331_000, 0) + // Minimum execution time: 77_751_000 picoseconds. + Weight::from_parts(82_016_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(8)) @@ -249,6 +298,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:1 w:0) /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:2 w:2) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:1 w:0) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Leaderboard` (r:1 w:1) + /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) /// Storage: `Nfts::Account` (r:0 w:4) /// Proof: `Nfts::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) /// Storage: `Nfts::ItemPriceOf` (r:0 w:2) @@ -257,12 +312,72 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn handle_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `2152` + // Measured: `2135` // Estimated: `7662` - // Minimum execution time: 127_517_000 picoseconds. - Weight::from_parts(155_423_000, 0) + // Minimum execution time: 144_786_000 picoseconds. + Weight::from_parts(151_331_000, 0) .saturating_add(Weight::from_parts(0, 7662)) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(14)) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(17)) + } + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) + fn add_property() -> Weight { + // Proof Size summary in bytes: + // Measured: `318` + // Estimated: `102287` + // Minimum execution time: 7_812_000 picoseconds. + Weight::from_parts(8_412_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) + fn remove_property() -> Weight { + // Proof Size summary in bytes: + // Measured: `318` + // Estimated: `102287` + // Minimum execution time: 8_975_000 picoseconds. + Weight::from_parts(9_389_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::Admins` (r:1 w:1) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + fn add_to_admins() -> Weight { + // Proof Size summary in bytes: + // Measured: `118` + // Estimated: `1806` + // Minimum execution time: 10_116_000 picoseconds. + Weight::from_parts(10_550_000, 0) + .saturating_add(Weight::from_parts(0, 1806)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::Admins` (r:1 w:1) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + fn remove_from_admins() -> Weight { + // Proof Size summary in bytes: + // Measured: `159` + // Estimated: `1806` + // Minimum execution time: 11_207_000 picoseconds. + Weight::from_parts(11_767_000, 0) + .saturating_add(Weight::from_parts(0, 1806)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + fn request_token() -> Weight { + // Proof Size summary in bytes: + // Measured: `224` + // Estimated: `3566` + // Minimum execution time: 33_530_000 picoseconds. + Weight::from_parts(37_591_000, 0) + .saturating_add(Weight::from_parts(0, 3566)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d61cfc6..5942b5b 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -21,51 +21,52 @@ scale-info = { version = "2.5.0", default-features = false, features = [ ] } log = { version = '0.4.14', default-features = false } -sp-genesis-builder = { version = "0.1.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sp-genesis-builder = { version = "0.1.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } -pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } +pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } serde_json = { version = "1.0.111", default-features = false, features = [ "alloc", ] } -pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -node-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } # Used for the node template's RPCs -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # Used for runtime benchmarking -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } +frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } # Local Dependencies pallet-game = { version = "4.0.0-dev", default-features = false, path = "../pallets/game" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } +substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } [features] default = ["std"] @@ -107,6 +108,7 @@ std = [ "pallet-nfts/std", "node-primitives/std", "pallet-insecure-randomness-collective-flip/std", + "pallet-skip-feeless-payment/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -120,6 +122,7 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", + "pallet-skip-feeless-payment/runtime-benchmarks", ] try-runtime = [ "frame-try-runtime/try-runtime", @@ -135,4 +138,5 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-nfts/try-runtime", "pallet-insecure-randomness-collective-flip/try-runtime", -] \ No newline at end of file + "pallet-skip-feeless-payment/try-runtime", +] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0718001..54c6fc0 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -264,16 +264,19 @@ impl sp_core::Get for MaxProperties { } } -// Define the parameter types using the custom struct. parameter_types! { pub const GamePalletId: PalletId = PalletId(*b"py/rlxdl"); pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; + pub const MaxAdmin: u32 = 10; + pub const RequestLimits: BlockNumber = 100800; + pub const GameStringLimit: u32 = 500; } /// Configure the pallet-game in pallets/game. impl pallet_game::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type Currency = Balances; type WeightInfo = pallet_game::weights::SubstrateWeight; type GameOrigin = EnsureRoot; type CollectionId = u32; @@ -282,8 +285,10 @@ impl pallet_game::Config for Runtime { type PalletId = GamePalletId; type MaxOngoingGames = MaxOngoingGame; type GameRandomness = RandomnessCollectiveFlip; - type StringLimit = StringLimit; + type StringLimit = GameStringLimit; type LeaderboardLimit = LeaderLimit; + type MaxAdmins = MaxAdmin; + type RequestLimit = RequestLimits; } parameter_types! { @@ -336,6 +341,10 @@ impl pallet_nfts::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} +impl pallet_skip_feeless_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + impl frame_system::offchain::CreateSignedTransaction for Runtime where RuntimeCall: From, @@ -367,7 +376,9 @@ where frame_system::CheckEra::::from(generic::Era::mortal(period, current_block)), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + pallet_skip_feeless_payment::SkipCheckIfFeeless::from( + pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + ), ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { @@ -378,7 +389,7 @@ where raw_payload.using_encoded(|payload| C::sign(payload, public))?; let address = account; let (call, extra, _) = raw_payload.deconstruct(); - Some((call, (sp_runtime::MultiAddress::Id(address), signature.into(), extra))) + Some((call, (sp_runtime::MultiAddress::Id(address), signature, extra))) } } @@ -409,6 +420,7 @@ construct_runtime!( GameModule: pallet_game, Nfts: pallet_nfts, RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, + SkipFeelessPayment: pallet_skip_feeless_payment, } ); @@ -427,7 +439,10 @@ pub type SignedExtra = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, + pallet_skip_feeless_payment::SkipCheckIfFeeless< + Runtime, + pallet_transaction_payment::ChargeTransactionPayment, + >, ); /// All migrations of the runtime, aside from the ones declared in the pallets.