difftreelog
fix disallow transfer/minting tokens to zero addr
in: master
2 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,16 +18,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a2e47a1fbe209ee101dd6d61285226744c6c8d3c21c8dc878ba6cb9f467f3a"
dependencies = [
- "gimli 0.24.0",
-]
-
-[[package]]
-name = "addr2line"
-version = "0.16.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd"
-dependencies = [
- "gimli 0.25.0",
+ "gimli",
]
[[package]]
@@ -66,7 +57,7 @@
"aes",
"block-cipher",
"ghash",
- "subtle 2.4.1",
+ "subtle 2.4.0",
]
[[package]]
@@ -97,17 +88,6 @@
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
-name = "ahash"
-version = "0.7.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
-dependencies = [
- "getrandom 0.2.3",
- "once_cell",
- "version_check",
-]
-
-[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -142,9 +122,18 @@
[[package]]
name = "anyhow"
-version = "1.0.42"
+version = "1.0.41"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61"
+
+[[package]]
+name = "approx"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486"
+checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
+dependencies = [
+ "num-traits",
+]
[[package]]
name = "approx"
@@ -247,11 +236,12 @@
[[package]]
name = "async-io"
-version = "1.6.0"
+version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b"
+checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b"
dependencies = [
"concurrent-queue",
+ "fastrand",
"futures-lite",
"libc",
"log",
@@ -322,7 +312,7 @@
"memchr",
"num_cpus",
"once_cell",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
"pin-utils",
"slab",
"wasm-bindgen-futures",
@@ -369,7 +359,7 @@
"futures-sink",
"futures-util",
"memchr",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
]
[[package]]
@@ -382,7 +372,7 @@
"futures-sink",
"futures-util",
"memchr",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
]
[[package]]
@@ -419,16 +409,16 @@
[[package]]
name = "backtrace"
-version = "0.3.61"
+version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01"
+checksum = "b7815ea54e4d821e791162e078acbebfd6d8c8939cd559c9335dceb1c8ca7282"
dependencies = [
- "addr2line 0.16.0",
+ "addr2line",
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
- "object 0.26.0",
+ "object 0.25.3",
"rustc-demangle",
]
@@ -458,9 +448,9 @@
[[package]]
name = "beef"
-version = "0.5.1"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bed554bd50246729a1ec158d08aa3235d1b69d94ad120ebe187e28894787e736"
+checksum = "6736e2428df2ca2848d846c43e88745121a6654696e349ce0054a420815a7409"
dependencies = [
"serde",
]
@@ -471,7 +461,7 @@
source = "git+https://github.com/paritytech/grandpa-bridge-gadget?branch=polkadot-v0.9.8#55ae3329847e0bbde51c9d45991d99f444777555"
dependencies = [
"beefy-primitives",
- "futures 0.3.16",
+ "futures 0.3.15",
"hex",
"log",
"parity-scale-codec",
@@ -500,7 +490,7 @@
dependencies = [
"beefy-gadget",
"beefy-primitives",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 15.1.0",
"jsonrpc-derive 15.1.0",
@@ -538,9 +528,9 @@
[[package]]
name = "bindgen"
-version = "0.59.1"
+version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "453c49e5950bb0eb63bb3df640e31618846c89d5b7faa54040d76e98e0134375"
+checksum = "fd4865004a46a0aafb2a0a5eb19d3c9fc46ee5f063a6cfc605c69ac9ecf5263d"
dependencies = [
"bitflags",
"cexpr",
@@ -560,18 +550,6 @@
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
-
-[[package]]
-name = "bitvec"
-version = "0.19.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
-dependencies = [
- "funty",
- "radium 0.5.3",
- "tap",
- "wyz",
-]
[[package]]
name = "bitvec"
@@ -580,7 +558,7 @@
checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848"
dependencies = [
"funty",
- "radium 0.6.2",
+ "radium",
"tap",
"wyz",
]
@@ -782,9 +760,9 @@
[[package]]
name = "camino"
-version = "1.0.4"
+version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9"
+checksum = "52d74260d9bf6944e2208aa46841b4b8f0d7ffc0849a06837b2f510337f86b2b"
dependencies = [
"serde",
]
@@ -827,18 +805,18 @@
[[package]]
name = "cc"
-version = "1.0.69"
+version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
+checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
dependencies = [
"jobserver",
]
[[package]]
name = "cexpr"
-version = "0.5.0"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db507a7679252d2276ed0dd8113c6875ec56d3089f9225b2b42c30cc1f8e5c89"
+checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom",
]
@@ -1016,18 +994,19 @@
[[package]]
name = "cpp_demangle"
-version = "0.3.3"
+version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea47428dc9d2237f3c6bc134472edfd63ebba0af932e783506dcfd66f10d18a"
+checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390"
dependencies = [
"cfg-if 1.0.0",
+ "glob",
]
[[package]]
name = "cpufeatures"
-version = "0.1.5"
+version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef"
+checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8"
dependencies = [
"libc",
]
@@ -1057,7 +1036,7 @@
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-entity",
- "gimli 0.24.0",
+ "gimli",
"log",
"regalloc",
"serde",
@@ -1256,7 +1235,7 @@
checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
dependencies = [
"generic-array 0.14.4",
- "subtle 2.4.1",
+ "subtle 2.4.0",
]
[[package]]
@@ -1307,7 +1286,7 @@
"cumulus-client-consensus-common",
"cumulus-client-network",
"cumulus-primitives-core",
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"parking_lot 0.10.2",
"polkadot-node-primitives",
@@ -1331,7 +1310,7 @@
"async-trait",
"cumulus-client-consensus-common",
"cumulus-primitives-core",
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"parking_lot 0.10.2",
"polkadot-client",
@@ -1360,7 +1339,7 @@
dependencies = [
"async-trait",
"dyn-clone",
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"polkadot-primitives",
"polkadot-runtime",
@@ -1383,7 +1362,7 @@
source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.8#ed6ba5dfb2c112c29505e856e8971da3420ce6d0"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"parity-scale-codec",
"parking_lot 0.10.2",
@@ -1407,7 +1386,7 @@
source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.8#ed6ba5dfb2c112c29505e856e8971da3420ce6d0"
dependencies = [
"cumulus-primitives-core",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"parity-scale-codec",
"polkadot-node-primitives",
@@ -1644,14 +1623,14 @@
[[package]]
name = "curve25519-dalek"
-version = "2.1.3"
+version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216"
+checksum = "434e1720189a637d44fe464f4df1e6eb900b4835255b14354497c78af37d9bb8"
dependencies = [
"byteorder",
"digest 0.8.1",
"rand_core 0.5.1",
- "subtle 2.4.1",
+ "subtle 2.4.0",
"zeroize",
]
@@ -1664,7 +1643,7 @@
"byteorder",
"digest 0.9.0",
"rand_core 0.5.1",
- "subtle 2.4.1",
+ "subtle 2.4.0",
"zeroize",
]
@@ -1742,14 +1721,13 @@
[[package]]
name = "derive_more"
-version = "0.99.16"
+version = "0.99.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df"
+checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
- "rustc_version 0.3.3",
"syn",
]
@@ -1857,9 +1835,9 @@
[[package]]
name = "ed25519"
-version = "1.2.0"
+version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4620d40f6d2601794401d6dd95a5cf69b6c157852539470eeda433a99b3c0efc"
+checksum = "8d0860415b12243916284c67a9be413e044ee6668247b99ba26d94b2bc06c8f6"
dependencies = [
"signature",
]
@@ -1961,9 +1939,9 @@
[[package]]
name = "erased-serde"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3de9ad4541d99dc22b59134e7ff8dc3d6c988c89ecd7324bf10a8362b07a2afa"
+checksum = "e5b36e6f2295f393f44894c6031f67df4d185b984cd54d08f768ce678007efcd"
dependencies = [
"serde",
]
@@ -2125,7 +2103,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e43f2f1833d64e33f15592464d6fdd70f349dda7b1a53088eb83cd94014008c5"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
]
[[package]]
@@ -2164,9 +2142,9 @@
[[package]]
name = "fastrand"
-version = "1.5.0"
+version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e"
+checksum = "77b705829d1e87f762c2df6da140b26af5839e1033aa84aa5f56bb688e4e1bdb"
dependencies = [
"instant",
]
@@ -2181,7 +2159,7 @@
"fc-db",
"fp-consensus",
"fp-rpc",
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"parity-scale-codec",
"sc-client-api",
@@ -2219,7 +2197,7 @@
"fc-db",
"fp-consensus",
"fp-rpc",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"sc-client-api",
@@ -2243,7 +2221,7 @@
"fp-evm",
"fp-rpc",
"fp-storage",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 14.2.0",
"jsonrpc-derive 14.2.2",
@@ -2310,7 +2288,7 @@
checksum = "74a1bfdcc776e63e49f741c7ce6116fa1b887e8ac2e3ccb14dd4aa113e54feb9"
dependencies = [
"either",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"num-traits",
@@ -2695,9 +2673,9 @@
[[package]]
name = "futures"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1adc00f486adfc9ce99f77d717836f0c5aa84965eb0b4f051f4e83f7cab53f8b"
+checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27"
dependencies = [
"futures-channel",
"futures-core",
@@ -2710,9 +2688,9 @@
[[package]]
name = "futures-channel"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "74ed2411805f6e4e3d9bc904c95d5d423b89b3b25dc0250aa74729de20629ff9"
+checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2"
dependencies = [
"futures-core",
"futures-sink",
@@ -2720,9 +2698,9 @@
[[package]]
name = "futures-core"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99"
+checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1"
[[package]]
name = "futures-cpupool"
@@ -2736,9 +2714,9 @@
[[package]]
name = "futures-executor"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4d0d535a57b87e1ae31437b892713aee90cd2d7b0ee48727cd11fc72ef54761c"
+checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79"
dependencies = [
"futures-core",
"futures-task",
@@ -2748,9 +2726,9 @@
[[package]]
name = "futures-io"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582"
+checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
[[package]]
name = "futures-lite"
@@ -2763,15 +2741,15 @@
"futures-io",
"memchr",
"parking",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
"waker-fn",
]
[[package]]
name = "futures-macro"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c54913bae956fb8df7f4dc6fc90362aa72e69148e3f39041fbe8742d21e0ac57"
+checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121"
dependencies = [
"autocfg",
"proc-macro-hack",
@@ -2793,15 +2771,15 @@
[[package]]
name = "futures-sink"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c0f30aaa67363d119812743aa5f33c201a7a66329f97d1a887022971feea4b53"
+checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282"
[[package]]
name = "futures-task"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbe54a98670017f3be909561f6ad13e810d9a51f3f061b902062ca3da80799f2"
+checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae"
[[package]]
name = "futures-timer"
@@ -2817,9 +2795,9 @@
[[package]]
name = "futures-util"
-version = "0.3.16"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67eb846bfd58e44a8481a00049e82c43e0ccb5d61f8dc071057cb19249dd4d78"
+checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967"
dependencies = [
"autocfg",
"futures 0.1.31",
@@ -2830,7 +2808,7 @@
"futures-sink",
"futures-task",
"memchr",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
@@ -2906,12 +2884,6 @@
]
[[package]]
-name = "gimli"
-version = "0.25.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7"
-
-[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2919,9 +2891,9 @@
[[package]]
name = "globset"
-version = "0.4.8"
+version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd"
+checksum = "f0fc1b9fa0e64ffb1aa5b95daa0f0f167734fd528b7c02eabc581d9d843649b1"
dependencies = [
"aho-corasick",
"bstr",
@@ -3016,16 +2988,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
- "ahash 0.4.7",
-]
-
-[[package]]
-name = "hashbrown"
-version = "0.11.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
-dependencies = [
- "ahash 0.7.4",
+ "ahash",
]
[[package]]
@@ -3039,9 +3002,9 @@
[[package]]
name = "hermit-abi"
-version = "0.1.19"
+version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
dependencies = [
"libc",
]
@@ -3054,9 +3017,9 @@
[[package]]
name = "hex-literal"
-version = "0.3.3"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21e4590e13640f19f249fe3e4eca5113bc4289f2497710378190e7f4bd96f45b"
+checksum = "5af1f635ef1bc545d78392b136bfe1c9809e029023c84a3638a864a10b8819c8"
[[package]]
name = "hex_fmt"
@@ -3163,13 +3126,13 @@
[[package]]
name = "http-body"
-version = "0.4.2"
+version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9"
+checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5"
dependencies = [
"bytes 1.0.1",
"http 0.2.4",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
]
[[package]]
@@ -3222,7 +3185,7 @@
"itoa",
"log",
"net2",
- "rustc_version 0.2.3",
+ "rustc_version",
"time",
"tokio 0.1.22",
"tokio-buf",
@@ -3251,7 +3214,7 @@
"httparse",
"httpdate 0.3.2",
"itoa",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"socket2 0.3.19",
"tokio 0.2.25",
"tower-service",
@@ -3270,11 +3233,11 @@
"futures-core",
"futures-util",
"http 0.2.4",
- "http-body 0.4.2",
+ "http-body 0.4.3",
"httparse",
"httpdate 1.0.1",
"itoa",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
"tokio 1.9.0",
"tower-service",
"tracing",
@@ -3355,7 +3318,7 @@
checksum = "ae8ab7f67bad3240049cb24fb9cb0b4c2c6af4c245840917fbbdededeee91179"
dependencies = [
"async-io",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-lite",
"if-addrs",
"ipnet",
@@ -3366,9 +3329,9 @@
[[package]]
name = "impl-codec"
-version = "0.5.1"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443"
+checksum = "df170efa359aebdd5cb7fe78edcc67107748e4737bdca8a8fb40d15ea7a877ed"
dependencies = [
"parity-scale-codec",
]
@@ -3404,20 +3367,20 @@
[[package]]
name = "indexmap"
-version = "1.7.0"
+version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
+checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
- "hashbrown 0.11.2",
+ "hashbrown",
"serde",
]
[[package]]
name = "instant"
-version = "0.1.10"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d"
+checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
dependencies = [
"cfg-if 1.0.0",
]
@@ -3443,7 +3406,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64fa110ec7b8f493f416eed552740d10e7030ad5f63b2308f82c9608ec2df275"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 2.0.2",
]
@@ -3746,10 +3709,10 @@
dependencies = [
"async-trait",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpsee-types",
"log",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"rustls 0.19.1",
"rustls-native-certs 0.5.0",
"serde",
@@ -3846,9 +3809,9 @@
[[package]]
name = "libc"
-version = "0.2.98"
+version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
+checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "libloading"
@@ -3884,7 +3847,7 @@
dependencies = [
"atomic",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"lazy_static",
"libp2p-core",
"libp2p-deflate",
@@ -3910,7 +3873,7 @@
"libp2p-yamux",
"parity-multiaddr",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"smallvec 1.6.1",
"wasm-timer",
]
@@ -3926,7 +3889,7 @@
"ed25519-dalek",
"either",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"lazy_static",
"libsecp256k1 0.3.5",
@@ -3935,7 +3898,7 @@
"multistream-select",
"parity-multiaddr",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"prost",
"prost-build",
"rand 0.7.3",
@@ -3956,7 +3919,7 @@
checksum = "a2181a641cd15f9b6ba71b1335800f309012a0a97a29ffaabbbf40e9d3d58f08"
dependencies = [
"flate2",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
]
@@ -3967,7 +3930,7 @@
checksum = "62e63dab8b5ff35e0c101a3e51e843ba782c07bbb1682f5fd827622e0d02b98b"
dependencies = [
"async-std-resolver",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"log",
"smallvec 1.6.1",
@@ -3982,7 +3945,7 @@
dependencies = [
"cuckoofilter",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"libp2p-swarm",
"log",
@@ -4003,7 +3966,7 @@
"byteorder",
"bytes 1.0.1",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"hex_fmt",
"libp2p-core",
"libp2p-swarm",
@@ -4024,7 +3987,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f668f00efd9883e8b7bcc582eaf0164615792608f886f6577da18bcbeea0a46"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"libp2p-swarm",
"log",
@@ -4045,7 +4008,7 @@
"bytes 1.0.1",
"either",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"libp2p-swarm",
"log",
@@ -4069,7 +4032,7 @@
"async-io",
"data-encoding",
"dns-parser",
- "futures 0.3.16",
+ "futures 0.3.15",
"if-watch",
"lazy_static",
"libp2p-core",
@@ -4089,7 +4052,7 @@
dependencies = [
"asynchronous-codec 0.6.0",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"log",
"nohash-hasher",
@@ -4107,7 +4070,7 @@
dependencies = [
"bytes 1.0.1",
"curve25519-dalek 3.1.0",
- "futures 0.3.16",
+ "futures 0.3.15",
"lazy_static",
"libp2p-core",
"log",
@@ -4127,7 +4090,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4bfaffac63bf3c7ec11ed9d8879d455966ddea7e78ee14737f0b6dce0d1cd1"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"libp2p-swarm",
"log",
@@ -4144,7 +4107,7 @@
dependencies = [
"asynchronous-codec 0.6.0",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"log",
"prost",
@@ -4159,9 +4122,9 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce3374f3b28162db9d3442c9347c4f14cb01e8290052615c7d341d40eae0599"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"rand 0.7.3",
"salsa20",
"sha3 0.9.1",
@@ -4175,12 +4138,12 @@
dependencies = [
"asynchronous-codec 0.6.0",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"libp2p-core",
"libp2p-swarm",
"log",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"prost",
"prost-build",
"rand 0.7.3",
@@ -4198,7 +4161,7 @@
dependencies = [
"async-trait",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"libp2p-swarm",
"log",
@@ -4217,7 +4180,7 @@
checksum = "1e04d8e1eef675029ec728ba14e8d0da7975d84b6679b699b4ae91a1de9c3a92"
dependencies = [
"either",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"log",
"rand 0.7.3",
@@ -4243,7 +4206,7 @@
checksum = "2b1a27d21c477951799e99d5c105d78868258502ce092988040a808d5a19bbd9"
dependencies = [
"async-io",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"if-watch",
"ipnet",
@@ -4260,7 +4223,7 @@
checksum = "ffd6564bb3b7ff203661ccbb69003c2b551e34cef974f2d6c6a28306a12170b5"
dependencies = [
"async-std",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"log",
]
@@ -4271,7 +4234,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d413e4cf9b8e5dfbcd2a60d3dc5a3391308bdb463684093d4f67137b7113de"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"js-sys",
"libp2p-core",
"parity-send-wrapper",
@@ -4286,7 +4249,7 @@
checksum = "cace60995ef6f637e4752cccbb2590f6bc358e8741a0d066307636c69a4b3a74"
dependencies = [
"either",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-rustls",
"libp2p-core",
"log",
@@ -4303,7 +4266,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f35da42cfc6d5cb0dcf3ad6881bc68d146cdf38f98655e09e33fbba4d13eabc4"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p-core",
"parking_lot 0.11.1",
"thiserror",
@@ -4312,9 +4275,9 @@
[[package]]
name = "librocksdb-sys"
-version = "6.20.3"
+version = "6.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c309a9d2470844aceb9a4a098cf5286154d20596868b75a6b36357d2bb9ca25d"
+checksum = "5da125e1c0f22c7cae785982115523a0738728498547f415c9054cb17c7e89f9"
dependencies = [
"bindgen",
"cc",
@@ -4334,7 +4297,7 @@
"hmac-drbg 0.2.0",
"rand 0.7.3",
"sha2 0.8.2",
- "subtle 2.4.1",
+ "subtle 2.4.0",
"typenum",
]
@@ -4365,7 +4328,7 @@
dependencies = [
"crunchy",
"digest 0.9.0",
- "subtle 2.4.1",
+ "subtle 2.4.0",
]
[[package]]
@@ -4414,11 +4377,11 @@
[[package]]
name = "linregress"
-version = "0.4.3"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e6e407dadb4ca4b31bc69c27aff00e7ca4534fdcee855159b039a7cebb5f395"
+checksum = "b1ff7f341d23e1275eec0656a9a07225fcc86216c4322392868adffe59023d1a"
dependencies = [
- "nalgebra",
+ "nalgebra 0.27.1",
"statrs",
]
@@ -4456,7 +4419,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f374d42cdfc1d7dbf3d3dec28afab2eb97ffbf43a3234d795b5986dbf4b90ba"
dependencies = [
- "hashbrown 0.9.1",
+ "hashbrown",
]
[[package]]
@@ -4581,7 +4544,7 @@
checksum = "814bbecfc0451fc314eeea34f05bbcd5b98a7ad7af37faee088b86a1e633f1d4"
dependencies = [
"hash-db",
- "hashbrown 0.9.1",
+ "hashbrown",
"parity-util-mem",
]
@@ -4618,7 +4581,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
]
@@ -4628,7 +4591,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c023c3f16109e7f33aa451f773fd61070e265b4977d0b6e344a51049296dd7df"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"rand 0.7.3",
"thrift",
]
@@ -4644,9 +4607,9 @@
[[package]]
name = "minicbor-derive"
-version = "0.6.4"
+version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "54999f917cd092b13904737e26631aa2b2b88d625db68e4bab461dcd8006c788"
+checksum = "7f2b9e8883d58e34b18facd16c4564a77ea50fce028ad3d0ee6753440e37acc8"
dependencies = [
"proc-macro2",
"quote",
@@ -4799,28 +4762,43 @@
checksum = "7d91ec0a2440aaff5f78ec35631a7027d50386c6163aa975f7caa0d5da4b6ff8"
dependencies = [
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"smallvec 1.6.1",
"unsigned-varint 0.7.0",
]
[[package]]
name = "nalgebra"
+version = "0.26.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "476d1d59fe02fe54c86356e91650cd892f392782a1cb9fc524ec84f7aa9e1d06"
+dependencies = [
+ "approx 0.4.0",
+ "matrixmultiply",
+ "num-complex 0.3.1",
+ "num-rational 0.3.2",
+ "num-traits",
+ "rand 0.8.4",
+ "rand_distr",
+ "simba 0.4.0",
+ "typenum",
+]
+
+[[package]]
+name = "nalgebra"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "462fffe4002f4f2e1f6a9dcf12cc1a6fc0e15989014efc02a941d3e0f5dc2120"
dependencies = [
- "approx",
+ "approx 0.5.0",
"matrixmultiply",
"nalgebra-macros",
- "num-complex",
+ "num-complex 0.4.0",
"num-rational 0.4.0",
"num-traits",
- "rand 0.8.4",
- "rand_distr",
- "simba",
+ "simba 0.5.1",
"typenum",
]
@@ -4876,7 +4854,7 @@
"fp-rpc",
"frame-benchmarking",
"frame-benchmarking-cli",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-pubsub 15.1.0",
"log",
@@ -4955,7 +4933,7 @@
"fc-rpc",
"fc-rpc-core",
"fp-rpc",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-pubsub 15.1.0",
"nft-runtime",
@@ -5071,12 +5049,10 @@
[[package]]
name = "nom"
-version = "6.1.2"
+version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
+checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
- "bitvec 0.19.5",
- "funty",
"memchr",
"version_check",
]
@@ -5094,6 +5070,15 @@
[[package]]
name = "num-complex"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-complex"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085"
@@ -5125,6 +5110,17 @@
[[package]]
name = "num-rational"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
@@ -5166,9 +5162,9 @@
[[package]]
name = "object"
-version = "0.26.0"
+version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c55827317fb4c08822499848a14237d2874d6f139828893017237e7ab93eb386"
+checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7"
dependencies = [
"memchr",
]
@@ -6129,23 +6125,22 @@
[[package]]
name = "parity-scale-codec"
-version = "2.2.0"
+version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8975095a2a03bbbdc70a74ab11a4f76a6d0b84680d87c68d722531b0ac28e8a9"
+checksum = "b310f220c335f9df1b3d2e9fbe3890bbfeef5030dad771620f48c5c229877cd3"
dependencies = [
"arrayvec 0.7.1",
- "bitvec 0.20.4",
+ "bitvec",
"byte-slice-cast",
- "impl-trait-for-tuples",
"parity-scale-codec-derive",
"serde",
]
[[package]]
name = "parity-scale-codec-derive"
-version = "2.2.0"
+version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "40dbbfef7f0a1143c5b06e0d76a6278e25dac0bc1af4be51a0fbb73f07e7ad09"
+checksum = "81038e13ca2c32587201d544ea2e6b6c47120f1e4eae04478f9f60b6bcb89145"
dependencies = [
"proc-macro-crate 1.0.0",
"proc-macro2",
@@ -6186,7 +6181,7 @@
dependencies = [
"cfg-if 1.0.0",
"ethereum-types",
- "hashbrown 0.9.1",
+ "hashbrown",
"impl-trait-for-tuples",
"lru",
"parity-util-mem-derive",
@@ -6224,9 +6219,9 @@
[[package]]
name = "parity-ws"
-version = "0.10.1"
+version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "322d72dfe461b8b9e367d057ceace105379d64d5b03907d23c481ccf3fbf8aa4"
+checksum = "9e02a625dd75084c2a7024f07c575b61b782f729d18702dabb3cdbf31911dc61"
dependencies = [
"byteorder",
"bytes 0.4.12",
@@ -6254,7 +6249,7 @@
dependencies = [
"lock_api 0.3.4",
"parking_lot_core 0.6.2",
- "rustc_version 0.2.3",
+ "rustc_version",
]
[[package]]
@@ -6288,7 +6283,7 @@
"cloudabi",
"libc",
"redox_syscall 0.1.57",
- "rustc_version 0.2.3",
+ "rustc_version",
"smallvec 0.6.14",
"winapi 0.3.9",
]
@@ -6434,11 +6429,11 @@
[[package]]
name = "pin-project"
-version = "1.0.8"
+version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
+checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
dependencies = [
- "pin-project-internal 1.0.8",
+ "pin-project-internal 1.0.7",
]
[[package]]
@@ -6454,9 +6449,9 @@
[[package]]
name = "pin-project-internal"
-version = "1.0.8"
+version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
+checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
dependencies = [
"proc-macro2",
"quote",
@@ -6471,9 +6466,9 @@
[[package]]
name = "pin-project-lite"
-version = "0.2.7"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443"
+checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
[[package]]
name = "pin-utils"
@@ -6498,7 +6493,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"polkadot-node-network-protocol",
"polkadot-node-primitives",
"polkadot-node-subsystem",
@@ -6512,7 +6507,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"polkadot-node-network-protocol",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
@@ -6525,7 +6520,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"lru",
"parity-scale-codec",
"polkadot-erasure-coding",
@@ -6548,7 +6543,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"lru",
"parity-scale-codec",
"polkadot-erasure-coding",
@@ -6568,7 +6563,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"frame-benchmarking-cli",
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"polkadot-node-core-pvf",
"polkadot-service",
@@ -6617,7 +6612,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"always-assert",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"polkadot-node-network-protocol",
"polkadot-node-primitives",
@@ -6662,7 +6657,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"polkadot-node-network-protocol",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
@@ -6681,7 +6676,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"parking_lot 0.11.1",
"polkadot-node-network-protocol",
@@ -6700,7 +6695,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"polkadot-erasure-coding",
"polkadot-node-primitives",
@@ -6718,9 +6713,9 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
+ "bitvec",
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"kvdb",
"lru",
@@ -6748,8 +6743,8 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
- "futures 0.3.16",
+ "bitvec",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"kvdb",
"parity-scale-codec",
@@ -6768,8 +6763,8 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
- "futures 0.3.16",
+ "bitvec",
+ "futures 0.3.15",
"polkadot-erasure-coding",
"polkadot-node-primitives",
"polkadot-node-subsystem",
@@ -6786,7 +6781,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
"polkadot-primitives",
@@ -6802,7 +6797,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"polkadot-node-core-pvf",
"polkadot-node-primitives",
@@ -6819,7 +6814,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
"polkadot-primitives",
@@ -6835,7 +6830,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"polkadot-node-subsystem",
"polkadot-overseer",
@@ -6852,8 +6847,8 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
- "futures 0.3.16",
+ "bitvec",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
@@ -6871,11 +6866,11 @@
"assert_matches",
"async-process",
"async-std",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"libc",
"parity-scale-codec",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"polkadot-core-primitives",
"polkadot-parachain",
"rand 0.8.4",
@@ -6896,7 +6891,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"memory-lru",
"parity-util-mem",
"polkadot-node-subsystem",
@@ -6932,7 +6927,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"polkadot-node-jaeger",
"polkadot-node-primitives",
@@ -6947,7 +6942,7 @@
version = "0.1.0"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"parity-scale-codec",
"polkadot-parachain",
"polkadot-primitives",
@@ -6973,14 +6968,14 @@
"async-std",
"async-trait",
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"lazy_static",
"log",
"mick-jaeger",
"parity-scale-codec",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"polkadot-node-jaeger",
"polkadot-node-network-protocol",
"polkadot-node-primitives",
@@ -7001,13 +6996,13 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"itertools 0.10.1",
"lru",
"metered-channel",
"parity-scale-codec",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"polkadot-node-jaeger",
"polkadot-node-network-protocol",
"polkadot-node-primitives",
@@ -7029,7 +7024,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"lru",
"polkadot-node-primitives",
@@ -7062,7 +7057,7 @@
version = "0.9.8"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
+ "bitvec",
"frame-system",
"hex-literal",
"parity-scale-codec",
@@ -7148,7 +7143,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"beefy-primitives",
- "bitvec 0.20.4",
+ "bitvec",
"frame-election-provider-support",
"frame-executive",
"frame-support",
@@ -7219,7 +7214,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"beefy-primitives",
- "bitvec 0.20.4",
+ "bitvec",
"frame-support",
"frame-system",
"impl-trait-for-tuples",
@@ -7261,7 +7256,7 @@
version = "0.9.8"
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
- "bitvec 0.20.4",
+ "bitvec",
"derive_more",
"frame-support",
"frame-system",
@@ -7302,7 +7297,7 @@
"beefy-gadget",
"beefy-primitives",
"frame-system-rpc-runtime-api",
- "futures 0.3.16",
+ "futures 0.3.15",
"hex-literal",
"kvdb",
"kvdb-rocksdb",
@@ -7388,7 +7383,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"arrayvec 0.5.2",
- "futures 0.3.16",
+ "futures 0.3.15",
"indexmap",
"parity-scale-codec",
"polkadot-node-network-protocol",
@@ -7419,7 +7414,7 @@
source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.8#3a10ee63c0b5703a1c802db3438ab7e01344a8ce"
dependencies = [
"beefy-primitives",
- "bitvec 0.20.4",
+ "bitvec",
"frame-election-provider-support",
"frame-executive",
"frame-support",
@@ -7477,7 +7472,7 @@
"frame-benchmarking",
"frame-system",
"futures 0.1.31",
- "futures 0.3.16",
+ "futures 0.3.15",
"hex",
"pallet-balances",
"pallet-staking",
@@ -7563,9 +7558,9 @@
[[package]]
name = "primitive-types"
-version = "0.9.1"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e"
+checksum = "2415937401cb030a2a0a4d922483f945fa068f52a7dbb22ce0fe5f2b6f6adace"
dependencies = [
"fixed-hash",
"impl-codec",
@@ -7631,9 +7626,9 @@
[[package]]
name = "proc-macro2"
-version = "1.0.28"
+version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
+checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
"unicode-xid",
]
@@ -7705,9 +7700,9 @@
[[package]]
name = "psm"
-version = "0.1.14"
+version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14ce37fa8c0428a37307d163292add09b3aedc003472e6b3622486878404191d"
+checksum = "21ff0279b4a85e576b97e4a21d13e437ebcd56612706cde5d3f0d5c9399490c0"
dependencies = [
"cc",
]
@@ -7754,12 +7749,6 @@
dependencies = [
"proc-macro2",
]
-
-[[package]]
-name = "radium"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]]
name = "radium"
@@ -8155,9 +8144,9 @@
[[package]]
name = "rustc-demangle"
-version = "0.1.20"
+version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49"
+checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce"
[[package]]
name = "rustc-hash"
@@ -8178,15 +8167,6 @@
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver 0.9.0",
-]
-
-[[package]]
-name = "rustc_version"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
-dependencies = [
- "semver 0.11.0",
]
[[package]]
@@ -8241,9 +8221,9 @@
[[package]]
name = "ruzstd"
-version = "0.2.4"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8cada0ef59efa6a5f4dc5e491f93d9f31e3fc7758df421ff1de8a706338e1100"
+checksum = "3d425143485a37727c7a46e689bbe3b883a00f42b4a52c4ac0f44855c1009b00"
dependencies = [
"byteorder",
"twox-hash",
@@ -8255,7 +8235,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"pin-project 0.4.28",
"static_assertions",
]
@@ -8272,7 +8252,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d3d055a2582e6b00ed7a31c1524040aa391092bf636328350813f3a0605215c"
dependencies = [
- "rustc_version 0.2.3",
+ "rustc_version",
]
[[package]]
@@ -8313,7 +8293,7 @@
"async-trait",
"derive_more",
"either",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"ip_network",
"libp2p",
@@ -8339,7 +8319,7 @@
version = "0.9.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"parity-scale-codec",
@@ -8411,7 +8391,7 @@
dependencies = [
"chrono",
"fdlimit",
- "futures 0.3.16",
+ "futures 0.3.15",
"hex",
"libp2p",
"log",
@@ -8449,7 +8429,7 @@
dependencies = [
"derive_more",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"hash-db",
"kvdb",
"lazy_static",
@@ -8526,7 +8506,7 @@
dependencies = [
"async-trait",
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"parity-scale-codec",
@@ -8558,7 +8538,7 @@
"async-trait",
"derive_more",
"fork-tree",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"merlin",
@@ -8602,7 +8582,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 15.1.0",
"jsonrpc-derive 15.1.0",
@@ -8639,7 +8619,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"impl-trait-for-tuples",
"log",
@@ -8762,13 +8742,13 @@
"dyn-clone",
"finality-grandpa",
"fork-tree",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"linked-hash-map",
"log",
"parity-scale-codec",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"rand 0.7.3",
"sc-block-builder",
"sc-client-api",
@@ -8800,7 +8780,7 @@
dependencies = [
"derive_more",
"finality-grandpa",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 15.1.0",
"jsonrpc-derive 15.1.0",
@@ -8823,7 +8803,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"num-traits",
"parity-scale-codec",
@@ -8844,7 +8824,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"ansi_term 0.12.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"log",
"parity-util-mem",
@@ -8863,7 +8843,7 @@
dependencies = [
"async-trait",
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-util",
"hex",
"merlin",
@@ -8873,7 +8853,7 @@
"sp-application-crypto",
"sp-core",
"sp-keystore",
- "subtle 2.4.1",
+ "subtle 2.4.0",
]
[[package]]
@@ -8912,7 +8892,7 @@
"erased-serde",
"fnv",
"fork-tree",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"hex",
"ip_network",
@@ -8924,7 +8904,7 @@
"nohash-hasher",
"parity-scale-codec",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"prost",
"prost-build",
"rand 0.7.3",
@@ -8953,7 +8933,7 @@
version = "0.9.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"libp2p",
"log",
@@ -8972,7 +8952,7 @@
dependencies = [
"bytes 0.5.6",
"fnv",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"hex",
"hyper 0.13.10",
@@ -8998,7 +8978,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p",
"log",
"serde_json",
@@ -9020,7 +9000,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"hash-db",
"jsonrpc-core 15.1.0",
"jsonrpc-pubsub 15.1.0",
@@ -9056,7 +9036,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 15.1.0",
"jsonrpc-derive 15.1.0",
@@ -9102,7 +9082,7 @@
"directories",
"exit-future",
"futures 0.1.31",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"hash-db",
"jsonrpc-core 15.1.0",
@@ -9112,7 +9092,7 @@
"parity-scale-codec",
"parity-util-mem",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"rand 0.7.3",
"sc-block-builder",
"sc-chain-spec",
@@ -9200,11 +9180,11 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"chrono",
- "futures 0.3.16",
+ "futures 0.3.15",
"libp2p",
"log",
"parking_lot 0.11.1",
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"rand 0.7.3",
"serde",
"serde_json",
@@ -9268,7 +9248,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"linked-hash-map",
"log",
"parity-util-mem",
@@ -9289,7 +9269,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"intervalier",
"log",
"parity-scale-codec",
@@ -9327,13 +9307,13 @@
dependencies = [
"arrayref",
"arrayvec 0.5.2",
- "curve25519-dalek 2.1.3",
+ "curve25519-dalek 2.1.2",
"getrandom 0.1.16",
"merlin",
"rand 0.7.3",
"rand_core 0.5.1",
"sha2 0.8.2",
- "subtle 2.4.1",
+ "subtle 2.4.0",
"zeroize",
]
@@ -9522,9 +9502,9 @@
[[package]]
name = "sha-1"
-version = "0.9.7"
+version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a0c8611594e2ab4ebbf06ec7cbbf0a99450b8570e96cbf5188b5d5f6ef18d81"
+checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
@@ -9594,9 +9574,9 @@
[[package]]
name = "shlex"
-version = "1.0.0"
+version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d"
+checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "signal-hook"
@@ -9619,9 +9599,21 @@
[[package]]
name = "signature"
-version = "1.3.1"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f0242b8e50dd9accdd56170e94ca1ebd223b098eb9c83539a6e367d0f36ae68"
+
+[[package]]
+name = "simba"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c19772be3c4dd2ceaacf03cb41d5885f2a02c4d8804884918e3a258480803335"
+checksum = "5132a955559188f3d13c9ba831e77c802ddc8782783f050ed0c52f5988b95f4c"
+dependencies = [
+ "approx 0.4.0",
+ "num-complex 0.3.1",
+ "num-traits",
+ "paste",
+]
[[package]]
name = "simba"
@@ -9629,8 +9621,8 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e82063457853d00243beda9952e910b82593e4b07ae9f721b9278a99a0d3d5c"
dependencies = [
- "approx",
- "num-complex",
+ "approx 0.5.0",
+ "num-complex 0.4.0",
"num-traits",
"paste",
]
@@ -9664,9 +9656,9 @@
[[package]]
name = "slotmap"
-version = "1.0.5"
+version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a952280edbecfb1d4bd3cf2dbc309dc6ab523e53487c438ae21a6df09fe84bc4"
+checksum = "585cd5dffe4e9e06f6dfdf66708b70aca3f781bed561f4f667b2d9c0d4559e36"
dependencies = [
"version_check",
]
@@ -9698,9 +9690,9 @@
"rand 0.7.3",
"rand_core 0.5.1",
"ring",
- "rustc_version 0.2.3",
+ "rustc_version",
"sha2 0.9.5",
- "subtle 2.4.1",
+ "subtle 2.4.0",
"x25519-dalek",
]
@@ -9734,11 +9726,11 @@
"base64 0.12.3",
"bytes 0.5.6",
"flate2",
- "futures 0.3.16",
+ "futures 0.3.15",
"httparse",
"log",
"rand 0.7.3",
- "sha-1 0.9.7",
+ "sha-1 0.9.6",
]
[[package]]
@@ -9749,11 +9741,11 @@
dependencies = [
"base64 0.13.0",
"bytes 1.0.1",
- "futures 0.3.16",
+ "futures 0.3.15",
"httparse",
"log",
"rand 0.8.4",
- "sha-1 0.9.7",
+ "sha-1 0.9.6",
]
[[package]]
@@ -9853,7 +9845,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"lru",
"parity-scale-codec",
@@ -9872,7 +9864,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"async-trait",
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-timer 3.0.2",
"libp2p",
"log",
@@ -9964,7 +9956,7 @@
"byteorder",
"dyn-clonable",
"ed25519-dalek",
- "futures 0.3.16",
+ "futures 0.3.15",
"hash-db",
"hash256-std-hasher",
"hex",
@@ -10065,7 +10057,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"hash-db",
"libsecp256k1 0.3.5",
"log",
@@ -10103,7 +10095,7 @@
dependencies = [
"async-trait",
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"merlin",
"parity-scale-codec",
"parking_lot 0.11.1",
@@ -10366,7 +10358,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"derive_more",
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"parity-scale-codec",
"serde",
@@ -10410,7 +10402,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"futures-core",
"futures-timer 3.0.2",
"lazy_static",
@@ -10498,13 +10490,13 @@
[[package]]
name = "statrs"
-version = "0.15.0"
+version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05bdbb8e4e78216a85785a85d3ec3183144f98d0097b9281802c019bb07a6f05"
+checksum = "1e0c1f144861fbfd2a8cc82d564ccbf7fb3b7834d4fa128b84e9c2a73371aead"
dependencies = [
- "approx",
+ "approx 0.4.0",
"lazy_static",
- "nalgebra",
+ "nalgebra 0.26.2",
"num-traits",
"rand 0.8.4",
]
@@ -10542,9 +10534,9 @@
[[package]]
name = "structopt"
-version = "0.3.22"
+version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71"
+checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
dependencies = [
"clap",
"lazy_static",
@@ -10553,9 +10545,9 @@
[[package]]
name = "structopt-derive"
-version = "0.4.15"
+version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10"
+checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
dependencies = [
"heck",
"proc-macro-error",
@@ -10612,7 +10604,7 @@
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
"frame-system-rpc-runtime-api",
- "futures 0.3.16",
+ "futures 0.3.15",
"jsonrpc-core 15.1.0",
"jsonrpc-core-client 15.1.0",
"jsonrpc-derive 15.1.0",
@@ -10650,7 +10642,7 @@
dependencies = [
"async-trait",
"futures 0.1.31",
- "futures 0.3.16",
+ "futures 0.3.15",
"hash-db",
"hex",
"parity-scale-codec",
@@ -10677,7 +10669,7 @@
version = "3.0.0"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.8#74101dc21cfffb4c2d014fcc28edc166d5ca1b16"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"substrate-test-utils-derive",
"tokio 0.2.25",
]
@@ -10732,15 +10724,15 @@
[[package]]
name = "subtle"
-version = "2.4.1"
+version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
+checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
[[package]]
name = "syn"
-version = "1.0.74"
+version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"
+checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [
"proc-macro2",
"quote",
@@ -10749,9 +10741,9 @@
[[package]]
name = "synstructure"
-version = "0.12.5"
+version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "474aaa926faa1603c40b7885a9eaea29b444d1cb2850cb7c0e37bb1a4182f4fa"
+checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2",
"quote",
@@ -10811,18 +10803,18 @@
[[package]]
name = "thiserror"
-version = "1.0.26"
+version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
+checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.26"
+version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
+checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d"
dependencies = [
"proc-macro2",
"quote",
@@ -10900,9 +10892,9 @@
[[package]]
name = "tinyvec"
-version = "1.3.1"
+version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338"
+checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342"
dependencies = [
"tinyvec_macros",
]
@@ -10967,7 +10959,7 @@
checksum = "4b7b349f11a7047e6d1276853e612d152f5e8a352c61917887cc2169e2366b4c"
dependencies = [
"autocfg",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
]
[[package]]
@@ -11234,7 +11226,7 @@
dependencies = [
"cfg-if 1.0.0",
"log",
- "pin-project-lite 0.2.7",
+ "pin-project-lite 0.2.6",
"tracing-attributes",
"tracing-core",
]
@@ -11265,7 +11257,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [
- "pin-project 1.0.8",
+ "pin-project 1.0.7",
"tracing",
]
@@ -11292,9 +11284,9 @@
[[package]]
name = "tracing-subscriber"
-version = "0.2.19"
+version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab69019741fca4d98be3c62d2b75254528b5432233fd8a4d2739fec20278de48"
+checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5"
dependencies = [
"ansi_term 0.12.1",
"chrono",
@@ -11314,12 +11306,12 @@
[[package]]
name = "trie-db"
-version = "0.22.6"
+version = "0.22.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9eac131e334e81b6b3be07399482042838adcd7957aa0010231d0813e39e02fa"
+checksum = "cd81fe0c8bc2b528a51c9d2c31dae4483367a26a723a3c9a4a8120311d7774e3"
dependencies = [
"hash-db",
- "hashbrown 0.11.2",
+ "hashbrown",
"log",
"rustc-hex",
"smallvec 1.6.1",
@@ -11444,9 +11436,9 @@
[[package]]
name = "uint"
-version = "0.9.1"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6470ab50f482bde894a037a57064480a246dbfdd5960bd65a44824693f08da5f"
+checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e"
dependencies = [
"byteorder",
"crunchy",
@@ -11483,9 +11475,9 @@
[[package]]
name = "unicode-segmentation"
-version = "1.8.0"
+version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
+checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
[[package]]
name = "unicode-width"
@@ -11501,12 +11493,12 @@
[[package]]
name = "universal-hash"
-version = "0.4.1"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
+checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402"
dependencies = [
"generic-array 0.14.4",
- "subtle 2.4.1",
+ "subtle 2.4.0",
]
[[package]]
@@ -11587,9 +11579,9 @@
[[package]]
name = "vcpkg"
-version = "0.2.15"
+version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
+checksum = "70455df2fdf4e9bf580a92e443f1eb0303c390d682e2ea817312c9e81f8c3399"
[[package]]
name = "vec_map"
@@ -11742,7 +11734,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"js-sys",
"parking_lot 0.11.1",
"pin-utils",
@@ -11857,7 +11849,7 @@
checksum = "c5d2a763e7a6fc734218e0e463196762a4f409c483063d81e0e85f96343b2e0a"
dependencies = [
"anyhow",
- "gimli 0.24.0",
+ "gimli",
"more-asserts",
"object 0.24.0",
"target-lexicon",
@@ -11876,7 +11868,7 @@
"cranelift-codegen",
"cranelift-entity",
"cranelift-wasm",
- "gimli 0.24.0",
+ "gimli",
"indexmap",
"log",
"more-asserts",
@@ -11902,7 +11894,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d4539ea734422b7c868107e2187d7746d8affbcaa71916d72639f53757ad707"
dependencies = [
- "addr2line 0.15.2",
+ "addr2line",
"anyhow",
"cfg-if 1.0.0",
"cranelift-codegen",
@@ -11910,7 +11902,7 @@
"cranelift-frontend",
"cranelift-native",
"cranelift-wasm",
- "gimli 0.24.0",
+ "gimli",
"log",
"more-asserts",
"object 0.24.0",
@@ -11951,7 +11943,7 @@
dependencies = [
"anyhow",
"cfg-if 1.0.0",
- "gimli 0.24.0",
+ "gimli",
"lazy_static",
"libc",
"object 0.24.0",
@@ -12190,7 +12182,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7d9028f208dd5e63c614be69f115c1b53cacc1111437d4c765185856666c107"
dependencies = [
- "futures 0.3.16",
+ "futures 0.3.15",
"log",
"nohash-hasher",
"parking_lot 0.11.1",
@@ -12206,9 +12198,9 @@
[[package]]
name = "zeroize"
-version = "1.4.1"
+version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "377db0846015f7ae377174787dd452e1c5f5a9050bc6f954911d01f116daa0cd"
+checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd"
dependencies = [
"zeroize_derive",
]
pallets/nft/src/lib.rsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![recursion_limit = "1024"]7#![cfg_attr(not(feature = "std"), no_std)]8#![allow(9 clippy::too_many_arguments,10 clippy::unnecessary_mut_passed,11 clippy::unused_unit12)]1314extern crate alloc;1516pub use serde::{Serialize, Deserialize};1718pub use frame_support::{19 construct_runtime, decl_event, decl_module, decl_storage, decl_error,20 dispatch::DispatchResult,21 ensure, fail, parameter_types,22 traits::{23 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,24 Randomness, IsSubType, WithdrawReasons,25 },26 weights::{27 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},28 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,29 WeightToFeePolynomial, DispatchClass,30 },31 StorageValue, transactional,32};3334use frame_system::{self as system, ensure_signed};35use sp_core::H160;36use sp_std::vec;37use sp_runtime::sp_std::prelude::Vec;38use core::ops::{Deref, DerefMut};39use nft_data_structs::{40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,41 CUSTOM_DATA_LIMIT, COLLECTION_NUMBER_LIMIT, ACCOUNT_TOKEN_OWNERSHIP_LIMIT,42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, COLLECTION_ADMINS_LIMIT,43 OFFCHAIN_SCHEMA_LIMIT, AccessMode, Collection, CreateItemData, CollectionLimits, CollectionId,44 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,45 FungibleItemType, ReFungibleItemType,46};4748#[cfg(test)]49mod mock;5051#[cfg(test)]52mod tests;5354mod default_weights;55mod eth;56mod sponsorship;57pub use sponsorship::NftSponsorshipHandler;58pub use eth::sponsoring::NftEthSponsorshipHandler;5960pub use eth::NftErcSupport;61pub use eth::account::*;62use eth::erc::{ERC20Events, ERC721Events};6364#[cfg(feature = "runtime-benchmarks")]65mod benchmarking;6667pub trait WeightInfo {68 fn create_collection() -> Weight;69 fn destroy_collection() -> Weight;70 fn add_to_white_list() -> Weight;71 fn remove_from_white_list() -> Weight;72 fn set_public_access_mode() -> Weight;73 fn set_mint_permission() -> Weight;74 fn change_collection_owner() -> Weight;75 fn add_collection_admin() -> Weight;76 fn remove_collection_admin() -> Weight;77 fn set_collection_sponsor() -> Weight;78 fn confirm_sponsorship() -> Weight;79 fn remove_collection_sponsor() -> Weight;80 fn create_item(s: usize) -> Weight;81 fn burn_item() -> Weight;82 fn transfer() -> Weight;83 fn approve() -> Weight;84 fn transfer_from() -> Weight;85 fn set_offchain_schema() -> Weight;86 fn set_const_on_chain_schema() -> Weight;87 fn set_variable_on_chain_schema() -> Weight;88 fn set_variable_meta_data() -> Weight;89 fn enable_contract_sponsoring() -> Weight;90 fn set_schema_version() -> Weight;91 fn set_contract_sponsoring_rate_limit() -> Weight;92 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;93 fn toggle_contract_white_list() -> Weight;94 fn add_to_contract_white_list() -> Weight;95 fn remove_from_contract_white_list() -> Weight;96 fn set_collection_limits() -> Weight;97}9899decl_error! {100 /// Error for non-fungible-token module.101 pub enum Error for Module<T: Config> {102 /// Total collections bound exceeded.103 TotalCollectionsLimitExceeded,104 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.105 CollectionDecimalPointLimitExceeded,106 /// Collection name can not be longer than 63 char.107 CollectionNameLimitExceeded,108 /// Collection description can not be longer than 255 char.109 CollectionDescriptionLimitExceeded,110 /// Token prefix can not be longer than 15 char.111 CollectionTokenPrefixLimitExceeded,112 /// This collection does not exist.113 CollectionNotFound,114 /// Item not exists.115 TokenNotFound,116 /// Admin not found117 AdminNotFound,118 /// Arithmetic calculation overflow.119 NumOverflow,120 /// Account already has admin role.121 AlreadyAdmin,122 /// You do not own this collection.123 NoPermission,124 /// This address is not set as sponsor, use setCollectionSponsor first.125 ConfirmUnsetSponsorFail,126 /// Collection is not in mint mode.127 PublicMintingNotAllowed,128 /// Sender parameter and item owner must be equal.129 MustBeTokenOwner,130 /// Item balance not enough.131 TokenValueTooLow,132 /// Size of item is too large.133 NftSizeLimitExceeded,134 /// No approve found135 ApproveNotFound,136 /// Requested value more than approved.137 TokenValueNotEnough,138 /// Only approved addresses can call this method.139 ApproveRequired,140 /// Address is not in white list.141 AddresNotInWhiteList,142 /// Number of collection admins bound exceeded.143 CollectionAdminsLimitExceeded,144 /// Owned tokens by a single address bound exceeded.145 AddressOwnershipLimitExceeded,146 /// Length of items properties must be greater than 0.147 EmptyArgument,148 /// const_data exceeded data limit.149 TokenConstDataLimitExceeded,150 /// variable_data exceeded data limit.151 TokenVariableDataLimitExceeded,152 /// Not NFT item data used to mint in NFT collection.153 NotNftDataUsedToMintNftCollectionToken,154 /// Not Fungible item data used to mint in Fungible collection.155 NotFungibleDataUsedToMintFungibleCollectionToken,156 /// Not Re Fungible item data used to mint in Re Fungible collection.157 NotReFungibleDataUsedToMintReFungibleCollectionToken,158 /// Unexpected collection type.159 UnexpectedCollectionType,160 /// Can't store metadata in fungible tokens.161 CantStoreMetadataInFungibleTokens,162 /// Collection token limit exceeded163 CollectionTokenLimitExceeded,164 /// Account token limit exceeded per collection165 AccountTokenLimitExceeded,166 /// Collection limit bounds per collection exceeded167 CollectionLimitBoundsExceeded,168 /// Tried to enable permissions which are only permitted to be disabled169 OwnerPermissionsCantBeReverted,170 /// Schema data size limit bound exceeded171 SchemaDataLimitExceeded,172 /// Maximum refungibility exceeded173 WrongRefungiblePieces,174 /// createRefungible should be called with one owner175 BadCreateRefungibleCall,176 /// Gas limit exceeded177 OutOfGas,178 /// Collection settings not allowing items transferring179 TransferNotAllowed,180 }181}182183#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]184pub struct CollectionHandle<T: Config> {185 pub id: CollectionId,186 collection: Collection<T>,187 recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,188}189impl<T: Config> CollectionHandle<T> {190 pub fn get_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {191 <CollectionById<T>>::get(id).map(|collection| Self {192 id,193 collection,194 recorder: pallet_evm_coder_substrate::SubstrateRecorder::new(195 eth::collection_id_to_address(id),196 gas_limit,197 ),198 })199 }200 pub fn get(id: CollectionId) -> Option<Self> {201 Self::get_with_gas_limit(id, u64::MAX)202 }203 pub fn log(&self, log: impl evm_coder::ToLog) -> DispatchResult {204 self.recorder.log_sub(log)205 }206 fn consume_gas(&self, gas: u64) -> DispatchResult {207 self.recorder.consume_gas_sub(gas)208 }209 pub fn submit_logs(self) -> DispatchResult {210 self.recorder.submit_logs()211 }212 pub fn save(self) -> DispatchResult {213 self.recorder.submit_logs()?;214 <CollectionById<T>>::insert(self.id, self.collection);215 Ok(())216 }217}218impl<T: Config> Deref for CollectionHandle<T> {219 type Target = Collection<T>;220221 fn deref(&self) -> &Self::Target {222 &self.collection223 }224}225226impl<T: Config> DerefMut for CollectionHandle<T> {227 fn deref_mut(&mut self) -> &mut Self::Target {228 &mut self.collection229 }230}231232pub trait Config: system::Config + pallet_evm_coder_substrate::Config + Sized {233 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;234235 /// Weight information for extrinsics in this pallet.236 type WeightInfo: WeightInfo;237238 type EvmAddressMapping: pallet_evm::AddressMapping<Self::AccountId>;239 type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;240241 type CrossAccountId: CrossAccountId<Self::AccountId>;242 type Currency: Currency<Self::AccountId>;243 type CollectionCreationPrice: Get<244 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,245 >;246 type TreasuryAccountId: Get<Self::AccountId>;247}248249// # Used definitions250//251// ## User control levels252//253// chain-controlled - key is uncontrolled by user254// i.e autoincrementing index255// can use non-cryptographic hash256// real - key is controlled by user257// but it is hard to generate enough colliding values, i.e owner of signed txs258// can use non-cryptographic hash259// controlled - key is completly controlled by users260// i.e maps with mutable keys261// should use cryptographic hash262//263// ## User control level downgrade reasons264//265// ?1 - chain-controlled -> controlled266// collections/tokens can be destroyed, resulting in massive holes267// ?2 - chain-controlled -> controlled268// same as ?1, but can be only added, resulting in easier exploitation269// ?3 - real -> controlled270// no confirmation required, so addresses can be easily generated271decl_storage! {272 trait Store for Module<T: Config> as Nft {273274 //#region Private members275 /// Id of next collection276 CreatedCollectionCount: u32;277 /// Used for migrations278 ChainVersion: u64;279 /// Id of last collection token280 /// Collection id (controlled?1)281 ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;282 //#endregion283284 //#region Bound counters285 /// Amount of collections destroyed, used for total amount tracking with286 /// CreatedCollectionCount287 DestroyedCollectionCount: u32;288 /// Total amount of account owned tokens (NFTs + RFTs + unique fungibles)289 /// Account id (real)290 pub AccountItemCount get(fn account_item_count): map hasher(twox_64_concat) T::AccountId => u32;291 //#endregion292293 //#region Basic collections294 /// Collection info295 /// Collection id (controlled?1)296 pub CollectionById get(fn collection_id) config(): map hasher(blake2_128_concat) CollectionId => Option<Collection<T>> = None;297 /// List of collection admins298 /// Collection id (controlled?2)299 pub AdminList get(fn admin_list_collection): map hasher(blake2_128_concat) CollectionId => Vec<T::CrossAccountId>;300 /// Whitelisted collection users301 /// Collection id (controlled?2), user id (controlled?3)302 pub WhiteList get(fn white_list): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => bool;303 //#endregion304305 /// How many of collection items user have306 /// Collection id (controlled?2), account id (real)307 pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => u128;308309 /// Amount of items which spender can transfer out of owners account (via transferFrom)310 /// Collection id (controlled?2), (token id (controlled ?2) + owner account id (real) + spender account id (controlled?3))311 /// TODO: Off chain worker should remove from this map when token gets removed312 pub Allowances get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId, T::AccountId) => u128;313314 //#region Item collections315 /// Collection id (controlled?2), token id (controlled?1)316 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<NftItemType<T::CrossAccountId>>;317 /// Collection id (controlled?2), owner (controlled?2)318 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => FungibleItemType;319 /// Collection id (controlled?2), token id (controlled?1)320 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<ReFungibleItemType<T::CrossAccountId>>;321 //#endregion322323 //#region Index list324 /// Collection id (controlled?2), tokens owner (controlled?2)325 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => Vec<TokenId>;326 //#endregion327328 //#region Tokens transfer rate limit baskets329 /// (Collection id (controlled?2), who created (real))330 /// TODO: Off chain worker should remove from this map when collection gets removed331 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => T::BlockNumber;332 /// Collection id (controlled?2), token id (controlled?2)333 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;334 /// Collection id (controlled?2), owning user (real)335 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;336 /// Collection id (controlled?2), token id (controlled?2)337 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;338 //#endregion339340 /// Variable metadata sponsoring341 /// Collection id (controlled?2), token id (controlled?2)342 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber> = None;343 }344 add_extra_genesis {345 build(|config: &GenesisConfig<T>| {346 // Modification of storage347 for (_num, _c) in &config.collection_id {348 <Module<T>>::init_collection(_c);349 }350351 for (_num, _c, _i) in &config.nft_item_id {352 <Module<T>>::init_nft_token(*_c, _i);353 }354355 for (collection_id, account_id, fungible_item) in &config.fungible_item_id {356 <Module<T>>::init_fungible_token(*collection_id, &T::CrossAccountId::from_sub(account_id.clone()), fungible_item);357 }358359 for (_num, _c, _i) in &config.refungible_item_id {360 <Module<T>>::init_refungible_token(*_c, _i);361 }362 })363 }364}365366decl_event!(367 pub enum Event<T>368 where369 AccountId = <T as frame_system::Config>::AccountId,370 CrossAccountId = <T as Config>::CrossAccountId,371 {372 /// New collection was created373 ///374 /// # Arguments375 ///376 /// * collection_id: Globally unique identifier of newly created collection.377 ///378 /// * mode: [CollectionMode] converted into u8.379 ///380 /// * account_id: Collection owner.381 CollectionCreated(CollectionId, u8, AccountId),382383 /// New item was created.384 ///385 /// # Arguments386 ///387 /// * collection_id: Id of the collection where item was created.388 ///389 /// * item_id: Id of an item. Unique within the collection.390 ///391 /// * recipient: Owner of newly created item392 ItemCreated(CollectionId, TokenId, CrossAccountId),393394 /// Collection item was burned.395 ///396 /// # Arguments397 ///398 /// collection_id.399 ///400 /// item_id: Identifier of burned NFT.401 ItemDestroyed(CollectionId, TokenId),402403 /// Item was transferred404 ///405 /// * collection_id: Id of collection to which item is belong406 ///407 /// * item_id: Id of an item408 ///409 /// * sender: Original owner of item410 ///411 /// * recipient: New owner of item412 ///413 /// * amount: Always 1 for NFT414 Transfer(CollectionId, TokenId, CrossAccountId, CrossAccountId, u128),415416 /// * collection_id417 ///418 /// * item_id419 ///420 /// * sender421 ///422 /// * spender423 ///424 /// * amount425 Approved(CollectionId, TokenId, CrossAccountId, CrossAccountId, u128),426 }427);428429decl_module! {430 pub struct Module<T: Config> for enum Call431 where432 origin: T::Origin433 {434 fn deposit_event() = default;435 const CollectionAdminsLimit: u64 = COLLECTION_ADMINS_LIMIT;436 type Error = Error<T>;437438 fn on_initialize(_now: T::BlockNumber) -> Weight {439 0440 }441442 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner and admin of the collection are set to the address that signed the transaction. Both addresses can be changed later.443 ///444 /// # Permissions445 ///446 /// * Anyone.447 ///448 /// # Arguments449 ///450 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.451 ///452 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.453 ///454 /// * token_prefix: UTF-8 string with token prefix.455 ///456 /// * mode: [CollectionMode] collection type and type dependent data.457 // returns collection ID458 #[weight = <T as Config>::WeightInfo::create_collection()]459 #[transactional]460 pub fn create_collection(origin,461 collection_name: Vec<u16>,462 collection_description: Vec<u16>,463 token_prefix: Vec<u8>,464 mode: CollectionMode) -> DispatchResult {465466 // Anyone can create a collection467 let who = ensure_signed(origin)?;468469 // Take a (non-refundable) deposit of collection creation470 let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();471 imbalance.subsume(<<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(472 &T::TreasuryAccountId::get(),473 T::CollectionCreationPrice::get(),474 ));475 <T as Config>::Currency::settle(476 &who,477 imbalance,478 WithdrawReasons::TRANSFER,479 ExistenceRequirement::KeepAlive,480 ).map_err(|_| Error::<T>::NoPermission)?;481482 let decimal_points = match mode {483 CollectionMode::Fungible(points) => points,484 _ => 0485 };486487 let created_count = CreatedCollectionCount::get();488 let destroyed_count = DestroyedCollectionCount::get();489490 // bound Total number of collections491 ensure!(created_count - destroyed_count < COLLECTION_NUMBER_LIMIT, Error::<T>::TotalCollectionsLimitExceeded);492493 // check params494 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);495 ensure!(collection_name.len() <= 64, Error::<T>::CollectionNameLimitExceeded);496 ensure!(collection_description.len() <= 256, Error::<T>::CollectionDescriptionLimitExceeded);497 ensure!(token_prefix.len() <= 16, Error::<T>::CollectionTokenPrefixLimitExceeded);498499 // Generate next collection ID500 let next_id = created_count501 .checked_add(1)502 .ok_or(Error::<T>::NumOverflow)?;503504 CreatedCollectionCount::put(next_id);505506 let limits = CollectionLimits {507 sponsored_data_size: CUSTOM_DATA_LIMIT,508 ..Default::default()509 };510511 // Create new collection512 let new_collection = Collection {513 owner: who.clone(),514 name: collection_name,515 mode: mode.clone(),516 mint_mode: false,517 access: AccessMode::Normal,518 description: collection_description,519 decimal_points,520 token_prefix,521 offchain_schema: Vec::new(),522 schema_version: SchemaVersion::ImageURL,523 sponsorship: SponsorshipState::Disabled,524 variable_on_chain_schema: Vec::new(),525 const_on_chain_schema: Vec::new(),526 limits,527 transfers_enabled: true,528 };529530 // Add new collection to map531 <CollectionById<T>>::insert(next_id, new_collection);532533 // call event534 Self::deposit_event(RawEvent::CollectionCreated(next_id, mode.id(), who));535536 Ok(())537 }538539 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.540 ///541 /// # Permissions542 ///543 /// * Collection Owner.544 ///545 /// # Arguments546 ///547 /// * collection_id: collection to destroy.548 #[weight = <T as Config>::WeightInfo::destroy_collection()]549 #[transactional]550 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {551552 let sender = ensure_signed(origin)?;553 let collection = Self::get_collection(collection_id)?;554 Self::check_owner_permissions(&collection, &sender)?;555 if !collection.limits.owner_can_destroy {556 fail!(Error::<T>::NoPermission);557 }558559 <AddressTokens<T>>::remove_prefix(collection_id, None);560 <Allowances<T>>::remove_prefix(collection_id, None);561 <Balance<T>>::remove_prefix(collection_id, None);562 <ItemListIndex>::remove(collection_id);563 <AdminList<T>>::remove(collection_id);564 <CollectionById<T>>::remove(collection_id);565 <WhiteList<T>>::remove_prefix(collection_id, None);566567 <NftItemList<T>>::remove_prefix(collection_id, None);568 <FungibleItemList<T>>::remove_prefix(collection_id, None);569 <ReFungibleItemList<T>>::remove_prefix(collection_id, None);570571 <NftTransferBasket<T>>::remove_prefix(collection_id, None);572 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);573 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id, None);574575 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);576577 DestroyedCollectionCount::put(DestroyedCollectionCount::get()578 .checked_add(1)579 .ok_or(Error::<T>::NumOverflow)?);580581 Ok(())582 }583584 /// Add an address to white list.585 ///586 /// # Permissions587 ///588 /// * Collection Owner589 /// * Collection Admin590 ///591 /// # Arguments592 ///593 /// * collection_id.594 ///595 /// * address.596 #[weight = <T as Config>::WeightInfo::add_to_white_list()]597 #[transactional]598 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{599600 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);601 let collection = Self::get_collection(collection_id)?;602603 Self::toggle_white_list_internal(604 &sender,605 &collection,606 &address,607 true,608 )?;609610 Ok(())611 }612613 /// Remove an address from white list.614 ///615 /// # Permissions616 ///617 /// * Collection Owner618 /// * Collection Admin619 ///620 /// # Arguments621 ///622 /// * collection_id.623 ///624 /// * address.625 #[weight = <T as Config>::WeightInfo::remove_from_white_list()]626 #[transactional]627 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{628629 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);630 let collection = Self::get_collection(collection_id)?;631632 Self::toggle_white_list_internal(633 &sender,634 &collection,635 &address,636 false,637 )?;638639 Ok(())640 }641642 /// Toggle between normal and white list access for the methods with access for `Anyone`.643 ///644 /// # Permissions645 ///646 /// * Collection Owner.647 ///648 /// # Arguments649 ///650 /// * collection_id.651 ///652 /// * mode: [AccessMode]653 #[weight = <T as Config>::WeightInfo::set_public_access_mode()]654 #[transactional]655 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult656 {657 let sender = ensure_signed(origin)?;658659 let mut target_collection = Self::get_collection(collection_id)?;660 Self::check_owner_permissions(&target_collection, &sender)?;661 target_collection.access = mode;662 target_collection.save()663 }664665 /// Allows Anyone to create tokens if:666 /// * White List is enabled, and667 /// * Address is added to white list, and668 /// * This method was called with True parameter669 ///670 /// # Permissions671 /// * Collection Owner672 ///673 /// # Arguments674 ///675 /// * collection_id.676 ///677 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.678 #[weight = <T as Config>::WeightInfo::set_mint_permission()]679 #[transactional]680 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult681 {682 let sender = ensure_signed(origin)?;683684 let mut target_collection = Self::get_collection(collection_id)?;685 Self::check_owner_permissions(&target_collection, &sender)?;686 target_collection.mint_mode = mint_permission;687 target_collection.save()688 }689690 /// Change the owner of the collection.691 ///692 /// # Permissions693 ///694 /// * Collection Owner.695 ///696 /// # Arguments697 ///698 /// * collection_id.699 ///700 /// * new_owner.701 #[weight = <T as Config>::WeightInfo::change_collection_owner()]702 #[transactional]703 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {704705 let sender = ensure_signed(origin)?;706 let mut target_collection = Self::get_collection(collection_id)?;707 Self::check_owner_permissions(&target_collection, &sender)?;708 target_collection.owner = new_owner;709 target_collection.save()710 }711712 /// Adds an admin of the Collection.713 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.714 ///715 /// # Permissions716 ///717 /// * Collection Owner.718 /// * Collection Admin.719 ///720 /// # Arguments721 ///722 /// * collection_id: ID of the Collection to add admin for.723 ///724 /// * new_admin_id: Address of new admin to add.725 #[weight = <T as Config>::WeightInfo::add_collection_admin()]726 #[transactional]727 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {728 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);729 let collection = Self::get_collection(collection_id)?;730 Self::check_owner_or_admin_permissions(&collection, &sender)?;731 let mut admin_arr = <AdminList<T>>::get(collection_id);732733 match admin_arr.binary_search(&new_admin_id) {734 Ok(_) => {},735 Err(idx) => {736 ensure!(admin_arr.len() < COLLECTION_ADMINS_LIMIT as usize, Error::<T>::CollectionAdminsLimitExceeded);737 admin_arr.insert(idx, new_admin_id);738 <AdminList<T>>::insert(collection_id, admin_arr);739 }740 }741 Ok(())742 }743744 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.745 ///746 /// # Permissions747 ///748 /// * Collection Owner.749 /// * Collection Admin.750 ///751 /// # Arguments752 ///753 /// * collection_id: ID of the Collection to remove admin for.754 ///755 /// * account_id: Address of admin to remove.756 #[weight = <T as Config>::WeightInfo::remove_collection_admin()]757 #[transactional]758 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {759 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);760 let collection = Self::get_collection(collection_id)?;761 Self::check_owner_or_admin_permissions(&collection, &sender)?;762 let mut admin_arr = <AdminList<T>>::get(collection_id);763764 if let Ok(idx) = admin_arr.binary_search(&account_id) {765 admin_arr.remove(idx);766 <AdminList<T>>::insert(collection_id, admin_arr);767 }768 Ok(())769 }770771 /// # Permissions772 ///773 /// * Collection Owner774 ///775 /// # Arguments776 ///777 /// * collection_id.778 ///779 /// * new_sponsor.780 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]781 #[transactional]782 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {783 let sender = ensure_signed(origin)?;784 let mut target_collection = Self::get_collection(collection_id)?;785 Self::check_owner_permissions(&target_collection, &sender)?;786787 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor);788 target_collection.save()789 }790791 /// # Permissions792 ///793 /// * Sponsor.794 ///795 /// # Arguments796 ///797 /// * collection_id.798 #[weight = <T as Config>::WeightInfo::confirm_sponsorship()]799 #[transactional]800 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {801 let sender = ensure_signed(origin)?;802803 let mut target_collection = Self::get_collection(collection_id)?;804 ensure!(805 target_collection.sponsorship.pending_sponsor() == Some(&sender),806 Error::<T>::ConfirmUnsetSponsorFail807 );808809 target_collection.sponsorship = SponsorshipState::Confirmed(sender);810 target_collection.save()811 }812813 /// Switch back to pay-per-own-transaction model.814 ///815 /// # Permissions816 ///817 /// * Collection owner.818 ///819 /// # Arguments820 ///821 /// * collection_id.822 #[weight = <T as Config>::WeightInfo::remove_collection_sponsor()]823 #[transactional]824 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {825 let sender = ensure_signed(origin)?;826827 let mut target_collection = Self::get_collection(collection_id)?;828 Self::check_owner_permissions(&target_collection, &sender)?;829830 target_collection.sponsorship = SponsorshipState::Disabled;831 target_collection.save()832 }833834 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.835 ///836 /// # Permissions837 ///838 /// * Collection Owner.839 /// * Collection Admin.840 /// * Anyone if841 /// * White List is enabled, and842 /// * Address is added to white list, and843 /// * MintPermission is enabled (see SetMintPermission method)844 ///845 /// # Arguments846 ///847 /// * collection_id: ID of the collection.848 ///849 /// * owner: Address, initial owner of the NFT.850 ///851 /// * data: Token data to store on chain.852 // #[weight =853 // (130_000_000 as Weight)854 // .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))855 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))856 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]857858 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]859 #[transactional]860 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {861 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);862 let collection = Self::get_collection(collection_id)?;863864 Self::create_item_internal(&sender, &collection, &owner, data)?;865866 collection.submit_logs()867 }868869 /// This method creates multiple items in a collection created with CreateCollection method.870 ///871 /// # Permissions872 ///873 /// * Collection Owner.874 /// * Collection Admin.875 /// * Anyone if876 /// * White List is enabled, and877 /// * Address is added to white list, and878 /// * MintPermission is enabled (see SetMintPermission method)879 ///880 /// # Arguments881 ///882 /// * collection_id: ID of the collection.883 ///884 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].885 ///886 /// * owner: Address, initial owner of the NFT.887 #[weight = <T as Config>::WeightInfo::create_item(items_data.iter()888 .map(|data| { data.data_size() })889 .sum())]890 #[transactional]891 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {892893 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);894 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);895 let collection = Self::get_collection(collection_id)?;896897 Self::create_multiple_items_internal(&sender, &collection, &owner, items_data)?;898899 collection.submit_logs()900 }901902 // TODO! transaction weight903904 /// Set transfers_enabled value for particular collection905 ///906 /// # Permissions907 ///908 /// * Collection Owner.909 ///910 /// # Arguments911 ///912 /// * collection_id: ID of the collection.913 ///914 /// * value: New flag value.915 #[weight = <T as Config>::WeightInfo::burn_item()]916 #[transactional]917 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {918919 let sender = ensure_signed(origin)?;920 let mut target_collection = Self::get_collection(collection_id)?;921922 Self::check_owner_permissions(&target_collection, &sender)?;923924 target_collection.transfers_enabled = value;925 target_collection.save()926 }927928 /// Destroys a concrete instance of NFT.929 ///930 /// # Permissions931 ///932 /// * Collection Owner.933 /// * Collection Admin.934 /// * Current NFT Owner.935 ///936 /// # Arguments937 ///938 /// * collection_id: ID of the collection.939 ///940 /// * item_id: ID of NFT to burn.941 #[weight = <T as Config>::WeightInfo::burn_item()]942 #[transactional]943 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {944945 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);946 let target_collection = Self::get_collection(collection_id)?;947948 Self::burn_item_internal(&sender, &target_collection, item_id, value)?;949950 target_collection.submit_logs()951 }952953 /// Change ownership of the token.954 ///955 /// # Permissions956 ///957 /// * Collection Owner958 /// * Collection Admin959 /// * Current NFT owner960 ///961 /// # Arguments962 ///963 /// * recipient: Address of token recipient.964 ///965 /// * collection_id.966 ///967 /// * item_id: ID of the item968 /// * Non-Fungible Mode: Required.969 /// * Fungible Mode: Ignored.970 /// * Re-Fungible Mode: Required.971 ///972 /// * value: Amount to transfer.973 /// * Non-Fungible Mode: Ignored974 /// * Fungible Mode: Must specify transferred amount975 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)976 #[weight = <T as Config>::WeightInfo::transfer()]977 #[transactional]978 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {979 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);980 let collection = Self::get_collection(collection_id)?;981982 Self::transfer_internal(&sender, &recipient, &collection, item_id, value)?;983984 collection.submit_logs()985 }986987 /// Set, change, or remove approved address to transfer the ownership of the NFT.988 ///989 /// # Permissions990 ///991 /// * Collection Owner992 /// * Collection Admin993 /// * Current NFT owner994 ///995 /// # Arguments996 ///997 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).998 ///999 /// * collection_id.1000 ///1001 /// * item_id: ID of the item.1002 #[weight = <T as Config>::WeightInfo::approve()]1003 #[transactional]1004 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResult {1005 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1006 let collection = Self::get_collection(collection_id)?;10071008 Self::approve_internal(&sender, &spender, &collection, item_id, amount)?;10091010 collection.submit_logs()1011 }10121013 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.1014 ///1015 /// # Permissions1016 /// * Collection Owner1017 /// * Collection Admin1018 /// * Current NFT owner1019 /// * Address approved by current NFT owner1020 ///1021 /// # Arguments1022 ///1023 /// * from: Address that owns token.1024 ///1025 /// * recipient: Address of token recipient.1026 ///1027 /// * collection_id.1028 ///1029 /// * item_id: ID of the item.1030 ///1031 /// * value: Amount to transfer.1032 #[weight = <T as Config>::WeightInfo::transfer_from()]1033 #[transactional]1034 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResult {1035 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1036 let collection = Self::get_collection(collection_id)?;10371038 Self::transfer_from_internal(&sender, &from, &recipient, &collection, item_id, value)?;10391040 collection.submit_logs()1041 }1042 // #[weight = 0]1043 // // let no_perm_mes = "You do not have permissions to modify this collection";1044 // // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);1045 // // let list_itm = <ApprovedList<T>>::get((collection_id, item_id));1046 // // ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);10471048 // // // on_nft_received call10491050 // // Self::transfer(origin, collection_id, item_id, new_owner)?;10511052 // Ok(())1053 // }10541055 /// Set off-chain data schema.1056 ///1057 /// # Permissions1058 ///1059 /// * Collection Owner1060 /// * Collection Admin1061 ///1062 /// # Arguments1063 ///1064 /// * collection_id.1065 ///1066 /// * schema: String representing the offchain data schema.1067 #[weight = <T as Config>::WeightInfo::set_variable_meta_data()]1068 #[transactional]1069 pub fn set_variable_meta_data (1070 origin,1071 collection_id: CollectionId,1072 item_id: TokenId,1073 data: Vec<u8>1074 ) -> DispatchResult {1075 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);10761077 let collection = Self::get_collection(collection_id)?;10781079 Self::set_variable_meta_data_internal(&sender, &collection, item_id, data)?;10801081 Ok(())1082 }10831084 /// Set schema standard1085 /// ImageURL1086 /// Unique1087 ///1088 /// # Permissions1089 ///1090 /// * Collection Owner1091 /// * Collection Admin1092 ///1093 /// # Arguments1094 ///1095 /// * collection_id.1096 ///1097 /// * schema: SchemaVersion: enum1098 #[weight = <T as Config>::WeightInfo::set_schema_version()]1099 #[transactional]1100 pub fn set_schema_version(1101 origin,1102 collection_id: CollectionId,1103 version: SchemaVersion1104 ) -> DispatchResult {1105 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1106 let mut target_collection = Self::get_collection(collection_id)?;1107 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1108 target_collection.schema_version = version;1109 target_collection.save()1110 }11111112 /// Set off-chain data schema.1113 ///1114 /// # Permissions1115 ///1116 /// * Collection Owner1117 /// * Collection Admin1118 ///1119 /// # Arguments1120 ///1121 /// * collection_id.1122 ///1123 /// * schema: String representing the offchain data schema.1124 #[weight = <T as Config>::WeightInfo::set_offchain_schema()]1125 #[transactional]1126 pub fn set_offchain_schema(1127 origin,1128 collection_id: CollectionId,1129 schema: Vec<u8>1130 ) -> DispatchResult {1131 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1132 let mut target_collection = Self::get_collection(collection_id)?;1133 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11341135 // check schema limit1136 ensure!(schema.len() as u32 <= OFFCHAIN_SCHEMA_LIMIT, "");11371138 target_collection.offchain_schema = schema;1139 target_collection.save()1140 }11411142 /// Set const on-chain data schema.1143 ///1144 /// # Permissions1145 ///1146 /// * Collection Owner1147 /// * Collection Admin1148 ///1149 /// # Arguments1150 ///1151 /// * collection_id.1152 ///1153 /// * schema: String representing the const on-chain data schema.1154 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1155 #[transactional]1156 pub fn set_const_on_chain_schema (1157 origin,1158 collection_id: CollectionId,1159 schema: Vec<u8>1160 ) -> DispatchResult {1161 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1162 let mut target_collection = Self::get_collection(collection_id)?;1163 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11641165 // check schema limit1166 ensure!(schema.len() as u32 <= CONST_ON_CHAIN_SCHEMA_LIMIT, "");11671168 target_collection.const_on_chain_schema = schema;1169 target_collection.save()1170 }11711172 /// Set variable on-chain data schema.1173 ///1174 /// # Permissions1175 ///1176 /// * Collection Owner1177 /// * Collection Admin1178 ///1179 /// # Arguments1180 ///1181 /// * collection_id.1182 ///1183 /// * schema: String representing the variable on-chain data schema.1184 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1185 #[transactional]1186 pub fn set_variable_on_chain_schema (1187 origin,1188 collection_id: CollectionId,1189 schema: Vec<u8>1190 ) -> DispatchResult {1191 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1192 let mut target_collection = Self::get_collection(collection_id)?;1193 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11941195 // check schema limit1196 ensure!(schema.len() as u32 <= VARIABLE_ON_CHAIN_SCHEMA_LIMIT, "");11971198 target_collection.variable_on_chain_schema = schema;1199 target_collection.save()1200 }12011202 #[weight = <T as Config>::WeightInfo::set_collection_limits()]1203 #[transactional]1204 pub fn set_collection_limits(1205 origin,1206 collection_id: u32,1207 new_limits: CollectionLimits<T::BlockNumber>,1208 ) -> DispatchResult {1209 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1210 let mut target_collection = Self::get_collection(collection_id)?;1211 Self::check_owner_permissions(&target_collection, sender.as_sub())?;1212 let old_limits = &target_collection.limits;12131214 // collection bounds1215 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1216 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&1217 new_limits.sponsored_data_size <= CUSTOM_DATA_LIMIT,1218 Error::<T>::CollectionLimitBoundsExceeded);12191220 // token_limit check prev1221 ensure!(old_limits.token_limit >= new_limits.token_limit, Error::<T>::CollectionTokenLimitExceeded);1222 ensure!(new_limits.token_limit > 0, Error::<T>::CollectionTokenLimitExceeded);12231224 ensure!(1225 (old_limits.owner_can_transfer || !new_limits.owner_can_transfer) &&1226 (old_limits.owner_can_destroy || !new_limits.owner_can_destroy),1227 Error::<T>::OwnerPermissionsCantBeReverted,1228 );12291230 target_collection.limits = new_limits;12311232 target_collection.save()1233 }1234 }1235}12361237impl<T: Config> Module<T> {1238 pub fn create_item_internal(1239 sender: &T::CrossAccountId,1240 collection: &CollectionHandle<T>,1241 owner: &T::CrossAccountId,1242 data: CreateItemData,1243 ) -> DispatchResult {1244 Self::can_create_items_in_collection(collection, sender, owner, 1)?;1245 Self::validate_create_item_args(collection, &data)?;1246 Self::create_item_no_validation(collection, owner, data)?;12471248 Ok(())1249 }12501251 pub fn transfer_internal(1252 sender: &T::CrossAccountId,1253 recipient: &T::CrossAccountId,1254 target_collection: &CollectionHandle<T>,1255 item_id: TokenId,1256 value: u128,1257 ) -> DispatchResult {1258 target_collection.consume_gas(2000000)?;1259 // Limits check1260 Self::is_correct_transfer(target_collection, recipient)?;12611262 // Transfer permissions check1263 ensure!(1264 Self::is_item_owner(sender, target_collection, item_id)1265 || Self::is_owner_or_admin_permissions(target_collection, sender),1266 Error::<T>::NoPermission1267 );12681269 if target_collection.access == AccessMode::WhiteList {1270 Self::check_white_list(target_collection, sender)?;1271 Self::check_white_list(target_collection, recipient)?;1272 }12731274 match target_collection.mode {1275 CollectionMode::NFT => Self::transfer_nft(1276 target_collection,1277 item_id,1278 sender.clone(),1279 recipient.clone(),1280 )?,1281 CollectionMode::Fungible(_) => {1282 Self::transfer_fungible(target_collection, value, sender, recipient)?1283 }1284 CollectionMode::ReFungible => Self::transfer_refungible(1285 target_collection,1286 item_id,1287 value,1288 sender.clone(),1289 recipient.clone(),1290 )?,1291 _ => (),1292 };12931294 Self::deposit_event(RawEvent::Transfer(1295 target_collection.id,1296 item_id,1297 sender.clone(),1298 recipient.clone(),1299 value,1300 ));13011302 Ok(())1303 }13041305 pub fn approve_internal(1306 sender: &T::CrossAccountId,1307 spender: &T::CrossAccountId,1308 collection: &CollectionHandle<T>,1309 item_id: TokenId,1310 amount: u128,1311 ) -> DispatchResult {1312 collection.consume_gas(2000000)?;1313 Self::token_exists(collection, item_id)?;13141315 // Transfer permissions check1316 let bypasses_limits = collection.limits.owner_can_transfer1317 && Self::is_owner_or_admin_permissions(collection, sender);13181319 let allowance_limit = if bypasses_limits {1320 None1321 } else if let Some(amount) = Self::owned_amount(sender, collection, item_id) {1322 Some(amount)1323 } else {1324 fail!(Error::<T>::NoPermission);1325 };13261327 if collection.access == AccessMode::WhiteList {1328 Self::check_white_list(collection, sender)?;1329 Self::check_white_list(collection, spender)?;1330 }13311332 let allowance: u128 = amount1333 .checked_add(<Allowances<T>>::get(1334 collection.id,1335 (item_id, sender.as_sub(), spender.as_sub()),1336 ))1337 .ok_or(Error::<T>::NumOverflow)?;1338 if let Some(limit) = allowance_limit {1339 ensure!(limit >= allowance, Error::<T>::TokenValueTooLow);1340 }1341 <Allowances<T>>::insert(1342 collection.id,1343 (item_id, sender.as_sub(), spender.as_sub()),1344 allowance,1345 );13461347 if matches!(collection.mode, CollectionMode::NFT) {1348 // TODO: NFT: only one owner may exist for token in ERC7211349 collection.log(ERC721Events::Approval {1350 owner: *sender.as_eth(),1351 approved: *spender.as_eth(),1352 token_id: item_id.into(),1353 })?;1354 }13551356 if matches!(collection.mode, CollectionMode::Fungible(_)) {1357 // TODO: NFT: only one owner may exist for token in ERC201358 collection.log(ERC20Events::Approval {1359 owner: *sender.as_eth(),1360 spender: *spender.as_eth(),1361 value: allowance.into(),1362 })?;1363 }13641365 Self::deposit_event(RawEvent::Approved(1366 collection.id,1367 item_id,1368 sender.clone(),1369 spender.clone(),1370 allowance,1371 ));1372 Ok(())1373 }13741375 pub fn transfer_from_internal(1376 sender: &T::CrossAccountId,1377 from: &T::CrossAccountId,1378 recipient: &T::CrossAccountId,1379 collection: &CollectionHandle<T>,1380 item_id: TokenId,1381 amount: u128,1382 ) -> DispatchResult {1383 collection.consume_gas(2000000)?;1384 // Check approval1385 let approval: u128 =1386 <Allowances<T>>::get(collection.id, (item_id, from.as_sub(), sender.as_sub()));13871388 // Limits check1389 Self::is_correct_transfer(collection, recipient)?;13901391 // Transfer permissions check1392 ensure!(1393 approval >= amount1394 || (collection.limits.owner_can_transfer1395 && Self::is_owner_or_admin_permissions(collection, sender)),1396 Error::<T>::NoPermission1397 );13981399 if collection.access == AccessMode::WhiteList {1400 Self::check_white_list(collection, sender)?;1401 Self::check_white_list(collection, recipient)?;1402 }14031404 // Reduce approval by transferred amount or remove if remaining approval drops to 01405 let allowance = approval.saturating_sub(amount);1406 if allowance > 0 {1407 <Allowances<T>>::insert(1408 collection.id,1409 (item_id, from.as_sub(), sender.as_sub()),1410 allowance,1411 );1412 } else {1413 <Allowances<T>>::remove(collection.id, (item_id, from.as_sub(), sender.as_sub()));1414 }14151416 match collection.mode {1417 CollectionMode::NFT => {1418 Self::transfer_nft(collection, item_id, from.clone(), recipient.clone())?1419 }1420 CollectionMode::Fungible(_) => {1421 Self::transfer_fungible(collection, amount, from, recipient)?1422 }1423 CollectionMode::ReFungible => Self::transfer_refungible(1424 collection,1425 item_id,1426 amount,1427 from.clone(),1428 recipient.clone(),1429 )?,1430 _ => (),1431 };14321433 if matches!(collection.mode, CollectionMode::Fungible(_)) {1434 collection.log(ERC20Events::Approval {1435 owner: *from.as_eth(),1436 spender: *sender.as_eth(),1437 value: allowance.into(),1438 })?;1439 }14401441 Ok(())1442 }14431444 pub fn set_variable_meta_data_internal(1445 sender: &T::CrossAccountId,1446 collection: &CollectionHandle<T>,1447 item_id: TokenId,1448 data: Vec<u8>,1449 ) -> DispatchResult {1450 Self::token_exists(collection, item_id)?;14511452 ensure!(1453 CUSTOM_DATA_LIMIT >= data.len() as u32,1454 Error::<T>::TokenVariableDataLimitExceeded1455 );14561457 // Modify permissions check1458 ensure!(1459 Self::is_item_owner(sender, collection, item_id)1460 || Self::is_owner_or_admin_permissions(collection, sender),1461 Error::<T>::NoPermission1462 );14631464 match collection.mode {1465 CollectionMode::NFT => Self::set_nft_variable_data(collection, item_id, data)?,1466 CollectionMode::ReFungible => {1467 Self::set_re_fungible_variable_data(collection, item_id, data)?1468 }1469 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1470 _ => fail!(Error::<T>::UnexpectedCollectionType),1471 };14721473 Ok(())1474 }14751476 pub fn create_multiple_items_internal(1477 sender: &T::CrossAccountId,1478 collection: &CollectionHandle<T>,1479 owner: &T::CrossAccountId,1480 items_data: Vec<CreateItemData>,1481 ) -> DispatchResult {1482 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;14831484 for data in &items_data {1485 Self::validate_create_item_args(collection, data)?;1486 }1487 for data in &items_data {1488 Self::create_item_no_validation(collection, owner, data.clone())?;1489 }14901491 Ok(())1492 }14931494 pub fn burn_item_internal(1495 sender: &T::CrossAccountId,1496 collection: &CollectionHandle<T>,1497 item_id: TokenId,1498 value: u128,1499 ) -> DispatchResult {1500 ensure!(1501 Self::is_item_owner(sender, collection, item_id)1502 || (collection.limits.owner_can_transfer1503 && Self::is_owner_or_admin_permissions(collection, sender)),1504 Error::<T>::NoPermission1505 );15061507 if collection.access == AccessMode::WhiteList {1508 Self::check_white_list(collection, sender)?;1509 }15101511 match collection.mode {1512 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1513 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1514 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1515 _ => (),1516 };15171518 Ok(())1519 }15201521 pub fn toggle_white_list_internal(1522 sender: &T::CrossAccountId,1523 collection: &CollectionHandle<T>,1524 address: &T::CrossAccountId,1525 whitelisted: bool,1526 ) -> DispatchResult {1527 Self::check_owner_or_admin_permissions(collection, sender)?;15281529 if whitelisted {1530 <WhiteList<T>>::insert(collection.id, address.as_sub(), true);1531 } else {1532 <WhiteList<T>>::remove(collection.id, address.as_sub());1533 }15341535 Ok(())1536 }15371538 fn is_correct_transfer(1539 collection: &CollectionHandle<T>,1540 recipient: &T::CrossAccountId,1541 ) -> DispatchResult {1542 let collection_id = collection.id;15431544 // check token limit and account token limit1545 let account_items: u32 =1546 <AddressTokens<T>>::get(collection_id, recipient.as_sub()).len() as u32;1547 ensure!(1548 collection.limits.account_token_ownership_limit > account_items,1549 Error::<T>::AccountTokenLimitExceeded1550 );15511552 // preliminary transfer check1553 ensure!(collection.transfers_enabled, Error::<T>::TransferNotAllowed);15541555 Ok(())1556 }15571558 fn can_create_items_in_collection(1559 collection: &CollectionHandle<T>,1560 sender: &T::CrossAccountId,1561 owner: &T::CrossAccountId,1562 amount: u32,1563 ) -> DispatchResult {1564 let collection_id = collection.id;15651566 // check token limit and account token limit1567 let total_items: u32 = ItemListIndex::get(collection_id)1568 .checked_add(amount)1569 .ok_or(Error::<T>::CollectionTokenLimitExceeded)?;1570 let account_items: u32 = (<AddressTokens<T>>::get(collection_id, owner.as_sub()).len()1571 as u32)1572 .checked_add(amount)1573 .ok_or(Error::<T>::AccountTokenLimitExceeded)?;1574 ensure!(1575 collection.limits.token_limit >= total_items,1576 Error::<T>::CollectionTokenLimitExceeded1577 );1578 ensure!(1579 collection.limits.account_token_ownership_limit >= account_items,1580 Error::<T>::AccountTokenLimitExceeded1581 );15821583 if !Self::is_owner_or_admin_permissions(collection, sender) {1584 ensure!(collection.mint_mode, Error::<T>::PublicMintingNotAllowed);1585 Self::check_white_list(collection, owner)?;1586 Self::check_white_list(collection, sender)?;1587 }15881589 Ok(())1590 }15911592 fn validate_create_item_args(1593 target_collection: &CollectionHandle<T>,1594 data: &CreateItemData,1595 ) -> DispatchResult {1596 match target_collection.mode {1597 CollectionMode::NFT => {1598 if !matches!(data, CreateItemData::NFT(_)) {1599 fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);1600 }1601 }1602 CollectionMode::Fungible(_) => {1603 if !matches!(data, CreateItemData::Fungible(_)) {1604 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1605 }1606 }1607 CollectionMode::ReFungible => {1608 if let CreateItemData::ReFungible(data) = data {1609 // Check refungibility limits1610 ensure!(1611 data.pieces <= MAX_REFUNGIBLE_PIECES,1612 Error::<T>::WrongRefungiblePieces1613 );1614 ensure!(data.pieces > 0, Error::<T>::WrongRefungiblePieces);1615 } else {1616 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1617 }1618 }1619 _ => {1620 fail!(Error::<T>::UnexpectedCollectionType);1621 }1622 };16231624 Ok(())1625 }16261627 fn create_item_no_validation(1628 collection: &CollectionHandle<T>,1629 owner: &T::CrossAccountId,1630 data: CreateItemData,1631 ) -> DispatchResult {1632 match data {1633 CreateItemData::NFT(data) => {1634 let item = NftItemType {1635 owner: owner.clone(),1636 const_data: data.const_data.into_inner(),1637 variable_data: data.variable_data.into_inner(),1638 };16391640 Self::add_nft_item(collection, item)?;1641 }1642 CreateItemData::Fungible(data) => {1643 Self::add_fungible_item(collection, owner, data.value)?;1644 }1645 CreateItemData::ReFungible(data) => {1646 let owner_list = vec![Ownership {1647 owner: owner.clone(),1648 fraction: data.pieces,1649 }];16501651 let item = ReFungibleItemType {1652 owner: owner_list,1653 const_data: data.const_data.into_inner(),1654 variable_data: data.variable_data.into_inner(),1655 };16561657 Self::add_refungible_item(collection, item)?;1658 }1659 };16601661 Ok(())1662 }16631664 fn add_fungible_item(1665 collection: &CollectionHandle<T>,1666 owner: &T::CrossAccountId,1667 value: u128,1668 ) -> DispatchResult {1669 let collection_id = collection.id;16701671 // Does new owner already have an account?1672 let balance: u128 = <FungibleItemList<T>>::get(collection_id, owner.as_sub()).value;16731674 // Mint1675 let item = FungibleItemType {1676 value: balance.checked_add(value).ok_or(Error::<T>::NumOverflow)?,1677 };1678 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), item);16791680 // Update balance1681 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1682 .checked_add(value)1683 .ok_or(Error::<T>::NumOverflow)?;1684 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);16851686 Self::deposit_event(RawEvent::ItemCreated(collection_id, 0, owner.clone()));1687 Ok(())1688 }16891690 fn add_refungible_item(1691 collection: &CollectionHandle<T>,1692 item: ReFungibleItemType<T::CrossAccountId>,1693 ) -> DispatchResult {1694 let collection_id = collection.id;16951696 let current_index = <ItemListIndex>::get(collection_id)1697 .checked_add(1)1698 .ok_or(Error::<T>::NumOverflow)?;1699 let itemcopy = item.clone();17001701 ensure!(item.owner.len() == 1, Error::<T>::BadCreateRefungibleCall,);1702 let item_owner = item.owner.first().expect("only one owner is defined");17031704 let value = item_owner.fraction;1705 let owner = item_owner.owner.clone();17061707 Self::add_token_index(collection_id, current_index, &owner)?;17081709 <ItemListIndex>::insert(collection_id, current_index);1710 <ReFungibleItemList<T>>::insert(collection_id, current_index, itemcopy);17111712 // Update balance1713 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1714 .checked_add(value)1715 .ok_or(Error::<T>::NumOverflow)?;1716 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);17171718 Self::deposit_event(RawEvent::ItemCreated(collection_id, current_index, owner));1719 Ok(())1720 }17211722 fn add_nft_item(1723 collection: &CollectionHandle<T>,1724 item: NftItemType<T::CrossAccountId>,1725 ) -> DispatchResult {1726 let collection_id = collection.id;17271728 let current_index = <ItemListIndex>::get(collection_id)1729 .checked_add(1)1730 .ok_or(Error::<T>::NumOverflow)?;17311732 let item_owner = item.owner.clone();1733 Self::add_token_index(collection_id, current_index, &item.owner)?;17341735 <ItemListIndex>::insert(collection_id, current_index);1736 <NftItemList<T>>::insert(collection_id, current_index, item);17371738 // Update balance1739 let new_balance = <Balance<T>>::get(collection_id, item_owner.as_sub())1740 .checked_add(1)1741 .ok_or(Error::<T>::NumOverflow)?;1742 <Balance<T>>::insert(collection_id, item_owner.as_sub(), new_balance);17431744 collection.log(ERC721Events::Transfer {1745 from: H160::default(),1746 to: *item_owner.as_eth(),1747 token_id: current_index.into(),1748 })?;1749 Self::deposit_event(RawEvent::ItemCreated(1750 collection_id,1751 current_index,1752 item_owner,1753 ));1754 Ok(())1755 }17561757 fn burn_refungible_item(1758 collection: &CollectionHandle<T>,1759 item_id: TokenId,1760 owner: &T::CrossAccountId,1761 ) -> DispatchResult {1762 let collection_id = collection.id;17631764 let mut token = <ReFungibleItemList<T>>::get(collection_id, item_id)1765 .ok_or(Error::<T>::TokenNotFound)?;1766 let rft_balance = token1767 .owner1768 .iter()1769 .find(|&i| i.owner == *owner)1770 .ok_or(Error::<T>::TokenNotFound)?;1771 Self::remove_token_index(collection_id, item_id, owner)?;17721773 // update balance1774 let new_balance = <Balance<T>>::get(collection_id, rft_balance.owner.as_sub())1775 .checked_sub(rft_balance.fraction)1776 .ok_or(Error::<T>::NumOverflow)?;1777 <Balance<T>>::insert(collection_id, rft_balance.owner.as_sub(), new_balance);17781779 // Re-create owners list with sender removed1780 let index = token1781 .owner1782 .iter()1783 .position(|i| i.owner == *owner)1784 .expect("owned item is exists");1785 token.owner.remove(index);1786 let owner_count = token.owner.len();17871788 // Burn the token completely if this was the last (only) owner1789 if owner_count == 0 {1790 <ReFungibleItemList<T>>::remove(collection_id, item_id);1791 <VariableMetaDataBasket<T>>::remove(collection_id, item_id);1792 } else {1793 <ReFungibleItemList<T>>::insert(collection_id, item_id, token);1794 }17951796 Ok(())1797 }17981799 fn burn_nft_item(collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {1800 let collection_id = collection.id;18011802 let item =1803 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;1804 Self::remove_token_index(collection_id, item_id, &item.owner)?;18051806 // update balance1807 let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())1808 .checked_sub(1)1809 .ok_or(Error::<T>::NumOverflow)?;1810 <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);1811 <NftItemList<T>>::remove(collection_id, item_id);1812 <VariableMetaDataBasket<T>>::remove(collection_id, item_id);18131814 Self::deposit_event(RawEvent::ItemDestroyed(collection.id, item_id));1815 Ok(())1816 }18171818 fn burn_fungible_item(1819 owner: &T::CrossAccountId,1820 collection: &CollectionHandle<T>,1821 value: u128,1822 ) -> DispatchResult {1823 let collection_id = collection.id;18241825 let mut balance = <FungibleItemList<T>>::get(collection_id, owner.as_sub());1826 ensure!(balance.value >= value, Error::<T>::TokenValueNotEnough);18271828 // update balance1829 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1830 .checked_sub(value)1831 .ok_or(Error::<T>::NumOverflow)?;1832 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);18331834 if balance.value - value > 0 {1835 balance.value -= value;1836 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), balance);1837 } else {1838 <FungibleItemList<T>>::remove(collection_id, owner.as_sub());1839 }18401841 collection.log(ERC20Events::Transfer {1842 from: *owner.as_eth(),1843 to: H160::default(),1844 value: value.into(),1845 })?;1846 Ok(())1847 }18481849 pub fn get_collection(1850 collection_id: CollectionId,1851 ) -> Result<CollectionHandle<T>, sp_runtime::DispatchError> {1852 Ok(<CollectionHandle<T>>::get(collection_id).ok_or(Error::<T>::CollectionNotFound)?)1853 }18541855 fn check_owner_permissions(1856 target_collection: &CollectionHandle<T>,1857 subject: &T::AccountId,1858 ) -> DispatchResult {1859 ensure!(1860 *subject == target_collection.owner,1861 Error::<T>::NoPermission1862 );18631864 Ok(())1865 }18661867 fn is_owner_or_admin_permissions(1868 collection: &CollectionHandle<T>,1869 subject: &T::CrossAccountId,1870 ) -> bool {1871 *subject.as_sub() == collection.owner1872 || <AdminList<T>>::get(collection.id).contains(subject)1873 }18741875 fn check_owner_or_admin_permissions(1876 collection: &CollectionHandle<T>,1877 subject: &T::CrossAccountId,1878 ) -> DispatchResult {1879 ensure!(1880 Self::is_owner_or_admin_permissions(collection, subject),1881 Error::<T>::NoPermission1882 );18831884 Ok(())1885 }18861887 fn owned_amount(1888 subject: &T::CrossAccountId,1889 target_collection: &CollectionHandle<T>,1890 item_id: TokenId,1891 ) -> Option<u128> {1892 let collection_id = target_collection.id;18931894 match target_collection.mode {1895 CollectionMode::NFT => {1896 (<NftItemList<T>>::get(collection_id, item_id)?.owner == *subject).then(|| 1)1897 }1898 CollectionMode::Fungible(_) => {1899 Some(<FungibleItemList<T>>::get(collection_id, &subject.as_sub()).value)1900 }1901 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)?1902 .owner1903 .iter()1904 .find(|i| i.owner == *subject)1905 .map(|i| i.fraction),1906 CollectionMode::Invalid => None,1907 }1908 }19091910 fn is_item_owner(1911 subject: &T::CrossAccountId,1912 target_collection: &CollectionHandle<T>,1913 item_id: TokenId,1914 ) -> bool {1915 match target_collection.mode {1916 CollectionMode::Fungible(_) => true,1917 _ => Self::owned_amount(subject, target_collection, item_id).is_some(),1918 }1919 }19201921 fn check_white_list(1922 collection: &CollectionHandle<T>,1923 address: &T::CrossAccountId,1924 ) -> DispatchResult {1925 let collection_id = collection.id;19261927 let mes = Error::<T>::AddresNotInWhiteList;1928 ensure!(1929 <WhiteList<T>>::contains_key(collection_id, address.as_sub()),1930 mes1931 );19321933 Ok(())1934 }19351936 /// Check if token exists. In case of Fungible, check if there is an entry for1937 /// the owner in fungible balances double map1938 fn token_exists(target_collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {1939 let collection_id = target_collection.id;1940 let exists = match target_collection.mode {1941 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),1942 CollectionMode::Fungible(_) => true,1943 CollectionMode::ReFungible => {1944 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)1945 }1946 _ => false,1947 };19481949 ensure!(exists, Error::<T>::TokenNotFound);1950 Ok(())1951 }19521953 fn transfer_fungible(1954 collection: &CollectionHandle<T>,1955 value: u128,1956 owner: &T::CrossAccountId,1957 recipient: &T::CrossAccountId,1958 ) -> DispatchResult {1959 let collection_id = collection.id;19601961 let mut balance = <FungibleItemList<T>>::get(collection_id, owner.as_sub());1962 ensure!(balance.value >= value, Error::<T>::TokenValueTooLow);19631964 // Send balance to recipient (updates balanceOf of recipient)1965 Self::add_fungible_item(collection, recipient, value)?;19661967 // update balanceOf of sender1968 <Balance<T>>::insert(collection_id, owner.as_sub(), balance.value - value);19691970 // Reduce or remove sender1971 if balance.value == value {1972 <FungibleItemList<T>>::remove(collection_id, owner.as_sub());1973 } else {1974 balance.value -= value;1975 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), balance);1976 }19771978 collection.log(ERC20Events::Transfer {1979 from: *owner.as_eth(),1980 to: *recipient.as_eth(),1981 value: value.into(),1982 })?;1983 Self::deposit_event(RawEvent::Transfer(1984 collection.id,1985 1,1986 owner.clone(),1987 recipient.clone(),1988 value,1989 ));19901991 Ok(())1992 }19931994 fn transfer_refungible(1995 collection: &CollectionHandle<T>,1996 item_id: TokenId,1997 value: u128,1998 owner: T::CrossAccountId,1999 new_owner: T::CrossAccountId,2000 ) -> DispatchResult {2001 let collection_id = collection.id;2002 let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id)2003 .ok_or(Error::<T>::TokenNotFound)?;20042005 let item = full_item2006 .owner2007 .iter()2008 .find(|i| i.owner == owner)2009 .ok_or(Error::<T>::TokenNotFound)?;2010 let amount = item.fraction;20112012 ensure!(amount >= value, Error::<T>::TokenValueTooLow);20132014 // update balance2015 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.as_sub())2016 .checked_sub(value)2017 .ok_or(Error::<T>::NumOverflow)?;2018 <Balance<T>>::insert(collection_id, item.owner.as_sub(), balance_old_owner);20192020 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.as_sub())2021 .checked_add(value)2022 .ok_or(Error::<T>::NumOverflow)?;2023 <Balance<T>>::insert(collection_id, new_owner.as_sub(), balance_new_owner);20242025 let old_owner = item.owner.clone();2026 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);20272028 let mut new_full_item = full_item.clone();2029 // transfer2030 if amount == value && !new_owner_has_account {2031 // change owner2032 // new owner do not have account2033 new_full_item2034 .owner2035 .iter_mut()2036 .find(|i| i.owner == owner)2037 .expect("old owner does present in refungible")2038 .owner = new_owner.clone();2039 <ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);20402041 // update index collection2042 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;2043 } else {2044 new_full_item2045 .owner2046 .iter_mut()2047 .find(|i| i.owner == owner)2048 .expect("old owner does present in refungible")2049 .fraction -= value;20502051 // separate amount2052 if new_owner_has_account {2053 // new owner has account2054 new_full_item2055 .owner2056 .iter_mut()2057 .find(|i| i.owner == new_owner)2058 .expect("new owner has account")2059 .fraction += value;2060 } else {2061 // new owner do not have account2062 new_full_item.owner.push(Ownership {2063 owner: new_owner.clone(),2064 fraction: value,2065 });2066 Self::add_token_index(collection_id, item_id, &new_owner)?;2067 }20682069 <ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);2070 }20712072 Self::deposit_event(RawEvent::Transfer(2073 collection.id,2074 item_id,2075 owner,2076 new_owner,2077 amount,2078 ));20792080 Ok(())2081 }20822083 fn transfer_nft(2084 collection: &CollectionHandle<T>,2085 item_id: TokenId,2086 sender: T::CrossAccountId,2087 new_owner: T::CrossAccountId,2088 ) -> DispatchResult {2089 let collection_id = collection.id;2090 let mut item =2091 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;20922093 ensure!(sender == item.owner, Error::<T>::MustBeTokenOwner);20942095 // update balance2096 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.as_sub())2097 .checked_sub(1)2098 .ok_or(Error::<T>::NumOverflow)?;2099 <Balance<T>>::insert(collection_id, item.owner.as_sub(), balance_old_owner);21002101 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.as_sub())2102 .checked_add(1)2103 .ok_or(Error::<T>::NumOverflow)?;2104 <Balance<T>>::insert(collection_id, new_owner.as_sub(), balance_new_owner);21052106 // change owner2107 let old_owner = item.owner.clone();2108 item.owner = new_owner.clone();2109 <NftItemList<T>>::insert(collection_id, item_id, item);21102111 // update index collection2112 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;21132114 collection.log(ERC721Events::Transfer {2115 from: *sender.as_eth(),2116 to: *new_owner.as_eth(),2117 token_id: item_id.into(),2118 })?;2119 Self::deposit_event(RawEvent::Transfer(2120 collection.id,2121 item_id,2122 sender,2123 new_owner,2124 1,2125 ));21262127 Ok(())2128 }21292130 fn set_re_fungible_variable_data(2131 collection: &CollectionHandle<T>,2132 item_id: TokenId,2133 data: Vec<u8>,2134 ) -> DispatchResult {2135 let collection_id = collection.id;2136 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id)2137 .ok_or(Error::<T>::TokenNotFound)?;21382139 item.variable_data = data;21402141 <ReFungibleItemList<T>>::insert(collection_id, item_id, item);21422143 Ok(())2144 }21452146 fn set_nft_variable_data(2147 collection: &CollectionHandle<T>,2148 item_id: TokenId,2149 data: Vec<u8>,2150 ) -> DispatchResult {2151 let collection_id = collection.id;2152 let mut item =2153 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;21542155 item.variable_data = data;21562157 <NftItemList<T>>::insert(collection_id, item_id, item);21582159 Ok(())2160 }21612162 #[allow(dead_code)]2163 fn init_collection(item: &Collection<T>) {2164 // check params2165 assert!(2166 item.decimal_points <= MAX_DECIMAL_POINTS,2167 "decimal_points parameter must be lower than MAX_DECIMAL_POINTS"2168 );2169 assert!(2170 item.name.len() <= 64,2171 "Collection name can not be longer than 63 char"2172 );2173 assert!(2174 item.name.len() <= 256,2175 "Collection description can not be longer than 255 char"2176 );2177 assert!(2178 item.token_prefix.len() <= 16,2179 "Token prefix can not be longer than 15 char"2180 );21812182 // Generate next collection ID2183 let next_id = CreatedCollectionCount::get().checked_add(1).unwrap();21842185 CreatedCollectionCount::put(next_id);2186 }21872188 #[allow(dead_code)]2189 fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::CrossAccountId>) {2190 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();21912192 Self::add_token_index(collection_id, current_index, &item.owner).unwrap();21932194 <ItemListIndex>::insert(collection_id, current_index);21952196 // Update balance2197 let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())2198 .checked_add(1)2199 .unwrap();2200 <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);2201 }22022203 #[allow(dead_code)]2204 fn init_fungible_token(2205 collection_id: CollectionId,2206 owner: &T::CrossAccountId,2207 item: &FungibleItemType,2208 ) {2209 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();22102211 Self::add_token_index(collection_id, current_index, owner).unwrap();22122213 <ItemListIndex>::insert(collection_id, current_index);22142215 // Update balance2216 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())2217 .checked_add(item.value)2218 .unwrap();2219 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);2220 }22212222 #[allow(dead_code)]2223 fn init_refungible_token(2224 collection_id: CollectionId,2225 item: &ReFungibleItemType<T::CrossAccountId>,2226 ) {2227 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();22282229 let value = item.owner.first().unwrap().fraction;2230 let owner = item.owner.first().unwrap().owner.clone();22312232 Self::add_token_index(collection_id, current_index, &owner).unwrap();22332234 <ItemListIndex>::insert(collection_id, current_index);22352236 // Update balance2237 let new_balance = <Balance<T>>::get(collection_id, &owner.as_sub())2238 .checked_add(value)2239 .unwrap();2240 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);2241 }22422243 fn add_token_index(2244 collection_id: CollectionId,2245 item_index: TokenId,2246 owner: &T::CrossAccountId,2247 ) -> DispatchResult {2248 // add to account limit2249 if <AccountItemCount<T>>::contains_key(owner.as_sub()) {2250 // bound Owned tokens by a single address2251 let count = <AccountItemCount<T>>::get(owner.as_sub());2252 ensure!(2253 count < ACCOUNT_TOKEN_OWNERSHIP_LIMIT,2254 Error::<T>::AddressOwnershipLimitExceeded2255 );22562257 <AccountItemCount<T>>::insert(2258 owner.as_sub(),2259 count.checked_add(1).ok_or(Error::<T>::NumOverflow)?,2260 );2261 } else {2262 <AccountItemCount<T>>::insert(owner.as_sub(), 1);2263 }22642265 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());2266 if list_exists {2267 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());2268 let item_contains = list.contains(&item_index.clone());22692270 if !item_contains {2271 list.push(item_index);2272 }22732274 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);2275 } else {2276 let itm = vec![item_index];2277 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);2278 }22792280 Ok(())2281 }22822283 fn remove_token_index(2284 collection_id: CollectionId,2285 item_index: TokenId,2286 owner: &T::CrossAccountId,2287 ) -> DispatchResult {2288 // update counter2289 <AccountItemCount<T>>::insert(2290 owner.as_sub(),2291 <AccountItemCount<T>>::get(owner.as_sub())2292 .checked_sub(1)2293 .ok_or(Error::<T>::NumOverflow)?,2294 );22952296 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());2297 if list_exists {2298 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());2299 let item_contains = list.contains(&item_index.clone());23002301 if item_contains {2302 list.retain(|&item| item != item_index);2303 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);2304 }2305 }23062307 Ok(())2308 }23092310 fn move_token_index(2311 collection_id: CollectionId,2312 item_index: TokenId,2313 old_owner: &T::CrossAccountId,2314 new_owner: &T::CrossAccountId,2315 ) -> DispatchResult {2316 Self::remove_token_index(collection_id, item_index, old_owner)?;2317 Self::add_token_index(collection_id, item_index, new_owner)?;23182319 Ok(())2320 }2321}23222323sp_api::decl_runtime_apis! {2324 pub trait NftApi {2325 /// Used for ethereum integration2326 fn eth_contract_code(account: H160) -> Option<Vec<u8>>;2327 }2328}1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![recursion_limit = "1024"]7#![cfg_attr(not(feature = "std"), no_std)]8#![allow(9 clippy::too_many_arguments,10 clippy::unnecessary_mut_passed,11 clippy::unused_unit12)]1314extern crate alloc;1516pub use serde::{Serialize, Deserialize};1718pub use frame_support::{19 construct_runtime, decl_event, decl_module, decl_storage, decl_error,20 dispatch::DispatchResult,21 ensure, fail, parameter_types,22 traits::{23 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,24 Randomness, IsSubType, WithdrawReasons,25 },26 weights::{27 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},28 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,29 WeightToFeePolynomial, DispatchClass,30 },31 StorageValue, transactional,32};3334use frame_system::{self as system, ensure_signed};35use sp_core::H160;36use sp_std::vec;37use sp_runtime::sp_std::prelude::Vec;38use core::ops::{Deref, DerefMut};39use nft_data_structs::{40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,41 CUSTOM_DATA_LIMIT, COLLECTION_NUMBER_LIMIT, ACCOUNT_TOKEN_OWNERSHIP_LIMIT,42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, COLLECTION_ADMINS_LIMIT,43 OFFCHAIN_SCHEMA_LIMIT, AccessMode, Collection, CreateItemData, CollectionLimits, CollectionId,44 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,45 FungibleItemType, ReFungibleItemType,46};4748#[cfg(test)]49mod mock;5051#[cfg(test)]52mod tests;5354mod default_weights;55mod eth;56mod sponsorship;57pub use sponsorship::NftSponsorshipHandler;58pub use eth::sponsoring::NftEthSponsorshipHandler;5960pub use eth::NftErcSupport;61pub use eth::account::*;62use eth::erc::{ERC20Events, ERC721Events};6364#[cfg(feature = "runtime-benchmarks")]65mod benchmarking;6667pub trait WeightInfo {68 fn create_collection() -> Weight;69 fn destroy_collection() -> Weight;70 fn add_to_white_list() -> Weight;71 fn remove_from_white_list() -> Weight;72 fn set_public_access_mode() -> Weight;73 fn set_mint_permission() -> Weight;74 fn change_collection_owner() -> Weight;75 fn add_collection_admin() -> Weight;76 fn remove_collection_admin() -> Weight;77 fn set_collection_sponsor() -> Weight;78 fn confirm_sponsorship() -> Weight;79 fn remove_collection_sponsor() -> Weight;80 fn create_item(s: usize) -> Weight;81 fn burn_item() -> Weight;82 fn transfer() -> Weight;83 fn approve() -> Weight;84 fn transfer_from() -> Weight;85 fn set_offchain_schema() -> Weight;86 fn set_const_on_chain_schema() -> Weight;87 fn set_variable_on_chain_schema() -> Weight;88 fn set_variable_meta_data() -> Weight;89 fn enable_contract_sponsoring() -> Weight;90 fn set_schema_version() -> Weight;91 fn set_contract_sponsoring_rate_limit() -> Weight;92 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;93 fn toggle_contract_white_list() -> Weight;94 fn add_to_contract_white_list() -> Weight;95 fn remove_from_contract_white_list() -> Weight;96 fn set_collection_limits() -> Weight;97}9899decl_error! {100 /// Error for non-fungible-token module.101 pub enum Error for Module<T: Config> {102 /// Total collections bound exceeded.103 TotalCollectionsLimitExceeded,104 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.105 CollectionDecimalPointLimitExceeded,106 /// Collection name can not be longer than 63 char.107 CollectionNameLimitExceeded,108 /// Collection description can not be longer than 255 char.109 CollectionDescriptionLimitExceeded,110 /// Token prefix can not be longer than 15 char.111 CollectionTokenPrefixLimitExceeded,112 /// This collection does not exist.113 CollectionNotFound,114 /// Item not exists.115 TokenNotFound,116 /// Admin not found117 AdminNotFound,118 /// Arithmetic calculation overflow.119 NumOverflow,120 /// Account already has admin role.121 AlreadyAdmin,122 /// You do not own this collection.123 NoPermission,124 /// This address is not set as sponsor, use setCollectionSponsor first.125 ConfirmUnsetSponsorFail,126 /// Collection is not in mint mode.127 PublicMintingNotAllowed,128 /// Sender parameter and item owner must be equal.129 MustBeTokenOwner,130 /// Item balance not enough.131 TokenValueTooLow,132 /// Size of item is too large.133 NftSizeLimitExceeded,134 /// No approve found135 ApproveNotFound,136 /// Requested value more than approved.137 TokenValueNotEnough,138 /// Only approved addresses can call this method.139 ApproveRequired,140 /// Address is not in white list.141 AddresNotInWhiteList,142 /// Number of collection admins bound exceeded.143 CollectionAdminsLimitExceeded,144 /// Owned tokens by a single address bound exceeded.145 AddressOwnershipLimitExceeded,146 /// Length of items properties must be greater than 0.147 EmptyArgument,148 /// const_data exceeded data limit.149 TokenConstDataLimitExceeded,150 /// variable_data exceeded data limit.151 TokenVariableDataLimitExceeded,152 /// Not NFT item data used to mint in NFT collection.153 NotNftDataUsedToMintNftCollectionToken,154 /// Not Fungible item data used to mint in Fungible collection.155 NotFungibleDataUsedToMintFungibleCollectionToken,156 /// Not Re Fungible item data used to mint in Re Fungible collection.157 NotReFungibleDataUsedToMintReFungibleCollectionToken,158 /// Unexpected collection type.159 UnexpectedCollectionType,160 /// Can't store metadata in fungible tokens.161 CantStoreMetadataInFungibleTokens,162 /// Collection token limit exceeded163 CollectionTokenLimitExceeded,164 /// Account token limit exceeded per collection165 AccountTokenLimitExceeded,166 /// Collection limit bounds per collection exceeded167 CollectionLimitBoundsExceeded,168 /// Tried to enable permissions which are only permitted to be disabled169 OwnerPermissionsCantBeReverted,170 /// Schema data size limit bound exceeded171 SchemaDataLimitExceeded,172 /// Maximum refungibility exceeded173 WrongRefungiblePieces,174 /// createRefungible should be called with one owner175 BadCreateRefungibleCall,176 /// Gas limit exceeded177 OutOfGas,178 /// Collection settings not allowing items transferring179 TransferNotAllowed,180 /// Can't transfer tokens to ethereum zero address181 AddressIsZero,182 }183}184185#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]186pub struct CollectionHandle<T: Config> {187 pub id: CollectionId,188 collection: Collection<T>,189 recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,190}191impl<T: Config> CollectionHandle<T> {192 pub fn get_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {193 <CollectionById<T>>::get(id).map(|collection| Self {194 id,195 collection,196 recorder: pallet_evm_coder_substrate::SubstrateRecorder::new(197 eth::collection_id_to_address(id),198 gas_limit,199 ),200 })201 }202 pub fn get(id: CollectionId) -> Option<Self> {203 Self::get_with_gas_limit(id, u64::MAX)204 }205 pub fn log(&self, log: impl evm_coder::ToLog) -> DispatchResult {206 self.recorder.log_sub(log)207 }208 fn consume_gas(&self, gas: u64) -> DispatchResult {209 self.recorder.consume_gas_sub(gas)210 }211 pub fn submit_logs(self) -> DispatchResult {212 self.recorder.submit_logs()213 }214 pub fn save(self) -> DispatchResult {215 self.recorder.submit_logs()?;216 <CollectionById<T>>::insert(self.id, self.collection);217 Ok(())218 }219}220impl<T: Config> Deref for CollectionHandle<T> {221 type Target = Collection<T>;222223 fn deref(&self) -> &Self::Target {224 &self.collection225 }226}227228impl<T: Config> DerefMut for CollectionHandle<T> {229 fn deref_mut(&mut self) -> &mut Self::Target {230 &mut self.collection231 }232}233234pub trait Config: system::Config + pallet_evm_coder_substrate::Config + Sized {235 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;236237 /// Weight information for extrinsics in this pallet.238 type WeightInfo: WeightInfo;239240 type EvmAddressMapping: pallet_evm::AddressMapping<Self::AccountId>;241 type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;242243 type CrossAccountId: CrossAccountId<Self::AccountId>;244 type Currency: Currency<Self::AccountId>;245 type CollectionCreationPrice: Get<246 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,247 >;248 type TreasuryAccountId: Get<Self::AccountId>;249}250251// # Used definitions252//253// ## User control levels254//255// chain-controlled - key is uncontrolled by user256// i.e autoincrementing index257// can use non-cryptographic hash258// real - key is controlled by user259// but it is hard to generate enough colliding values, i.e owner of signed txs260// can use non-cryptographic hash261// controlled - key is completly controlled by users262// i.e maps with mutable keys263// should use cryptographic hash264//265// ## User control level downgrade reasons266//267// ?1 - chain-controlled -> controlled268// collections/tokens can be destroyed, resulting in massive holes269// ?2 - chain-controlled -> controlled270// same as ?1, but can be only added, resulting in easier exploitation271// ?3 - real -> controlled272// no confirmation required, so addresses can be easily generated273decl_storage! {274 trait Store for Module<T: Config> as Nft {275276 //#region Private members277 /// Id of next collection278 CreatedCollectionCount: u32;279 /// Used for migrations280 ChainVersion: u64;281 /// Id of last collection token282 /// Collection id (controlled?1)283 ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;284 //#endregion285286 //#region Bound counters287 /// Amount of collections destroyed, used for total amount tracking with288 /// CreatedCollectionCount289 DestroyedCollectionCount: u32;290 /// Total amount of account owned tokens (NFTs + RFTs + unique fungibles)291 /// Account id (real)292 pub AccountItemCount get(fn account_item_count): map hasher(twox_64_concat) T::AccountId => u32;293 //#endregion294295 //#region Basic collections296 /// Collection info297 /// Collection id (controlled?1)298 pub CollectionById get(fn collection_id) config(): map hasher(blake2_128_concat) CollectionId => Option<Collection<T>> = None;299 /// List of collection admins300 /// Collection id (controlled?2)301 pub AdminList get(fn admin_list_collection): map hasher(blake2_128_concat) CollectionId => Vec<T::CrossAccountId>;302 /// Whitelisted collection users303 /// Collection id (controlled?2), user id (controlled?3)304 pub WhiteList get(fn white_list): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => bool;305 //#endregion306307 /// How many of collection items user have308 /// Collection id (controlled?2), account id (real)309 pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => u128;310311 /// Amount of items which spender can transfer out of owners account (via transferFrom)312 /// Collection id (controlled?2), (token id (controlled ?2) + owner account id (real) + spender account id (controlled?3))313 /// TODO: Off chain worker should remove from this map when token gets removed314 pub Allowances get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId, T::AccountId) => u128;315316 //#region Item collections317 /// Collection id (controlled?2), token id (controlled?1)318 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<NftItemType<T::CrossAccountId>>;319 /// Collection id (controlled?2), owner (controlled?2)320 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => FungibleItemType;321 /// Collection id (controlled?2), token id (controlled?1)322 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<ReFungibleItemType<T::CrossAccountId>>;323 //#endregion324325 //#region Index list326 /// Collection id (controlled?2), tokens owner (controlled?2)327 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => Vec<TokenId>;328 //#endregion329330 //#region Tokens transfer rate limit baskets331 /// (Collection id (controlled?2), who created (real))332 /// TODO: Off chain worker should remove from this map when collection gets removed333 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => T::BlockNumber;334 /// Collection id (controlled?2), token id (controlled?2)335 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;336 /// Collection id (controlled?2), owning user (real)337 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;338 /// Collection id (controlled?2), token id (controlled?2)339 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;340 //#endregion341342 /// Variable metadata sponsoring343 /// Collection id (controlled?2), token id (controlled?2)344 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber> = None;345 }346 add_extra_genesis {347 build(|config: &GenesisConfig<T>| {348 // Modification of storage349 for (_num, _c) in &config.collection_id {350 <Module<T>>::init_collection(_c);351 }352353 for (_num, _c, _i) in &config.nft_item_id {354 <Module<T>>::init_nft_token(*_c, _i);355 }356357 for (collection_id, account_id, fungible_item) in &config.fungible_item_id {358 <Module<T>>::init_fungible_token(*collection_id, &T::CrossAccountId::from_sub(account_id.clone()), fungible_item);359 }360361 for (_num, _c, _i) in &config.refungible_item_id {362 <Module<T>>::init_refungible_token(*_c, _i);363 }364 })365 }366}367368decl_event!(369 pub enum Event<T>370 where371 AccountId = <T as frame_system::Config>::AccountId,372 CrossAccountId = <T as Config>::CrossAccountId,373 {374 /// New collection was created375 ///376 /// # Arguments377 ///378 /// * collection_id: Globally unique identifier of newly created collection.379 ///380 /// * mode: [CollectionMode] converted into u8.381 ///382 /// * account_id: Collection owner.383 CollectionCreated(CollectionId, u8, AccountId),384385 /// New item was created.386 ///387 /// # Arguments388 ///389 /// * collection_id: Id of the collection where item was created.390 ///391 /// * item_id: Id of an item. Unique within the collection.392 ///393 /// * recipient: Owner of newly created item394 ItemCreated(CollectionId, TokenId, CrossAccountId),395396 /// Collection item was burned.397 ///398 /// # Arguments399 ///400 /// collection_id.401 ///402 /// item_id: Identifier of burned NFT.403 ItemDestroyed(CollectionId, TokenId),404405 /// Item was transferred406 ///407 /// * collection_id: Id of collection to which item is belong408 ///409 /// * item_id: Id of an item410 ///411 /// * sender: Original owner of item412 ///413 /// * recipient: New owner of item414 ///415 /// * amount: Always 1 for NFT416 Transfer(CollectionId, TokenId, CrossAccountId, CrossAccountId, u128),417418 /// * collection_id419 ///420 /// * item_id421 ///422 /// * sender423 ///424 /// * spender425 ///426 /// * amount427 Approved(CollectionId, TokenId, CrossAccountId, CrossAccountId, u128),428 }429);430431decl_module! {432 pub struct Module<T: Config> for enum Call433 where434 origin: T::Origin435 {436 fn deposit_event() = default;437 const CollectionAdminsLimit: u64 = COLLECTION_ADMINS_LIMIT;438 type Error = Error<T>;439440 fn on_initialize(_now: T::BlockNumber) -> Weight {441 0442 }443444 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner and admin of the collection are set to the address that signed the transaction. Both addresses can be changed later.445 ///446 /// # Permissions447 ///448 /// * Anyone.449 ///450 /// # Arguments451 ///452 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.453 ///454 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.455 ///456 /// * token_prefix: UTF-8 string with token prefix.457 ///458 /// * mode: [CollectionMode] collection type and type dependent data.459 // returns collection ID460 #[weight = <T as Config>::WeightInfo::create_collection()]461 #[transactional]462 pub fn create_collection(origin,463 collection_name: Vec<u16>,464 collection_description: Vec<u16>,465 token_prefix: Vec<u8>,466 mode: CollectionMode) -> DispatchResult {467468 // Anyone can create a collection469 let who = ensure_signed(origin)?;470471 // Take a (non-refundable) deposit of collection creation472 let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();473 imbalance.subsume(<<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(474 &T::TreasuryAccountId::get(),475 T::CollectionCreationPrice::get(),476 ));477 <T as Config>::Currency::settle(478 &who,479 imbalance,480 WithdrawReasons::TRANSFER,481 ExistenceRequirement::KeepAlive,482 ).map_err(|_| Error::<T>::NoPermission)?;483484 let decimal_points = match mode {485 CollectionMode::Fungible(points) => points,486 _ => 0487 };488489 let created_count = CreatedCollectionCount::get();490 let destroyed_count = DestroyedCollectionCount::get();491492 // bound Total number of collections493 ensure!(created_count - destroyed_count < COLLECTION_NUMBER_LIMIT, Error::<T>::TotalCollectionsLimitExceeded);494495 // check params496 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);497 ensure!(collection_name.len() <= 64, Error::<T>::CollectionNameLimitExceeded);498 ensure!(collection_description.len() <= 256, Error::<T>::CollectionDescriptionLimitExceeded);499 ensure!(token_prefix.len() <= 16, Error::<T>::CollectionTokenPrefixLimitExceeded);500501 // Generate next collection ID502 let next_id = created_count503 .checked_add(1)504 .ok_or(Error::<T>::NumOverflow)?;505506 CreatedCollectionCount::put(next_id);507508 let limits = CollectionLimits {509 sponsored_data_size: CUSTOM_DATA_LIMIT,510 ..Default::default()511 };512513 // Create new collection514 let new_collection = Collection {515 owner: who.clone(),516 name: collection_name,517 mode: mode.clone(),518 mint_mode: false,519 access: AccessMode::Normal,520 description: collection_description,521 decimal_points,522 token_prefix,523 offchain_schema: Vec::new(),524 schema_version: SchemaVersion::ImageURL,525 sponsorship: SponsorshipState::Disabled,526 variable_on_chain_schema: Vec::new(),527 const_on_chain_schema: Vec::new(),528 limits,529 transfers_enabled: true,530 };531532 // Add new collection to map533 <CollectionById<T>>::insert(next_id, new_collection);534535 // call event536 Self::deposit_event(RawEvent::CollectionCreated(next_id, mode.id(), who));537538 Ok(())539 }540541 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.542 ///543 /// # Permissions544 ///545 /// * Collection Owner.546 ///547 /// # Arguments548 ///549 /// * collection_id: collection to destroy.550 #[weight = <T as Config>::WeightInfo::destroy_collection()]551 #[transactional]552 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {553554 let sender = ensure_signed(origin)?;555 let collection = Self::get_collection(collection_id)?;556 Self::check_owner_permissions(&collection, &sender)?;557 if !collection.limits.owner_can_destroy {558 fail!(Error::<T>::NoPermission);559 }560561 <AddressTokens<T>>::remove_prefix(collection_id, None);562 <Allowances<T>>::remove_prefix(collection_id, None);563 <Balance<T>>::remove_prefix(collection_id, None);564 <ItemListIndex>::remove(collection_id);565 <AdminList<T>>::remove(collection_id);566 <CollectionById<T>>::remove(collection_id);567 <WhiteList<T>>::remove_prefix(collection_id, None);568569 <NftItemList<T>>::remove_prefix(collection_id, None);570 <FungibleItemList<T>>::remove_prefix(collection_id, None);571 <ReFungibleItemList<T>>::remove_prefix(collection_id, None);572573 <NftTransferBasket<T>>::remove_prefix(collection_id, None);574 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);575 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id, None);576577 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);578579 DestroyedCollectionCount::put(DestroyedCollectionCount::get()580 .checked_add(1)581 .ok_or(Error::<T>::NumOverflow)?);582583 Ok(())584 }585586 /// Add an address to white list.587 ///588 /// # Permissions589 ///590 /// * Collection Owner591 /// * Collection Admin592 ///593 /// # Arguments594 ///595 /// * collection_id.596 ///597 /// * address.598 #[weight = <T as Config>::WeightInfo::add_to_white_list()]599 #[transactional]600 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{601602 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);603 let collection = Self::get_collection(collection_id)?;604605 Self::toggle_white_list_internal(606 &sender,607 &collection,608 &address,609 true,610 )?;611612 Ok(())613 }614615 /// Remove an address from white list.616 ///617 /// # Permissions618 ///619 /// * Collection Owner620 /// * Collection Admin621 ///622 /// # Arguments623 ///624 /// * collection_id.625 ///626 /// * address.627 #[weight = <T as Config>::WeightInfo::remove_from_white_list()]628 #[transactional]629 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{630631 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);632 let collection = Self::get_collection(collection_id)?;633634 Self::toggle_white_list_internal(635 &sender,636 &collection,637 &address,638 false,639 )?;640641 Ok(())642 }643644 /// Toggle between normal and white list access for the methods with access for `Anyone`.645 ///646 /// # Permissions647 ///648 /// * Collection Owner.649 ///650 /// # Arguments651 ///652 /// * collection_id.653 ///654 /// * mode: [AccessMode]655 #[weight = <T as Config>::WeightInfo::set_public_access_mode()]656 #[transactional]657 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult658 {659 let sender = ensure_signed(origin)?;660661 let mut target_collection = Self::get_collection(collection_id)?;662 Self::check_owner_permissions(&target_collection, &sender)?;663 target_collection.access = mode;664 target_collection.save()665 }666667 /// Allows Anyone to create tokens if:668 /// * White List is enabled, and669 /// * Address is added to white list, and670 /// * This method was called with True parameter671 ///672 /// # Permissions673 /// * Collection Owner674 ///675 /// # Arguments676 ///677 /// * collection_id.678 ///679 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.680 #[weight = <T as Config>::WeightInfo::set_mint_permission()]681 #[transactional]682 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult683 {684 let sender = ensure_signed(origin)?;685686 let mut target_collection = Self::get_collection(collection_id)?;687 Self::check_owner_permissions(&target_collection, &sender)?;688 target_collection.mint_mode = mint_permission;689 target_collection.save()690 }691692 /// Change the owner of the collection.693 ///694 /// # Permissions695 ///696 /// * Collection Owner.697 ///698 /// # Arguments699 ///700 /// * collection_id.701 ///702 /// * new_owner.703 #[weight = <T as Config>::WeightInfo::change_collection_owner()]704 #[transactional]705 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {706707 let sender = ensure_signed(origin)?;708 let mut target_collection = Self::get_collection(collection_id)?;709 Self::check_owner_permissions(&target_collection, &sender)?;710 target_collection.owner = new_owner;711 target_collection.save()712 }713714 /// Adds an admin of the Collection.715 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.716 ///717 /// # Permissions718 ///719 /// * Collection Owner.720 /// * Collection Admin.721 ///722 /// # Arguments723 ///724 /// * collection_id: ID of the Collection to add admin for.725 ///726 /// * new_admin_id: Address of new admin to add.727 #[weight = <T as Config>::WeightInfo::add_collection_admin()]728 #[transactional]729 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {730 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);731 let collection = Self::get_collection(collection_id)?;732 Self::check_owner_or_admin_permissions(&collection, &sender)?;733 let mut admin_arr = <AdminList<T>>::get(collection_id);734735 match admin_arr.binary_search(&new_admin_id) {736 Ok(_) => {},737 Err(idx) => {738 ensure!(admin_arr.len() < COLLECTION_ADMINS_LIMIT as usize, Error::<T>::CollectionAdminsLimitExceeded);739 admin_arr.insert(idx, new_admin_id);740 <AdminList<T>>::insert(collection_id, admin_arr);741 }742 }743 Ok(())744 }745746 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.747 ///748 /// # Permissions749 ///750 /// * Collection Owner.751 /// * Collection Admin.752 ///753 /// # Arguments754 ///755 /// * collection_id: ID of the Collection to remove admin for.756 ///757 /// * account_id: Address of admin to remove.758 #[weight = <T as Config>::WeightInfo::remove_collection_admin()]759 #[transactional]760 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {761 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);762 let collection = Self::get_collection(collection_id)?;763 Self::check_owner_or_admin_permissions(&collection, &sender)?;764 let mut admin_arr = <AdminList<T>>::get(collection_id);765766 if let Ok(idx) = admin_arr.binary_search(&account_id) {767 admin_arr.remove(idx);768 <AdminList<T>>::insert(collection_id, admin_arr);769 }770 Ok(())771 }772773 /// # Permissions774 ///775 /// * Collection Owner776 ///777 /// # Arguments778 ///779 /// * collection_id.780 ///781 /// * new_sponsor.782 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]783 #[transactional]784 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {785 let sender = ensure_signed(origin)?;786 let mut target_collection = Self::get_collection(collection_id)?;787 Self::check_owner_permissions(&target_collection, &sender)?;788789 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor);790 target_collection.save()791 }792793 /// # Permissions794 ///795 /// * Sponsor.796 ///797 /// # Arguments798 ///799 /// * collection_id.800 #[weight = <T as Config>::WeightInfo::confirm_sponsorship()]801 #[transactional]802 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {803 let sender = ensure_signed(origin)?;804805 let mut target_collection = Self::get_collection(collection_id)?;806 ensure!(807 target_collection.sponsorship.pending_sponsor() == Some(&sender),808 Error::<T>::ConfirmUnsetSponsorFail809 );810811 target_collection.sponsorship = SponsorshipState::Confirmed(sender);812 target_collection.save()813 }814815 /// Switch back to pay-per-own-transaction model.816 ///817 /// # Permissions818 ///819 /// * Collection owner.820 ///821 /// # Arguments822 ///823 /// * collection_id.824 #[weight = <T as Config>::WeightInfo::remove_collection_sponsor()]825 #[transactional]826 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {827 let sender = ensure_signed(origin)?;828829 let mut target_collection = Self::get_collection(collection_id)?;830 Self::check_owner_permissions(&target_collection, &sender)?;831832 target_collection.sponsorship = SponsorshipState::Disabled;833 target_collection.save()834 }835836 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.837 ///838 /// # Permissions839 ///840 /// * Collection Owner.841 /// * Collection Admin.842 /// * Anyone if843 /// * White List is enabled, and844 /// * Address is added to white list, and845 /// * MintPermission is enabled (see SetMintPermission method)846 ///847 /// # Arguments848 ///849 /// * collection_id: ID of the collection.850 ///851 /// * owner: Address, initial owner of the NFT.852 ///853 /// * data: Token data to store on chain.854 // #[weight =855 // (130_000_000 as Weight)856 // .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))857 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))858 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]859860 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]861 #[transactional]862 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {863 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);864 let collection = Self::get_collection(collection_id)?;865866 Self::create_item_internal(&sender, &collection, &owner, data)?;867868 collection.submit_logs()869 }870871 /// This method creates multiple items in a collection created with CreateCollection method.872 ///873 /// # Permissions874 ///875 /// * Collection Owner.876 /// * Collection Admin.877 /// * Anyone if878 /// * White List is enabled, and879 /// * Address is added to white list, and880 /// * MintPermission is enabled (see SetMintPermission method)881 ///882 /// # Arguments883 ///884 /// * collection_id: ID of the collection.885 ///886 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].887 ///888 /// * owner: Address, initial owner of the NFT.889 #[weight = <T as Config>::WeightInfo::create_item(items_data.iter()890 .map(|data| { data.data_size() })891 .sum())]892 #[transactional]893 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {894895 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);896 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);897 let collection = Self::get_collection(collection_id)?;898899 Self::create_multiple_items_internal(&sender, &collection, &owner, items_data)?;900901 collection.submit_logs()902 }903904 // TODO! transaction weight905906 /// Set transfers_enabled value for particular collection907 ///908 /// # Permissions909 ///910 /// * Collection Owner.911 ///912 /// # Arguments913 ///914 /// * collection_id: ID of the collection.915 ///916 /// * value: New flag value.917 #[weight = <T as Config>::WeightInfo::burn_item()]918 #[transactional]919 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {920921 let sender = ensure_signed(origin)?;922 let mut target_collection = Self::get_collection(collection_id)?;923924 Self::check_owner_permissions(&target_collection, &sender)?;925926 target_collection.transfers_enabled = value;927 target_collection.save()928 }929930 /// Destroys a concrete instance of NFT.931 ///932 /// # Permissions933 ///934 /// * Collection Owner.935 /// * Collection Admin.936 /// * Current NFT Owner.937 ///938 /// # Arguments939 ///940 /// * collection_id: ID of the collection.941 ///942 /// * item_id: ID of NFT to burn.943 #[weight = <T as Config>::WeightInfo::burn_item()]944 #[transactional]945 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {946947 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);948 let target_collection = Self::get_collection(collection_id)?;949950 Self::burn_item_internal(&sender, &target_collection, item_id, value)?;951952 target_collection.submit_logs()953 }954955 /// Change ownership of the token.956 ///957 /// # Permissions958 ///959 /// * Collection Owner960 /// * Collection Admin961 /// * Current NFT owner962 ///963 /// # Arguments964 ///965 /// * recipient: Address of token recipient.966 ///967 /// * collection_id.968 ///969 /// * item_id: ID of the item970 /// * Non-Fungible Mode: Required.971 /// * Fungible Mode: Ignored.972 /// * Re-Fungible Mode: Required.973 ///974 /// * value: Amount to transfer.975 /// * Non-Fungible Mode: Ignored976 /// * Fungible Mode: Must specify transferred amount977 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)978 #[weight = <T as Config>::WeightInfo::transfer()]979 #[transactional]980 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {981 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);982 let collection = Self::get_collection(collection_id)?;983984 Self::transfer_internal(&sender, &recipient, &collection, item_id, value)?;985986 collection.submit_logs()987 }988989 /// Set, change, or remove approved address to transfer the ownership of the NFT.990 ///991 /// # Permissions992 ///993 /// * Collection Owner994 /// * Collection Admin995 /// * Current NFT owner996 ///997 /// # Arguments998 ///999 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).1000 ///1001 /// * collection_id.1002 ///1003 /// * item_id: ID of the item.1004 #[weight = <T as Config>::WeightInfo::approve()]1005 #[transactional]1006 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResult {1007 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1008 let collection = Self::get_collection(collection_id)?;10091010 Self::approve_internal(&sender, &spender, &collection, item_id, amount)?;10111012 collection.submit_logs()1013 }10141015 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.1016 ///1017 /// # Permissions1018 /// * Collection Owner1019 /// * Collection Admin1020 /// * Current NFT owner1021 /// * Address approved by current NFT owner1022 ///1023 /// # Arguments1024 ///1025 /// * from: Address that owns token.1026 ///1027 /// * recipient: Address of token recipient.1028 ///1029 /// * collection_id.1030 ///1031 /// * item_id: ID of the item.1032 ///1033 /// * value: Amount to transfer.1034 #[weight = <T as Config>::WeightInfo::transfer_from()]1035 #[transactional]1036 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResult {1037 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1038 let collection = Self::get_collection(collection_id)?;10391040 Self::transfer_from_internal(&sender, &from, &recipient, &collection, item_id, value)?;10411042 collection.submit_logs()1043 }1044 // #[weight = 0]1045 // // let no_perm_mes = "You do not have permissions to modify this collection";1046 // // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);1047 // // let list_itm = <ApprovedList<T>>::get((collection_id, item_id));1048 // // ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);10491050 // // // on_nft_received call10511052 // // Self::transfer(origin, collection_id, item_id, new_owner)?;10531054 // Ok(())1055 // }10561057 /// Set off-chain data schema.1058 ///1059 /// # Permissions1060 ///1061 /// * Collection Owner1062 /// * Collection Admin1063 ///1064 /// # Arguments1065 ///1066 /// * collection_id.1067 ///1068 /// * schema: String representing the offchain data schema.1069 #[weight = <T as Config>::WeightInfo::set_variable_meta_data()]1070 #[transactional]1071 pub fn set_variable_meta_data (1072 origin,1073 collection_id: CollectionId,1074 item_id: TokenId,1075 data: Vec<u8>1076 ) -> DispatchResult {1077 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);10781079 let collection = Self::get_collection(collection_id)?;10801081 Self::set_variable_meta_data_internal(&sender, &collection, item_id, data)?;10821083 Ok(())1084 }10851086 /// Set schema standard1087 /// ImageURL1088 /// Unique1089 ///1090 /// # Permissions1091 ///1092 /// * Collection Owner1093 /// * Collection Admin1094 ///1095 /// # Arguments1096 ///1097 /// * collection_id.1098 ///1099 /// * schema: SchemaVersion: enum1100 #[weight = <T as Config>::WeightInfo::set_schema_version()]1101 #[transactional]1102 pub fn set_schema_version(1103 origin,1104 collection_id: CollectionId,1105 version: SchemaVersion1106 ) -> DispatchResult {1107 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1108 let mut target_collection = Self::get_collection(collection_id)?;1109 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1110 target_collection.schema_version = version;1111 target_collection.save()1112 }11131114 /// Set off-chain data schema.1115 ///1116 /// # Permissions1117 ///1118 /// * Collection Owner1119 /// * Collection Admin1120 ///1121 /// # Arguments1122 ///1123 /// * collection_id.1124 ///1125 /// * schema: String representing the offchain data schema.1126 #[weight = <T as Config>::WeightInfo::set_offchain_schema()]1127 #[transactional]1128 pub fn set_offchain_schema(1129 origin,1130 collection_id: CollectionId,1131 schema: Vec<u8>1132 ) -> DispatchResult {1133 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1134 let mut target_collection = Self::get_collection(collection_id)?;1135 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11361137 // check schema limit1138 ensure!(schema.len() as u32 <= OFFCHAIN_SCHEMA_LIMIT, "");11391140 target_collection.offchain_schema = schema;1141 target_collection.save()1142 }11431144 /// Set const on-chain data schema.1145 ///1146 /// # Permissions1147 ///1148 /// * Collection Owner1149 /// * Collection Admin1150 ///1151 /// # Arguments1152 ///1153 /// * collection_id.1154 ///1155 /// * schema: String representing the const on-chain data schema.1156 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1157 #[transactional]1158 pub fn set_const_on_chain_schema (1159 origin,1160 collection_id: CollectionId,1161 schema: Vec<u8>1162 ) -> DispatchResult {1163 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1164 let mut target_collection = Self::get_collection(collection_id)?;1165 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11661167 // check schema limit1168 ensure!(schema.len() as u32 <= CONST_ON_CHAIN_SCHEMA_LIMIT, "");11691170 target_collection.const_on_chain_schema = schema;1171 target_collection.save()1172 }11731174 /// Set variable on-chain data schema.1175 ///1176 /// # Permissions1177 ///1178 /// * Collection Owner1179 /// * Collection Admin1180 ///1181 /// # Arguments1182 ///1183 /// * collection_id.1184 ///1185 /// * schema: String representing the variable on-chain data schema.1186 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1187 #[transactional]1188 pub fn set_variable_on_chain_schema (1189 origin,1190 collection_id: CollectionId,1191 schema: Vec<u8>1192 ) -> DispatchResult {1193 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1194 let mut target_collection = Self::get_collection(collection_id)?;1195 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;11961197 // check schema limit1198 ensure!(schema.len() as u32 <= VARIABLE_ON_CHAIN_SCHEMA_LIMIT, "");11991200 target_collection.variable_on_chain_schema = schema;1201 target_collection.save()1202 }12031204 #[weight = <T as Config>::WeightInfo::set_collection_limits()]1205 #[transactional]1206 pub fn set_collection_limits(1207 origin,1208 collection_id: u32,1209 new_limits: CollectionLimits<T::BlockNumber>,1210 ) -> DispatchResult {1211 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1212 let mut target_collection = Self::get_collection(collection_id)?;1213 Self::check_owner_permissions(&target_collection, sender.as_sub())?;1214 let old_limits = &target_collection.limits;12151216 // collection bounds1217 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1218 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&1219 new_limits.sponsored_data_size <= CUSTOM_DATA_LIMIT,1220 Error::<T>::CollectionLimitBoundsExceeded);12211222 // token_limit check prev1223 ensure!(old_limits.token_limit >= new_limits.token_limit, Error::<T>::CollectionTokenLimitExceeded);1224 ensure!(new_limits.token_limit > 0, Error::<T>::CollectionTokenLimitExceeded);12251226 ensure!(1227 (old_limits.owner_can_transfer || !new_limits.owner_can_transfer) &&1228 (old_limits.owner_can_destroy || !new_limits.owner_can_destroy),1229 Error::<T>::OwnerPermissionsCantBeReverted,1230 );12311232 target_collection.limits = new_limits;12331234 target_collection.save()1235 }1236 }1237}12381239impl<T: Config> Module<T> {1240 pub fn create_item_internal(1241 sender: &T::CrossAccountId,1242 collection: &CollectionHandle<T>,1243 owner: &T::CrossAccountId,1244 data: CreateItemData,1245 ) -> DispatchResult {1246 ensure!(1247 owner != &T::CrossAccountId::from_eth(H160([0; 20])),1248 Error::<T>::AddressIsZero1249 );12501251 Self::can_create_items_in_collection(collection, sender, owner, 1)?;1252 Self::validate_create_item_args(collection, &data)?;1253 Self::create_item_no_validation(collection, owner, data)?;1254 pub fn transfer_internal(1255 sender: &T::CrossAccountId,1256 recipient: &T::CrossAccountId,1257 target_collection: &CollectionHandle<T>,1258 item_id: TokenId,1259 value: u128,1260 ) -> DispatchResult {1261 ensure!(1262 recipient != &T::CrossAccountId::from_eth(H160([0; 20])),1263 Error::<T>::AddressIsZero1264 );12651266 target_collection.consume_gas(2000000)?;1267 // Limits check1268 Self::is_correct_transfer(target_collection, recipient)?;12691270 // Transfer permissions check1271 ensure!(1272 Self::is_item_owner(sender, target_collection, item_id)1273 || Self::is_owner_or_admin_permissions(target_collection, sender),1274 Error::<T>::NoPermission1275 );12761277 if target_collection.access == AccessMode::WhiteList {1278 Self::check_white_list(target_collection, sender)?;1279 Self::check_white_list(target_collection, recipient)?;1280 }12811282 match target_collection.mode {1283 CollectionMode::NFT => Self::transfer_nft(1284 target_collection,1285 item_id,1286 sender.clone(),1287 recipient.clone(),1288 )?,1289 CollectionMode::Fungible(_) => {1290 Self::transfer_fungible(target_collection, value, sender, recipient)?1291 }1292 CollectionMode::ReFungible => Self::transfer_refungible(1293 target_collection,1294 item_id,1295 value,1296 sender.clone(),1297 recipient.clone(),1298 )?,1299 _ => (),1300 };13011302 Self::deposit_event(RawEvent::Transfer(1303 target_collection.id,1304 item_id,1305 sender.clone(),1306 recipient.clone(),1307 value,1308 ));13091310 Ok(())1311 }13121313 pub fn approve_internal(1314 sender: &T::CrossAccountId,1315 spender: &T::CrossAccountId,1316 collection: &CollectionHandle<T>,1317 item_id: TokenId,1318 amount: u128,1319 ) -> DispatchResult {1320 collection.consume_gas(2000000)?;1321 Self::token_exists(collection, item_id)?;13221323 // Transfer permissions check1324 let bypasses_limits = collection.limits.owner_can_transfer1325 && Self::is_owner_or_admin_permissions(collection, sender);13261327 let allowance_limit = if bypasses_limits {1328 None1329 } else if let Some(amount) = Self::owned_amount(sender, collection, item_id) {1330 Some(amount)1331 } else {1332 fail!(Error::<T>::NoPermission);1333 };13341335 if collection.access == AccessMode::WhiteList {1336 Self::check_white_list(collection, sender)?;1337 Self::check_white_list(collection, spender)?;1338 }13391340 let allowance: u128 = amount1341 .checked_add(<Allowances<T>>::get(1342 collection.id,1343 (item_id, sender.as_sub(), spender.as_sub()),1344 ))1345 .ok_or(Error::<T>::NumOverflow)?;1346 if let Some(limit) = allowance_limit {1347 ensure!(limit >= allowance, Error::<T>::TokenValueTooLow);1348 }1349 <Allowances<T>>::insert(1350 collection.id,1351 (item_id, sender.as_sub(), spender.as_sub()),1352 allowance,1353 );13541355 if matches!(collection.mode, CollectionMode::NFT) {1356 // TODO: NFT: only one owner may exist for token in ERC7211357 collection.log(ERC721Events::Approval {1358 owner: *sender.as_eth(),1359 approved: *spender.as_eth(),1360 token_id: item_id.into(),1361 })?;1362 }13631364 if matches!(collection.mode, CollectionMode::Fungible(_)) {1365 // TODO: NFT: only one owner may exist for token in ERC201366 collection.log(ERC20Events::Approval {1367 owner: *sender.as_eth(),1368 spender: *spender.as_eth(),1369 value: allowance.into(),1370 })?;1371 }13721373 Self::deposit_event(RawEvent::Approved(1374 collection.id,1375 item_id,1376 sender.clone(),1377 spender.clone(),1378 allowance,1379 ));1380 Ok(())1381 }13821383 pub fn transfer_from_internal(1384 sender: &T::CrossAccountId,1385 from: &T::CrossAccountId,1386 recipient: &T::CrossAccountId,1387 collection: &CollectionHandle<T>,1388 item_id: TokenId,1389 amount: u128,1390 ) -> DispatchResult {1391 collection.consume_gas(2000000)?;1392 // Check approval1393 let approval: u128 =1394 <Allowances<T>>::get(collection.id, (item_id, from.as_sub(), sender.as_sub()));13951396 // Limits check1397 Self::is_correct_transfer(collection, recipient)?;13981399 // Transfer permissions check1400 ensure!(1401 approval >= amount1402 || (collection.limits.owner_can_transfer1403 && Self::is_owner_or_admin_permissions(collection, sender)),1404 Error::<T>::NoPermission1405 );14061407 if collection.access == AccessMode::WhiteList {1408 Self::check_white_list(collection, sender)?;1409 Self::check_white_list(collection, recipient)?;1410 }14111412 // Reduce approval by transferred amount or remove if remaining approval drops to 01413 let allowance = approval.saturating_sub(amount);1414 if allowance > 0 {1415 <Allowances<T>>::insert(1416 collection.id,1417 (item_id, from.as_sub(), sender.as_sub()),1418 allowance,1419 );1420 } else {1421 <Allowances<T>>::remove(collection.id, (item_id, from.as_sub(), sender.as_sub()));1422 }14231424 match collection.mode {1425 CollectionMode::NFT => {1426 Self::transfer_nft(collection, item_id, from.clone(), recipient.clone())?1427 }1428 CollectionMode::Fungible(_) => {1429 Self::transfer_fungible(collection, amount, from, recipient)?1430 }1431 CollectionMode::ReFungible => Self::transfer_refungible(1432 collection,1433 item_id,1434 amount,1435 from.clone(),1436 recipient.clone(),1437 )?,1438 _ => (),1439 };14401441 if matches!(collection.mode, CollectionMode::Fungible(_)) {1442 collection.log(ERC20Events::Approval {1443 owner: *from.as_eth(),1444 spender: *sender.as_eth(),1445 value: allowance.into(),1446 })?;1447 }14481449 Ok(())1450 }14511452 pub fn set_variable_meta_data_internal(1453 sender: &T::CrossAccountId,1454 collection: &CollectionHandle<T>,1455 item_id: TokenId,1456 data: Vec<u8>,1457 ) -> DispatchResult {1458 Self::token_exists(collection, item_id)?;14591460 ensure!(1461 CUSTOM_DATA_LIMIT >= data.len() as u32,1462 Error::<T>::TokenVariableDataLimitExceeded1463 );14641465 // Modify permissions check1466 ensure!(1467 Self::is_item_owner(sender, collection, item_id)1468 || Self::is_owner_or_admin_permissions(collection, sender),1469 Error::<T>::NoPermission1470 );14711472 match collection.mode {1473 CollectionMode::NFT => Self::set_nft_variable_data(collection, item_id, data)?,1474 CollectionMode::ReFungible => {1475 Self::set_re_fungible_variable_data(collection, item_id, data)?1476 }1477 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1478 _ => fail!(Error::<T>::UnexpectedCollectionType),1479 };14801481 Ok(())1482 }14831484 pub fn create_multiple_items_internal(1485 sender: &T::CrossAccountId,1486 collection: &CollectionHandle<T>,1487 owner: &T::CrossAccountId,1488 items_data: Vec<CreateItemData>,1489 ) -> DispatchResult {1490 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;14911492 for data in &items_data {1493 Self::validate_create_item_args(collection, data)?;1494 }1495 for data in &items_data {1496 Self::create_item_no_validation(collection, owner, data.clone())?;1497 }14981499 Ok(())1500 }15011502 pub fn burn_item_internal(1503 sender: &T::CrossAccountId,1504 collection: &CollectionHandle<T>,1505 item_id: TokenId,1506 value: u128,1507 ) -> DispatchResult {1508 ensure!(1509 Self::is_item_owner(sender, collection, item_id)1510 || (collection.limits.owner_can_transfer1511 && Self::is_owner_or_admin_permissions(collection, sender)),1512 Error::<T>::NoPermission1513 );15141515 if collection.access == AccessMode::WhiteList {1516 Self::check_white_list(collection, sender)?;1517 }15181519 match collection.mode {1520 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1521 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1522 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1523 _ => (),1524 };15251526 Ok(())1527 }15281529 pub fn toggle_white_list_internal(1530 sender: &T::CrossAccountId,1531 collection: &CollectionHandle<T>,1532 address: &T::CrossAccountId,1533 whitelisted: bool,1534 ) -> DispatchResult {1535 Self::check_owner_or_admin_permissions(collection, sender)?;15361537 if whitelisted {1538 <WhiteList<T>>::insert(collection.id, address.as_sub(), true);1539 } else {1540 <WhiteList<T>>::remove(collection.id, address.as_sub());1541 }15421543 Ok(())1544 }15451546 fn is_correct_transfer(1547 collection: &CollectionHandle<T>,1548 recipient: &T::CrossAccountId,1549 ) -> DispatchResult {1550 let collection_id = collection.id;15511552 // check token limit and account token limit1553 let account_items: u32 =1554 <AddressTokens<T>>::get(collection_id, recipient.as_sub()).len() as u32;1555 ensure!(1556 collection.limits.account_token_ownership_limit > account_items,1557 Error::<T>::AccountTokenLimitExceeded1558 );15591560 // preliminary transfer check1561 ensure!(collection.transfers_enabled, Error::<T>::TransferNotAllowed);15621563 Ok(())1564 }15651566 fn can_create_items_in_collection(1567 collection: &CollectionHandle<T>,1568 sender: &T::CrossAccountId,1569 owner: &T::CrossAccountId,1570 amount: u32,1571 ) -> DispatchResult {1572 let collection_id = collection.id;15731574 // check token limit and account token limit1575 let total_items: u32 = ItemListIndex::get(collection_id)1576 .checked_add(amount)1577 .ok_or(Error::<T>::CollectionTokenLimitExceeded)?;1578 let account_items: u32 = (<AddressTokens<T>>::get(collection_id, owner.as_sub()).len()1579 as u32)1580 .checked_add(amount)1581 .ok_or(Error::<T>::AccountTokenLimitExceeded)?;1582 ensure!(1583 collection.limits.token_limit >= total_items,1584 Error::<T>::CollectionTokenLimitExceeded1585 );1586 ensure!(1587 collection.limits.account_token_ownership_limit >= account_items,1588 Error::<T>::AccountTokenLimitExceeded1589 );15901591 if !Self::is_owner_or_admin_permissions(collection, sender) {1592 ensure!(collection.mint_mode, Error::<T>::PublicMintingNotAllowed);1593 Self::check_white_list(collection, owner)?;1594 Self::check_white_list(collection, sender)?;1595 }15961597 Ok(())1598 }15991600 fn validate_create_item_args(1601 target_collection: &CollectionHandle<T>,1602 data: &CreateItemData,1603 ) -> DispatchResult {1604 match target_collection.mode {1605 CollectionMode::NFT => {1606 if !matches!(data, CreateItemData::NFT(_)) {1607 fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);1608 }1609 }1610 CollectionMode::Fungible(_) => {1611 if !matches!(data, CreateItemData::Fungible(_)) {1612 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1613 }1614 }1615 CollectionMode::ReFungible => {1616 if let CreateItemData::ReFungible(data) = data {1617 // Check refungibility limits1618 ensure!(1619 data.pieces <= MAX_REFUNGIBLE_PIECES,1620 Error::<T>::WrongRefungiblePieces1621 );1622 ensure!(data.pieces > 0, Error::<T>::WrongRefungiblePieces);1623 } else {1624 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1625 }1626 }1627 _ => {1628 fail!(Error::<T>::UnexpectedCollectionType);1629 }1630 };16311632 Ok(())1633 }16341635 fn create_item_no_validation(1636 collection: &CollectionHandle<T>,1637 owner: &T::CrossAccountId,1638 data: CreateItemData,1639 ) -> DispatchResult {1640 match data {1641 CreateItemData::NFT(data) => {1642 let item = NftItemType {1643 owner: owner.clone(),1644 const_data: data.const_data.into_inner(),1645 variable_data: data.variable_data.into_inner(),1646 };16471648 Self::add_nft_item(collection, item)?;1649 }1650 CreateItemData::Fungible(data) => {1651 Self::add_fungible_item(collection, owner, data.value)?;1652 }1653 CreateItemData::ReFungible(data) => {1654 let owner_list = vec![Ownership {1655 owner: owner.clone(),1656 fraction: data.pieces,1657 }];16581659 let item = ReFungibleItemType {1660 owner: owner_list,1661 const_data: data.const_data.into_inner(),1662 variable_data: data.variable_data.into_inner(),1663 };16641665 Self::add_refungible_item(collection, item)?;1666 }1667 };16681669 Ok(())1670 }16711672 fn add_fungible_item(1673 collection: &CollectionHandle<T>,1674 owner: &T::CrossAccountId,1675 value: u128,1676 ) -> DispatchResult {1677 let collection_id = collection.id;16781679 // Does new owner already have an account?1680 let balance: u128 = <FungibleItemList<T>>::get(collection_id, owner.as_sub()).value;16811682 // Mint1683 let item = FungibleItemType {1684 value: balance.checked_add(value).ok_or(Error::<T>::NumOverflow)?,1685 };1686 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), item);16871688 // Update balance1689 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1690 .checked_add(value)1691 .ok_or(Error::<T>::NumOverflow)?;1692 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);16931694 Self::deposit_event(RawEvent::ItemCreated(collection_id, 0, owner.clone()));1695 Ok(())1696 }16971698 fn add_refungible_item(1699 collection: &CollectionHandle<T>,1700 item: ReFungibleItemType<T::CrossAccountId>,1701 ) -> DispatchResult {1702 let collection_id = collection.id;17031704 let current_index = <ItemListIndex>::get(collection_id)1705 .checked_add(1)1706 .ok_or(Error::<T>::NumOverflow)?;1707 let itemcopy = item.clone();17081709 ensure!(item.owner.len() == 1, Error::<T>::BadCreateRefungibleCall,);1710 let item_owner = item.owner.first().expect("only one owner is defined");17111712 let value = item_owner.fraction;1713 let owner = item_owner.owner.clone();17141715 Self::add_token_index(collection_id, current_index, &owner)?;17161717 <ItemListIndex>::insert(collection_id, current_index);1718 <ReFungibleItemList<T>>::insert(collection_id, current_index, itemcopy);17191720 // Update balance1721 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1722 .checked_add(value)1723 .ok_or(Error::<T>::NumOverflow)?;1724 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);17251726 Self::deposit_event(RawEvent::ItemCreated(collection_id, current_index, owner));1727 Ok(())1728 }17291730 fn add_nft_item(1731 collection: &CollectionHandle<T>,1732 item: NftItemType<T::CrossAccountId>,1733 ) -> DispatchResult {1734 let collection_id = collection.id;17351736 let current_index = <ItemListIndex>::get(collection_id)1737 .checked_add(1)1738 .ok_or(Error::<T>::NumOverflow)?;17391740 let item_owner = item.owner.clone();1741 Self::add_token_index(collection_id, current_index, &item.owner)?;17421743 <ItemListIndex>::insert(collection_id, current_index);1744 <NftItemList<T>>::insert(collection_id, current_index, item);17451746 // Update balance1747 let new_balance = <Balance<T>>::get(collection_id, item_owner.as_sub())1748 .checked_add(1)1749 .ok_or(Error::<T>::NumOverflow)?;1750 <Balance<T>>::insert(collection_id, item_owner.as_sub(), new_balance);17511752 collection.log(ERC721Events::Transfer {1753 from: H160::default(),1754 to: *item_owner.as_eth(),1755 token_id: current_index.into(),1756 })?;1757 Self::deposit_event(RawEvent::ItemCreated(1758 collection_id,1759 current_index,1760 item_owner,1761 ));1762 Ok(())1763 }17641765 fn burn_refungible_item(1766 collection: &CollectionHandle<T>,1767 item_id: TokenId,1768 owner: &T::CrossAccountId,1769 ) -> DispatchResult {1770 let collection_id = collection.id;17711772 let mut token = <ReFungibleItemList<T>>::get(collection_id, item_id)1773 .ok_or(Error::<T>::TokenNotFound)?;1774 let rft_balance = token1775 .owner1776 .iter()1777 .find(|&i| i.owner == *owner)1778 .ok_or(Error::<T>::TokenNotFound)?;1779 Self::remove_token_index(collection_id, item_id, owner)?;17801781 // update balance1782 let new_balance = <Balance<T>>::get(collection_id, rft_balance.owner.as_sub())1783 .checked_sub(rft_balance.fraction)1784 .ok_or(Error::<T>::NumOverflow)?;1785 <Balance<T>>::insert(collection_id, rft_balance.owner.as_sub(), new_balance);17861787 // Re-create owners list with sender removed1788 let index = token1789 .owner1790 .iter()1791 .position(|i| i.owner == *owner)1792 .expect("owned item is exists");1793 token.owner.remove(index);1794 let owner_count = token.owner.len();17951796 // Burn the token completely if this was the last (only) owner1797 if owner_count == 0 {1798 <ReFungibleItemList<T>>::remove(collection_id, item_id);1799 <VariableMetaDataBasket<T>>::remove(collection_id, item_id);1800 } else {1801 <ReFungibleItemList<T>>::insert(collection_id, item_id, token);1802 }18031804 Ok(())1805 }18061807 fn burn_nft_item(collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {1808 let collection_id = collection.id;18091810 let item =1811 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;1812 Self::remove_token_index(collection_id, item_id, &item.owner)?;18131814 // update balance1815 let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())1816 .checked_sub(1)1817 .ok_or(Error::<T>::NumOverflow)?;1818 <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);1819 <NftItemList<T>>::remove(collection_id, item_id);1820 <VariableMetaDataBasket<T>>::remove(collection_id, item_id);18211822 Self::deposit_event(RawEvent::ItemDestroyed(collection.id, item_id));1823 Ok(())1824 }18251826 fn burn_fungible_item(1827 owner: &T::CrossAccountId,1828 collection: &CollectionHandle<T>,1829 value: u128,1830 ) -> DispatchResult {1831 let collection_id = collection.id;18321833 let mut balance = <FungibleItemList<T>>::get(collection_id, owner.as_sub());1834 ensure!(balance.value >= value, Error::<T>::TokenValueNotEnough);18351836 // update balance1837 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())1838 .checked_sub(value)1839 .ok_or(Error::<T>::NumOverflow)?;1840 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);18411842 if balance.value - value > 0 {1843 balance.value -= value;1844 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), balance);1845 } else {1846 <FungibleItemList<T>>::remove(collection_id, owner.as_sub());1847 }18481849 collection.log(ERC20Events::Transfer {1850 from: *owner.as_eth(),1851 to: H160::default(),1852 value: value.into(),1853 })?;1854 Ok(())1855 }18561857 pub fn get_collection(1858 collection_id: CollectionId,1859 ) -> Result<CollectionHandle<T>, sp_runtime::DispatchError> {1860 Ok(<CollectionHandle<T>>::get(collection_id).ok_or(Error::<T>::CollectionNotFound)?)1861 }18621863 fn check_owner_permissions(1864 target_collection: &CollectionHandle<T>,1865 subject: &T::AccountId,1866 ) -> DispatchResult {1867 ensure!(1868 *subject == target_collection.owner,1869 Error::<T>::NoPermission1870 );18711872 Ok(())1873 }18741875 fn is_owner_or_admin_permissions(1876 collection: &CollectionHandle<T>,1877 subject: &T::CrossAccountId,1878 ) -> bool {1879 *subject.as_sub() == collection.owner1880 || <AdminList<T>>::get(collection.id).contains(subject)1881 }18821883 fn check_owner_or_admin_permissions(1884 collection: &CollectionHandle<T>,1885 subject: &T::CrossAccountId,1886 ) -> DispatchResult {1887 ensure!(1888 Self::is_owner_or_admin_permissions(collection, subject),1889 Error::<T>::NoPermission1890 );18911892 Ok(())1893 }18941895 fn owned_amount(1896 subject: &T::CrossAccountId,1897 target_collection: &CollectionHandle<T>,1898 item_id: TokenId,1899 ) -> Option<u128> {1900 let collection_id = target_collection.id;19011902 match target_collection.mode {1903 CollectionMode::NFT => {1904 (<NftItemList<T>>::get(collection_id, item_id)?.owner == *subject).then(|| 1)1905 }1906 CollectionMode::Fungible(_) => {1907 Some(<FungibleItemList<T>>::get(collection_id, &subject.as_sub()).value)1908 }1909 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)?1910 .owner1911 .iter()1912 .find(|i| i.owner == *subject)1913 .map(|i| i.fraction),1914 CollectionMode::Invalid => None,1915 }1916 }19171918 fn is_item_owner(1919 subject: &T::CrossAccountId,1920 target_collection: &CollectionHandle<T>,1921 item_id: TokenId,1922 ) -> bool {1923 match target_collection.mode {1924 CollectionMode::Fungible(_) => true,1925 _ => Self::owned_amount(subject, target_collection, item_id).is_some(),1926 }1927 }19281929 fn check_white_list(1930 collection: &CollectionHandle<T>,1931 address: &T::CrossAccountId,1932 ) -> DispatchResult {1933 let collection_id = collection.id;19341935 let mes = Error::<T>::AddresNotInWhiteList;1936 ensure!(1937 <WhiteList<T>>::contains_key(collection_id, address.as_sub()),1938 mes1939 );19401941 Ok(())1942 }19431944 /// Check if token exists. In case of Fungible, check if there is an entry for1945 /// the owner in fungible balances double map1946 fn token_exists(target_collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {1947 let collection_id = target_collection.id;1948 let exists = match target_collection.mode {1949 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),1950 CollectionMode::Fungible(_) => true,1951 CollectionMode::ReFungible => {1952 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)1953 }1954 _ => false,1955 };19561957 ensure!(exists, Error::<T>::TokenNotFound);1958 Ok(())1959 }19601961 fn transfer_fungible(1962 collection: &CollectionHandle<T>,1963 value: u128,1964 owner: &T::CrossAccountId,1965 recipient: &T::CrossAccountId,1966 ) -> DispatchResult {1967 let collection_id = collection.id;19681969 let mut balance = <FungibleItemList<T>>::get(collection_id, owner.as_sub());1970 ensure!(balance.value >= value, Error::<T>::TokenValueTooLow);19711972 // Send balance to recipient (updates balanceOf of recipient)1973 Self::add_fungible_item(collection, recipient, value)?;19741975 // update balanceOf of sender1976 <Balance<T>>::insert(collection_id, owner.as_sub(), balance.value - value);19771978 // Reduce or remove sender1979 if balance.value == value {1980 <FungibleItemList<T>>::remove(collection_id, owner.as_sub());1981 } else {1982 balance.value -= value;1983 <FungibleItemList<T>>::insert(collection_id, owner.as_sub(), balance);1984 }19851986 collection.log(ERC20Events::Transfer {1987 from: *owner.as_eth(),1988 to: *recipient.as_eth(),1989 value: value.into(),1990 })?;1991 Self::deposit_event(RawEvent::Transfer(1992 collection.id,1993 1,1994 owner.clone(),1995 recipient.clone(),1996 value,1997 ));19981999 Ok(())2000 }20012002 fn transfer_refungible(2003 collection: &CollectionHandle<T>,2004 item_id: TokenId,2005 value: u128,2006 owner: T::CrossAccountId,2007 new_owner: T::CrossAccountId,2008 ) -> DispatchResult {2009 let collection_id = collection.id;2010 let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id)2011 .ok_or(Error::<T>::TokenNotFound)?;20122013 let item = full_item2014 .owner2015 .iter()2016 .find(|i| i.owner == owner)2017 .ok_or(Error::<T>::TokenNotFound)?;2018 let amount = item.fraction;20192020 ensure!(amount >= value, Error::<T>::TokenValueTooLow);20212022 // update balance2023 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.as_sub())2024 .checked_sub(value)2025 .ok_or(Error::<T>::NumOverflow)?;2026 <Balance<T>>::insert(collection_id, item.owner.as_sub(), balance_old_owner);20272028 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.as_sub())2029 .checked_add(value)2030 .ok_or(Error::<T>::NumOverflow)?;2031 <Balance<T>>::insert(collection_id, new_owner.as_sub(), balance_new_owner);20322033 let old_owner = item.owner.clone();2034 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);20352036 let mut new_full_item = full_item.clone();2037 // transfer2038 if amount == value && !new_owner_has_account {2039 // change owner2040 // new owner do not have account2041 new_full_item2042 .owner2043 .iter_mut()2044 .find(|i| i.owner == owner)2045 .expect("old owner does present in refungible")2046 .owner = new_owner.clone();2047 <ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);20482049 // update index collection2050 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;2051 } else {2052 new_full_item2053 .owner2054 .iter_mut()2055 .find(|i| i.owner == owner)2056 .expect("old owner does present in refungible")2057 .fraction -= value;20582059 // separate amount2060 if new_owner_has_account {2061 // new owner has account2062 new_full_item2063 .owner2064 .iter_mut()2065 .find(|i| i.owner == new_owner)2066 .expect("new owner has account")2067 .fraction += value;2068 } else {2069 // new owner do not have account2070 new_full_item.owner.push(Ownership {2071 owner: new_owner.clone(),2072 fraction: value,2073 });2074 Self::add_token_index(collection_id, item_id, &new_owner)?;2075 }20762077 <ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);2078 }20792080 Self::deposit_event(RawEvent::Transfer(2081 collection.id,2082 item_id,2083 owner,2084 new_owner,2085 amount,2086 ));20872088 Ok(())2089 }20902091 fn transfer_nft(2092 collection: &CollectionHandle<T>,2093 item_id: TokenId,2094 sender: T::CrossAccountId,2095 new_owner: T::CrossAccountId,2096 ) -> DispatchResult {2097 let collection_id = collection.id;2098 let mut item =2099 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;21002101 ensure!(sender == item.owner, Error::<T>::MustBeTokenOwner);21022103 // update balance2104 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.as_sub())2105 .checked_sub(1)2106 .ok_or(Error::<T>::NumOverflow)?;2107 <Balance<T>>::insert(collection_id, item.owner.as_sub(), balance_old_owner);21082109 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.as_sub())2110 .checked_add(1)2111 .ok_or(Error::<T>::NumOverflow)?;2112 <Balance<T>>::insert(collection_id, new_owner.as_sub(), balance_new_owner);21132114 // change owner2115 let old_owner = item.owner.clone();2116 item.owner = new_owner.clone();2117 <NftItemList<T>>::insert(collection_id, item_id, item);21182119 // update index collection2120 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;21212122 collection.log(ERC721Events::Transfer {2123 from: *sender.as_eth(),2124 to: *new_owner.as_eth(),2125 token_id: item_id.into(),2126 })?;2127 Self::deposit_event(RawEvent::Transfer(2128 collection.id,2129 item_id,2130 sender,2131 new_owner,2132 1,2133 ));21342135 Ok(())2136 }21372138 fn set_re_fungible_variable_data(2139 collection: &CollectionHandle<T>,2140 item_id: TokenId,2141 data: Vec<u8>,2142 ) -> DispatchResult {2143 let collection_id = collection.id;2144 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id)2145 .ok_or(Error::<T>::TokenNotFound)?;21462147 item.variable_data = data;21482149 <ReFungibleItemList<T>>::insert(collection_id, item_id, item);21502151 Ok(())2152 }21532154 fn set_nft_variable_data(2155 collection: &CollectionHandle<T>,2156 item_id: TokenId,2157 data: Vec<u8>,2158 ) -> DispatchResult {2159 let collection_id = collection.id;2160 let mut item =2161 <NftItemList<T>>::get(collection_id, item_id).ok_or(Error::<T>::TokenNotFound)?;21622163 item.variable_data = data;21642165 <NftItemList<T>>::insert(collection_id, item_id, item);21662167 Ok(())2168 }21692170 #[allow(dead_code)]2171 fn init_collection(item: &Collection<T>) {2172 // check params2173 assert!(2174 item.decimal_points <= MAX_DECIMAL_POINTS,2175 "decimal_points parameter must be lower than MAX_DECIMAL_POINTS"2176 );2177 assert!(2178 item.name.len() <= 64,2179 "Collection name can not be longer than 63 char"2180 );2181 assert!(2182 item.name.len() <= 256,2183 "Collection description can not be longer than 255 char"2184 );2185 assert!(2186 item.token_prefix.len() <= 16,2187 "Token prefix can not be longer than 15 char"2188 );21892190 // Generate next collection ID2191 let next_id = CreatedCollectionCount::get().checked_add(1).unwrap();21922193 CreatedCollectionCount::put(next_id);2194 }21952196 #[allow(dead_code)]2197 fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::CrossAccountId>) {2198 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();21992200 Self::add_token_index(collection_id, current_index, &item.owner).unwrap();22012202 <ItemListIndex>::insert(collection_id, current_index);22032204 // Update balance2205 let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())2206 .checked_add(1)2207 .unwrap();2208 <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);2209 }22102211 #[allow(dead_code)]2212 fn init_fungible_token(2213 collection_id: CollectionId,2214 owner: &T::CrossAccountId,2215 item: &FungibleItemType,2216 ) {2217 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();22182219 Self::add_token_index(collection_id, current_index, owner).unwrap();22202221 <ItemListIndex>::insert(collection_id, current_index);22222223 // Update balance2224 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())2225 .checked_add(item.value)2226 .unwrap();2227 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);2228 }22292230 #[allow(dead_code)]2231 fn init_refungible_token(2232 collection_id: CollectionId,2233 item: &ReFungibleItemType<T::CrossAccountId>,2234 ) {2235 let current_index = <ItemListIndex>::get(collection_id).checked_add(1).unwrap();22362237 let value = item.owner.first().unwrap().fraction;2238 let owner = item.owner.first().unwrap().owner.clone();22392240 Self::add_token_index(collection_id, current_index, &owner).unwrap();22412242 <ItemListIndex>::insert(collection_id, current_index);22432244 // Update balance2245 let new_balance = <Balance<T>>::get(collection_id, &owner.as_sub())2246 .checked_add(value)2247 .unwrap();2248 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);2249 }22502251 fn add_token_index(2252 collection_id: CollectionId,2253 item_index: TokenId,2254 owner: &T::CrossAccountId,2255 ) -> DispatchResult {2256 // add to account limit2257 if <AccountItemCount<T>>::contains_key(owner.as_sub()) {2258 // bound Owned tokens by a single address2259 let count = <AccountItemCount<T>>::get(owner.as_sub());2260 ensure!(2261 count < ACCOUNT_TOKEN_OWNERSHIP_LIMIT,2262 Error::<T>::AddressOwnershipLimitExceeded2263 );22642265 <AccountItemCount<T>>::insert(2266 owner.as_sub(),2267 count.checked_add(1).ok_or(Error::<T>::NumOverflow)?,2268 );2269 } else {2270 <AccountItemCount<T>>::insert(owner.as_sub(), 1);2271 }22722273 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());2274 if list_exists {2275 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());2276 let item_contains = list.contains(&item_index.clone());22772278 if !item_contains {2279 list.push(item_index);2280 }22812282 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);2283 } else {2284 let itm = vec![item_index];2285 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);2286 }22872288 Ok(())2289 }22902291 fn remove_token_index(2292 collection_id: CollectionId,2293 item_index: TokenId,2294 owner: &T::CrossAccountId,2295 ) -> DispatchResult {2296 // update counter2297 <AccountItemCount<T>>::insert(2298 owner.as_sub(),2299 <AccountItemCount<T>>::get(owner.as_sub())2300 .checked_sub(1)2301 .ok_or(Error::<T>::NumOverflow)?,2302 );23032304 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());2305 if list_exists {2306 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());2307 let item_contains = list.contains(&item_index.clone());23082309 if item_contains {2310 list.retain(|&item| item != item_index);2311 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);2312 }2313 }23142315 Ok(())2316 }23172318 fn move_token_index(2319 collection_id: CollectionId,2320 item_index: TokenId,2321 old_owner: &T::CrossAccountId,2322 new_owner: &T::CrossAccountId,2323 ) -> DispatchResult {2324 Self::remove_token_index(collection_id, item_index, old_owner)?;2325 Self::add_token_index(collection_id, item_index, new_owner)?;23262327 Ok(())2328 }2329}23302331sp_api::decl_runtime_apis! {2332 pub trait NftApi {2333 /// Used for ethereum integration2334 fn eth_contract_code(account: H160) -> Option<Vec<u8>>;2335 }2336}