diff --git a/Cargo.lock b/Cargo.lock index 706045912..e3dd77f2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,11 +161,12 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "3.0.6" +version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", + "once_cell", "windows-sys 0.59.0", ] @@ -195,7 +196,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -418,7 +419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -444,7 +445,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -561,7 +562,7 @@ checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -677,7 +678,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "synstructure 0.13.1", ] @@ -700,7 +701,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -785,7 +786,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 0.38.42", + "rustix 0.38.44", "slab", "tracing", "windows-sys 0.59.0", @@ -797,7 +798,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" dependencies = [ - "event-listener 5.3.1", + "event-listener 5.4.0", "event-listener-strategy", "pin-project-lite", ] @@ -826,9 +827,9 @@ dependencies = [ "async-task", "blocking", "cfg-if", - "event-listener 5.3.1", + "event-listener 5.4.0", "futures-lite", - "rustix 0.38.42", + "rustix 0.38.44", "tracing", ] @@ -844,7 +845,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.42", + "rustix 0.38.44", "signal-hook-registry", "slab", "windows-sys 0.59.0", @@ -858,13 +859,13 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1055,7 +1056,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1109,9 +1110,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "bitvec" @@ -1256,9 +1257,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.11.1" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "786a307d683a5bf92e6fd5fd69a7eb613751668d1d8d67d802846dfe367c62c8" +checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0" dependencies = [ "memchr", "regex-automata 0.4.9", @@ -1357,7 +1358,7 @@ checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" dependencies = [ "camino", "cargo-platform", - "semver 1.0.24", + "semver 1.0.25", "serde", "serde_json", "thiserror 1.0.69", @@ -1371,9 +1372,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.5" +version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" dependencies = [ "jobserver", "libc", @@ -1556,9 +1557,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.23" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" dependencies = [ "clap_builder", "clap_derive", @@ -1566,9 +1567,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" dependencies = [ "anstream", "anstyle", @@ -1579,23 +1580,23 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.40" +version = "4.5.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2e663e3e3bed2d32d065a8404024dad306e699a04263ec59919529f803aee9" +checksum = "33a7e468e750fa4b6be660e8b5651ad47372e8fb114030b594c2d75d48c5ffd0" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1807,6 +1808,7 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-mmr", "pallet-multisig", + "pallet-namespace", "pallet-network-membership", "pallet-network-score", "pallet-registries", @@ -1958,6 +1960,7 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-mmr", "pallet-multisig", + "pallet-namespace", "pallet-network-membership", "pallet-network-score", "pallet-preimage", @@ -2053,7 +2056,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "futures", "hex", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "kvdb", "kvdb-rocksdb", "log", @@ -2182,7 +2185,7 @@ name = "cord-node-rpc" version = "0.9.5" dependencies = [ "cord-primitives", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "mmr-rpc", "pallet-transaction-payment-rpc", "sc-chain-spec", @@ -2704,9 +2707,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" dependencies = [ "libc", ] @@ -2892,9 +2895,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" [[package]] name = "crypto-bigint" @@ -3018,7 +3021,7 @@ dependencies = [ "async-trait", "cumulus-primitives-core", "futures", - "jsonrpsee-core 0.24.7", + "jsonrpsee-core 0.24.8", "parity-scale-codec", "polkadot-overseer", "sc-client-api", @@ -3066,14 +3069,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "cxx" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d44ff199ff93242c3afe480ab588d544dd08d72e92885e152ffebc670f076ad" +checksum = "0fc894913dccfed0f84106062c284fa021c3ba70cb1d78797d6f5165d4492e45" dependencies = [ "cc", "cxxbridge-cmd", @@ -3085,47 +3088,47 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fd8f17ad454fc1e4f4ab83abffcc88a532e90350d3ffddcb73030220fcbd52" +checksum = "503b2bfb6b3e8ce7f95d865a67419451832083d3186958290cee6c53e39dfcfe" dependencies = [ "cc", "codespan-reporting", "proc-macro2", "quote", "scratch", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "cxxbridge-cmd" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4717c9c806a9e07fdcb34c84965a414ea40fafe57667187052cf1eb7f5e8a8a9" +checksum = "e0d2cb64a95b4b5a381971482235c4db2e0208302a962acdbe314db03cbbe2fb" dependencies = [ "clap", "codespan-reporting", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "cxxbridge-flags" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f6515329bf3d98f4073101c7866ff2bec4e635a13acb82e3f3753fff0bf43cb" +checksum = "5f797b0206463c9c2a68ed605ab28892cca784f1ef066050f4942e3de26ad885" [[package]] name = "cxxbridge-macro" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb93e6a7ce8ec985c02bbb758237a31598b340acbbc3c19c5a4fa6adaaac92ab" +checksum = "e79010a2093848e65a3e0f7062d3f02fb2ef27f866416dfe436fccfa73d3bb59" dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3173,7 +3176,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3195,7 +3198,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3213,15 +3216,15 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +checksum = "0e60eed09d8c01d3cee5b7d30acb059b76614c918fa0f992e0dd6eeb10daad6f" [[package]] name = "data-encoding-macro" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" +checksum = "5b16d9d0d88a5273d830dac8b78ceb217ffc9b1d5404e5597a3542515329405b" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -3229,12 +3232,12 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" +checksum = "1145d32e826a7748b69ee8fc62d3e6355ff7f1051df53141e7048162fc90481b" dependencies = [ "data-encoding", - "syn 1.0.109", + "syn 2.0.96", ] [[package]] @@ -3303,7 +3306,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3314,7 +3317,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3327,7 +3330,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3347,7 +3350,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3442,7 +3445,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3494,7 +3497,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.91", + "syn 2.0.96", "termcolor", "toml 0.8.19", "walkdir", @@ -3520,9 +3523,9 @@ checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" [[package]] name = "dyn-clonable" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4" +checksum = "a36efbb9bfd58e1723780aa04b61aba95ace6a05d9ffabfdb0b43672552f0805" dependencies = [ "dyn-clonable-impl", "dyn-clone", @@ -3530,13 +3533,13 @@ dependencies = [ [[package]] name = "dyn-clonable-impl" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5" +checksum = "7e8671d54058979a37a26f3511fbf8d198ba1aa35ffb202c42587d918d77213a" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.96", ] [[package]] @@ -3609,7 +3612,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3665,7 +3668,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3685,27 +3688,27 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "enumflags2" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d232db7f5956f3f14313dc2f87985c58bd2c695ce124c8cdd984e08e15ac133d" +checksum = "ba2f4b465f5318854c6f8dd686ede6c0a9dc67d4b1ac241cf0eb51521a309147" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" +checksum = "fc4caf64a58d7a6d65ab00639b046ff54399a39f5f2554728895ace4b297cd79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3784,9 +3787,9 @@ dependencies = [ [[package]] name = "event-listener" -version = "5.3.1" +version = "5.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae" dependencies = [ "concurrent-queue", "parking", @@ -3799,7 +3802,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2" dependencies = [ - "event-listener 5.3.1", + "event-listener 5.4.0", "pin-project-lite", ] @@ -3824,7 +3827,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3862,11 +3865,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb42427514b063d97ce21d5199f36c0c307d981434a6be32582bc79fe5bd2303" dependencies = [ "expander", - "indexmap 2.7.0", + "indexmap 2.7.1", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4155,7 +4158,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4250,7 +4253,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "futures", "indicatif", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "serde", @@ -4325,7 +4328,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0)", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4337,7 +4340,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4347,7 +4350,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4471,7 +4474,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29f9df8a11882c4e3335eb2d18a0137c505d9ca927470b0cac9c6f0ae07d28f7" dependencies = [ - "rustix 0.38.42", + "rustix 0.38.44", "windows-sys 0.48.0", ] @@ -4548,9 +4551,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" +checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532" dependencies = [ "fastrand", "futures-core", @@ -4567,7 +4570,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4715,9 +4718,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "governor" @@ -4762,7 +4765,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.7.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -4781,7 +4784,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.2.0", - "indexmap 2.7.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -5156,7 +5159,7 @@ dependencies = [ "hyper 1.5.2", "hyper-util", "log", - "rustls 0.23.20", + "rustls 0.23.21", "rustls-native-certs 0.8.1", "rustls-pki-types", "tokio", @@ -5321,7 +5324,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -5479,7 +5482,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -5514,9 +5517,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -5599,19 +5602,19 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "is-terminal" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" dependencies = [ "hermit-abi 0.4.0", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5693,9 +5696,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -5726,16 +5729,16 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5c71d8c1a731cc4227c2f698d377e7848ca12c8a48866fc5e6951c43a4db843" +checksum = "834af00800e962dee8f7bfc0f60601de215e73e78e5497d733a2919da837d3c8" dependencies = [ - "jsonrpsee-core 0.24.7", - "jsonrpsee-http-client 0.24.7", + "jsonrpsee-core 0.24.8", + "jsonrpsee-http-client 0.24.8", "jsonrpsee-proc-macros", "jsonrpsee-server", - "jsonrpsee-types 0.24.7", - "jsonrpsee-ws-client 0.24.7", + "jsonrpsee-types 0.24.8", + "jsonrpsee-ws-client 0.24.8", "tokio", "tracing", ] @@ -5772,7 +5775,7 @@ dependencies = [ "http 1.2.0", "jsonrpsee-core 0.23.2", "pin-project", - "rustls 0.23.20", + "rustls 0.23.21", "rustls-pki-types", "rustls-platform-verifier", "soketto 0.8.1", @@ -5786,16 +5789,16 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "548125b159ba1314104f5bb5f38519e03a41862786aa3925cf349aae9cdd546e" +checksum = "def0fd41e2f53118bd1620478d12305b2c75feef57ea1f93ef70568c98081b7e" dependencies = [ "base64 0.22.1", "futures-util", "http 1.2.0", - "jsonrpsee-core 0.24.7", + "jsonrpsee-core 0.24.8", "pin-project", - "rustls 0.23.20", + "rustls 0.23.21", "rustls-pki-types", "rustls-platform-verifier", "soketto 0.8.1", @@ -5854,9 +5857,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2882f6f8acb9fdaec7cefc4fd607119a9bd709831df7d7672a1d3b644628280" +checksum = "76637f6294b04e747d68e69336ef839a3493ca62b35bf488ead525f7da75c5bb" dependencies = [ "async-trait", "bytes", @@ -5865,7 +5868,7 @@ dependencies = [ "http 1.2.0", "http-body 1.0.1", "http-body-util", - "jsonrpsee-types 0.24.7", + "jsonrpsee-types 0.24.8", "parking_lot 0.12.3", "pin-project", "rand", @@ -5900,9 +5903,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3638bc4617f96675973253b3a45006933bde93c2fd8a6170b33c777cc389e5b" +checksum = "87c24e981ad17798bbca852b0738bfb7b94816ed687bd0d5da60bfa35fa0fdc3" dependencies = [ "async-trait", "base64 0.22.1", @@ -5910,9 +5913,9 @@ dependencies = [ "hyper 1.5.2", "hyper-rustls 0.27.5", "hyper-util", - "jsonrpsee-core 0.24.7", - "jsonrpsee-types 0.24.7", - "rustls 0.23.20", + "jsonrpsee-core 0.24.8", + "jsonrpsee-types 0.24.8", + "rustls 0.23.21", "rustls-platform-verifier", "serde", "serde_json", @@ -5925,22 +5928,22 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06c01ae0007548e73412c08e2285ffe5d723195bf268bce67b1b77c3bb2a14d" +checksum = "6fcae0c6c159e11541080f1f829873d8f374f81eda0abc67695a13fc8dc1a580" dependencies = [ "heck 0.5.0", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "jsonrpsee-server" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ad8ddc14be1d4290cd68046e7d1d37acd408efed6d3ca08aefcc3ad6da069c" +checksum = "66b7a3df90a1a60c3ed68e7ca63916b53e9afa928e33531e87f61a9c8e9ae87b" dependencies = [ "futures-util", "http 1.2.0", @@ -5948,8 +5951,8 @@ dependencies = [ "http-body-util", "hyper 1.5.2", "hyper-util", - "jsonrpsee-core 0.24.7", - "jsonrpsee-types 0.24.7", + "jsonrpsee-core 0.24.8", + "jsonrpsee-types 0.24.8", "pin-project", "route-recognizer", "serde", @@ -5991,9 +5994,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a178c60086f24cc35bb82f57c651d0d25d99c4742b4d335de04e97fa1f08a8a1" +checksum = "ddb81adb1a5ae9182df379e374a79e24e992334e7346af4d065ae5b2acb8d4c6" dependencies = [ "http 1.2.0", "serde", @@ -6016,14 +6019,14 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.24.7" +version = "0.24.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fe322e0896d0955a3ebdd5bf813571c53fea29edd713bc315b76620b327e86d" +checksum = "6f4f3642a292f5b76d8a16af5c88c16a0860f2ccc778104e5c848b28183d9538" dependencies = [ "http 1.2.0", - "jsonrpsee-client-transport 0.24.7", - "jsonrpsee-core 0.24.7", - "jsonrpsee-types 0.24.7", + "jsonrpsee-client-transport 0.24.8", + "jsonrpsee-core 0.24.8", + "jsonrpsee-types 0.24.8", "url", ] @@ -6470,7 +6473,7 @@ dependencies = [ "proc-macro-warning 0.4.2", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -6579,7 +6582,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "libc", "redox_syscall 0.5.8", ] @@ -6649,9 +6652,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.20" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +checksum = "df9b68e50e6e0b26f672573834882eb57759f6db9b3be2ea3c35c91188bb4eaa" dependencies = [ "cc", "pkg-config", @@ -6699,9 +6702,9 @@ checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "lioness" @@ -6736,7 +6739,7 @@ dependencies = [ "futures-timer", "hex-literal", "hickory-resolver", - "indexmap 2.7.0", + "indexmap 2.7.1", "libc", "mockall 0.13.1", "multiaddr 0.17.1", @@ -6785,9 +6788,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" [[package]] name = "lru" @@ -6809,9 +6812,9 @@ dependencies = [ [[package]] name = "lz4" -version = "1.28.0" +version = "1.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1febb2b4a79ddd1980eede06a8f7902197960aa0383ffcfdd62fe723036725" +checksum = "a20b523e860d03443e98350ceaac5e71c6ba89aea7d960769ec3ce37f4de5af4" dependencies = [ "lz4-sys", ] @@ -6844,7 +6847,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -6858,7 +6861,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -6869,7 +6872,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -6880,7 +6883,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -6932,7 +6935,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.42", + "rustix 0.38.44", ] [[package]] @@ -7005,9 +7008,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" dependencies = [ "adler2", ] @@ -7072,7 +7075,7 @@ name = "mmr-rpc" version = "28.0.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "parity-scale-codec", "serde", "sp-api", @@ -7132,7 +7135,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -7250,9 +7253,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" [[package]] name = "multistream-select" @@ -7337,17 +7340,16 @@ dependencies = [ [[package]] name = "netlink-proto" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b33524dc0968bfad349684447bfce6db937a9ac3332a1fe60c0c5a5ce63f21" +checksum = "b2741a6c259755922e3ed29ebce3b299cc2160c4acae94b465b5938ab02c2bbe" dependencies = [ "bytes", "futures", "log", "netlink-packet-core", "netlink-sys", - "thiserror 1.0.69", - "tokio", + "thiserror 2.0.11", ] [[package]] @@ -7402,7 +7404,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "cfg-if", "cfg_aliases 0.1.1", "libc", @@ -7503,7 +7505,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -7636,9 +7638,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl-probe" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "option-ext" @@ -7670,7 +7672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7b1d40dd8f367db3c65bec8d3dd47d4a604ee8874480738f93191bddab4e0e0" dependencies = [ "expander", - "indexmap 2.7.0", + "indexmap 2.7.1", "itertools 0.11.0", "petgraph", "proc-macro-crate 3.2.0", @@ -8075,7 +8077,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -8300,6 +8302,7 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-namespace", "pallet-registries", "pallet-schema-accounts", "parity-scale-codec", @@ -8519,6 +8522,26 @@ dependencies = [ "scale-info", ] +[[package]] +name = "pallet-namespace" +version = "0.9.5" +dependencies = [ + "bitflags 1.3.2", + "cord-identifier", + "cord-primitives", + "cord-utilities", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0)", +] + [[package]] name = "pallet-network-membership" version = "0.9.5" @@ -8744,6 +8767,7 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-namespace", "pallet-schema-accounts", "parity-scale-codec", "scale-info", @@ -8953,7 +8977,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -9054,7 +9078,7 @@ name = "pallet-transaction-payment-rpc" version = "30.0.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "sp-api", @@ -9340,7 +9364,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.9", + "thiserror 2.0.11", "ucd-trie", ] @@ -9364,7 +9388,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -9385,34 +9409,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.7.0", + "indexmap 2.7.1", ] [[package]] name = "pin-project" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" +checksum = "1e2ec53ad785f4d35dac0adea7f7dc6f1bb277ad84a680c7afefeae05d1f5916" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" +checksum = "d56a66c0c55993aa927429d0f8a0abfd74f084e4d9c192cffed01e418d83eefb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -9776,19 +9800,19 @@ dependencies = [ "polkavm-common 0.9.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "polkavm-derive-impl" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12d2840cc62a0550156b1676fed8392271ddf2fab4a00661db56231424674624" +checksum = "2f2116a92e6e96220a398930f4c8a6cda1264206f3e2034fc9982bfd93f261f7" dependencies = [ "polkavm-common 0.18.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -9798,7 +9822,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl 0.9.0", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -9807,8 +9831,8 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c16669ddc7433e34c1007d31080b80901e3e8e523cb9d4b441c3910cf9294b" dependencies = [ - "polkavm-derive-impl 0.18.0", - "syn 2.0.91", + "polkavm-derive-impl 0.18.1", + "syn 2.0.96", ] [[package]] @@ -9842,7 +9866,7 @@ dependencies = [ "concurrent-queue", "hermit-abi 0.4.0", "pin-project-lite", - "rustix 0.38.42", + "rustix 0.38.44", "tracing", "windows-sys 0.59.0", ] @@ -9944,12 +9968,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" dependencies = [ "proc-macro2", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10046,7 +10070,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10057,14 +10081,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -10103,7 +10127,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10112,7 +10136,7 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14cae93065090804185d3b75f0bf93b8eeda30c7a9b4a33d3bdb3988d6229e50" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "lazy_static", "num-traits", "rand", @@ -10158,7 +10182,7 @@ dependencies = [ "prost 0.13.4", "prost-types", "regex", - "syn 2.0.91", + "syn 2.0.96", "tempfile", ] @@ -10172,7 +10196,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10185,7 +10209,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10208,9 +10232,9 @@ dependencies = [ [[package]] name = "quanta" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773ce68d0bb9bc7ef20be3536ffe94e223e1f365bd374108b2659fac0c65cfe6" +checksum = "3bd1fe6824cea6538803de3ff1bc0cf3949024db3d43c9643024bfb33a807c0e" dependencies = [ "crossbeam-utils", "libc", @@ -10299,9 +10323,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -10372,11 +10396,11 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.2.0" +version = "11.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" +checksum = "c6928fa44c097620b706542d428957635951bade7143269085389d42c8a4927e" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", ] [[package]] @@ -10448,7 +10472,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", ] [[package]] @@ -10479,7 +10503,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -10721,7 +10745,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.24", + "semver 1.0.25", ] [[package]] @@ -10749,14 +10773,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.42" +version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "errno", "libc", - "linux-raw-sys 0.4.14", + "linux-raw-sys 0.4.15", "windows-sys 0.59.0", ] @@ -10799,9 +10823,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.20" +version = "0.23.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" +checksum = "8f287924602bf649d949c63dc8ac8b235fa5387d394020705b80c4eb597ce5b8" dependencies = [ "log", "once_cell", @@ -10846,7 +10870,7 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework 3.1.0", + "security-framework 3.2.0", ] [[package]] @@ -10884,7 +10908,7 @@ dependencies = [ "jni", "log", "once_cell", - "rustls 0.23.20", + "rustls 0.23.21", "rustls-native-certs 0.7.3", "rustls-platform-verifier-android", "rustls-webpki 0.102.8", @@ -10923,9 +10947,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" [[package]] name = "ruzstd" @@ -11095,7 +11119,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -11259,7 +11283,7 @@ version = "0.34.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ "futures", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "sc-consensus-babe", "sc-consensus-epochs", "sc-rpc-api", @@ -11317,7 +11341,7 @@ version = "13.0.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ "futures", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "parking_lot 0.12.3", @@ -11395,7 +11419,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "finality-grandpa", "futures", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "sc-client-api", @@ -11777,7 +11801,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "rand", - "rustls 0.23.20", + "rustls 0.23.21", "sc-client-api", "sc-network", "sc-network-common", @@ -11809,7 +11833,7 @@ version = "29.0.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ "futures", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "parking_lot 0.12.3", @@ -11840,7 +11864,7 @@ name = "sc-rpc-api" version = "0.33.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "parity-scale-codec", "sc-chain-spec", "sc-mixnet", @@ -11868,7 +11892,7 @@ dependencies = [ "http-body-util", "hyper 1.5.2", "ip_network", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "sc-rpc-api", "serde", @@ -11889,7 +11913,7 @@ dependencies = [ "futures-util", "hex", "itertools 0.11.0", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "parking_lot 0.12.3", @@ -11921,7 +11945,7 @@ dependencies = [ "exit-future", "futures", "futures-timer", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "parking_lot 0.12.3", @@ -12023,7 +12047,7 @@ name = "sc-sync-state-rpc" version = "0.34.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "parity-scale-codec", "sc-chain-spec", "sc-client-api", @@ -12114,7 +12138,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -12125,7 +12149,7 @@ dependencies = [ "async-trait", "futures", "futures-timer", - "indexmap 2.7.0", + "indexmap 2.7.1", "itertools 0.11.0", "linked-hash-map", "log", @@ -12242,7 +12266,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -12268,7 +12292,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -12290,7 +12314,7 @@ dependencies = [ "proc-macro2", "quote", "scale-info", - "syn 2.0.91", + "syn 2.0.96", "thiserror 1.0.69", ] @@ -12326,9 +12350,9 @@ dependencies = [ [[package]] name = "schnellru" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367" +checksum = "356285bbf17bea63d9e52e96bd18f039672ac92b55b8cb997d6162a2a37d1649" dependencies = [ "ahash", "cfg-if", @@ -12424,7 +12448,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "core-foundation 0.9.4", "core-foundation-sys", "libc", @@ -12434,11 +12458,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d3f8c9bfcc3cbb6b0179eb57042d75b1582bdc65c3cb95f3fa999509c03cbc" +checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "core-foundation 0.10.0", "core-foundation-sys", "libc", @@ -12447,9 +12471,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" dependencies = [ "core-foundation-sys", "libc", @@ -12475,9 +12499,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" dependencies = [ "serde", ] @@ -12502,9 +12526,9 @@ checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -12520,20 +12544,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ "itoa", "memchr", @@ -12582,7 +12606,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -12696,7 +12720,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c80e565e7dcc4f1ef247e2f395550d4cf7d777746d5988e7e4e3156b71077fc" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", ] [[package]] @@ -12953,7 +12977,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -13188,7 +13212,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13239,7 +13263,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0)", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -13258,17 +13282,17 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -13284,7 +13308,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "environmental", "parity-scale-codec", @@ -13503,7 +13527,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13529,20 +13553,20 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "Inflector", "expander", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -13624,7 +13648,7 @@ source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" [[package]] name = "sp-storage" @@ -13641,7 +13665,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "impl-serde 0.5.0", "parity-scale-codec", @@ -13676,7 +13700,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "parity-scale-codec", "tracing", @@ -13755,7 +13779,7 @@ dependencies = [ "proc-macro-warning 1.0.2", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -13773,7 +13797,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#682f8cd22f5bcb76d1b98820b62be49d11deae10" +source = "git+https://github.com/paritytech/polkadot-sdk#17ae06272b366cbeb9429e01a3bf70d30a885a6f" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -14019,7 +14043,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14047,7 +14071,7 @@ dependencies = [ "docify", "frame-system-rpc-runtime-api", "futures", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "parity-scale-codec", "sc-rpc-api", @@ -14079,7 +14103,7 @@ version = "0.33.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ "async-trait", - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "log", "sc-rpc-api", "serde", @@ -14091,7 +14115,7 @@ name = "substrate-state-trie-migration-rpc" version = "27.0.0" source = "git+https://github.com/dhiway/substrate-sdk?branch=release-v1.17.0#d9b1353c0148179afb9edac1c830fbb7c67f9932" dependencies = [ - "jsonrpsee 0.24.7", + "jsonrpsee 0.24.8", "parity-scale-codec", "sc-client-api", "sc-rpc-api", @@ -14197,7 +14221,7 @@ dependencies = [ "scale-info", "scale-typegen", "subxt-metadata", - "syn 2.0.91", + "syn 2.0.96", "thiserror 1.0.69", "tokio", ] @@ -14258,7 +14282,7 @@ dependencies = [ "quote", "scale-typegen", "subxt-codegen", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14311,9 +14335,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.91" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -14340,7 +14364,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14349,7 +14373,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "core-foundation 0.9.4", "system-configuration-sys", ] @@ -14384,14 +14408,15 @@ checksum = "42a4d50cdb458045afc8131fd91b64904da29548bcb63c7236e0844936c13078" [[package]] name = "tempfile" -version = "3.14.0" +version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" dependencies = [ "cfg-if", "fastrand", + "getrandom", "once_cell", - "rustix 0.38.42", + "rustix 0.38.44", "windows-sys 0.59.0", ] @@ -14410,7 +14435,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" dependencies = [ - "rustix 0.38.42", + "rustix 0.38.44", "windows-sys 0.59.0", ] @@ -14431,11 +14456,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.11", ] [[package]] @@ -14446,18 +14471,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14593,9 +14618,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.42.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -14611,13 +14636,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14658,7 +14683,7 @@ version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ - "rustls 0.23.20", + "rustls 0.23.21", "tokio", ] @@ -14739,7 +14764,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.7.0", + "indexmap 2.7.1", "serde", "serde_spanned", "toml_datetime", @@ -14767,7 +14792,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "bytes", "http 1.2.0", "http-body 1.0.1", @@ -14809,7 +14834,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14852,7 +14877,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -14987,9 +15012,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "trybuild" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dcd332a5496c026f1e14b7f3d2b7bd98e509660c04239c58b0ba38a12daded4" +checksum = "b812699e0c4f813b872b373a4471717d9eb550da14b311058a4d9cf4173cbca6" dependencies = [ "dissimilar", "glob", @@ -15095,9 +15120,9 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" [[package]] name = "unicode-normalization" @@ -15207,9 +15232,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vcpkg" @@ -15298,34 +15323,35 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -15336,9 +15362,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -15346,31 +15372,34 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-encoder" -version = "0.222.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3432682105d7e994565ef928ccf5856cf6af4ba3dddebedb737f61caed70f956" +checksum = "b7249cf8cb0c6b9cb42bce90c0a5feb276fbf963fa385ff3d818ab3d90818ed6" dependencies = [ "leb128", - "wasmparser 0.222.0", + "wasmparser 0.224.0", ] [[package]] @@ -15520,13 +15549,13 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.222.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4adf50fde1b1a49c1add6a80d47aea500c88db70551805853aa8b88f3ea27ab5" +checksum = "65881a664fdd43646b647bb27bf186ab09c05bf56779d40aed4c6dce47d423f5" dependencies = [ - "bitflags 2.6.0", - "indexmap 2.7.0", - "semver 1.0.24", + "bitflags 2.8.0", + "indexmap 2.7.1", + "semver 1.0.25", ] [[package]] @@ -15735,9 +15764,9 @@ dependencies = [ [[package]] name = "wast" -version = "222.0.0" +version = "224.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce7191f4b7da0dd300cc32476abae6457154e4625d9b1bc26890828a9a26f6e" +checksum = "d722a51e62b669d17e5a9f6bc8ec210178b37d869114355aa46989686c5c6391" dependencies = [ "bumpalo", "leb128", @@ -15748,18 +15777,18 @@ dependencies = [ [[package]] name = "wat" -version = "1.222.0" +version = "1.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fde61b4b52f9a84ae31b5e8902a2cd3162ea45d8bf564c729c3288fe52f4334" +checksum = "71dece6a7dd5bcbcf8d256606c7fb3faa36286d46bf3f98185407719a5ceede2" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -15802,9 +15831,9 @@ dependencies = [ [[package]] name = "wide" -version = "0.7.30" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e6db2670d2be78525979e9a5f9c69d296fd7d670549fe9ebf70f8708cb5019" +checksum = "41b5576b9a81633f3e8df296ce0063042a73507636cbe956c61133dd7034ab22" dependencies = [ "bytemuck", "safe_arch", @@ -16101,9 +16130,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.20" +version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] @@ -16193,14 +16222,14 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "xml-rs" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" +checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" [[package]] name = "xmltree" @@ -16267,7 +16296,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "synstructure 0.13.1", ] @@ -16289,7 +16318,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -16309,7 +16338,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "synstructure 0.13.1", ] @@ -16330,7 +16359,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -16352,7 +16381,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index df579b38d..a63e6a53e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "node/testing", "pallets/asset", "pallets/chain-space", + "pallets/namespace", "pallets/did", "pallets/did-name", "pallets/identity", @@ -898,6 +899,7 @@ pallet-registries = { path = "pallets/registries", default-features = false } pallet-entries = { path = "pallets/entries", default-features = false } pallet-schema-accounts = { path = "pallets/schema-accounts", default-features = false } pallet-meta-tx = { path = "pallets/meta-tx", default-features = false } +pallet-namespace = { path = 'pallets/namespace', default-features = false } [profile.release] diff --git a/README.md b/README.md index 0d6044a90..38811e485 100644 --- a/README.md +++ b/README.md @@ -208,13 +208,40 @@ If you would like to contribute, please fork the repository, follow the [contrib ### Before submitting the PR -There are 3 tests which run as part of PR validation. +There are 4 tests which run as part of PR validation. -- Build - `cargo build --release` +- #### Cargo Format + + Ensures the code format is in accordance with official Rust guidelines. Add the formatted files as part of the commit. -- Clippy - `cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings` + ```bash + cargo +nightly fmt --all + ``` + +- #### Build + + Transform CORD codebase into executable binary. + + ```bash + cargo build --release + ``` + +- Clippy + + Runs the linter to maintain clean and idiomatic code. + + ```bash + cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings` + ``` + +- Test + + Runs CORD Network unit tests, integration tests and benchmarks defined for all modules. + + ```bash + cargo test --release --locked --features=runtime-benchmarks --no-fail-fast --verbose --color always --all --all-targets + ``` -- Test - `cargo test --release --locked --features=runtime-benchmarks --no-fail-fast --verbose --color always --all --all-targets` Note that each of these would take significant time to run, and hence, if you are working on a specific pallet, you can use `-p --lib` instead of `--all`. That should be faster than normal full test locally. diff --git a/pallets/asset/src/mock.rs b/pallets/asset/src/mock.rs index c76af0c4f..af2667745 100644 --- a/pallets/asset/src/mock.rs +++ b/pallets/asset/src/mock.rs @@ -65,7 +65,7 @@ impl mock_origin::Config for Test { parameter_types! { pub const MaxEncodedValueLength: u32 = 1_024; - pub const MaxAssetDistribution: u32 = u32::MAX; + pub const MaxAssetDistribution: u32 = 25; } impl Config for Test { diff --git a/pallets/asset/src/tests.rs b/pallets/asset/src/tests.rs index d6515f9e6..739d6ad00 100644 --- a/pallets/asset/src/tests.rs +++ b/pallets/asset/src/tests.rs @@ -1,5 +1,5 @@ use super::*; -use crate::mock::*; +use crate::{mock::*, types::AssetIssuanceEntry, Error}; use codec::Encode; use cord_utilities::mock::{mock_origin::DoubleOrigin, SubjectId}; use frame_support::{assert_err, assert_ok, BoundedVec}; @@ -278,12 +278,15 @@ fn asset_unauthorized_operation_should_fail() { authorization_id.clone() )); - assert_err!(Asset::issue( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), // Unauthorized author attempting the action - issue_entry.clone(), - issue_entry_digest, - unauthorized_authorization_id.clone() - ), Error::::UnauthorizedOperation); + assert_err!( + Asset::issue( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), // Unauthorized author attempting the action + issue_entry.clone(), + issue_entry_digest, + unauthorized_authorization_id.clone() + ), + Error::::UnauthorizedOperation + ); assert_ok!(Asset::issue( DoubleOrigin(author.clone(), creator.clone()).into(), @@ -292,29 +295,32 @@ fn asset_unauthorized_operation_should_fail() { authorization_id.clone() )); - assert_err!(Asset::transfer( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), - transfer_entry.clone(), - transfer_entry_digest, - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::transfer( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), + transfer_entry.clone(), + transfer_entry_digest, + ), + Error::::UnauthorizedOperation ); - assert_err!(Asset::transfer( - DoubleOrigin(author.clone(), creator.clone()).into(), - unauthorized_transfer_entry.clone(), - unauthorized_entry_digest, - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::transfer( + DoubleOrigin(author.clone(), creator.clone()).into(), + unauthorized_transfer_entry.clone(), + unauthorized_entry_digest, + ), + Error::::UnauthorizedOperation ); - assert_err!(Asset::status_change( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), - asset_id.clone(), - Some(instance_id.clone()), - AssetStatusOf::INACTIVE - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::status_change( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), + asset_id.clone(), + Some(instance_id.clone()), + AssetStatusOf::INACTIVE + ), + Error::::UnauthorizedOperation ); assert_ok!(Asset::vc_create( @@ -324,13 +330,14 @@ fn asset_unauthorized_operation_should_fail() { authorization_id.clone() )); - assert_err!(Asset::vc_issue( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - unauthorized_authorization_id - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::vc_issue( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + unauthorized_authorization_id + ), + Error::::UnauthorizedOperation ); assert_ok!(Asset::vc_issue( @@ -340,31 +347,33 @@ fn asset_unauthorized_operation_should_fail() { authorization_id )); - assert_err!(Asset::vc_transfer( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), - transfer_entry.clone(), - transfer_entry_digest, - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::vc_transfer( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), + transfer_entry.clone(), + transfer_entry_digest, + ), + Error::::UnauthorizedOperation ); - assert_err!(Asset::vc_transfer( - DoubleOrigin(author.clone(), creator.clone()).into(), - unauthorized_transfer_entry.clone(), - unauthorized_entry_digest, - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::vc_transfer( + DoubleOrigin(author.clone(), creator.clone()).into(), + unauthorized_transfer_entry.clone(), + unauthorized_entry_digest, + ), + Error::::UnauthorizedOperation ); - assert_err!(Asset::vc_status_change( - DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), - asset_id.clone(), - Some(instance_id.clone()), - AssetStatusOf::INACTIVE - ), - Error::::UnauthorizedOperation + assert_err!( + Asset::vc_status_change( + DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), + asset_id.clone(), + Some(instance_id.clone()), + AssetStatusOf::INACTIVE + ), + Error::::UnauthorizedOperation ); - }); } @@ -3057,3 +3066,98 @@ fn asset_vc_status_change_with_wrong_asset_id_should_fail() { ); }); } + +#[test] +fn asset_issue_should_fail_when_distribution_limit_exceeds() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 200u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 1000; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + let issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); + + new_test_ext().execute_with(|| { + // Create and approve space + assert_ok!(Space::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + space_digest, + )); + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id.clone(), capacity)); + assert_ok!(Asset::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + entry.clone(), + digest, + authorization_id.clone() + )); + + let max_distribution = ::MaxAssetDistribution::get(); + + for _ in 0..max_distribution { + let issuance_entry = AssetIssuanceEntry { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(1), + }; + + let issuance_digest = + ::Hashing::hash(&issuance_entry.encode()[..]); + + assert_ok!(Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issuance_entry, + issuance_digest, + authorization_id.clone() + )); + } + let exceeding_entry = AssetIssuanceEntry { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(1), + }; + + let exceeding_digest = + ::Hashing::hash(&exceeding_entry.encode()[..]); + + assert_err!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + exceeding_entry, + exceeding_digest, + authorization_id.clone() + ), + Error::::DistributionLimitExceeded + ); + }); +} diff --git a/pallets/entries/Cargo.toml b/pallets/entries/Cargo.toml index 48baa39da..9116238c1 100644 --- a/pallets/entries/Cargo.toml +++ b/pallets/entries/Cargo.toml @@ -41,6 +41,7 @@ sp-core = { workspace = true } cord-utilities = { workspace = true } sp-keystore = { workspace = true } serde_json = { workspace = true } +pallet-namespace = { workspace = true } pallet-registries = { workspace = true } pallet-schema-accounts = { workspace = true } @@ -66,6 +67,7 @@ std = [ "sp-std/std", "identifier/std", "cord-utilities/std", + "pallet-namespace/std", "pallet-registries/std", "pallet-schema-accounts/std", ] @@ -75,6 +77,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "cord-utilities/runtime-benchmarks", + "pallet-namespace/runtime-benchmarks", "pallet-registries/runtime-benchmarks", "pallet-schema-accounts/runtime-benchmarks", ] diff --git a/pallets/entries/src/lib.rs b/pallets/entries/src/lib.rs index d1b250519..b42a71d81 100644 --- a/pallets/entries/src/lib.rs +++ b/pallets/entries/src/lib.rs @@ -75,8 +75,10 @@ pub mod pallet { CordIdentifierType, IdentifierCreator, IdentifierTimeline, IdentifierType, Ss58Identifier, }; - /// Type of the Authorization - pub type AuthorizationIdOf = Ss58Identifier; + /// Type of the Namespace Authorization + pub type NamespaceAuthorizationIdOf = Ss58Identifier; + /// Type of the Registry Authorization + pub type RegistryAuthorizationIdOf = Ss58Identifier; /// Type of the Registry Entry Digest pub type RegistryEntryHashOf = ::Hash; /// Type of the Registry Identifier @@ -222,7 +224,7 @@ pub mod pallet { pub fn create( origin: OriginFor, _registry_entry_id: RegistryEntryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, digest: RegistryEntryHashOf, _blob: Option>, ) -> DispatchResult { @@ -321,7 +323,7 @@ pub mod pallet { pub fn update( origin: OriginFor, registry_entry_id: RegistryEntryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, digest: RegistryEntryHashOf, _blob: Option>, ) -> DispatchResult { @@ -387,7 +389,7 @@ pub mod pallet { pub fn revoke( origin: OriginFor, registry_entry_id: RegistryEntryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let updater = ensure_signed(origin)?; let registry_id = pallet_registries::Pallet::::ensure_authorization_origin( @@ -444,7 +446,7 @@ pub mod pallet { pub fn reinstate( origin: OriginFor, registry_entry_id: RegistryEntryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let updater = ensure_signed(origin)?; let registry_id = pallet_registries::Pallet::::ensure_authorization_origin( @@ -521,9 +523,9 @@ pub mod pallet { pub fn update_ownership( origin: OriginFor, registry_entry_id: RegistryEntryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, new_owner: CreatorOf, - new_owner_authorization: AuthorizationIdOf, + new_owner_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let updater = ensure_signed(origin)?; let registry_id = pallet_registries::Pallet::::ensure_authorization_origin( diff --git a/pallets/entries/src/mock.rs b/pallets/entries/src/mock.rs index 62517be59..ee6fba49e 100644 --- a/pallets/entries/src/mock.rs +++ b/pallets/entries/src/mock.rs @@ -20,8 +20,9 @@ use super::*; use crate as pallet_entries; use cord_utilities::mock::{mock_origin, SubjectId}; use frame_support::{derive_impl, parameter_types}; +use pallet_namespace::IsPermissioned; -//use frame_system::EnsureRoot; +use frame_system::EnsureRoot; use sp_runtime::{ traits::{IdentifyAccount, IdentityLookup, Verify}, BuildStorage, MultiSignature, @@ -37,6 +38,7 @@ frame_support::construct_runtime!( System: frame_system, Identifier: identifier, MockOrigin: mock_origin, + NameSpace: pallet_namespace, SchemaAccounts: pallet_schema_accounts, Registries: pallet_registries, Entries: pallet_entries, @@ -63,6 +65,28 @@ impl mock_origin::Config for Test { type SubjectId = SubjectId; } +pub struct NetworkPermission; +impl IsPermissioned for NetworkPermission { + fn is_permissioned() -> bool { + true + } +} + +parameter_types! { + #[derive(Debug, Clone)] + pub const MaxNameSpaceDelegates: u32 = 5u32; + pub const MaxNameSpaceBlobSize: u32 = 4u32 * 1024; +} + +impl pallet_namespace::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkPermission; + type MaxNameSpaceDelegates = MaxNameSpaceDelegates; + type MaxNameSpaceBlobSize = MaxNameSpaceBlobSize; + type WeightInfo = (); +} + parameter_types! { pub const MaxEncodedSchemaLength: u32 = 15_360; } diff --git a/pallets/entries/src/tests.rs b/pallets/entries/src/tests.rs index 8188693e3..8d8c18789 100644 --- a/pallets/entries/src/tests.rs +++ b/pallets/entries/src/tests.rs @@ -24,6 +24,7 @@ use serde_json::json; use sp_runtime::traits::Hash; use sp_std::prelude::*; +use pallet_namespace::{NameSpaceCodeOf, NameSpaceIdOf}; use pallet_registries::{RegistryBlobOf, RegistryHashOf}; use pallet_schema_accounts::{InputSchemaOf, SchemaHashOf, SchemaIdOf}; @@ -46,7 +47,9 @@ pub fn generate_registry_entry_id(id_digest: &RegistryHashOf) -> R } /// Generates a Authorization ID -pub fn generate_authorization_id(digest: &RegistryHashOf) -> AuthorizationIdOf { +pub fn generate_authorization_id( + digest: &RegistryHashOf, +) -> RegistryAuthorizationIdOf { Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::RegistryAuthorization) .unwrap() } @@ -57,6 +60,22 @@ pub fn generate_schema_id(digest: &SchemaHashOf) -> SchemaIdOf { .unwrap() } +/// Generates a Namespace ID +pub fn generate_namespace_id(digest: &NameSpaceCodeOf) -> NameSpaceIdOf { + Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap() +} + +/// Generates a Namespace Authorization ID +pub fn generate_namespace_authorization_id( + digest: &NameSpaceCodeOf, +) -> NamespaceAuthorizationIdOf { + Ss58Identifier::create_identifier( + &(digest).encode()[..], + IdentifierType::NameSpaceAuthorization, + ) + .unwrap() +} + pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]); pub(crate) const ACCOUNT_01: AccountId = AccountId::new([2u8; 32]); pub(crate) const ACCOUNT_02: AccountId = AccountId::new([3u8; 32]); @@ -64,6 +83,21 @@ pub(crate) const ACCOUNT_02: AccountId = AccountId::new([3u8; 32]); #[test] fn create_registry_entry_should_work() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -82,7 +116,8 @@ fn create_registry_entry_should_work() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -92,11 +127,18 @@ fn create_registry_entry_should_work() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -175,6 +217,21 @@ fn create_registry_entry_should_work() { #[test] fn update_registry_entry_should_work() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -193,7 +250,8 @@ fn update_registry_entry_should_work() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -203,11 +261,18 @@ fn update_registry_entry_should_work() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -327,6 +392,21 @@ fn update_registry_entry_should_work() { #[test] fn revoke_registry_entry_should_work() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -345,7 +425,8 @@ fn revoke_registry_entry_should_work() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -355,11 +436,18 @@ fn revoke_registry_entry_should_work() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -440,6 +528,21 @@ fn revoke_registry_entry_should_work() { #[test] fn reinstating_revoked_registry_entry_should_work() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -458,7 +561,8 @@ fn reinstating_revoked_registry_entry_should_work() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -468,11 +572,18 @@ fn reinstating_revoked_registry_entry_should_work() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -567,6 +678,21 @@ fn reinstating_revoked_registry_entry_should_work() { fn update_registry_entry_should_work_for_valid_creator() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -585,13 +711,14 @@ fn update_registry_entry_should_work_for_valid_creator() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -602,11 +729,18 @@ fn update_registry_entry_should_work_for_valid_creator() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -616,6 +750,7 @@ fn update_registry_entry_should_work_for_valid_creator() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -735,6 +870,21 @@ fn update_registry_entry_should_work_for_valid_creator() { #[test] fn update_registry_entry_should_work_for_valid_admin() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -753,7 +903,8 @@ fn update_registry_entry_should_work_for_valid_admin() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -763,11 +914,18 @@ fn update_registry_entry_should_work_for_valid_admin() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -890,6 +1048,21 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; let non_creator = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -908,20 +1081,21 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let non_creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &non_creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let non_creator_authorization_id: AuthorizationIdOf = + let non_creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&non_creator_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -932,11 +1106,18 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -946,6 +1127,7 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -953,6 +1135,7 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), non_creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1061,6 +1244,27 @@ fn update_registry_entry_should_fail_for_non_registry_admin() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; let invalid_admin = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let invalid_admin_namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &invalid_admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let invalid_admin_namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&invalid_admin_namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1085,13 +1289,14 @@ fn update_registry_entry_should_fail_for_non_registry_admin() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let invalid_admin_auth_id_digest = ::Hashing::hash( @@ -1103,7 +1308,7 @@ fn update_registry_entry_should_fail_for_non_registry_admin() { .concat()[..], ); - let invalid_admin_authorization_id: AuthorizationIdOf = + let invalid_admin_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&invalid_admin_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1114,11 +1319,26 @@ fn update_registry_entry_should_fail_for_non_registry_admin() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + + /* Add a invalid-admin as part of the namespace so can form a different registry */ + assert_ok!(NameSpace::add_delegate( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_id.clone(), + invalid_admin.clone(), + namespace_authorization_id.clone() + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob.clone()), )); @@ -1128,13 +1348,14 @@ fn update_registry_entry_should_fail_for_non_registry_admin() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); assert_ok!(Registries::create( frame_system::RawOrigin::Signed(invalid_admin.clone()).into(), - registry_id.clone(), registry_digest, + invalid_admin_namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -1244,6 +1465,21 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; let new_owner = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest_admin = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id_admin: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest_admin); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1262,20 +1498,21 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let new_owner_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &new_owner.encode()[..], &admin.encode()[..]].concat()[..], ); - let new_owner_authorization_id: AuthorizationIdOf = + let new_owner_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&new_owner_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1286,11 +1523,18 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id_admin.clone(), Some(schema_id), Some(blob), )); @@ -1300,6 +1544,7 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id_admin.clone(), authorization_id.clone(), )); @@ -1308,6 +1553,7 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), new_owner.clone(), + namespace_authorization_id_admin.clone(), authorization_id.clone(), )); @@ -1407,6 +1653,21 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; let new_owner = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1425,20 +1686,21 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let new_owner_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &new_owner.encode()[..], &admin.encode()[..]].concat()[..], ); - let new_owner_authorization_id: AuthorizationIdOf = + let new_owner_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&new_owner_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1449,11 +1711,18 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -1463,6 +1732,7 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1471,6 +1741,7 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), new_owner.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1570,6 +1841,21 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership let admin = ACCOUNT_00; let creator = ACCOUNT_01; let new_owner = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1588,20 +1874,21 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let new_owner_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &new_owner.encode()[..], &admin.encode()[..]].concat()[..], ); - let new_owner_authorization_id: AuthorizationIdOf = + let new_owner_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&new_owner_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1612,11 +1899,18 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -1626,6 +1920,7 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1634,6 +1929,7 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), new_owner.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1785,6 +2081,21 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner let admin = ACCOUNT_00; let creator = ACCOUNT_01; let new_owner = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1803,20 +2114,21 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let new_owner_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &new_owner.encode()[..], &admin.encode()[..]].concat()[..], ); - let new_owner_authorization_id: AuthorizationIdOf = + let new_owner_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&new_owner_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1827,11 +2139,18 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -1841,6 +2160,7 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1849,6 +2169,7 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), new_owner.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1995,6 +2316,21 @@ fn update_ownership_should_fail_for_updating_themselves() { let admin = ACCOUNT_00; let creator = ACCOUNT_01; let new_owner = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -2013,13 +2349,14 @@ fn update_ownership_should_fail_for_updating_themselves() { &[®istry_id.encode()[..], &admin.encode()[..], &admin.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let creator_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &creator.encode()[..], &admin.encode()[..]].concat()[..], ); - let creator_authorization_id: AuthorizationIdOf = + let creator_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&creator_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -2030,11 +2367,18 @@ fn update_ownership_should_fail_for_updating_themselves() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + /* Test creation of a Namespace */ + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(admin.clone()).into(), + namespace_digest, + None, + )); + /* Test creation of a Registry */ assert_ok!(Registries::create( frame_system::RawOrigin::Signed(admin.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -2044,6 +2388,7 @@ fn update_ownership_should_fail_for_updating_themselves() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), creator.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -2052,6 +2397,7 @@ fn update_ownership_should_fail_for_updating_themselves() { frame_system::RawOrigin::Signed(admin.clone()).into(), registry_id.clone(), new_owner.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); diff --git a/pallets/namespace/Cargo.toml b/pallets/namespace/Cargo.toml new file mode 100644 index 000000000..006fec14c --- /dev/null +++ b/pallets/namespace/Cargo.toml @@ -0,0 +1,73 @@ +[package] +name = 'pallet-namespace' +description = 'Manage Name-Spaces.' +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] + +[dev-dependencies] +sp-core = { features = ["std"], workspace = true } +sp-keystore = { features = ["std"], workspace = true } +cord-utilities = { features = ["mock"], workspace = true } + +[dependencies] +codec = { features = ["derive"], workspace = true } +scale-info = { features = ["derive"], workspace = true } +bitflags = { workspace = true } + +# Internal dependencies +cord-primitives = { workspace = true } +cord-utilities = { workspace = true } +identifier = { workspace = true } + +# Substrate dependencies +frame-benchmarking = { optional = true, workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-core = { optional = true, workspace = true } +sp-io = { optional = true, workspace = true } +sp-keystore = { optional = true, workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + + +[features] +default = ['std'] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "cord-utilities/runtime-benchmarks", +] +std = [ + "codec/std", + "identifier/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "cord-primitives/std", + "cord-utilities/std", + "scale-info/std", + "sp-core/std", + "sp-io/std", + "sp-keystore/std", + "sp-runtime/std", + "sp-std/std", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "identifier/try-runtime", + "cord-utilities/try-runtime", + "sp-runtime/try-runtime" +] diff --git a/pallets/namespace/src/lib.rs b/pallets/namespace/src/lib.rs new file mode 100644 index 000000000..868f5787e --- /dev/null +++ b/pallets/namespace/src/lib.rs @@ -0,0 +1,1030 @@ +// This file is part of CORD – https://cord.network + +// Copyright (C) Dhiway Networks Pvt. Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// CORD is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// CORD is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with CORD. If not, see . +// + +//! # NameSpace Pallet +//! +//! The NameSpace pallet provides a framework for creating and managing +//! isolated namespaces within the CORD blockchain that can be governed and +//! moderated with a fine-grained permission system. It allows for the creation, +//! approval, and archival of namespaces, as well as the management of delegates +//! within these namespaces. +//! +//! ## Overview +//! +//! The NameSpace pallet allows for the creation of distinct namespaces on the CORD +//! blockchain, each with its own set of rules and governance. These namespaces can +//! be used to manage different ecosystems or communities within the larger +//! blockchain environment. NameSpaces are created with a unique identifier and can +//! be managed by appointed delegates. +//! +//! ## Interface +//! +//! The pallet provides dispatchable functions for namespace management: +//! +//! - `create`: Initializes a new namespace with a unique identifier. +//! - `archive`: Marks a namespace as archived, effectively freezing its state. +//! - `restore`: Unarchives a namespace, returning it to active status. +//! - `add_delegate`: Adds a delegate to a namespace, granting them specific permissions. +//! - `add_admin_delegate`: Adds an admin delegate to a namespace, granting them administrative +//! permissions. +//! - `add_audit_delegate`: Adds an audit delegate to a namespace, granting them audit permissions. +//! - `remove_delegate`: Removes a delegate from a namespace, revoking their permissions. +//! +//! ## Permissions +//! +//! The pallet uses a permissions system to manage the actions that delegates +//! can perform within a namespace. Permissions are granular and can be assigned to +//! different roles, such as an admin or a regular delegate. +//! +//! ## Data Privacy +//! +//! The NameSpace pallet is designed with data privacy as a core consideration. +//! It does not directly store any personal or sensitive information on-chain. +//! Instead, it manages references to off-chain data, ensuring that the +//! blockchain layer remains compliant with data privacy regulations. Users and +//! developers are responsible for ensuring that the off-chain data handling +//! processes adhere to the applicable laws and standards. +//! +//! ## Usage +//! +//! The NameSpace pallet can be used by other pallets to create +//! compartmentalized and governed sections of the blockchain. This is +//! particularly useful for applications that require distinct governance models +//! or privacy settings within a shared ecosystem. +//! +//! ## Governance Integration +//! +//! The NameSpace pallet is integrated with on-chain governance pallets to +//! allow namespace administrators and delegates to propose changes, vote on +//! initiatives, or manage the namespace in accordance with the collective decisions +//! of its members. +//! +//! ## Examples +//! +//! - Creating a new namespace for a community-driven project. +//! - Archiving a namespace that is no longer active or has violated terms of use. +//! - Restoring an archived namespace to reactivate it for further use after compliance checks. +//! - Adding delegates to a namespace to ensure ongoing compliance with governance standards. + +#![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::unused_unit)] + +#[cfg(test)] +pub mod mock; + +#[cfg(test)] +mod tests; + +use frame_support::{ensure, storage::types::StorageMap, BoundedVec}; +pub mod types; +pub use crate::{pallet::*, types::*}; +use codec::Encode; +use frame_system::WeightInfo; +use identifier::{ + types::{CallTypeOf, IdentifierTypeOf, Timepoint}, + EventEntryOf, +}; +use sp_runtime::traits::{Hash, UniqueSaturatedInto}; + +/// Type of a NameSpace Hash +pub type NameSpaceHashOf = ::Hash; + +/// Type of Maximum allowed size of a NameSpace Blob +pub type MaxNameSpaceBlobSizeOf = ::MaxNameSpaceBlobSize; + +/// Type of a NameSpace Blob +pub type NameSpaceBlobOf = BoundedVec>; + +/// Type of a namespace creator. +pub type NameSpaceCreatorOf = ::AccountId; + +/// Namespace Identifier +pub type NameSpaceIdOf = Ss58Identifier; + +/// Registry Identifier +pub type RegistryIdOf = Ss58Identifier; + +/// Authorization Identifier +pub type AuthorizationIdOf = Ss58Identifier; + +/// Namespace input code +pub type NameSpaceCodeOf = ::Hash; + +/// Registry Identifier mapped to a Namespace. +pub type MaxRegistriesOf = ::MaxNameSpaceDelegates; + +/// Type of on-chain Namespace details +pub type NameSpaceDetailsOf = NameSpaceDetails< + NameSpaceHashOf, + NameSpaceCreatorOf, + StatusOf, + BoundedVec>, +>; + +/// Type of Namespace Authorization details +pub type NameSpaceAuthorizationOf = + NameSpaceAuthorization, Permissions>; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + pub use cord_primitives::{IsPermissioned, StatusOf}; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + pub use identifier::{IdentifierCreator, IdentifierTimeline, IdentifierType, Ss58Identifier}; + + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + + #[pallet::config] + pub trait Config: frame_system::Config + identifier::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + // TODO: Remove below two constants. + type ChainSpaceOrigin: EnsureOrigin; + type NetworkPermission: IsPermissioned; + + #[pallet::constant] + type MaxNameSpaceDelegates: Get; + + #[pallet::constant] + type MaxNameSpaceBlobSize: Get; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + } + + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] + pub struct Pallet(_); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + /// Namespace information stored on chain. + /// It maps from an identifier to its details. + #[pallet::storage] + pub type NameSpaces = + StorageMap<_, Blake2_128Concat, NameSpaceIdOf, NameSpaceDetailsOf, OptionQuery>; + + /// Namespace authorizations stored on-chain. + /// It maps from an identifier to delegates. + #[pallet::storage] + pub type Authorizations = StorageMap< + _, + Blake2_128Concat, + AuthorizationIdOf, + NameSpaceAuthorizationOf, + OptionQuery, + >; + + /// Namespace delegates stored on chain. + /// It maps from an identifier to a bounded vec of delegates and + /// permissions. + #[pallet::storage] + pub(super) type Delegates = StorageMap< + _, + Blake2_128Concat, + NameSpaceIdOf, + BoundedVec, T::MaxNameSpaceDelegates>, + ValueQuery, + >; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// A new namespace authorization has been added. + /// \[namespace identifier, authorization, delegate\] + Authorization { + namespace: NameSpaceIdOf, + authorization: AuthorizationIdOf, + delegate: NameSpaceCreatorOf, + }, + /// A namespace authorization has been removed. + /// \[namespace identifier, authorization, ] + Deauthorization { namespace: NameSpaceIdOf, authorization: AuthorizationIdOf }, + /// A new namespace has been created. + /// \[namespace identifier, creator, authorization\] + Create { + namespace: NameSpaceIdOf, + creator: NameSpaceCreatorOf, + authorization: AuthorizationIdOf, + }, + /// A namespace has been archived. + /// \[namespace identifier, authority\] + Archive { namespace: NameSpaceIdOf, authority: NameSpaceCreatorOf }, + /// A namespace has been restored. + /// \[namespace identifier, authority\] + Restore { namespace: NameSpaceIdOf, authority: NameSpaceCreatorOf }, + /// A namespace has been restored. + /// \[namespace identifier, \] + Revoke { namespace: NameSpaceIdOf }, + } + + #[pallet::error] + #[derive(PartialEq)] + pub enum Error { + /// NameSpace identifier is not unique + NameSpaceAlreadyAnchored, + /// NameSpace identifier not found + NameSpaceNotFound, + /// Only when the author is not the controller or delegate. + UnauthorizedOperation, + /// Invalid Identifier + InvalidIdentifier, + /// Invalid Identifier Length + InvalidIdentifierLength, + /// Invalid Identifier Prefix + InvalidIdentifierPrefix, + /// Archived NameSpace + ArchivedNameSpace, + /// NameSpace not Archived + NameSpaceNotArchived, + /// NameSpace delegation limit exceeded + NameSpaceDelegatesLimitExceeded, + /// Empty transaction. + EmptyTransaction, + /// Authority already added + DelegateAlreadyAdded, + /// Authorization Id not found + AuthorizationNotFound, + /// Delegate not found. + DelegateNotFound, + /// Namespace Registry list limit exceeded. + NameSpaceRegistryListLimitExceeded, + } + + #[pallet::call] + impl Pallet { + /// Adds a delegate with the ability to assert new entries to a namespace. + /// + /// The `ASSERT` permission allows the delegate to sign and add new + /// entries within the namespace. This function is called to grant a + /// delegate this specific permission. It checks that the caller has the + /// necessary authorization (admin rights) to add a delegate to the + /// namespace. If the caller is authorized, the delegate is added with the + /// `ASSERT` permission using the `space_delegate_addition` + /// internal function. + /// + /// # Parameters + /// - `origin`: The origin of the call, which must be signed by an admin of the namespace. + /// - `namespace_id`: The identifier of the namespace to which the delegate is being added. + /// - `delegate`: The identifier of the delegate being added to the namespace. + /// - `authorization`: The authorization ID used to validate the addition. + /// + /// # Returns + /// Returns `Ok(())` if the delegate was successfully added with + /// `ASSERT` permission, or an `Err` with an appropriate error if the + /// operation fails. + /// + /// # Errors + /// - `UnauthorizedOperation`: If the caller is not an admin of the namespace. + /// - Propagates errors from `space_delegate_addition` if it fails. + #[pallet::call_index(0)] + #[pallet::weight({0})] + pub fn add_delegate( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + delegate: NameSpaceCreatorOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = + Self::ensure_authorization_delegator_origin(&authorization, &creator)?; + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + let permissions = Permissions::ASSERT; + Self::space_delegate_addition(auth_space_id, delegate, creator, permissions)?; + + Ok(()) + } + + /// Adds an administrative delegate to a namespace. + /// + /// The `ADMIN` permission grants the delegate extensive control over + /// the namespace, including the ability to manage other delegates and + /// change namespace configurations. This function is called to + /// grant a delegate these administrative privileges. It verifies that + /// the caller has the necessary authorization (admin rights) to add an + /// admin delegate to the namespace. If the caller is authorized, + /// the delegate is added with the `ADMIN` permission using the + /// `space_delegate_addition` internal function. + /// + /// # Parameters + /// - `origin`: The origin of the call, which must be signed by an existing admin of the + /// namespace. + /// - `namespace_id`: The identifier of the namespace to which the admin delegate is being + /// added. + /// - `delegate`: The identifier of the delegate being granted admin permissions. + /// - `authorization`: The authorization ID used to validate the addition. + /// + /// # Returns + /// Returns `Ok(())` if the admin delegate was successfully added, or an + /// `Err` with an appropriate error if the operation fails. + /// + /// # Errors + /// - `UnauthorizedOperation`: If the caller is not an admin of the namespace. + /// - Propagates errors from `space_delegate_addition` if it fails. + #[pallet::call_index(1)] + #[pallet::weight({0})] + pub fn add_admin_delegate( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + delegate: NameSpaceCreatorOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = Self::ensure_authorization_admin_origin(&authorization, &creator)?; + + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + let permissions = Permissions::ADMIN; + Self::space_delegate_addition(auth_space_id, delegate, creator, permissions)?; + + Ok(()) + } + + /// Adds an audit delegate to a namespace. + /// + /// The `AUDIT` permission grants the delegate the ability to perform + /// oversight and compliance checks within the namespace. This function is + /// used to assign a delegate these audit privileges. It ensures that + /// the caller has the necessary authorization (admin rights) to add an + /// audit delegate to the namespace. If the caller is authorized, the + /// delegate is added with the `AUDIT` permission using the + /// `space_delegate_addition` internal function. + /// + /// # Parameters + /// - `origin`: The origin of the call, which must be signed by an existing admin of the + /// namespace. + /// - `namespace_id`: The identifier of the namespace to which the audit delegate is being + /// added. + /// - `delegate`: The identifier of the delegate being granted audit permissions. + /// - `authorization`: The authorization ID used to validate the addition. + /// + /// # Returns + /// Returns `Ok(())` if the audit delegate was successfully added, or an + /// `Err` with an appropriate error if the operation fails. + #[pallet::call_index(2)] + #[pallet::weight({0})] + pub fn add_delegator( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + delegate: NameSpaceCreatorOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = Self::ensure_authorization_admin_origin(&authorization, &creator)?; + + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + let permissions = Permissions::DELEGATE; + Self::space_delegate_addition(auth_space_id, delegate, creator, permissions)?; + + Ok(()) + } + + /// Removes a delegate from a specified namespace. + /// + /// This function will remove an existing delegate from a namespace, given + /// the namespace ID and the delegate's authorization ID. It checks that the + /// namespace exists, is not archived and that the provided + /// authorization corresponds to a delegate of the namespace. It also + /// verifies that the caller has the authority to remove a delegate. + /// + /// # Parameters + /// - `origin`: The origin of the transaction, which must be signed by the creator or an + /// admin. + /// - `namespace_id`: The identifier of the namespace from which the delegate is being + /// removed. + /// - `remove_authorization`: The authorization ID of the delegate to be removed. + /// - `authorization`: An identifier for the authorization being used to validate the + /// removal. + /// + /// # Returns + /// - `DispatchResult`: This function returns `Ok(())` if the delegate is successfully + /// removed, or an error (`DispatchError`) if any of the checks fail. + /// + /// # Errors + /// - `AuthorizationNotFound`: If the provided `remove_authorization` does not exist. + /// - `UnauthorizedOperation`: If the origin is not authorized to remove a delegate from the + /// namespace. + /// - `NameSpaceNotFound`: If the specified namespace ID does not correspond to an existing + /// namespace. + /// - `ArchivedNameSpace`: If the namespace is archived and no longer active. + /// - `DelegateNotFound`: If the delegate specified by `remove_authorization` is not found + /// in the namespace. + /// + /// # Events + /// + /// - `Deauthorization`: Emitted when a delegate is successfully removed from a namespace. + /// The event includes the namespace ID and the authorization ID of the removed delegate. + #[pallet::call_index(3)] + #[pallet::weight({0})] + pub fn remove_delegate( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + remove_authorization: AuthorizationIdOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = + Self::ensure_authorization_admin_remove_origin(&authorization, &creator)?; + + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + // Ensure the authorization exists and retrieve its details. + let authorization_details = Authorizations::::get(&remove_authorization) + .ok_or(Error::::AuthorizationNotFound)?; + + let mut delegates = Delegates::::get(&namespace_id); + if let Some(index) = delegates.iter().position(|d| d == &authorization_details.delegate) + { + delegates.remove(index); + Delegates::::insert(&namespace_id, delegates); + + Authorizations::::remove(&remove_authorization); + + Self::update_activity( + &namespace_id, + IdentifierTypeOf::NameSpaceAuthorization, + CallTypeOf::Deauthorization, + )?; + + Self::deposit_event(Event::Deauthorization { + namespace: namespace_id, + authorization: remove_authorization, + }); + + Ok(()) + } else { + Err(Error::::DelegateNotFound.into()) + } + } + + /// Creates a new namespace with a unique identifier based on the provided + /// namespace code and the creator's identity. + /// + /// This function generates a unique identifier for the namespace by hashing + /// the encoded namespace code and creator's identifier. It ensures that the + /// generated namespace identifier is not already in use. An authorization + /// ID is also created for the new namespace, which is used to manage + /// delegations. The creator is automatically added as a delegate with + /// all permissions. + /// + /// # Parameters + /// - `origin`: The origin of the transaction, which must be signed by the creator. + /// - `space_code`: A unique code representing the namespace to be created. + /// + /// # Returns + /// - `DispatchResult`: Returns `Ok(())` if the namespace is successfully created, or an + /// error (`DispatchError`) if: + /// - The generated namespace identifier is already in use. + /// - The generated authorization ID is of invalid length. + /// - The namespace delegates limit is exceeded. + /// + /// # Errors + /// - `InvalidIdentifierLength`: If the generated identifiers for the namespace or + /// authorization are of invalid length. + /// - `NameSpaceAlreadyAnchored`: If the namespace identifier is already in use. + /// - `NameSpaceDelegatesLimitExceeded`: If the namespace exceeds the limit of allowed + /// delegates. + /// + /// # Events + /// - `Create`: Emitted when a new namespace is successfully created. It includes the + /// namespace identifier, the creator's identifier, and the authorization ID. + #[pallet::call_index(4)] + #[pallet::weight({0})] + pub fn create( + origin: OriginFor, + digest: NameSpaceHashOf, + _blob: Option>, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + + // Id Digest = concat (H(, + // )) + let id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let identifier = Ss58Identifier::create_identifier( + &id_digest.encode()[..], + IdentifierType::NameSpace, + ) + .map_err(|_| Error::::InvalidIdentifierLength)?; + + ensure!( + !>::contains_key(&identifier), + Error::::NameSpaceAlreadyAnchored + ); + + // Construct the authorization_id from the provided parameters. + // Id Digest = concat (H(, + // )) + let auth_id_digest = T::Hashing::hash( + &[&identifier.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat() + [..], + ); + + let authorization_id = Ss58Identifier::create_identifier( + &auth_id_digest.encode(), + IdentifierType::NameSpaceAuthorization, + ) + .map_err(|_| Error::::InvalidIdentifierLength)?; + + let mut delegates: BoundedVec, T::MaxNameSpaceDelegates> = + BoundedVec::default(); + delegates + .try_push(creator.clone()) + .map_err(|_| Error::::NameSpaceDelegatesLimitExceeded)?; + + Delegates::::insert(&identifier, delegates); + + Authorizations::::insert( + &authorization_id, + NameSpaceAuthorizationOf:: { + namespace_id: identifier.clone(), + delegate: creator.clone(), + permissions: Permissions::all(), + delegator: creator.clone(), + }, + ); + + >::insert( + &identifier, + NameSpaceDetailsOf:: { + digest, + creator: creator.clone(), + archive: false, + registry_ids: Some(BoundedVec::default()), + }, + ); + + Self::update_activity(&identifier, IdentifierTypeOf::NameSpace, CallTypeOf::Genesis) + .map_err(Error::::from)?; + + Self::deposit_event(Event::Create { + namespace: identifier, + creator, + authorization: authorization_id, + }); + + Ok(()) + } + + /// Archives a namespace, rendering it inactive. + /// + /// This function marks a namespace as archived based on the provided namespace + /// ID. It checks that the namespace exists, is not already archived. + /// Additionally, it verifies that the caller has the + /// authority to archive the namespace, as indicated by the provided + /// authorization ID. + /// + /// # Parameters + /// - `origin`: The origin of the transaction, which must be signed by the creator or an + /// admin with the appropriate authority. + /// - `namespace_id`: The identifier of the namespace to be archived. + /// - `authorization`: An identifier for the authorization being used to validate the + /// archival. + /// + /// # Returns + /// - `DispatchResult`: Returns `Ok(())` if the namespace is successfully archived, or an + /// error (`DispatchError`) if: + /// - The namespace does not exist. + /// - `ArchivedNameSpace`: If the namespace is already archived. + /// - `UnauthorizedOperation`: If the caller does not have the authority to archive the + /// namespace. + /// + /// # Errors + /// - `NameSpaceNotFound`: If the specified namespace ID does not correspond to an existing + /// namespace. + /// - `ArchivedNameSpace`: If the namespace is already archived. + /// - `UnauthorizedOperation`: If the caller is not authorized to archive the namespace. + /// + /// # Events + /// - `Archive`: Emitted when a namespace is successfully archived. It includes the + /// namespace ID and the authority who performed the archival. + #[pallet::call_index(6)] + #[pallet::weight({0})] + pub fn archive( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = Self::ensure_authorization_admin_origin(&authorization, &creator)?; + + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + let namespace_details = + NameSpaces::::get(&namespace_id).ok_or(Error::::NameSpaceNotFound)?; + ensure!(!namespace_details.archive, Error::::ArchivedNameSpace); + + >::insert( + &namespace_id, + NameSpaceDetailsOf:: { archive: true, ..namespace_details }, + ); + + Self::update_activity(&namespace_id, IdentifierTypeOf::NameSpace, CallTypeOf::Archive) + .map_err(Error::::from)?; + + Self::deposit_event(Event::Archive { namespace: namespace_id, authority: creator }); + + Ok(()) + } + + /// Restores an archived namespace, making it active again. + /// + /// This function unarchives a namespace based on the provided namespace ID. It + /// checks that the namespace exists, is currently archived. + /// It also verifies that the caller has the authority to + /// restore the namespace, as indicated by the provided authorization ID. + /// + /// # Parameters + /// - `origin`: The origin of the transaction, which must be signed by the creator or an + /// admin with the appropriate authority. + /// - `namespace_id`: The identifier of the namespace to be restored. + /// - `authorization`: An identifier for the authorization being used to validate the + /// restoration. + /// + /// # Returns + /// - `DispatchResult`: Returns `Ok(())` if the namespace is successfully restored, or an + /// error (`DispatchError`) if: + /// - The namespace does not exist. + /// - The namespace is not archived. + /// - The caller does not have the authority to restore the namespace. + /// + /// # Errors + /// - `NameSpaceNotFound`: If the specified namespace ID does not correspond to an existing + /// namespace. + /// - `NameSpaceNotArchived`: If the namespace is not currently archived. + /// - `UnauthorizedOperation`: If the caller is not authorized to restore the namespace. + /// + /// # Events + /// - `Restore`: Emitted when a namespace is successfully restored. It includes the + /// namespace ID and the authority who performed the restoration. + #[pallet::call_index(7)] + #[pallet::weight({0})] + pub fn restore( + origin: OriginFor, + namespace_id: NameSpaceIdOf, + authorization: AuthorizationIdOf, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + let auth_space_id = + Self::ensure_authorization_restore_origin(&authorization, &creator)?; + + ensure!(auth_space_id == namespace_id, Error::::UnauthorizedOperation); + + let namespace_details = + NameSpaces::::get(&namespace_id).ok_or(Error::::NameSpaceNotFound)?; + ensure!(namespace_details.archive, Error::::NameSpaceNotArchived); + + >::insert( + &namespace_id, + NameSpaceDetailsOf:: { archive: false, ..namespace_details }, + ); + + Self::update_activity(&namespace_id, IdentifierTypeOf::NameSpace, CallTypeOf::Restore) + .map_err(Error::::from)?; + + Self::deposit_event(Event::Restore { namespace: namespace_id, authority: creator }); + + Ok(()) + } + } +} + +impl Pallet { + /// Adds a delegate to a namespace with specified permissions. + /// + /// This function will add a new delegate to a namespace, given the namespace's ID, + /// the delegate's information, and the required permissions. It constructs + /// an authorization ID based on the namespace ID, delegate, and creator, + /// ensuring that the delegate is not already added. It also checks that the + /// namespace is not archived and has not exceeded its capacity. + fn space_delegate_addition( + namespace_id: NameSpaceIdOf, + delegate: NameSpaceCreatorOf, + creator: NameSpaceCreatorOf, + permissions: Permissions, + ) -> Result<(), Error> { + // Id Digest = concat (H(, + // , )) + let id_digest = T::Hashing::hash( + &[&namespace_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let delegate_authorization_id = Ss58Identifier::create_identifier( + &id_digest.encode(), + IdentifierType::NameSpaceAuthorization, + ) + .map_err(|_| Error::::InvalidIdentifierLength)?; + + ensure!( + !Authorizations::::contains_key(&delegate_authorization_id), + Error::::DelegateAlreadyAdded + ); + + let mut delegates = Delegates::::get(&namespace_id); + delegates + .try_push(delegate.clone()) + .map_err(|_| Error::::NameSpaceDelegatesLimitExceeded)?; + Delegates::::insert(&namespace_id, delegates); + + Authorizations::::insert( + &delegate_authorization_id, + NameSpaceAuthorizationOf:: { + namespace_id: namespace_id.clone(), + delegate: delegate.clone(), + permissions, + delegator: creator, + }, + ); + + Self::update_activity( + &namespace_id, + IdentifierTypeOf::NameSpaceAuthorization, + CallTypeOf::Authorization, + ) + .map_err(Error::::from)?; + + Self::deposit_event(Event::Authorization { + namespace: namespace_id, + authorization: delegate_authorization_id, + delegate, + }); + + Ok(()) + } + + /// Checks if a given entity is a delegate for the specified namespace. + /// + /// This function retrieves the list of delegates for a namespace and determines + /// whether the specified delegate is among them. It is a read-only + /// operation and does not modify the state. + pub fn is_a_delegate(tx_id: &NameSpaceIdOf, delegate: NameSpaceCreatorOf) -> bool { + >::get(tx_id).iter().any(|d| d == &delegate) + } + + /// Verifies if a given delegate has a specific authorization. + /// + /// This function checks if the provided delegate is associated with the + /// given authorization ID and has the 'ASSERT' permission. + pub fn ensure_authorization_origin( + authorization_id: &AuthorizationIdOf, + delegate: &NameSpaceCreatorOf, + ) -> Result> { + let d = + >::get(authorization_id).ok_or(Error::::AuthorizationNotFound)?; + + ensure!(d.delegate == *delegate, Error::::UnauthorizedOperation); + + // TODO: Update all similar function names. + Self::validate_space_for_transaction(&d.namespace_id)?; + + ensure!(d.permissions.contains(Permissions::ASSERT), Error::::UnauthorizedOperation); + + Ok(d.namespace_id) + } + + pub fn ensure_authorization_restore_origin( + authorization_id: &AuthorizationIdOf, + delegate: &NameSpaceCreatorOf, + ) -> Result> { + let d = + >::get(authorization_id).ok_or(Error::::AuthorizationNotFound)?; + + ensure!(d.delegate == *delegate, Error::::UnauthorizedOperation); + + Self::validate_space_for_restore_transaction(&d.namespace_id)?; + + ensure!(d.permissions.contains(Permissions::ADMIN), Error::::UnauthorizedOperation); + + Ok(d.namespace_id) + } + + /// Checks if a given delegate is an admin for the namespace associated with the + /// authorization ID. + /// + /// This function verifies whether the specified delegate is the admin of + /// the namespace by checking the 'ADMIN' permission within the authorization + /// tied to the provided authorization ID. + pub fn ensure_authorization_admin_origin( + authorization_id: &AuthorizationIdOf, + delegate: &NameSpaceCreatorOf, + ) -> Result> { + let d = + >::get(authorization_id).ok_or(Error::::AuthorizationNotFound)?; + + ensure!(d.delegate == *delegate, Error::::UnauthorizedOperation); + + Self::validate_space_for_transaction(&d.namespace_id)?; + + ensure!(d.permissions.contains(Permissions::ADMIN), Error::::UnauthorizedOperation); + + Ok(d.namespace_id) + } + + /// Ensures that the given delegate is authorized to perform an audit + /// operation on a namespace. + /// + /// This function checks whether the provided `authorization_id` corresponds + /// to an existing authorization and whether the delegate associated with + /// that authorization is allowed to perform audit operations. It also + /// increments usage and validates the namespace for transactions. + pub fn ensure_authorization_delegator_origin( + authorization_id: &AuthorizationIdOf, + delegate: &NameSpaceCreatorOf, + ) -> Result> { + let d = + >::get(authorization_id).ok_or(Error::::AuthorizationNotFound)?; + + ensure!(d.delegate == *delegate, Error::::UnauthorizedOperation); + + Self::validate_space_for_transaction(&d.namespace_id)?; + + ensure!( + d.permissions.contains(Permissions::DELEGATE | Permissions::ADMIN), + Error::::UnauthorizedOperation + ); + + Ok(d.namespace_id) + } + + /// Checks if a given delegate is an admin for the namespace associated with the + /// authorization ID. + /// + /// This function verifies whether the specified delegate is the admin of + /// the namespace by checking the 'ADMIN' permission within the authorization + /// tied to the provided authorization ID. + pub fn ensure_authorization_admin_remove_origin( + authorization_id: &AuthorizationIdOf, + delegate: &NameSpaceCreatorOf, + ) -> Result> { + let d = + >::get(authorization_id).ok_or(Error::::AuthorizationNotFound)?; + + ensure!(d.delegate == *delegate, Error::::UnauthorizedOperation); + + Self::validate_space_for_transaction(&d.namespace_id)?; + + ensure!(d.permissions.contains(Permissions::ADMIN), Error::::UnauthorizedOperation); + + Ok(d.namespace_id) + } + + /// Validates that a namespace is eligible for a new transaction. + /// + /// This function ensures that a namespace is not archived and has + /// not exceeded its capacity limit before allowing a new transaction to be + /// recorded. It is a critical check that enforces the integrity and + /// constraints of namespace usage on the chain. + pub fn validate_space_for_transaction(namespace_id: &NameSpaceIdOf) -> Result<(), Error> { + let namespace_details = + NameSpaces::::get(namespace_id).ok_or(Error::::NameSpaceNotFound)?; + + // Ensure the namespace is not archived. + ensure!(!namespace_details.archive, Error::::ArchivedNameSpace); + + Ok(()) + } + + /// Validates a namespace for restore transactions. + /// + /// This function checks that the specified namespace is archived alread. + /// It is designed to be called before performing any administrative actions + /// on a namespace to ensure that the namespace is in a proper state for such transactions. + pub fn validate_space_for_restore_transaction( + namespace_id: &NameSpaceIdOf, + ) -> Result<(), Error> { + let namespace_details = + NameSpaces::::get(namespace_id).ok_or(Error::::NameSpaceNotFound)?; + + // Ensure the namespace is archived. + ensure!(namespace_details.archive, Error::::NameSpaceNotArchived); + + Ok(()) + } + + /// Validates that a namespace can accommodate a batch of new entries without + /// exceeding its capacity. + /// + /// This function ensures that a namespace is not archived and has + /// enough remaining capacity to accommodate a specified number of new + /// entries. It is a critical check that enforces the integrity and + /// constraints of namespace usage on the chain, especially when dealing + /// with batch operations. + pub fn validate_space_for_transaction_entries( + namespace_id: &NameSpaceIdOf, + _entries: u16, + ) -> Result<(), Error> { + let namespace_details = + NameSpaces::::get(namespace_id).ok_or(Error::::NameSpaceNotFound)?; + + // Ensure the namespace is not archived. + ensure!(!namespace_details.archive, Error::::ArchivedNameSpace); + + Ok(()) + } + + /// Adds a registry ID to the list of registry IDs associated with a namespace. + /// + /// This function updates the namespace's `registry_ids` list by appending the specified + /// `registry_id` if it is not already present. If the list is uninitialized (i.e., `None`), + /// it initializes the list and adds the `registry_id`. The function ensures that the + /// `BoundedVec` does not exceed its capacity, returning an error if the limit is reached. + /// + /// # Parameters + /// - `namespace_id`: A reference to the ID of the namespace where the registry ID should be + /// added. + /// - `registry_id`: A reference to the registry ID to be added to the namespace's list of + /// registry IDs. + /// + /// # Returns + /// - `Ok(())`: If the `registry_id` was successfully added or was already present in the list. + /// - `Err(Error::NameSpaceNotFound)`: If the specified namespace does not exist. + /// - `Err(Error::NameSpaceRegistryListLimitExceeded)`: If the `registry_ids` list exceeds + /// its maximum capacity while attempting to add the `registry_id`. + /// + /// # Errors + /// - Returns `NameSpaceNotFound` if the `namespace_id` does not exist in the storage. + /// - Returns `NameSpaceRegistryListLimitExceeded` if the `registry_ids` list cannot accommodate + /// any more entries. + pub fn add_registry_id_to_namespace_details( + namespace_id: &NameSpaceIdOf, + registry_id: &RegistryIdOf, + ) -> Result<(), Error> { + NameSpaces::::try_mutate(namespace_id, |space_opt| { + if let Some(space_details) = space_opt { + if let Some(ref mut registry_ids) = space_details.registry_ids { + if !registry_ids.contains(registry_id) { + registry_ids + .try_push(registry_id.clone()) + .map_err(|_| Error::::NameSpaceRegistryListLimitExceeded)?; + } + } else { + // Below is required to avoid runtime panic when intialized with None. + let mut new_registry_ids = BoundedVec::default(); + new_registry_ids + .try_push(registry_id.clone()) + .map_err(|_| Error::::NameSpaceRegistryListLimitExceeded)?; + space_details.registry_ids = Some(new_registry_ids); + } + + Ok(()) + } else { + Err(Error::::NameSpaceNotFound) + } + }) + } + + /// Updates the global timeline with a new activity event for a namespace. + /// + /// This function is an internal mechanism that logs each significant change + /// to a namespace on the global timeline. It is automatically called by the + /// system whenever an update to a namespace occurs, capturing the type of + /// activity and the precise time at which it happened. This automated + /// tracking is crucial for maintaining a consistent and auditable record of + /// all namespace-related activities. + pub fn update_activity( + tx_id: &NameSpaceIdOf, + tx_type: IdentifierTypeOf, + tx_action: CallTypeOf, + ) -> Result<(), Error> { + let tx_moment = Self::timepoint(); + + let tx_entry = EventEntryOf { action: tx_action, location: tx_moment }; + let _ = IdentifierTimeline::update_timeline::(tx_id, tx_type, tx_entry); + Ok(()) + } + + /// Retrieves the current timepoint. + /// + /// This function returns a `Timepoint` structure containing the current + /// block number and extrinsic index. It is typically used in conjunction + /// with `update_activity` to record when an event occurred. + pub fn timepoint() -> Timepoint { + Timepoint { + height: frame_system::Pallet::::block_number().unique_saturated_into(), + index: frame_system::Pallet::::extrinsic_index().unwrap_or_default(), + } + } +} diff --git a/pallets/namespace/src/mock.rs b/pallets/namespace/src/mock.rs new file mode 100644 index 000000000..c2ba1fb94 --- /dev/null +++ b/pallets/namespace/src/mock.rs @@ -0,0 +1,121 @@ +// This file is part of CORD – https://cord.network + +// Copyright (C) Dhiway Networks Pvt. Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// CORD is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// CORD is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with CORD. If not, see . + +use crate as pallet_namespace; +use cord_utilities::mock::{mock_origin, SubjectId}; +use frame_support::{derive_impl, parameter_types}; +use pallet_namespace::IsPermissioned; + +use frame_system::EnsureRoot; +use sp_runtime::{ + traits::{IdentifyAccount, IdentityLookup, Verify}, + BuildStorage, MultiSignature, +}; + +type Signature = MultiSignature; +type AccountPublic = ::Signer; +pub type AccountId = ::AccountId; +pub(crate) type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test { + System: frame_system, + NameSpace: pallet_namespace, + Identifier: identifier, + MockOrigin: mock_origin, + } +); + +parameter_types! { + pub const SS58Prefix: u8 = 29; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Test { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Block = Block; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type SS58Prefix = SS58Prefix; +} + +impl mock_origin::Config for Test { + type RuntimeOrigin = RuntimeOrigin; + type AccountId = AccountId; + type SubjectId = SubjectId; +} + +pub struct NetworkPermission; +impl IsPermissioned for NetworkPermission { + fn is_permissioned() -> bool { + true + } +} + +parameter_types! { + #[derive(Debug, Clone)] + pub const MaxNameSpaceDelegates: u32 = 5u32; + pub const MaxNameSpaceBlobSize: u32 = 4u32 * 1024; +} + +impl pallet_namespace::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkPermission; + type MaxNameSpaceDelegates = MaxNameSpaceDelegates; + type MaxNameSpaceBlobSize = MaxNameSpaceBlobSize; + type WeightInfo = (); +} + +parameter_types! { + pub const MaxEventsHistory: u32 = 6u32; +} + +impl identifier::Config for Test { + type MaxEventsHistory = MaxEventsHistory; +} + +parameter_types! { + storage NameSpaceEvents: u32 = 0; +} + +/// All events of this pallet. +pub fn space_events_since_last_call() -> Vec> { + let events = System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| if let RuntimeEvent::NameSpace(inner) = e { Some(inner) } else { None }) + .collect::>(); + let already_seen = NameSpaceEvents::get(); + NameSpaceEvents::set(&(events.len() as u32)); + events.into_iter().skip(already_seen as usize).collect() +} + +#[allow(dead_code)] +pub(crate) fn new_test_ext() -> sp_io::TestExternalities { + let t: sp_runtime::Storage = + frame_system::GenesisConfig::::default().build_storage().unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + #[cfg(feature = "runtime-benchmarks")] + let keystore = sp_keystore::testing::MemoryKeystore::new(); + #[cfg(feature = "runtime-benchmarks")] + ext.register_extension(sp_keystore::KeystoreExt(sp_std::sync::Arc::new(keystore))); + ext.execute_with(|| System::set_block_number(1)); + ext +} diff --git a/pallets/namespace/src/tests.rs b/pallets/namespace/src/tests.rs new file mode 100644 index 000000000..3ffadae69 --- /dev/null +++ b/pallets/namespace/src/tests.rs @@ -0,0 +1,62 @@ +use super::*; +use crate::mock::*; +use codec::Encode; +use frame_support::assert_ok; +use sp_runtime::traits::Hash; +use sp_std::prelude::*; + +/// Generate a namespace id from a digest. +pub fn generate_namespace_id(digest: &NameSpaceCodeOf) -> NameSpaceIdOf { + Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap() +} + +/// Generate an authorization id from a digest. +pub fn generate_authorization_id(digest: &NameSpaceCodeOf) -> AuthorizationIdOf { + Ss58Identifier::create_identifier( + &(digest).encode()[..], + IdentifierType::NameSpaceAuthorization, + ) + .unwrap() +} + +pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]); +pub(crate) const ACCOUNT_01: AccountId = AccountId::new([2u8; 32]); + +//TEST FUNCTION FOR ADD DELEGATE +#[test] +fn add_delegate_should_succeed() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + + let raw_blob = [1u8; 256].to_vec(); + let blob: NameSpaceBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length of for the test runtime."); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + Some(blob), + )); + + assert_ok!(NameSpace::add_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_id, + delegate.clone(), + authorization_id, + )); + }); +} diff --git a/pallets/namespace/src/types.rs b/pallets/namespace/src/types.rs new file mode 100644 index 000000000..ae9339a27 --- /dev/null +++ b/pallets/namespace/src/types.rs @@ -0,0 +1,102 @@ +// This file is part of CORD – https://cord.network + +// Copyright (C) Dhiway Networks Pvt. Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// CORD is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// CORD is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with CORD. If not, see . +// +//! # Space Management Module Types +//! +//! This module defines types used for managing spaces within the blockchain, +//! including permissions, space details, and space authorizations. + +use bitflags::bitflags; +use codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; + +bitflags! { + #[derive(Encode, Decode, TypeInfo, MaxEncodedLen)] + pub struct Permissions: u32 { + const ASSERT = 0b0000_0001; + const DELEGATE = 0b0000_0010; + const ADMIN = 0b0000_0100; + } +} + +impl Permissions { + // Encodes the permission bitflags into a 4-byte array. + /// + /// This method is useful for serialization and storage purposes, as it + /// converts the internal representation of the permissions into a format + /// that can be easily stored and transmitted. + /// + /// Returns a `[u8; 4]` representing the encoded permissions. + pub fn as_u8(self) -> [u8; 4] { + let x: u32 = self.bits; + let b1: u8 = ((x >> 24) & 0xff) as u8; + let b2: u8 = ((x >> 16) & 0xff) as u8; + let b3: u8 = ((x >> 8) & 0xff) as u8; + let b4: u8 = (x & 0xff) as u8; + [b4, b3, b2, b1] + } +} + +impl Default for Permissions { + /// Provides a default for the Permissions struct. + /// + /// By default, the `ASSERT` permission is granted + fn default() -> Self { + Permissions::ASSERT + } +} + +/// Details of an on-chain namespace. +/// +/// This structure holds metadata about a namespace, including its identifier, +/// creator, capacity, and current usage. It also tracks the approval and +/// archival status of the namespace. +/// +/// ## Fields +/// +/// - `code`: The unique code or identifier for the namespace. +/// - `creator`: The account or entity that created the namespace. +/// - `archive`: Indicates whether the namespace is currently archived. +#[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, PartialEq, Eq, TypeInfo)] +pub struct NameSpaceDetails { + pub digest: NameSpaceHashOf, + pub creator: NameSpaceCreatorOf, + pub archive: StatusOf, + pub registry_ids: Option, +} + +/// Authorization details for a namespace delegate. +/// +/// This structure defines the permissions granted to a delegate within a namespace, +/// as well as the delegator who granted these permissions. It is used to manage +/// and verify the actions that delegates are allowed to perform within a namespace. +/// +/// ## Fields +/// +/// - `namespace_id`: The identifier of the namespace to which the authorization applies. +/// - `delegate`: The entity that has been granted permissions within the namespace. +/// - `permissions`: The specific permissions granted to the delegate. +/// - `delegator`: The entity that granted the permissions to the delegates +#[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, PartialEq, Eq, TypeInfo)] +pub struct NameSpaceAuthorization { + pub namespace_id: NameSpaceIdOf, + pub delegate: NameSpaceCreatorOf, + pub permissions: Permissions, + pub delegator: NameSpaceCreatorOf, +} diff --git a/pallets/network-score/src/tests.rs b/pallets/network-score/src/tests.rs index f7a9e738b..2c26ba9d8 100644 --- a/pallets/network-score/src/tests.rs +++ b/pallets/network-score/src/tests.rs @@ -915,3 +915,120 @@ fn reference_identifier_not_found_test() { >::remove(message_id_revise.clone(), creator.clone()); }); } + +#[test] +fn revise_rating_with_space_mismatch_should_fail() { + let creator = DID_00.clone(); + let author = ACCOUNT_00.clone(); + + let message_id = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let entity_id = BoundedVec::try_from([73u8; 10].to_vec()).unwrap(); + let provider_id = BoundedVec::try_from([74u8; 10].to_vec()).unwrap(); + + // Valid rating entry + let entry = RatingInputEntryOf:: { + entity_id: entity_id.clone(), + provider_id: provider_id.clone(), + total_encoded_rating: 250u64, + count_of_txn: 7u64, + rating_type: RatingTypeOf::Overall, + provider_did: creator.clone(), + }; + + let entry_digest = + ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + // Create "main" space: + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + // Create "mismatch" space: + let mismatch_raw_space = [3u8; 256].to_vec(); + let mismatch_space_digest = + ::Hashing::hash(&mismatch_raw_space.encode()[..]); + let mismatch_space_id_digest = ::Hashing::hash( + &[&mismatch_space_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let mismatch_space_id: SpaceIdOf = generate_space_id::(&mismatch_space_id_digest); + + // Auth ID for main space + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let authorization_id: AuthorizationIdOf = + Ss58Identifier::create_identifier(&auth_digest.encode()[..], IdentifierType::Authorization) + .unwrap(); + + // Auth ID for mismatch space + let mismatch_auth_digest = ::Hashing::hash( + &[&mismatch_space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let mismatch_authorization_id: AuthorizationIdOf = Ss58Identifier::create_identifier( + &mismatch_auth_digest.encode()[..], + IdentifierType::Authorization, + ) + .unwrap(); + + new_test_ext().execute_with(|| { + System::set_block_number(1); + + // Create & approve main space + assert_ok!(Space::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + space_digest + )); + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, 3u64)); + + // Register a 'credit' rating in main space + assert_ok!(Score::register_rating( + DoubleOrigin(author.clone(), creator.clone()).into(), + entry.clone(), + entry_digest, + message_id.clone(), + authorization_id.clone(), + )); + + // Create & approve mismatch space + assert_ok!(Space::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + mismatch_space_digest + )); + assert_ok!(Space::approve(RawOrigin::Root.into(), mismatch_space_id, 3u64)); + + // Revoke the original rating to produce a 'debit' entry + let revoke_msg_id = BoundedVec::try_from([80u8; 10].to_vec()).unwrap(); + let revoke_digest = ::Hashing::hash(&[50u8; 16].to_vec()[..]); + let orig_rating_id = >::get(&message_id, &creator).unwrap(); + + assert_ok!(Score::revoke_rating( + DoubleOrigin(author.clone(), creator.clone()).into(), + orig_rating_id.clone(), + revoke_msg_id.clone(), + revoke_digest, + authorization_id.clone(), + )); + + // Attempt to revise using the mismatch space + let mismatch_msg_id = BoundedVec::try_from([88u8; 10].to_vec()).unwrap(); + let mismatch_digest = + ::Hashing::hash(&[90u8; 16].to_vec()[..]); + + // This call should fail with SpaceMismatch, because the rating was made in 'space_id', + // but we pass 'mismatch_authorization_id' that points to 'mismatch_space_id'. + assert_err!( + Score::revise_rating( + DoubleOrigin(author.clone(), creator.clone()).into(), + entry.clone(), + mismatch_digest, + mismatch_msg_id, + orig_rating_id.clone(), + mismatch_authorization_id, + ), + Error::::SpaceMismatch + ); + }); +} diff --git a/pallets/registries/Cargo.toml b/pallets/registries/Cargo.toml index dda6b12cc..293bc7807 100644 --- a/pallets/registries/Cargo.toml +++ b/pallets/registries/Cargo.toml @@ -24,6 +24,7 @@ codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } bitflags = { workspace = true } log = { workspace = true } +pallet-namespace = { workspace = true } pallet-schema-accounts = { workspace = true } # Internal dependencies @@ -49,6 +50,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "cord-utilities/runtime-benchmarks", + "pallet-namespace/runtime-benchmarks", ] std = [ "codec/std", @@ -64,6 +66,7 @@ std = [ "sp-keystore/std", "sp-runtime/std", "sp-std/std", + "pallet-namespace/std", "pallet-schema-accounts/std", ] try-runtime = [ @@ -72,6 +75,7 @@ try-runtime = [ "identifier/try-runtime", "cord-utilities/try-runtime", "sp-runtime/try-runtime", + "pallet-namespace/std", "pallet-schema-accounts/std", ] diff --git a/pallets/registries/src/benchmarking.rs b/pallets/registries/src/benchmarking.rs index c2aa88fbd..db540ec28 100644 --- a/pallets/registries/src/benchmarking.rs +++ b/pallets/registries/src/benchmarking.rs @@ -6,6 +6,7 @@ use frame_benchmarking::{account, benchmarks}; use frame_support::sp_runtime::traits::Hash; use frame_system::RawOrigin; use identifier::{IdentifierType, Ss58Identifier}; +use pallet_namespace::{NameSpaceCodeOf, NameSpaceIdOf}; use pallet_schema_accounts::{InputSchemaOf, SchemaHashOf}; use sp_std::prelude::*; @@ -17,7 +18,9 @@ pub fn generate_registry_id(digest: &RegistryHashOf) -> RegistryId Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Registries).unwrap() } -pub fn generate_authorization_id(digest: &RegistryHashOf) -> AuthorizationIdOf { +pub fn generate_authorization_id( + digest: &RegistryHashOf, +) -> RegistryAuthorizationIdOf { Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::RegistryAuthorization) .unwrap() } @@ -27,11 +30,26 @@ pub fn generate_schema_id(digest: &SchemaHashOf) -> SchemaIdOf { .unwrap() } +pub fn generate_namespace_id(digest: &NameSpaceCodeOf) -> NameSpaceIdOf { + Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap() +} + +pub fn generate_namespace_authorization_id( + digest: &NameSpaceCodeOf, +) -> NamespaceAuthorizationIdOf { + Ss58Identifier::create_identifier( + &(digest).encode()[..], + IdentifierType::NameSpaceAuthorization, + ) + .unwrap() +} + const SEED: u32 = 0; benchmarks! { where_clause { where + T: pallet_namespace::Config, T: pallet_schema_accounts::Config, T: frame_system::Config, } @@ -40,6 +58,20 @@ benchmarks! { add_delegate { let creator: T::AccountId = account("creator", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -58,13 +90,13 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let delegate_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], ); - let delegate_authorization_id: AuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); + let delegate_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -72,10 +104,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -84,6 +122,7 @@ benchmarks! { RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -101,6 +140,20 @@ benchmarks! { add_admin_delegate { let creator: T::AccountId = account("creator", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -119,13 +172,13 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let delegate_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], ); - let delegate_authorization_id: AuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); + let delegate_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -133,17 +186,28 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; let origin = RawOrigin::Signed(creator.clone()).into(); - }: _(origin, registry_id.clone(), delegate.clone(), authorization_id.clone() + }: _( + origin, + registry_id.clone(), + delegate.clone(), + namespace_authorization_id.clone(), + authorization_id.clone() ) verify { assert_last_event::( @@ -160,6 +224,20 @@ benchmarks! { add_delegator { let creator: T::AccountId = account("creator", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -178,13 +256,13 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let delegate_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], ); - let delegate_authorization_id: AuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); + let delegate_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -192,10 +270,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -204,6 +288,7 @@ benchmarks! { RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -221,6 +306,20 @@ benchmarks! { remove_delegate { let creator: T::AccountId = account("creator", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -239,13 +338,13 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let delegate_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], ); - let delegate_authorization_id: AuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); + let delegate_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -253,10 +352,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -265,6 +370,7 @@ benchmarks! { RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone() )?; @@ -272,6 +378,7 @@ benchmarks! { RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate_authorization_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -287,6 +394,20 @@ benchmarks! { create { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -305,7 +426,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -313,10 +434,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + }: _( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob) ) @@ -334,6 +461,20 @@ benchmarks! { update { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -359,7 +500,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -367,10 +508,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -380,6 +527,7 @@ benchmarks! { registry_id.clone(), new_digest, Some(new_blob.clone()), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -396,6 +544,20 @@ benchmarks! { revoke { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -414,7 +576,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -422,10 +584,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -433,6 +601,7 @@ benchmarks! { }: _( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -448,6 +617,20 @@ benchmarks! { reinstate { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -466,7 +649,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -474,10 +657,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -485,12 +674,14 @@ benchmarks! { Pallet::::revoke( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() )?; }: _( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -506,6 +697,20 @@ benchmarks! { archive { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -524,7 +729,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -532,10 +737,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -543,6 +754,7 @@ benchmarks! { }: _( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { @@ -558,6 +770,20 @@ benchmarks! { restore { let creator: T::AccountId = account("creator", 0, SEED); + + let namespace = [1u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -576,7 +802,7 @@ benchmarks! { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -584,10 +810,16 @@ benchmarks! { let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + pallet_namespace::Pallet::::create( + RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )?; + Pallet::::create( RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id.clone()), Some(blob), )?; @@ -595,12 +827,14 @@ benchmarks! { Pallet::::archive( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )?; }: _( RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone() ) verify { diff --git a/pallets/registries/src/lib.rs b/pallets/registries/src/lib.rs index 56c2c4514..3f581504c 100644 --- a/pallets/registries/src/lib.rs +++ b/pallets/registries/src/lib.rs @@ -108,8 +108,12 @@ use identifier::{ }; use sp_runtime::traits::{Hash, UniqueSaturatedInto}; -/// Authorization Identifier -pub type AuthorizationIdOf = Ss58Identifier; +/// Registry Authorization Identifier +pub type RegistryAuthorizationIdOf = Ss58Identifier; +/// Namespace Authorization Identifier +pub type NamespaceAuthorizationIdOf = Ss58Identifier; +/// Type of the Namespace Id +pub type NameSpaceIdOf = Ss58Identifier; /// Type of the Registry Id pub type RegistryIdOf = Ss58Identifier; /// Tyoe of the Registry Digest @@ -129,7 +133,7 @@ pub type RegistryAuthorizationOf = RegistryAuthorization, Permissions>; /// Type of Registry Details pub type RegistryDetailsOf = - RegistryDetails, StatusOf, RegistryHashOf, SchemaIdOf>; + RegistryDetails, StatusOf, RegistryHashOf, NameSpaceIdOf, SchemaIdOf>; #[frame_support::pallet] pub mod pallet { @@ -146,7 +150,7 @@ pub mod pallet { const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::config] - pub trait Config: frame_system::Config + identifier::Config { + pub trait Config: frame_system::Config + pallet_namespace::Config + identifier::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; #[pallet::constant] @@ -178,8 +182,13 @@ pub mod pallet { /// Registry authorizations stored on-chain. /// It maps from an identifier to delegates. #[pallet::storage] - pub type Authorizations = - StorageMap<_, Blake2_128Concat, AuthorizationIdOf, RegistryAuthorizationOf, OptionQuery>; + pub type Authorizations = StorageMap< + _, + Blake2_128Concat, + RegistryAuthorizationIdOf, + RegistryAuthorizationOf, + OptionQuery, + >; /// Registry delegates stored on chain. /// It maps from an identifier to a bounded vec of delegates and @@ -197,21 +206,21 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// A new registry authorization has been added. - /// \[registry identifier, authorization, delegate\] + /// \[registry identifier, registry authorization, delegate\] Authorization { registry_id: RegistryIdOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, delegate: RegistryCreatorOf, }, /// A registry authorization has been removed. /// \[registry identifier, authorization, ] - Deauthorization { registry_id: RegistryIdOf, authorization: AuthorizationIdOf }, + Deauthorization { registry_id: RegistryIdOf, authorization: RegistryAuthorizationIdOf }, /// A new registry has been created. - /// \[registry identifier, creator, authorization\] + /// \[registry identifier, creator, registry authorization\] Create { registry_id: RegistryIdOf, creator: RegistryCreatorOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, }, /// A registry has been revoked. /// \[registry identifier, authority\] @@ -220,17 +229,17 @@ pub mod pallet { /// \[registry identifier, authority\] Reinstate { registry_id: RegistryIdOf, authority: RegistryCreatorOf }, /// A existing registry has been updated. - /// \[registry identifier, updater, authorization\] + /// \[registry identifier, updater, registry authorization\] Update { registry_id: RegistryIdOf, updater: RegistryCreatorOf, - authorization: AuthorizationIdOf, + authorization: RegistryAuthorizationIdOf, }, /// A registry has been archived. - /// \[registry identifier, authority\] + /// \[registry identifier, authority\] Archive { registry_id: RegistryIdOf, authority: RegistryCreatorOf }, /// A registry has been restored. - /// \[registry identifier, authority\] + /// \[registry identifier,authority\] Restore { registry_id: RegistryIdOf, authority: RegistryCreatorOf }, } @@ -289,8 +298,10 @@ pub mod pallet { /// added. /// - `delegate`: The account identifier of the delegate being granted the `ASSERT` /// permission. - /// - `authorization`: The authorization ID used to validate the caller's permission to add - /// a delegate. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: The authorization ID used to validate the caller's + /// permission to add a delegate. /// /// # Returns /// Returns `Ok(())` if the delegate is successfully added with `ASSERT` @@ -307,12 +318,21 @@ pub mod pallet { origin: OriginFor, registry_id: RegistryIdOf, delegate: RegistryCreatorOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + + // Verify Registry Authorization let auth_registry_id = - Self::ensure_authorization_delegator_origin(&authorization, &creator)?; + Self::ensure_authorization_delegator_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); let permissions = Permissions::ASSERT; @@ -339,8 +359,10 @@ pub mod pallet { /// - `registry_id`: The unique identifier of the registry to which the admin delegate is /// being added. /// - `delegate`: The account identifier of the delegate being granted admin permissions. - /// - `authorization`: The authorization ID used to validate the caller's permission to add - /// an admin delegate to the specified registry. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: The authorization ID used to validate the caller's + /// permission to add an admin delegate to the specified registry. /// /// # Returns /// Returns `Ok(())` if the admin delegate is successfully added, or an `Err` @@ -357,12 +379,23 @@ pub mod pallet { origin: OriginFor, registry_id: RegistryIdOf, delegate: RegistryCreatorOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + + // Verify Registry Authorization let auth_registry_id = - Self::ensure_authorization_admin_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -388,8 +421,10 @@ pub mod pallet { /// - `registry_id`: The unique identifier of the registry to which the audit delegate is /// being added. /// - `delegate`: The account identifier of the delegate being granted audit permissions. - /// - `authorization`: The authorization ID used to validate the caller's permission to add - /// the audit delegate. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: The authorization ID used to validate the caller's + /// permission to add the audit delegate. /// /// # Returns /// Returns `Ok(())` if the audit delegate is successfully added, or an `Err` @@ -406,12 +441,22 @@ pub mod pallet { origin: OriginFor, registry_id: RegistryIdOf, delegate: RegistryCreatorOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_admin_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -435,8 +480,10 @@ pub mod pallet { /// - `registry_id`: The unique identifier of the registry from which the delegate is being /// removed. /// - `remove_authorization`: The authorization ID of the delegate to be removed. - /// - `authorization`: The authorization ID validating the caller’s permission to perform - /// the removal. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: The authorization ID validating the caller’s permission to + /// perform the removal. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the delegate was successfully removed, or an @@ -461,16 +508,30 @@ pub mod pallet { pub fn remove_delegate( origin: OriginFor, registry_id: RegistryIdOf, - remove_authorization: AuthorizationIdOf, - authorization: AuthorizationIdOf, + remove_authorization: RegistryAuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_admin_remove_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_remove_origin(®istry_authorization, &creator)?; // Ensure remover does not de-delagate themselves & // remover has valid authoirzation for this particular registry-id. - ensure!(authorization != remove_authorization, Error::::UnauthorizedOperation); + ensure!( + registry_authorization != remove_authorization, + Error::::UnauthorizedOperation + ); ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); // Ensure the authorization exists and retrieve its details. @@ -514,8 +575,9 @@ pub mod pallet { /// /// # Parameters /// - `origin`: The origin of the transaction, signed by the creator. - /// - `registry_id`: A unique code created to identify the registry. /// - `digest`: The digest representing the registry data to be created. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. /// - `schema_id`: (Optional) A unique code represnting the Schema. /// - `blob`: (Optional) Metadata or data associated with the registry. /// @@ -540,28 +602,25 @@ pub mod pallet { #[pallet::weight({0})] pub fn create( origin: OriginFor, - _registry_id: RegistryIdOf, digest: RegistryHashOf, + namespace_authorization: NamespaceAuthorizationIdOf, schema_id: Option, _blob: Option>, ) -> DispatchResult { let creator = ensure_signed(origin)?; - // TODO: Create the identifier at SDK level & validate at chain level. + let namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + // Id Digest = concat (H(, // )) let id_digest = ::Hashing::hash( &[&digest.encode()[..], &creator.encode()[..]].concat()[..], ); - // /* Ensure that registry_id is of valid ss58 format, - // * and also the type matches to be of `Registries`. - // */ - // ensure!( - // Self::is_valid_ss58_format(®istry_id), - // Error::::InvalidRegistryIdentifier - // ); - let identifier = Ss58Identifier::create_identifier( &id_digest.encode()[..], IdentifierType::Registries, @@ -612,10 +671,18 @@ pub mod pallet { revoked: false, archived: false, digest, + namespace_id: namespace_id.clone(), schema_id, }, ); + // Update the namespace with the newly added registry. + pallet_namespace::Pallet::::add_registry_id_to_namespace_details( + &namespace_id, + &identifier, + ) + .map_err(>::from)?; + Self::update_activity(&identifier, IdentifierTypeOf::Registries, CallTypeOf::Genesis) .map_err(Error::::from)?; @@ -639,8 +706,10 @@ pub mod pallet { /// - `origin`: The origin of the transaction, which must be signed by the creator or an /// admin with the appropriate authority. /// - `registry_id`: The identifier of the registry to be revoked. - /// - `authorization`: An identifier for the authorization being used to validate the - /// revocation. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: An identifier for the authorization being used to validate + /// the revocation. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the registry is successfully revoked, or an @@ -663,12 +732,22 @@ pub mod pallet { pub fn revoke( origin: OriginFor, registry_id: RegistryIdOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_admin_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -701,8 +780,10 @@ pub mod pallet { /// - `origin`: The origin of the transaction, which must be signed by the creator or an /// admin with the appropriate authority. /// - `registry_id`: The identifier of the registry to be reinstated. - /// - `authorization`: An identifier for the authorization being used to validate the - /// reinstatement. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: An identifier for the authorization being used to validate + /// the reinstatement. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the registry is successfully reinstated, or an @@ -725,12 +806,22 @@ pub mod pallet { pub fn reinstate( origin: OriginFor, registry_id: RegistryIdOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_reinstate_origin(&authorization, &creator)?; + Self::ensure_authorization_reinstate_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -770,8 +861,10 @@ pub mod pallet { /// - `digest`: The new digest (hash) to be assigned to the registry. /// - `blob`: An optional new blob (data) to be assigned to the registry. If `None`, the /// existing blob remains unchanged. - /// - `authorization`: An identifier for the authorization being used to validate the - /// update. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: An identifier for the authorization being used to validate + /// the update. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the registry is successfully updated, or an @@ -787,6 +880,8 @@ pub mod pallet { /// # Events /// - `Update`: Emitted when a registry is successfully updated. It includes the registry /// ID, the updater, and the authorization used. + /// TODO: + /// Move optional parameter as last argument. #[pallet::call_index(8)] #[pallet::weight({0})] pub fn update( @@ -794,15 +889,25 @@ pub mod pallet { registry_id: RegistryIdOf, digest: RegistryHashOf, _blob: Option>, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let mut registry = RegistryInfo::::get(®istry_id).ok_or(Error::::RegistryNotFound)?; let auth_registry_id = - Self::ensure_authorization_admin_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); registry.digest = digest; @@ -815,7 +920,7 @@ pub mod pallet { Self::deposit_event(Event::Update { registry_id: registry_id.clone(), updater: creator, - authorization, + authorization: registry_authorization, }); Ok(()) @@ -832,8 +937,10 @@ pub mod pallet { /// - `origin`: The origin of the transaction, which must be signed by the creator or an /// admin with the appropriate authority. /// - `registry_id`: The identifier of the registry to be archived. - /// - `authorization`: An identifier for the authorization being used to validate the - /// archival. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: An identifier for the authorization being used to validate + /// the archival. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the registry is successfully archived, or an @@ -856,12 +963,22 @@ pub mod pallet { pub fn archive( origin: OriginFor, registry_id: RegistryIdOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_admin_origin(&authorization, &creator)?; + Self::ensure_authorization_admin_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -894,8 +1011,10 @@ pub mod pallet { /// - `origin`: The origin of the transaction, which must be signed by the creator or an /// admin with the appropriate authority. /// - `registry_id`: The identifier of the registry to be restored. - /// - `authorization`: An identifier for the authorization being used to validate the - /// restoration. + /// - `namespace_authorization`: The Namespace authorization ID used to validate the + /// caller's permission inside a namespace. + /// - `registry_authorization`: An identifier for the authorization being used to validate + /// the restoration. /// /// # Returns /// - `DispatchResult`: Returns `Ok(())` if the registry is successfully restored, or an @@ -918,12 +1037,22 @@ pub mod pallet { pub fn restore( origin: OriginFor, registry_id: RegistryIdOf, - authorization: AuthorizationIdOf, + namespace_authorization: NamespaceAuthorizationIdOf, + registry_authorization: RegistryAuthorizationIdOf, ) -> DispatchResult { let creator = ensure_signed(origin)?; + // Verify Namespace Authorization + // TODO: Revist where admin permission of namespace is required. + // For now keeping everything under normal `ASSERT` permission. + let _namespace_id = pallet_namespace::Pallet::::ensure_authorization_origin( + &namespace_authorization, + &creator, + ) + .map_err(>::from)?; + let auth_registry_id = - Self::ensure_authorization_restore_origin(&authorization, &creator)?; + Self::ensure_authorization_restore_origin(®istry_authorization, &creator)?; ensure!(auth_registry_id == registry_id, Error::::UnauthorizedOperation); @@ -1024,7 +1153,7 @@ impl Pallet { /// This function checks if the provided delegate is associated with the /// given authorization ID and has the 'ASSERT' permission. pub fn ensure_authorization_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1045,7 +1174,7 @@ impl Pallet { /// given authorization ID and has the 'ADMIN' permission. /// This asserts for delegates authorization has the permission to reinstate. pub fn ensure_authorization_reinstate_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1067,7 +1196,7 @@ impl Pallet { /// given authorization ID and has the 'ADMIN' permission. /// This asserts for delegates authorization has the permission to restore. pub fn ensure_authorization_restore_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1089,7 +1218,7 @@ impl Pallet { /// the registry by checking the 'ADMIN' permission within the authorization /// tied to the provided authorization ID. pub fn ensure_authorization_admin_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1112,7 +1241,7 @@ impl Pallet { /// that authorization is allowed to perform audit operations. It also /// increments usage and validates the registry for transactions. pub fn ensure_authorization_delegator_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1137,7 +1266,7 @@ impl Pallet { /// the registry by checking the 'ADMIN' permission within the authorization /// tied to the provided authorization ID. pub fn ensure_authorization_admin_remove_origin( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> Result> { let d = @@ -1242,7 +1371,7 @@ impl Pallet { /// } /// ``` pub fn is_admin_authorization( - authorization_id: &AuthorizationIdOf, + authorization_id: &RegistryAuthorizationIdOf, delegate: &RegistryCreatorOf, ) -> bool { if let Some(auth) = >::get(authorization_id) { @@ -1284,23 +1413,4 @@ impl Pallet { index: frame_system::Pallet::::extrinsic_index().unwrap_or_default(), } } - - /// Method to check if the input identifier calculated from sdk - /// is actually a valid SS58 Identifier Format and of valid type `Registries`. - pub fn is_valid_ss58_format(identifier: &Ss58Identifier) -> bool { - match identifier.get_type() { - Ok(id_type) => - if id_type == IdentifierType::Registries { - log::debug!("The SS58 identifier is of type Registries."); - true - } else { - log::debug!("The SS58 identifier is not of type Registries."); - false - }, - Err(e) => { - log::debug!("Invalid SS58 identifier. Error: {:?}", e); - false - }, - } - } } diff --git a/pallets/registries/src/mock.rs b/pallets/registries/src/mock.rs index 0f31711a6..43fd50f6e 100644 --- a/pallets/registries/src/mock.rs +++ b/pallets/registries/src/mock.rs @@ -20,6 +20,8 @@ use crate as pallet_registries; use cord_utilities::mock::{mock_origin, SubjectId}; use frame_support::{derive_impl, parameter_types}; +use frame_system::EnsureRoot; +use pallet_namespace::IsPermissioned; use sp_runtime::{ traits::{IdentifyAccount, IdentityLookup, Verify}, BuildStorage, MultiSignature, @@ -34,6 +36,7 @@ frame_support::construct_runtime!( pub enum Test { System: frame_system, SchemaAccounts: pallet_schema_accounts, + NameSpace: pallet_namespace, Registries: pallet_registries, Identifier: identifier, MockOrigin: mock_origin, @@ -64,6 +67,28 @@ parameter_types! { pub const MaxEncodedSchemaLength: u32 = 15_360; } +pub struct NetworkPermission; +impl IsPermissioned for NetworkPermission { + fn is_permissioned() -> bool { + true + } +} + +parameter_types! { + #[derive(Debug, Clone)] + pub const MaxNameSpaceDelegates: u32 = 5u32; + pub const MaxNameSpaceBlobSize: u32 = 4u32 * 1024; +} + +impl pallet_namespace::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkPermission; + type MaxNameSpaceDelegates = MaxNameSpaceDelegates; + type MaxNameSpaceBlobSize = MaxNameSpaceBlobSize; + type WeightInfo = (); +} + impl pallet_schema_accounts::Config for Test { type RuntimeEvent = RuntimeEvent; type MaxEncodedSchemaLength = MaxEncodedSchemaLength; diff --git a/pallets/registries/src/tests.rs b/pallets/registries/src/tests.rs index b611138bf..394990e6b 100644 --- a/pallets/registries/src/tests.rs +++ b/pallets/registries/src/tests.rs @@ -2,6 +2,7 @@ use super::*; use crate::mock::*; use codec::Encode; use frame_support::{assert_err, assert_ok}; +use pallet_namespace::{NameSpaceCodeOf, NameSpaceIdOf}; use pallet_schema_accounts::{InputSchemaOf, SchemaHashOf}; use sp_runtime::traits::Hash; use sp_std::prelude::*; @@ -10,7 +11,9 @@ pub fn generate_registry_id(digest: &RegistryHashOf) -> RegistryId Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Registries).unwrap() } -pub fn generate_authorization_id(digest: &RegistryHashOf) -> AuthorizationIdOf { +pub fn generate_authorization_id( + digest: &RegistryHashOf, +) -> RegistryAuthorizationIdOf { Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::RegistryAuthorization) .unwrap() } @@ -20,6 +23,20 @@ pub fn generate_schema_id(digest: &SchemaHashOf) -> SchemaIdOf { .unwrap() } +pub fn generate_namespace_id(digest: &NameSpaceCodeOf) -> NameSpaceIdOf { + Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap() +} + +pub fn generate_namespace_authorization_id( + digest: &NameSpaceCodeOf, +) -> NamespaceAuthorizationIdOf { + Ss58Identifier::create_identifier( + &(digest).encode()[..], + IdentifierType::NameSpaceAuthorization, + ) + .unwrap() +} + pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]); pub(crate) const ACCOUNT_01: AccountId = AccountId::new([2u8; 32]); pub(crate) const ACCOUNT_02: AccountId = AccountId::new([3u8; 32]); @@ -28,6 +45,21 @@ pub(crate) const ACCOUNT_02: AccountId = AccountId::new([3u8; 32]); fn add_delegate_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -46,7 +78,8 @@ fn add_delegate_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -56,10 +89,16 @@ fn add_delegate_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -69,6 +108,7 @@ fn add_delegate_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -78,6 +118,21 @@ fn add_delegate_should_succeed() { fn add_admin_delegate_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -96,7 +151,8 @@ fn add_admin_delegate_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -106,10 +162,16 @@ fn add_admin_delegate_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -119,6 +181,7 @@ fn add_admin_delegate_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, )); }); @@ -128,6 +191,21 @@ fn add_admin_delegate_should_succeed() { fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -146,7 +224,8 @@ fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -156,10 +235,16 @@ fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -169,6 +254,7 @@ fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -177,6 +263,7 @@ fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::DelegateAlreadyAdded @@ -188,6 +275,21 @@ fn add_admin_delegate_should_fail_if_admin_delegate_already_exists() { fn add_delegator_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -206,7 +308,8 @@ fn add_delegator_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -216,10 +319,16 @@ fn add_delegator_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -228,6 +337,7 @@ fn add_delegator_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, )); }); @@ -237,6 +347,21 @@ fn add_delegator_should_succeed() { fn add_delegator_should_fail_if_delegator_already_exists() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -255,7 +380,8 @@ fn add_delegator_should_fail_if_delegator_already_exists() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -265,10 +391,16 @@ fn add_delegator_should_fail_if_delegator_already_exists() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -277,6 +409,7 @@ fn add_delegator_should_fail_if_delegator_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -285,6 +418,7 @@ fn add_delegator_should_fail_if_delegator_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::DelegateAlreadyAdded @@ -296,6 +430,21 @@ fn add_delegator_should_fail_if_delegator_already_exists() { fn add_delegate_should_fail_if_registries_is_not_created() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let registry_digest = ::Hashing::hash(®istry.encode()[..]); @@ -310,14 +459,22 @@ fn add_delegate_should_fail_if_registries_is_not_created() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + //Should throw Error if registry is not created or found assert_err!( Registries::add_delegate( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::AuthorizationNotFound @@ -329,6 +486,21 @@ fn add_delegate_should_fail_if_registries_is_not_created() { fn add_admin_delegate_should_fail_if_registries_is_not_created() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let registry_digest = ::Hashing::hash(®istry.encode()[..]); @@ -343,14 +515,22 @@ fn add_admin_delegate_should_fail_if_registries_is_not_created() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + //Should throw Error if registry is not created or found assert_err!( Registries::add_admin_delegate( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::AuthorizationNotFound @@ -362,6 +542,21 @@ fn add_admin_delegate_should_fail_if_registries_is_not_created() { fn add_delegator_should_fail_if_registries_is_not_created() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let registry_digest = ::Hashing::hash(®istry.encode()[..]); @@ -376,14 +571,22 @@ fn add_delegator_should_fail_if_registries_is_not_created() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + //Should throw Error if registry is not created or found assert_err!( Registries::add_delegator( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::AuthorizationNotFound @@ -395,6 +598,21 @@ fn add_delegator_should_fail_if_registries_is_not_created() { fn add_delegate_should_fail_if_the_regisrty_is_revoked() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -413,7 +631,8 @@ fn add_delegate_should_fail_if_the_regisrty_is_revoked() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -423,10 +642,16 @@ fn add_delegate_should_fail_if_the_regisrty_is_revoked() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -434,6 +659,7 @@ fn add_delegate_should_fail_if_the_regisrty_is_revoked() { assert_ok!(Registries::revoke( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -442,6 +668,7 @@ fn add_delegate_should_fail_if_the_regisrty_is_revoked() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id, delegate, + namespace_authorization_id.clone(), authorization_id, ), Error::::RegistryRevoked @@ -454,6 +681,27 @@ fn add_delegate_should_fail_if_a_non_delegate_tries_to_add() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; let creator1 = ACCOUNT_02; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let namespace_auth_id_digest_2 = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator1.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id_2: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest_2); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -472,7 +720,8 @@ fn add_delegate_should_fail_if_a_non_delegate_tries_to_add() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -482,10 +731,23 @@ fn add_delegate_should_fail_if_a_non_delegate_tries_to_add() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(NameSpace::add_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_id, + creator1.clone(), + namespace_authorization_id.clone(), + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -495,6 +757,7 @@ fn add_delegate_should_fail_if_a_non_delegate_tries_to_add() { frame_system::RawOrigin::Signed(creator1.clone()).into(), registry_id, delegate, + namespace_authorization_id_2.clone(), authorization_id, ), Error::::UnauthorizedOperation @@ -506,6 +769,21 @@ fn add_delegate_should_fail_if_a_non_delegate_tries_to_add() { fn add_delegate_should_fail_if_delegate_already_exists() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -524,7 +802,8 @@ fn add_delegate_should_fail_if_delegate_already_exists() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -534,10 +813,16 @@ fn add_delegate_should_fail_if_delegate_already_exists() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob) )); @@ -546,6 +831,7 @@ fn add_delegate_should_fail_if_delegate_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -554,6 +840,7 @@ fn add_delegate_should_fail_if_delegate_already_exists() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::DelegateAlreadyAdded @@ -564,6 +851,21 @@ fn add_delegate_should_fail_if_delegate_already_exists() { #[test] fn creating_a_new_registries_should_succeed() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -572,12 +874,6 @@ fn creating_a_new_registries_should_succeed() { let registry_digest = ::Hashing::hash(®istry.encode()[..]); - let id_digest = ::Hashing::hash( - &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], - ); - - let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); - let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) .expect("Test Schema should fit into the expected input length of for the test runtime."); @@ -586,10 +882,16 @@ fn creating_a_new_registries_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob), )); @@ -599,6 +901,21 @@ fn creating_a_new_registries_should_succeed() { #[test] fn creating_a_duplicate_registries_should_fail() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -607,12 +924,6 @@ fn creating_a_duplicate_registries_should_fail() { let registry_digest = ::Hashing::hash(®istry.encode()[..]); - let id_digest = ::Hashing::hash( - &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], - ); - - let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); - let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) .expect("Test Schema should fit into the expected input length of for the test runtime."); @@ -621,10 +932,16 @@ fn creating_a_duplicate_registries_should_fail() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -632,8 +949,8 @@ fn creating_a_duplicate_registries_should_fail() { assert_err!( Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), None, Some(blob), ), @@ -645,6 +962,21 @@ fn creating_a_duplicate_registries_should_fail() { #[test] fn revoking_a_registry_should_succeed() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -663,7 +995,8 @@ fn revoking_a_registry_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -673,10 +1006,16 @@ fn revoking_a_registry_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -684,6 +1023,7 @@ fn revoking_a_registry_should_succeed() { assert_ok!(Registries::revoke( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -693,6 +1033,21 @@ fn revoking_a_registry_should_succeed() { fn reinstating_an_revoked_a_registry_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -711,7 +1066,8 @@ fn reinstating_an_revoked_a_registry_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -721,10 +1077,16 @@ fn reinstating_an_revoked_a_registry_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -732,12 +1094,14 @@ fn reinstating_an_revoked_a_registry_should_succeed() { assert_ok!(Registries::revoke( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); assert_ok!(Registries::reinstate( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -745,6 +1109,7 @@ fn reinstating_an_revoked_a_registry_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -753,6 +1118,21 @@ fn reinstating_an_revoked_a_registry_should_succeed() { #[test] fn reinstating_an_non_revoked_a_registry_should_fail() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -771,7 +1151,8 @@ fn reinstating_an_non_revoked_a_registry_should_fail() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -781,10 +1162,16 @@ fn reinstating_an_non_revoked_a_registry_should_fail() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -793,6 +1180,7 @@ fn reinstating_an_non_revoked_a_registry_should_fail() { Registries::reinstate( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::RegistryNotRevoked @@ -803,6 +1191,21 @@ fn reinstating_an_non_revoked_a_registry_should_fail() { #[test] fn archiving_a_registry_should_succeed() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -821,7 +1224,8 @@ fn archiving_a_registry_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -831,10 +1235,15 @@ fn archiving_a_registry_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -842,6 +1251,7 @@ fn archiving_a_registry_should_succeed() { assert_ok!(Registries::archive( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -851,6 +1261,21 @@ fn archiving_a_registry_should_succeed() { fn restoring_an_archived_a_registry_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -869,7 +1294,8 @@ fn restoring_an_archived_a_registry_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -879,10 +1305,15 @@ fn restoring_an_archived_a_registry_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -890,12 +1321,14 @@ fn restoring_an_archived_a_registry_should_succeed() { assert_ok!(Registries::archive( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); assert_ok!(Registries::restore( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -903,6 +1336,7 @@ fn restoring_an_archived_a_registry_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -911,6 +1345,21 @@ fn restoring_an_archived_a_registry_should_succeed() { #[test] fn restoring_an_non_archived_a_registry_should_fail() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -929,7 +1378,8 @@ fn restoring_an_non_archived_a_registry_should_fail() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -939,10 +1389,16 @@ fn restoring_an_non_archived_a_registry_should_fail() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -951,6 +1407,7 @@ fn restoring_an_non_archived_a_registry_should_fail() { Registries::restore( frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::RegistryNotArchived @@ -961,6 +1418,21 @@ fn restoring_an_non_archived_a_registry_should_fail() { #[test] fn registry_delegation_should_fail_if_registry_delegates_limit_exceeded() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -983,11 +1455,17 @@ fn registry_delegation_should_fail_if_registry_delegates_limit_exceeded() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + // Create the Registries assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1020,6 +1498,21 @@ fn registry_delegation_should_fail_if_registry_delegates_limit_exceeded() { fn remove_delegate_should_succeed() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1038,13 +1531,14 @@ fn remove_delegate_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let delegate_auth_id_digest = ::Hashing::hash( &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], ); - let delegate_authorization_id: AuthorizationIdOf = + let delegate_authorization_id: RegistryAuthorizationIdOf = generate_authorization_id::(&delegate_auth_id_digest); let raw_schema = [2u8; 256].to_vec(); @@ -1055,10 +1549,16 @@ fn remove_delegate_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1067,6 +1567,7 @@ fn remove_delegate_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1074,6 +1575,7 @@ fn remove_delegate_should_succeed() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate_authorization_id, + namespace_authorization_id.clone(), authorization_id.clone(), )); }); @@ -1083,6 +1585,21 @@ fn remove_delegate_should_succeed() { fn remove_delegate_should_fail_for_creator_removing_themselves() { let creator = ACCOUNT_00; let delegate = ACCOUNT_01; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1101,7 +1618,8 @@ fn remove_delegate_should_fail_for_creator_removing_themselves() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -1111,10 +1629,16 @@ fn remove_delegate_should_fail_for_creator_removing_themselves() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { - assert_ok!(Registries::create( + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1123,6 +1647,7 @@ fn remove_delegate_should_fail_for_creator_removing_themselves() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1131,6 +1656,7 @@ fn remove_delegate_should_fail_for_creator_removing_themselves() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), authorization_id.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::UnauthorizedOperation @@ -1141,6 +1667,21 @@ fn remove_delegate_should_fail_for_creator_removing_themselves() { #[test] fn update_registry_should_succeed() { let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let new_digest = ::Hashing::hash(&[3u8; 256].to_vec().encode()[..]); @@ -1165,7 +1706,8 @@ fn update_registry_should_succeed() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -1175,10 +1717,16 @@ fn update_registry_should_succeed() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(initial_blob), )); @@ -1188,6 +1736,7 @@ fn update_registry_should_succeed() { registry_id.clone(), new_digest, Some(new_blob.clone()), + namespace_authorization_id.clone(), authorization_id.clone(), )); @@ -1216,6 +1765,20 @@ fn add_delegate_should_fail_if_registry_delegates_limit_exceeded() { let delegate_5: AccountId = AccountId::new([6u8; 32]); let registry = [2u8; 256].to_vec(); + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let raw_blob = [2u8; 256].to_vec(); let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) .expect("Test blob should fit into the expected input length of for the test runtime."); @@ -1232,7 +1795,8 @@ fn add_delegate_should_fail_if_registry_delegates_limit_exceeded() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -1242,11 +1806,17 @@ fn add_delegate_should_fail_if_registry_delegates_limit_exceeded() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + // Create the Registries assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1258,6 +1828,7 @@ fn add_delegate_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); } @@ -1269,6 +1840,7 @@ fn add_delegate_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate_5.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::RegistryDelegatesLimitExceeded @@ -1284,6 +1856,21 @@ fn add_admin_delegate_should_fail_if_registry_delegates_limit_exceeded() { let delegate_3: AccountId = AccountId::new([4u8; 32]); let delegate_4: AccountId = AccountId::new([5u8; 32]); let delegate_5: AccountId = AccountId::new([6u8; 32]); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1302,7 +1889,8 @@ fn add_admin_delegate_should_fail_if_registry_delegates_limit_exceeded() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -1312,11 +1900,17 @@ fn add_admin_delegate_should_fail_if_registry_delegates_limit_exceeded() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + // Create the Registries assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1328,6 +1922,7 @@ fn add_admin_delegate_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); } @@ -1339,6 +1934,7 @@ fn add_admin_delegate_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate_5.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::RegistryDelegatesLimitExceeded @@ -1354,6 +1950,21 @@ fn add_delegator_should_fail_if_registry_delegates_limit_exceeded() { let delegate_3: AccountId = AccountId::new([4u8; 32]); let delegate_4: AccountId = AccountId::new([5u8; 32]); let delegate_5: AccountId = AccountId::new([6u8; 32]); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + let registry = [2u8; 256].to_vec(); let raw_blob = [2u8; 256].to_vec(); @@ -1372,7 +1983,8 @@ fn add_delegator_should_fail_if_registry_delegates_limit_exceeded() { &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], ); - let authorization_id: AuthorizationIdOf = generate_authorization_id::(&auth_id_digest); + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); let raw_schema = [2u8; 256].to_vec(); let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) @@ -1382,11 +1994,17 @@ fn add_delegator_should_fail_if_registry_delegates_limit_exceeded() { let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + // Create the Registries assert_ok!(Registries::create( frame_system::RawOrigin::Signed(creator.clone()).into(), - registry_id.clone(), registry_digest, + namespace_authorization_id.clone(), Some(schema_id), Some(blob.clone()), )); @@ -1398,6 +2016,7 @@ fn add_delegator_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), )); } @@ -1409,9 +2028,966 @@ fn add_delegator_should_fail_if_registry_delegates_limit_exceeded() { frame_system::RawOrigin::Signed(creator.clone()).into(), registry_id.clone(), delegate_5.clone(), + namespace_authorization_id.clone(), authorization_id.clone(), ), Error::::RegistryDelegatesLimitExceeded ); }); } + +#[test] +fn registry_id_should_be_updated_on_namespace_chainstorage_on_create() { + let creator = ACCOUNT_00; + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let registry = [2u8; 256].to_vec(); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length of for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let registry_2 = [3u8; 256].to_vec(); + + let raw_blob_2 = [3u8; 256].to_vec(); + let blob_2: RegistryBlobOf = BoundedVec::try_from(raw_blob_2) + .expect("Test blob should fit into the expected input length of for the test runtime."); + + let registry_digest_2 = ::Hashing::hash(®istry_2.encode()[..]); + + let id_digest_2 = ::Hashing::hash( + &[®istry_digest_2.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id_2: RegistryIdOf = generate_registry_id::(&id_digest_2); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length of for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + // Create Registry 1 + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id.clone()), + Some(blob) + )); + + // Create Registry 2 + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest_2, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob_2) + )); + + // Verify if the newly created registry-id is added as a list in the Namespace Chain + // Storage. + let name_space_details = pallet_namespace::NameSpaces::::get(namespace_id.clone()) + .ok_or(pallet_namespace::pallet::Error::::NameSpaceNotFound) + .unwrap(); + assert!( + name_space_details + .registry_ids + .clone() + .unwrap_or_default() + .contains(®istry_id), + "Registry ID 1 not found in the Namespace Chain Storage." + ); + assert!( + name_space_details.registry_ids.unwrap_or_default().contains(®istry_id_2), + "Registry ID 2 not found in the Namespace Chain Storage." + ); + + // Verify if the newly created registry-id 1 is present in the Registry Chain Storage. + let registry_info = RegistryInfo::::get(®istry_id) + .ok_or(Error::::RegistryNotFound) + .unwrap(); + assert_eq!( + registry_info.namespace_id, namespace_id, + "Namespace ID not found in the Registry 1 Chain Storage." + ); + + // Verify if the newly created registry-id 2 is present in the Registry Chain Storage. + let registry_info = RegistryInfo::::get(®istry_id_2) + .ok_or(Error::::RegistryNotFound) + .unwrap(); + assert_eq!( + registry_info.namespace_id, namespace_id, + "Namespace ID not found in the Registry 2 Chain Storage." + ); + }); +} + +#[test] +fn remove_delegate_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let delegate_auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let delegate_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&delegate_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_ok!(Registries::add_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + delegate.clone(), + namespace_authorization_id.clone(), + authorization_id.clone(), + )); + + assert_err!( + Registries::remove_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + delegate_authorization_id, + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn remove_delegate_should_fail_if_remove_authorization_is_not_found_as_delegate_not_added() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); + + let delegate_auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let delegate_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&delegate_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_err!( + Registries::remove_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + delegate_authorization_id, + namespace_authorization_id.clone(), + authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn remove_delegate_should_fail_if_remove_authorization_is_not_found_as_non_existant_auth_id_entered( +) { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_ok!(Registries::add_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + delegate.clone(), + namespace_authorization_id.clone(), + authorization_id.clone(), + )); + + assert_err!( + Registries::remove_delegate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + non_existent_authorization_id, + namespace_authorization_id.clone(), + authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn revoke_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_err!( + Registries::revoke( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn reinstate_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_ok!(Registries::revoke( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + authorization_id.clone(), + )); + + assert_err!( + Registries::reinstate( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn update_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let new_digest = + ::Hashing::hash(&[3u8; 256].to_vec().encode()[..]); + + let raw_blob = [2u8; 256].to_vec(); + let initial_blob: RegistryBlobOf = BoundedVec::try_from(raw_blob.clone()) + .expect("Test Blob should fit into the expected input length for the test runtime."); + + let new_raw_blob = [4u8; 256].to_vec(); + let new_blob: RegistryBlobOf = BoundedVec::try_from(new_raw_blob.clone()) + .expect("New Test Blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(initial_blob), + )); + + assert_err!( + Registries::update( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + new_digest, + Some(new_blob.clone()), + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn archive_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_err!( + Registries::archive( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn restore_should_fail_if_admin_authorization_is_not_found() { + let creator = ACCOUNT_00; + let registry = [2u8; 256].to_vec(); + + let namespace = [2u8; 256].to_vec(); + let namespace_digest = ::Hashing::hash(&namespace.encode()[..]); + + let id_digest = ::Hashing::hash( + &[&namespace_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_id: NameSpaceIdOf = generate_namespace_id::(&id_digest); + + let namespace_auth_id_digest = ::Hashing::hash( + &[&namespace_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + let namespace_authorization_id: NamespaceAuthorizationIdOf = + generate_namespace_authorization_id::(&namespace_auth_id_digest); + + let raw_blob = [2u8; 256].to_vec(); + let blob: RegistryBlobOf = BoundedVec::try_from(raw_blob) + .expect("Test blob should fit into the expected input length for the test runtime."); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let auth_id_digest = ::Hashing::hash( + &[®istry_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&auth_id_digest); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + let raw_schema = [2u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length for the test runtime."); + let _digest: SchemaHashOf = ::Hashing::hash(&schema[..]); + let schema_id_digest = ::Hashing::hash(&schema.encode()[..]); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(NameSpace::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + namespace_digest, + None, + )); + + assert_ok!(Registries::create( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_digest, + namespace_authorization_id.clone(), + Some(schema_id), + Some(blob.clone()), + )); + + assert_ok!(Registries::archive( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + authorization_id.clone(), + )); + + assert_err!( + Registries::restore( + frame_system::RawOrigin::Signed(creator.clone()).into(), + registry_id.clone(), + namespace_authorization_id.clone(), + non_existent_authorization_id.clone(), + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_origin(&non_existent_authorization_id, &delegate), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_reinstate_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_reinstate_origin( + &non_existent_authorization_id, + &delegate + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_restore_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_restore_origin( + &non_existent_authorization_id, + &delegate + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_admin_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_admin_origin( + &non_existent_authorization_id, + &delegate + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_delegator_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_delegator_origin( + &non_existent_authorization_id, + &delegate + ), + Error::::AuthorizationNotFound + ); + }); +} + +#[test] +fn ensure_authorization_admin_remove_origin_should_fail_if_authorization_is_not_found() { + let creator = ACCOUNT_00; + let delegate = ACCOUNT_01; + let registry = [2u8; 256].to_vec(); + + let registry_digest = ::Hashing::hash(®istry.encode()[..]); + + let id_digest = ::Hashing::hash( + &[®istry_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + + let registry_id: RegistryIdOf = generate_registry_id::(&id_digest); + + let non_existent_auth_id_digest = + ::Hashing::hash(®istry_id.encode()[..]); + + let non_existent_authorization_id: RegistryAuthorizationIdOf = + generate_authorization_id::(&non_existent_auth_id_digest); + + new_test_ext().execute_with(|| { + assert_err!( + Registries::ensure_authorization_admin_remove_origin( + &non_existent_authorization_id, + &delegate + ), + Error::::AuthorizationNotFound + ); + }); +} diff --git a/pallets/registries/src/types.rs b/pallets/registries/src/types.rs index 37c66a9e6..fdcb25be1 100644 --- a/pallets/registries/src/types.rs +++ b/pallets/registries/src/types.rs @@ -75,11 +75,12 @@ impl Default for Permissions { /// - `digest`: A hash representing unique content or metadata of the registry. /// - `schema_id`: (Optional) Identifier linking the registry to a specific schema. #[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub struct RegistryDetails { +pub struct RegistryDetails { pub creator: RegistryCreatorOf, pub revoked: StatusOf, pub archived: StatusOf, pub digest: RegistryHashOf, + pub namespace_id: NameSpaceIdOf, pub schema_id: Option, } diff --git a/pallets/schema/src/lib.rs b/pallets/schema/src/lib.rs index 13e94386e..4ae7dc3ed 100644 --- a/pallets/schema/src/lib.rs +++ b/pallets/schema/src/lib.rs @@ -131,6 +131,7 @@ pub mod pallet { } #[pallet::error] + #[derive(PartialEq)] pub enum Error { /// Schema identifier is not unique. SchemaAlreadyAnchored, diff --git a/pallets/schema/src/tests.rs b/pallets/schema/src/tests.rs index e0db0451f..c10c9c504 100644 --- a/pallets/schema/src/tests.rs +++ b/pallets/schema/src/tests.rs @@ -20,7 +20,7 @@ use super::*; use crate::mock::*; use codec::Encode; use cord_utilities::mock::{mock_origin::DoubleOrigin, SubjectId}; -use frame_support::{assert_noop, assert_ok, BoundedVec}; +use frame_support::{assert_err, assert_noop, assert_ok, BoundedVec}; use frame_system::RawOrigin; use sp_core::H256; use sp_runtime::{traits::Hash, AccountId32}; @@ -314,3 +314,35 @@ fn test_schema_lookup() { } }); } +#[test] +fn check_schema_not_found() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 3u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let raw_schema = [3u8; 256].to_vec(); + let schema: InputSchemaOf = BoundedVec::try_from(raw_schema) + .expect("Test Schema should fit into the expected input length of for the test runtime."); + let schema_id_digest = ::Hashing::hash( + &[&schema.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + ); + let schema_id: SchemaIdOf = generate_schema_id::(&schema_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + space_digest, + )); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_err!(Schema::is_valid(&schema_id), Error::::SchemaNotFound); + }); +} diff --git a/primitives/identifier/src/curi.rs b/primitives/identifier/src/curi.rs index dfa301c10..776e2d709 100644 --- a/primitives/identifier/src/curi.rs +++ b/primitives/identifier/src/curi.rs @@ -46,6 +46,8 @@ pub enum IdentifierType { Entries, RegistryAuthorization, SchemaAccounts, + NameSpace, + NameSpaceAuthorization, } impl IdentifierType { @@ -62,6 +64,8 @@ impl IdentifierType { const IDENT_ENTRIES: u16 = 9944; const IDENT_REGISTRYAUTH: u16 = 10001; const IDENT_SCHEMA_ACCOUNTS: u16 = 10501; + const IDENT_NAMESPACE: u16 = 12501; + const IDENT_NAMESPACE_AUTH: u16 = 13101; fn ident_value(&self) -> u16 { match self { @@ -78,6 +82,8 @@ impl IdentifierType { IdentifierType::Entries => Self::IDENT_ENTRIES, IdentifierType::RegistryAuthorization => Self::IDENT_REGISTRYAUTH, IdentifierType::SchemaAccounts => Self::IDENT_SCHEMA_ACCOUNTS, + IdentifierType::NameSpace => Self::IDENT_NAMESPACE, + IdentifierType::NameSpaceAuthorization => Self::IDENT_NAMESPACE_AUTH, } } fn from_u16(value: u16) -> Option { @@ -95,6 +101,8 @@ impl IdentifierType { 9944 => Some(IdentifierType::Entries), 10001 => Some(IdentifierType::RegistryAuthorization), 10501 => Some(IdentifierType::SchemaAccounts), + 12501 => Some(IdentifierType::NameSpace), + 13101 => Some(IdentifierType::NameSpaceAuthorization), _ => None, } } diff --git a/primitives/identifier/src/types.rs b/primitives/identifier/src/types.rs index 8db4c9c8d..de616a087 100644 --- a/primitives/identifier/src/types.rs +++ b/primitives/identifier/src/types.rs @@ -85,4 +85,6 @@ pub enum IdentifierTypeOf { Entries, RegistryAuthorization, SchemaAccounts, + NameSpace, + NameSpaceAuthorization, } diff --git a/runtimes/braid/Cargo.toml b/runtimes/braid/Cargo.toml index 49dbd95c0..9e25d77ac 100644 --- a/runtimes/braid/Cargo.toml +++ b/runtimes/braid/Cargo.toml @@ -55,6 +55,7 @@ pallet-cord-session-benchmarking = { workspace = true } pallet-registries = { workspace = true } pallet-entries = { workspace = true } pallet-schema-accounts = { workspace = true } +pallet-namespace = { workspace = true } # Internal runtime API (with default disabled) pallet-did-runtime-api = { workspace = true } @@ -188,6 +189,7 @@ std = [ "pallet-registries/std", "pallet-entries/std", "pallet-schema-accounts/std", + "pallet-namespace/std", "pallet-network-score/std", "pallet-network-membership/std", "pallet-runtime-upgrade/std", @@ -244,6 +246,7 @@ runtime-benchmarks = [ "pallet-schema/runtime-benchmarks", "pallet-cord-statement/runtime-benchmarks", "pallet-chain-space/runtime-benchmarks", + "pallet-namespace/runtime-benchmarks", "pallet-network-membership/runtime-benchmarks", "hex-literal", "pallet-sudo/runtime-benchmarks", @@ -288,6 +291,7 @@ try-runtime = [ "pallet-schema/try-runtime", "pallet-chain-space/try-runtime", "pallet-cord-statement/try-runtime", + "pallet-namespace/try-runtime", "pallet-did/try-runtime", "pallet-did-name/try-runtime", "pallet-network-score/try-runtime", diff --git a/runtimes/braid/src/lib.rs b/runtimes/braid/src/lib.rs index 8c70412d0..7b39c5af9 100644 --- a/runtimes/braid/src/lib.rs +++ b/runtimes/braid/src/lib.rs @@ -820,6 +820,20 @@ parameter_types! { pub const MaxRegistryDelegates: u32 = 10_000; } +parameter_types! { + pub const MaxNameSpaceDelegates: u32 = 10_000; + pub const MaxNameSpaceBlobSize: u32 = 4 * 1024; +} + +impl pallet_namespace::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkInfo; + type MaxNameSpaceDelegates = MaxNameSpaceDelegates; + type MaxNameSpaceBlobSize = MaxNameSpaceBlobSize; + type WeightInfo = (); +} + impl pallet_registries::Config for Runtime { type RuntimeEvent = RuntimeEvent; type MaxRegistryDelegates = MaxRegistryDelegates; @@ -1081,6 +1095,9 @@ mod runtime { #[runtime::pallet_index(77)] pub type NetworkScore = pallet_network_score::Pallet; + #[runtime::pallet_index(78)] + pub type NameSpace = pallet_namespace::Pallet; + #[runtime::pallet_index(80)] pub type NetworkInfo = pallet_config::Pallet; diff --git a/runtimes/common/api/identifier/Cargo.toml b/runtimes/common/api/identifier/Cargo.toml index d738e5d11..93d47399f 100644 --- a/runtimes/common/api/identifier/Cargo.toml +++ b/runtimes/common/api/identifier/Cargo.toml @@ -15,10 +15,7 @@ workspace = true # External dependencies codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -# serde = { optional = true, features = ["alloc", "derive"], workspace = true } -# Internal dependencies -# cord-uri = { workspace = true, default-features = true } # Substrate sp-api = { workspace = true } @@ -33,8 +30,5 @@ std = [ "frame-system/std", "codec/std", "sp-api/std", - # "sp-std/std", - # "serde/std", "scale-info/std", - # "cord-uri/std", ] diff --git a/runtimes/loom/Cargo.toml b/runtimes/loom/Cargo.toml index c86750d68..51e06bff2 100644 --- a/runtimes/loom/Cargo.toml +++ b/runtimes/loom/Cargo.toml @@ -46,6 +46,7 @@ pallet-schema = { workspace = true } pallet-config = { workspace = true } pallet-chain-space = { workspace = true } pallet-cord-statement = { workspace = true } +pallet-namespace = { workspace = true } pallet-network-membership = { workspace = true } pallet-runtime-upgrade = { workspace = true } pallet-cord-identity = { workspace = true } @@ -194,6 +195,7 @@ std = [ "pallet-schema/std", "pallet-chain-space/std", "pallet-cord-statement/std", + "pallet-namespace/std", "pallet-network-score/std", "pallet-network-membership/std", "pallet-runtime-upgrade/std", @@ -255,6 +257,7 @@ runtime-benchmarks = [ "pallet-schema/runtime-benchmarks", "pallet-cord-statement/runtime-benchmarks", "pallet-chain-space/runtime-benchmarks", + "pallet-namespace/runtime-benchmarks", "pallet-network-membership/runtime-benchmarks", "hex-literal", "pallet-sudo/runtime-benchmarks", @@ -304,6 +307,7 @@ try-runtime = [ "pallet-schema/try-runtime", "pallet-chain-space/try-runtime", "pallet-cord-statement/try-runtime", + "pallet-namespace/try-runtime", "pallet-did/try-runtime", "pallet-did-name/try-runtime", "pallet-network-score/try-runtime", diff --git a/runtimes/loom/src/lib.rs b/runtimes/loom/src/lib.rs index f8efcc55d..3ee12fbdf 100644 --- a/runtimes/loom/src/lib.rs +++ b/runtimes/loom/src/lib.rs @@ -971,6 +971,20 @@ impl pallet_chain_space::Config for Runtime { type WeightInfo = weights::pallet_chain_space::WeightInfo; } +parameter_types! { + pub const MaxNameSpaceDelegates: u32 = 10_000; + pub const MaxNameSpaceBlobSize: u32 = 4 * 1024; +} + +impl pallet_namespace::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkInfo; + type MaxNameSpaceDelegates = MaxNameSpaceDelegates; + type MaxNameSpaceBlobSize = MaxNameSpaceBlobSize; + type WeightInfo = (); +} + parameter_types! { pub const MaxRegistryBlobSize: u32 = 4 * 1024; pub const MaxEncodedInputLength: u32 = 30; @@ -1256,6 +1270,9 @@ mod runtime { #[runtime::pallet_index(77)] pub type NetworkScore = pallet_network_score::Pallet; + #[runtime::pallet_index(78)] + pub type NameSpace = pallet_namespace::Pallet; + #[runtime::pallet_index(80)] pub type NetworkInfo = pallet_config::Pallet; diff --git a/runtimes/weave/Cargo.toml b/runtimes/weave/Cargo.toml index 25c019596..035d0faba 100644 --- a/runtimes/weave/Cargo.toml +++ b/runtimes/weave/Cargo.toml @@ -42,6 +42,7 @@ cord-runtime-common = { workspace = true } pallet-config = { workspace = true } cord-uri = { workspace = true } + # Substrate sp-api = { workspace = true } sp-application-crypto = { workspace = true } @@ -165,7 +166,6 @@ substrate-wasm-builder = { workspace = true, optional = true, default-features = [features] default = ['std'] -no_std = [] std = [ "bs58/std", "blake2/std", @@ -333,6 +333,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", ] +no_std = [] try-runtime = [ "frame-executive/try-runtime", diff --git a/runtimes/weave/src/lib.rs b/runtimes/weave/src/lib.rs index 47c54fbac..55b7d4ab4 100644 --- a/runtimes/weave/src/lib.rs +++ b/runtimes/weave/src/lib.rs @@ -1302,10 +1302,6 @@ parameter_types! { pub const MaxEventsHistory: u32 = u32::MAX; } -// impl identifier::Config for Runtime { -// type MaxEventsHistory = MaxEventsHistory; -// } - impl pallet_remark::Config for Runtime { type WeightInfo = weights::pallet_remark::WeightInfo; type RuntimeEvent = RuntimeEvent; diff --git a/test-utils/service/src/lib.rs b/test-utils/service/src/lib.rs index 485a00754..470f8364f 100644 --- a/test-utils/service/src/lib.rs +++ b/test-utils/service/src/lib.rs @@ -178,7 +178,7 @@ where interval.tick().await; if full_nodes.iter().all(|(id, service, _, _)| full_predicate(*id, service)) { - break + break; } } };