diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 8810fc7ebb..3b101fb31b 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -833,15 +833,15 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -892,7 +892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fork-tree" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1300,10 +1300,10 @@ dependencies = [ [[package]] name = "impl-codec" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2010,6 +2010,14 @@ dependencies = [ "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.9" @@ -2249,7 +2257,7 @@ dependencies = [ "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -2287,7 +2295,7 @@ version = "2.0.0" dependencies = [ "node-primitives 2.0.0", "node-runtime 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "srml-balances 2.0.0", @@ -2314,7 +2322,7 @@ dependencies = [ name = "node-primitives" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", @@ -2342,7 +2350,7 @@ version = "2.0.0" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2387,7 +2395,7 @@ dependencies = [ "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "node-template-runtime 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "substrate-basic-authorship 2.0.0", @@ -2409,7 +2417,7 @@ dependencies = [ name = "node-template-runtime" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -2583,21 +2591,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "bitvec 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parity-codec-derive" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parity-multiaddr" version = "0.5.0" @@ -2631,16 +2627,28 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "bitvec 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "byte-slice-cast 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec-derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "vecarray 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-scale-codec-derive" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parity-send-wrapper" version = "0.1.0" @@ -2701,6 +2709,16 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.2.14" @@ -2751,6 +2769,20 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "paste" version = "0.1.5" @@ -2827,11 +2859,11 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fixed-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-codec 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-codec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3159,13 +3191,13 @@ dependencies = [ [[package]] name = "rhododendron" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3559,7 +3591,7 @@ version = "2.0.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3581,7 +3613,7 @@ dependencies = [ "environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-offchain 2.0.0", @@ -3598,9 +3630,9 @@ dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3613,7 +3645,7 @@ name = "sr-sandbox" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -3633,7 +3665,7 @@ name = "sr-version" version = "2.0.0" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3643,7 +3675,7 @@ dependencies = [ name = "srml-assets" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3658,7 +3690,7 @@ name = "srml-aura" version = "2.0.0" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3678,7 +3710,7 @@ dependencies = [ name = "srml-authorship" version = "0.1.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3693,7 +3725,7 @@ version = "2.0.0" dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3713,7 +3745,7 @@ dependencies = [ name = "srml-balances" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3730,7 +3762,7 @@ name = "srml-collective" version = "2.0.0" dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3749,7 +3781,7 @@ dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3770,7 +3802,7 @@ dependencies = [ name = "srml-democracy" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3787,7 +3819,7 @@ name = "srml-elections" version = "2.0.0" dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3803,7 +3835,7 @@ dependencies = [ name = "srml-example" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3818,7 +3850,7 @@ name = "srml-executive" version = "2.0.0" dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3834,7 +3866,7 @@ dependencies = [ name = "srml-finality-tracker" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3849,7 +3881,7 @@ dependencies = [ name = "srml-generic-asset" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3863,7 +3895,7 @@ dependencies = [ name = "srml-grandpa" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3880,7 +3912,7 @@ dependencies = [ name = "srml-im-online" version = "0.1.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3895,7 +3927,7 @@ dependencies = [ name = "srml-indices" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "ref_thread_local 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3912,7 +3944,7 @@ dependencies = [ name = "srml-metadata" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -3923,7 +3955,7 @@ name = "srml-session" version = "2.0.0" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -3940,7 +3972,7 @@ dependencies = [ name = "srml-staking" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3961,7 +3993,7 @@ dependencies = [ name = "srml-sudo" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -3978,7 +4010,7 @@ version = "2.0.0" dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4027,7 +4059,7 @@ dependencies = [ name = "srml-support-test" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -4042,7 +4074,7 @@ name = "srml-system" version = "2.0.0" dependencies = [ "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -4056,7 +4088,7 @@ dependencies = [ name = "srml-timestamp" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -4071,7 +4103,7 @@ dependencies = [ name = "srml-treasury" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -4163,7 +4195,7 @@ dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 2.0.0", "node-runtime 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4191,7 +4223,7 @@ version = "2.0.0" dependencies = [ "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", @@ -4261,7 +4293,7 @@ dependencies = [ "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "sr-primitives 2.0.0", @@ -4289,7 +4321,7 @@ dependencies = [ "kvdb-rocksdb 0.1.4 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4312,7 +4344,7 @@ dependencies = [ "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -4338,7 +4370,7 @@ dependencies = [ name = "substrate-consensus-aura-primitives" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-client 2.0.0", @@ -4359,7 +4391,7 @@ dependencies = [ "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4387,7 +4419,7 @@ dependencies = [ name = "substrate-consensus-babe-primitives" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -4405,7 +4437,7 @@ dependencies = [ "futures-timer 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -4419,7 +4451,7 @@ dependencies = [ name = "substrate-consensus-common-primitives" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-client 2.0.0", @@ -4433,9 +4465,9 @@ dependencies = [ "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rhododendron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rhododendron 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", @@ -4456,7 +4488,7 @@ dependencies = [ "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4477,7 +4509,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -4500,12 +4532,12 @@ name = "substrate-finality-grandpa" version = "2.0.0" dependencies = [ "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "finality-grandpa 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "finality-grandpa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4530,7 +4562,7 @@ dependencies = [ name = "substrate-finality-grandpa-primitives" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -4542,7 +4574,7 @@ dependencies = [ name = "substrate-inherents" version = "2.0.0" dependencies = [ - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -4592,7 +4624,7 @@ dependencies = [ "linked_hash_set 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickcheck 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4626,7 +4658,7 @@ dependencies = [ "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4684,10 +4716,10 @@ dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4716,7 +4748,7 @@ dependencies = [ "jsonrpc-derive 12.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 12.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4779,8 +4811,8 @@ dependencies = [ "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4830,7 +4862,7 @@ version = "2.0.0" dependencies = [ "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 2.0.0", ] @@ -4843,7 +4875,7 @@ dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", @@ -4879,7 +4911,7 @@ version = "2.0.0" dependencies = [ "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-client-db 2.0.0", @@ -4897,7 +4929,7 @@ dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -4942,7 +4974,7 @@ dependencies = [ "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", @@ -4957,7 +4989,7 @@ dependencies = [ "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4976,7 +5008,7 @@ dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", "trie-bench 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5388,7 +5420,7 @@ name = "transaction-factory" version = "0.0.1" dependencies = [ "log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-cli 2.0.0", "substrate-client 2.0.0", @@ -5406,7 +5438,7 @@ dependencies = [ "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-standardmap 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6063,7 +6095,7 @@ dependencies = [ "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" -"checksum finality-grandpa 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e7cba2aaadf09932452a4fc054a77451b31eb99bc0b42bf54bd44f01a9daf4" +"checksum finality-grandpa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9681c1f75941ea47584573dd2bc10558b2067d460612945887e00744e43393be" "checksum fixed-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "516877b7b9a1cc2d0293cbce23cd6203f0edbfd4090e6ca4489fecb5aa73050e" "checksum flate2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "550934ad4808d5d39365e5d61727309bf18b3b02c6c56b729cb92e7dd84bc3d8" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" @@ -6113,7 +6145,7 @@ dependencies = [ "checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" "checksum hyper 0.12.33 (registry+https://github.com/rust-lang/crates.io-index)" = "7cb44cbce9d8ee4fb36e4c0ad7b794ac44ebaad924b9c8291a63215bb44c2c8f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum impl-codec 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62ed8ff267bc916dd848a800b96d3129aec73d5b23a5e3d018c83655d0c55371" +"checksum impl-codec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c441b3d2b5e24b407161e76d482b7bbd29b5da357707839ac40d95152f031f" "checksum impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5158079de9d4158e0ce1de3ae0bd7be03904efc40b3d7dd8b8c301cbf6b52b56" "checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" @@ -6171,6 +6203,7 @@ dependencies = [ "checksum linked_hash_set 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7c91c4c7bbeb4f2f7c4e5be11e6a05bd6830bc37249c47ce1ad86ad453ff9c" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" +"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c275b6ad54070ac2d665eef9197db647b32239c9d244bfb6f041a766d00da5b3" "checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" @@ -6213,10 +6246,10 @@ dependencies = [ "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2900f06356edf90de66a2922db622b36178dca71e85625eae58d0d9cc6cff2ac" -"checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" "checksum parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "045b3c7af871285146300da35b1932bb6e4639b66c7c98e85d06a32cbc4e8fa7" "checksum parity-multihash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "df3a17dc27848fd99e4f87eb0f8c9baba6ede0a6d555400c850ca45254ef4ce3" -"checksum parity-scale-codec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b72212671aded3ca515379ea16aa774289e06cd595c7e31f06afdc48d6516e3" +"checksum parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "00fd14ff806ad82cea9a8f909bb116443d92efda7c9acd4502690af64741ad81" +"checksum parity-scale-codec-derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a81f3cd93ed368a8e41c4e79538e99ca6e8f536096de23e3a0bc3e782093ce28" "checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2005637ccf93dbb60c85081ccaaf3f945f573da48dcc79f27f9646caa3ec1dc" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" @@ -6224,10 +6257,12 @@ dependencies = [ "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" "checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" +"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" +"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4a4a1c555c6505821f9d58b8779d0f630a6b7e4e1be24ba718610acf01fa79" "checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" @@ -6238,7 +6273,7 @@ dependencies = [ "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" -"checksum primitive-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "366ef730e56c11fd21ab3e518866cf7feb0fdf7f7c16ddc68485579e9d802787" +"checksum primitive-types 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e44400d651ca5276415dc8e00541c5c9d03844f1f0a87ad28f0a8fadcb2300bc" "checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-hack 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "982a35d1194084ba319d65c4a68d24ca28f5fdb5b8bc20899e4eef8641ea5178" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" @@ -6275,7 +6310,7 @@ dependencies = [ "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" "checksum regex-syntax 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5485bf1523a9ed51c4964273f22f63f24e31632adb5dad134f488f86a3875c" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum rhododendron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "057fecd57cc69e24d9d215c9f283a42133c3f48952e4fc06b088ecf3ce3d90bb" +"checksum rhododendron 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36542aafc2429a4c010fafa079a20dee953b663cb2427f51d86cf1d436846b4d" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" "checksum rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1651697fefd273bfb4fd69466cc2a9d20de557a0213b97233b22b5e95924b5e" "checksum rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34fa7bcae7fca3c8471e8417088bbc3ad9af8066b0ecf4f3c0d98a0d772716e" diff --git a/substrate/core/basic-authorship/Cargo.toml b/substrate/core/basic-authorship/Cargo.toml index 9463e3c07f..e21c0abe68 100644 --- a/substrate/core/basic-authorship/Cargo.toml +++ b/substrate/core/basic-authorship/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] log = "0.4" futures-preview = "0.3.0-alpha.17" -codec = { package = "parity-codec", version = "4.1.1" } +codec = { package = "parity-scale-codec", version = "1.0.0" } sr-primitives = { path = "../../core/sr-primitives" } primitives = { package = "substrate-primitives", path = "../../core/primitives" } client = { package = "substrate-client", path = "../../core/client" } diff --git a/substrate/core/basic-authorship/src/basic_authorship.rs b/substrate/core/basic-authorship/src/basic_authorship.rs index 2a3fe8dab8..2030f2be5a 100644 --- a/substrate/core/basic-authorship/src/basic_authorship.rs +++ b/substrate/core/basic-authorship/src/basic_authorship.rs @@ -213,7 +213,7 @@ impl Proposer, A> wh "hash" => ?::Hash::from(block.header().hash()), ); - if Decode::decode(&mut block.encode().as_slice()).as_ref() != Some(&block) { + if Decode::decode(&mut block.encode().as_slice()).as_ref() != Ok(&block) { error!("Failed to verify block encoding/decoding"); } diff --git a/substrate/core/cli/src/lib.rs b/substrate/core/cli/src/lib.rs index 7cd7db8897..eb0e443a57 100644 --- a/substrate/core/cli/src/lib.rs +++ b/substrate/core/cli/src/lib.rs @@ -37,8 +37,8 @@ use network::{ use primitives::H256; use std::{ - io::{Write, Read, stdin, stdout, ErrorKind}, iter, fs::{self, File}, net::{Ipv4Addr, SocketAddr}, - path::{Path, PathBuf}, str::FromStr, + io::{Write, Read, Seek, Cursor, stdin, stdout, ErrorKind}, iter, fs::{self, File}, + net::{Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, str::FromStr, }; use names::{Generator, Name}; @@ -628,6 +628,11 @@ where ).map_err(Into::into) } +/// Internal trait used to cast to a dynamic type that implements Read and Seek. +trait ReadPlusSeek: Read + Seek {} + +impl ReadPlusSeek for T {} + fn import_blocks( cli: ImportBlocksCmd, spec_factory: S, @@ -646,9 +651,13 @@ where ..Default::default() }; - let file: Box = match cli.input { + let file: Box = match cli.input { Some(filename) => Box::new(File::open(filename)?), - None => Box::new(stdin()), + None => { + let mut buffer = Vec::new(); + stdin().read_to_end(&mut buffer)?; + Box::new(Cursor::new(buffer)) + }, }; let fut = service::chain_ops::import_blocks::(config, exit.into_exit(), file)?; diff --git a/substrate/core/client/Cargo.toml b/substrate/core/client/Cargo.toml index 6847e68d53..5848c67349 100644 --- a/substrate/core/client/Cargo.toml +++ b/substrate/core/client/Cargo.toml @@ -19,7 +19,7 @@ trie = { package = "substrate-trie", path = "../trie", optional = true } substrate-telemetry = { path = "../telemetry", optional = true } hash-db = { version = "0.15.0", default-features = false } kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } sr-primitives = { path = "../sr-primitives", default-features = false } runtime-version = { package = "sr-version", path = "../sr-version", default-features = false } @@ -36,7 +36,7 @@ kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b031 default = ["std"] std = [ "rstd/std", - "parity-codec/std", + "codec/std", "primitives/std", "inherents/std", "sr-primitives/std", diff --git a/substrate/core/client/db/Cargo.toml b/substrate/core/client/db/Cargo.toml index 5c1a0de55c..5df825fe12 100644 --- a/substrate/core/client/db/Cargo.toml +++ b/substrate/core/client/db/Cargo.toml @@ -17,7 +17,7 @@ primitives = { package = "substrate-primitives", path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } client = { package = "substrate-client", path = "../../client" } state-machine = { package = "substrate-state-machine", path = "../../state-machine" } -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } executor = { package = "substrate-executor", path = "../../executor" } state_db = { package = "substrate-state-db", path = "../../state-db" } trie = { package = "substrate-trie", path = "../../trie" } diff --git a/substrate/core/client/db/src/cache/list_entry.rs b/substrate/core/client/db/src/cache/list_entry.rs index 2ec5f01a44..6de369ecf5 100644 --- a/substrate/core/client/db/src/cache/list_entry.rs +++ b/substrate/core/client/db/src/cache/list_entry.rs @@ -18,7 +18,7 @@ use client::error::Result as ClientResult; use sr_primitives::traits::{Block as BlockT, NumberFor}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::cache::{CacheItemT, ComplexBlockId}; use crate::cache::list_storage::{Storage}; diff --git a/substrate/core/client/db/src/cache/list_storage.rs b/substrate/core/client/db/src/cache/list_storage.rs index 3c4a7252f3..a7bfc4dd58 100644 --- a/substrate/core/client/db/src/cache/list_storage.rs +++ b/substrate/core/client/db/src/cache/list_storage.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use kvdb::{KeyValueDB, DBTransaction}; use client::error::{Error as ClientError, Result as ClientResult}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; use crate::utils::{self, db_err, meta_keys}; @@ -151,7 +151,7 @@ impl Storage for DbStorage { .map_err(db_err) .and_then(|entry| match entry { Some(entry) => StorageEntry::::decode(&mut &entry[..]) - .ok_or_else(|| ClientError::Backend("Failed to decode cache entry".into())) + .map_err(|_| ClientError::Backend("Failed to decode cache entry".into())) .map(Some), None => Ok(None), }) @@ -236,9 +236,9 @@ mod meta { pub fn decode(encoded: &[u8]) -> ClientResult> { let input = &mut &*encoded; let finalized: Option> = Decode::decode(input) - .ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; + .map_err(|_| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; let unfinalized: Vec> = Decode::decode(input) - .ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; + .map_err(|_| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; Ok(Metadata { finalized, unfinalized }) } diff --git a/substrate/core/client/db/src/cache/mod.rs b/substrate/core/client/db/src/cache/mod.rs index a7632d6aeb..4d452b37d9 100644 --- a/substrate/core/client/db/src/cache/mod.rs +++ b/substrate/core/client/db/src/cache/mod.rs @@ -23,7 +23,7 @@ use kvdb::{KeyValueDB, DBTransaction}; use client::blockchain::Cache as BlockchainCache; use client::error::Result as ClientResult; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero}; use consensus_common::well_known_cache_keys::Id as CacheKeyId; diff --git a/substrate/core/client/db/src/lib.rs b/substrate/core/client/db/src/lib.rs index b22ffc50b5..a25ded0db3 100644 --- a/substrate/core/client/db/src/lib.rs +++ b/substrate/core/client/db/src/lib.rs @@ -42,7 +42,7 @@ use client::backend::NewBlockState; use client::blockchain::HeaderBackend; use client::ExecutionStrategies; use client::backend::{StorageCollection, ChildStorageCollection}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use hash_db::{Hasher, Prefix}; use kvdb::{KeyValueDB, DBTransaction}; use trie::{MemoryDB, PrefixedMemoryDB, prefixed_key}; @@ -338,8 +338,10 @@ impl client::blockchain::Backend for BlockchainDb { fn body(&self, id: BlockId) -> Result>, client::error::Error> { match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY, id)? { Some(body) => match Decode::decode(&mut &body[..]) { - Some(body) => Ok(Some(body)), - None => return Err(client::error::Error::Backend("Error decoding body".into())), + Ok(body) => Ok(Some(body)), + Err(err) => return Err(client::error::Error::Backend( + format!("Error decoding body: {}", err) + )), } None => Ok(None), } @@ -348,8 +350,10 @@ impl client::blockchain::Backend for BlockchainDb { fn justification(&self, id: BlockId) -> Result, client::error::Error> { match read_db(&*self.db, columns::KEY_LOOKUP, columns::JUSTIFICATION, id)? { Some(justification) => match Decode::decode(&mut &justification[..]) { - Some(justification) => Ok(Some(justification)), - None => return Err(client::error::Error::Backend("Error decoding justification".into())), + Ok(justification) => Ok(Some(justification)), + Err(err) => return Err(client::error::Error::Backend( + format!("Error decoding justification: {}", err) + )), } None => Ok(None), } @@ -838,7 +842,7 @@ impl> Backend { let changes_trie_config = self .state_at(BlockId::Hash(block))? .storage(well_known_keys::CHANGES_TRIE_CONFIG)? - .and_then(|v| Decode::decode(&mut &*v)); + .and_then(|v| Decode::decode(&mut &*v).ok()); *cached_changes_trie_config = Some(changes_trie_config.clone()); Ok(changes_trie_config) }, diff --git a/substrate/core/client/db/src/light.rs b/substrate/core/client/db/src/light.rs index 3714338fad..4ce0d0498c 100644 --- a/substrate/core/client/db/src/light.rs +++ b/substrate/core/client/db/src/light.rs @@ -29,7 +29,7 @@ use client::cht; use client::leaves::{LeafSet, FinalizationDisplaced}; use client::error::{Error as ClientError, Result as ClientResult}; use client::light::blockchain::Storage as LightBlockchainStorage; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use primitives::Blake2Hasher; use sr_primitives::generic::{DigestItem, BlockId}; use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, NumberFor}; @@ -360,7 +360,7 @@ impl LightStorage { let cht_start = cht::start_number(cht_size, cht_number); self.db.get(columns::CHT, &cht_key(cht_type, cht_start)?).map_err(db_err)? .ok_or_else(no_cht_for_block) - .and_then(|hash| Block::Hash::decode(&mut &*hash).ok_or_else(no_cht_for_block)) + .and_then(|hash| Block::Hash::decode(&mut &*hash).map_err(|_| no_cht_for_block())) } } @@ -887,7 +887,8 @@ pub(crate) mod tests { } fn get_authorities(cache: &dyn BlockchainCache, at: BlockId) -> Option> { - cache.get_at(&well_known_cache_keys::AUTHORITIES, &at).and_then(|val| Decode::decode(&mut &val[..])) + cache.get_at(&well_known_cache_keys::AUTHORITIES, &at) + .and_then(|val| Decode::decode(&mut &val[..]).ok()) } let auth1 = || AuthorityId::from_raw([1u8; 32]); diff --git a/substrate/core/client/db/src/utils.rs b/substrate/core/client/db/src/utils.rs index a2dd144c89..70f0ff2058 100644 --- a/substrate/core/client/db/src/utils.rs +++ b/substrate/core/client/db/src/utils.rs @@ -27,7 +27,7 @@ use kvdb_rocksdb::{Database, DatabaseConfig}; use log::debug; use client; -use parity_codec::Decode; +use codec::Decode; use trie::DBValue; use sr_primitives::generic::BlockId; use sr_primitives::traits::{ @@ -260,8 +260,8 @@ pub fn read_header( ) -> client::error::Result> { match read_db(db, col_index, col, id)? { Some(header) => match Block::Header::decode(&mut &header[..]) { - Some(header) => Ok(Some(header)), - None => return Err( + Ok(header) => Ok(Some(header)), + Err(_) => return Err( client::error::Error::Backend("Error decoding header".into()) ), } @@ -290,8 +290,10 @@ pub fn read_meta(db: &dyn KeyValueDB, col_meta: Option, col_header: { let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? { Some(h) => match Decode::decode(&mut &h[..]) { - Some(h) => h, - None => return Err(client::error::Error::Backend("Error decoding genesis hash".into())), + Ok(h) => h, + Err(err) => return Err(client::error::Error::Backend( + format!("Error decoding genesis hash: {}", err) + )), }, None => return Ok(Meta { best_hash: Default::default(), @@ -305,7 +307,7 @@ pub fn read_meta(db: &dyn KeyValueDB, col_meta: Option, col_header: let load_meta_block = |desc, key| -> Result<_, client::error::Error> { if let Some(Some(header)) = db.get(col_meta, key).and_then(|id| match id { - Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]))), + Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]).ok())), None => Ok(None), }).map_err(db_err)? { diff --git a/substrate/core/client/src/block_builder/block_builder.rs b/substrate/core/client/src/block_builder/block_builder.rs index 5e836b6bc2..22aac577e3 100644 --- a/substrate/core/client/src/block_builder/block_builder.rs +++ b/substrate/core/client/src/block_builder/block_builder.rs @@ -16,7 +16,7 @@ use super::api::BlockBuilder as BlockBuilderApi; use std::vec::Vec; -use parity_codec::Encode; +use codec::Encode; use sr_primitives::ApplyOutcome; use sr_primitives::generic::BlockId; use sr_primitives::traits::{ diff --git a/substrate/core/client/src/call_executor.rs b/substrate/core/client/src/call_executor.rs index 1b41cc3aa3..bd00b33e4a 100644 --- a/substrate/core/client/src/call_executor.rs +++ b/substrate/core/client/src/call_executor.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . use std::{sync::Arc, cmp::Ord, panic::UnwindSafe, result, cell::RefCell, rc::Rc}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::{ generic::BlockId, traits::Block as BlockT, }; diff --git a/substrate/core/client/src/children.rs b/substrate/core/client/src/children.rs index 4423ad8939..3128f86086 100644 --- a/substrate/core/client/src/children.rs +++ b/substrate/core/client/src/children.rs @@ -17,7 +17,7 @@ //! Functionality for reading and storing children hashes from db. use kvdb::{KeyValueDB, DBTransaction}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::error; use std::hash::Hash; @@ -41,8 +41,8 @@ pub fn read_children< }; let children: Vec = match Decode::decode(&mut &raw_val[..]) { - Some(children) => children, - None => return Err(error::Error::Backend("Error decoding children".into())), + Ok(children) => children, + Err(_) => return Err(error::Error::Backend("Error decoding children".into())), }; Ok(children) diff --git a/substrate/core/client/src/cht.rs b/substrate/core/client/src/cht.rs index b328200923..37462851a9 100644 --- a/substrate/core/client/src/cht.rs +++ b/substrate/core/client/src/cht.rs @@ -26,7 +26,7 @@ use std::collections::HashSet; use hash_db; -use parity_codec::Encode; +use codec::Encode; use trie; use primitives::{H256, convert_hash}; diff --git a/substrate/core/client/src/client.rs b/substrate/core/client/src/client.rs index 64519b60dd..cd6c2d63b7 100644 --- a/substrate/core/client/src/client.rs +++ b/substrate/core/client/src/client.rs @@ -50,7 +50,7 @@ use primitives::{ }; use primitives::storage::{StorageKey, StorageData}; use primitives::storage::well_known_keys; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use state_machine::{ DBValue, Backend as StateBackend, CodeExecutor, ChangesTrieAnchorBlockId, ExecutionStrategy, ExecutionManager, prove_read, prove_child_read, @@ -1327,7 +1327,7 @@ impl Client where Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info().best_number))? .storage(well_known_keys::CHANGES_TRIE_CONFIG) .map_err(|e| error::Error::from_state(Box::new(e)))? - .and_then(|c| Decode::decode(&mut &*c))) + .and_then(|c| Decode::decode(&mut &*c).ok())) } /// Prepare in-memory header that is used in execution environment. diff --git a/substrate/core/client/src/error.rs b/substrate/core/client/src/error.rs index d95263abce..6f087df9de 100644 --- a/substrate/core/client/src/error.rs +++ b/substrate/core/client/src/error.rs @@ -74,11 +74,11 @@ pub enum Error { #[display(fmt = "Remote data fetch has been failed")] RemoteFetchFailed, /// Error decoding call result. - #[display(fmt = "Error decoding call result of {}", _0)] - CallResultDecode(&'static str), + #[display(fmt = "Error decoding call result of {}: {}", _0, _1)] + CallResultDecode(&'static str, codec::Error), /// Error converting a parameter between runtime and node. #[display(fmt = "Error converting `{}` between runtime and node", _0)] - RuntimeParamConversion(&'static str), + RuntimeParamConversion(String), /// Changes tries are not supported. #[display(fmt = "Changes tries are not supported by the runtime")] ChangesTriesNotSupported, diff --git a/substrate/core/client/src/genesis.rs b/substrate/core/client/src/genesis.rs index 1a3ab4c1fa..bc401c8cd9 100644 --- a/substrate/core/client/src/genesis.rs +++ b/substrate/core/client/src/genesis.rs @@ -40,7 +40,7 @@ pub fn construct_genesis_block< #[cfg(test)] mod tests { use super::*; - use parity_codec::{Encode, Decode, Joiner}; + use codec::{Encode, Decode, Joiner}; use executor::native_executor_instance; use state_machine::{self, OverlayedChanges, ExecutionStrategy, InMemoryChangesTrieStorage}; use state_machine::backend::InMemory; diff --git a/substrate/core/client/src/leaves.rs b/substrate/core/client/src/leaves.rs index ed2cde6d5e..825c1bf7c0 100644 --- a/substrate/core/client/src/leaves.rs +++ b/substrate/core/client/src/leaves.rs @@ -20,7 +20,7 @@ use std::collections::BTreeMap; use std::cmp::Reverse; use kvdb::{KeyValueDB, DBTransaction}; use sr_primitives::traits::SimpleArithmetic; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::error; #[derive(Debug, Clone, PartialEq, Eq)] @@ -84,12 +84,12 @@ impl LeafSet where if !key.starts_with(prefix) { break } let raw_hash = &mut &key[prefix.len()..]; let hash = match Decode::decode(raw_hash) { - Some(hash) => hash, - None => return Err(error::Error::Backend("Error decoding hash".into())), + Ok(hash) => hash, + Err(_) => return Err(error::Error::Backend("Error decoding hash".into())), }; let number = match Decode::decode(&mut &value[..]) { - Some(number) => number, - None => return Err(error::Error::Backend("Error decoding number".into())), + Ok(number) => number, + Err(_) => return Err(error::Error::Backend("Error decoding number".into())), }; storage.entry(Reverse(number)).or_insert_with(Vec::new).push(hash); } diff --git a/substrate/core/client/src/light/call_executor.rs b/substrate/core/client/src/light/call_executor.rs index 5cd630ed79..9d8df1c541 100644 --- a/substrate/core/client/src/light/call_executor.rs +++ b/substrate/core/client/src/light/call_executor.rs @@ -22,7 +22,7 @@ use std::{ marker::PhantomData, cell::RefCell, rc::Rc, }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{One, Block as BlockT, Header as HeaderT}; @@ -149,7 +149,7 @@ where fn runtime_version(&self, id: &BlockId) -> ClientResult { let call_result = self.call(id, "Core_version", &[], ExecutionStrategy::NativeElseWasm, NeverOffchainExt::new())?; RuntimeVersion::decode(&mut call_result.as_slice()) - .ok_or_else(|| ClientError::VersionInvalid.into()) + .map_err(|_| ClientError::VersionInvalid.into()) } fn call_at_state< diff --git a/substrate/core/client/src/light/fetcher.rs b/substrate/core/client/src/light/fetcher.rs index b83907c932..e80541a096 100644 --- a/substrate/core/client/src/light/fetcher.rs +++ b/substrate/core/client/src/light/fetcher.rs @@ -22,7 +22,7 @@ use std::marker::PhantomData; use std::future::Future; use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use primitives::{ChangesTrieConfiguration, convert_hash}; use sr_primitives::traits::{ Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor, @@ -486,7 +486,7 @@ impl<'a, H, Number, Hash> ChangesTrieRootsStorage for RootsStorage<'a pub mod tests { use futures::future::Ready; use parking_lot::Mutex; - use parity_codec::Decode; + use codec::Decode; use crate::client::tests::prepare_client_with_key_changes; use executor::{self, NativeExecutor}; use crate::error::Error as ClientError; @@ -566,7 +566,7 @@ pub mod tests { // 'fetch' read proof from remote node let heap_pages = remote_client.storage(&remote_block_id, &StorageKey(well_known_keys::HEAP_PAGES.to_vec())) .unwrap() - .and_then(|v| Decode::decode(&mut &v.0[..])).unwrap(); + .and_then(|v| Decode::decode(&mut &v.0[..]).ok()).unwrap(); let remote_read_proof = remote_client.read_proof(&remote_block_id, well_known_keys::HEAP_PAGES).unwrap(); // check remote read proof locally diff --git a/substrate/core/client/src/runtime_api.rs b/substrate/core/client/src/runtime_api.rs index 890e265878..ed5c9fad48 100644 --- a/substrate/core/client/src/runtime_api.rs +++ b/substrate/core/client/src/runtime_api.rs @@ -39,7 +39,7 @@ pub use rstd::{slice, mem}; #[cfg(feature = "std")] use rstd::result; #[doc(hidden)] -pub use parity_codec::{Encode, Decode}; +pub use codec::{Encode, Decode}; #[cfg(feature = "std")] use crate::error; use sr_api_macros::decl_runtime_apis; diff --git a/substrate/core/consensus/aura/Cargo.toml b/substrate/core/consensus/aura/Cargo.toml index e7a5007e22..98f233b8f4 100644 --- a/substrate/core/consensus/aura/Cargo.toml +++ b/substrate/core/consensus/aura/Cargo.toml @@ -6,7 +6,7 @@ description = "Aura consensus algorithm for substrate" edition = "2018" [dependencies] -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } primitives = { package = "substrate-primitives", path = "../../primitives" } runtime_support = { package = "srml-support", path = "../../../srml/support" } runtime_version = { package = "sr-version", path = "../../sr-version" } diff --git a/substrate/core/consensus/aura/primitives/Cargo.toml b/substrate/core/consensus/aura/primitives/Cargo.toml index cbebd10a4d..ea8ffb4200 100644 --- a/substrate/core/consensus/aura/primitives/Cargo.toml +++ b/substrate/core/consensus/aura/primitives/Cargo.toml @@ -6,7 +6,7 @@ description = "Primitives for Aura consensus" edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } substrate-client = { path = "../../../client", default-features = false } primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } @@ -16,7 +16,7 @@ sr-primitives = { path = "../../../sr-primitives", default-features = false } default = ["std"] std = [ "rstd/std", - "parity-codec/std", + "codec/std", "sr-primitives/std", "substrate-client/std", "primitives/std", diff --git a/substrate/core/consensus/aura/primitives/src/lib.rs b/substrate/core/consensus/aura/primitives/src/lib.rs index 10c3c96e4f..1a0aa5583f 100644 --- a/substrate/core/consensus/aura/primitives/src/lib.rs +++ b/substrate/core/consensus/aura/primitives/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use parity_codec::{Encode, Decode, Codec}; +use codec::{Encode, Decode, Codec}; use substrate_client::decl_runtime_apis; use rstd::vec::Vec; use sr_primitives::ConsensusEngineId; diff --git a/substrate/core/consensus/aura/src/digest.rs b/substrate/core/consensus/aura/src/digest.rs index 82fd0cf655..3baa18587b 100644 --- a/substrate/core/consensus/aura/src/digest.rs +++ b/substrate/core/consensus/aura/src/digest.rs @@ -22,7 +22,7 @@ use primitives::Pair; use aura_primitives::AURA_ENGINE_ID; use sr_primitives::generic::{DigestItem, OpaqueDigestItemId}; -use parity_codec::{Encode, Codec}; +use codec::{Encode, Codec}; use std::fmt::Debug; type Signature

=

::Signature; diff --git a/substrate/core/consensus/aura/src/lib.rs b/substrate/core/consensus/aura/src/lib.rs index a08dcdf1d4..15966c611d 100644 --- a/substrate/core/consensus/aura/src/lib.rs +++ b/substrate/core/consensus/aura/src/lib.rs @@ -30,7 +30,7 @@ #![forbid(missing_docs, unsafe_code)] use std::{sync::Arc, time::Duration, thread, marker::PhantomData, hash::Hash, fmt::Debug, pin::Pin}; -use parity_codec::{Encode, Decode, Codec}; +use codec::{Encode, Decode, Codec}; use consensus_common::{self, BlockImport, Environment, Proposer, ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError, SelectChain, well_known_cache_keys::{self, Id as CacheKeyId} @@ -623,7 +623,7 @@ fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusErro let genesis_id = BlockId::Number(Zero::zero()); let genesis_authorities: Option> = cache .get_at(&well_known_cache_keys::AUTHORITIES, &genesis_id) - .and_then(|v| Decode::decode(&mut &v[..])); + .and_then(|v| Decode::decode(&mut &v[..]).ok()); if genesis_authorities.is_some() { return Ok(()); } @@ -651,7 +651,7 @@ fn authorities(client: &C, at: &BlockId) -> Result, Consensus .cache() .and_then(|cache| cache .get_at(&well_known_cache_keys::AUTHORITIES, at) - .and_then(|v| Decode::decode(&mut &v[..])) + .and_then(|v| Decode::decode(&mut &v[..]).ok()) ) .or_else(|| AuraApi::authorities(&*client.runtime_api(), at).ok()) .ok_or_else(|| consensus_common::Error::InvalidAuthoritiesSet.into()) diff --git a/substrate/core/consensus/babe/Cargo.toml b/substrate/core/consensus/babe/Cargo.toml index 331c85dda8..855daab1e0 100644 --- a/substrate/core/consensus/babe/Cargo.toml +++ b/substrate/core/consensus/babe/Cargo.toml @@ -6,8 +6,8 @@ description = "BABE consensus algorithm for substrate" edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", features = ["derive"] } -babe-primitives = { package = "substrate-consensus-babe-primitives", path = "primitives" } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } +babe_primitives = { package = "substrate-consensus-babe-primitives", path = "primitives" } primitives = { package = "substrate-primitives", path = "../../primitives" } num-bigint = "0.2" num-rational = "0.2" diff --git a/substrate/core/consensus/babe/primitives/Cargo.toml b/substrate/core/consensus/babe/primitives/Cargo.toml index 2c6ba886f4..cf52d270c7 100644 --- a/substrate/core/consensus/babe/primitives/Cargo.toml +++ b/substrate/core/consensus/babe/primitives/Cargo.toml @@ -11,7 +11,7 @@ rstd = { package = "sr-std", path = "../../../sr-std", default-features = false sr-primitives = { path = "../../../sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } slots = { package = "substrate-consensus-slots", path = "../../slots", optional = true } -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } schnorrkel = { version = "0.1.1", optional = true } [features] @@ -20,7 +20,7 @@ std = [ "rstd/std", "sr-primitives/std", "substrate-client/std", - "parity-codec/std", + "codec/std", "schnorrkel", "slots", ] diff --git a/substrate/core/consensus/babe/primitives/src/digest.rs b/substrate/core/consensus/babe/primitives/src/digest.rs index 6266b828fb..52e7e26e52 100644 --- a/substrate/core/consensus/babe/primitives/src/digest.rs +++ b/substrate/core/consensus/babe/primitives/src/digest.rs @@ -27,11 +27,14 @@ use super::SlotNumber; use sr_primitives::{DigestItem, generic::OpaqueDigestItemId}; #[cfg(feature = "std")] use std::fmt::Debug; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; #[cfg(feature = "std")] -use parity_codec::{Codec, Input}; +use codec::{Codec, Input, Error}; #[cfg(feature = "std")] -use schnorrkel::vrf::{VRFProof, VRFOutput, VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH}; +use schnorrkel::{ + SignatureError, errors::MultiSignatureStage, + vrf::{VRFProof, VRFOutput, VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH} +}; /// A BABE pre-digest #[cfg(feature = "std")] @@ -72,21 +75,26 @@ impl Encode for BabePreDigest { authority_index: self.authority_index, slot_number: self.slot_number, }; - parity_codec::Encode::encode(&tmp) + codec::Encode::encode(&tmp) } } +#[cfg(feature = "std")] +impl codec::EncodeLike for BabePreDigest {} + #[cfg(feature = "std")] impl Decode for BabePreDigest { - fn decode(i: &mut R) -> Option { + fn decode(i: &mut R) -> Result { let RawBabePreDigest { vrf_output, vrf_proof, authority_index, slot_number } = Decode::decode(i)?; // Verify (at compile time) that the sizes in babe_primitives are correct let _: [u8; super::VRF_OUTPUT_LENGTH] = vrf_output; let _: [u8; super::VRF_PROOF_LENGTH] = vrf_proof; - Some(BabePreDigest { - vrf_proof: VRFProof::from_bytes(&vrf_proof).ok()?, - vrf_output: VRFOutput::from_bytes(&vrf_output).ok()?, + Ok(BabePreDigest { + vrf_proof: VRFProof::from_bytes(&vrf_proof) + .map_err(convert_error)?, + vrf_output: VRFOutput::from_bytes(&vrf_output) + .map_err(convert_error)?, authority_index, slot_number, }) @@ -136,3 +144,33 @@ impl CompatibleDigestItem for DigestItem where self.try_to(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID)) } } + +#[cfg(feature = "std")] +fn convert_error(e: SignatureError) -> codec::Error { + use SignatureError::*; + use MultiSignatureStage::*; + match e { + EquationFalse => "Signature error: `EquationFalse`".into(), + PointDecompressionError => "Signature error: `PointDecompressionError`".into(), + ScalarFormatError => "Signature error: `ScalarFormatError`".into(), + BytesLengthError { .. } => "Signature error: `BytesLengthError`".into(), + MuSigAbsent { musig_stage: Commitment } => + "Signature error: `MuSigAbsent` at stage `Commitment`".into(), + MuSigAbsent { musig_stage: Reveal } => + "Signature error: `MuSigAbsent` at stage `Reveal`".into(), + MuSigAbsent { musig_stage: Cosignature } => + "Signature error: `MuSigAbsent` at stage `Commitment`".into(), + MuSigInconsistent { musig_stage: Commitment, duplicate: true } => + "Signature error: `MuSigInconsistent` at strage `Commitment` on duplicate".into(), + MuSigInconsistent { musig_stage: Commitment, duplicate: false } => + "Signature error: `MuSigInconsistent` at strage `Commitment` on not duplicate".into(), + MuSigInconsistent { musig_stage: Reveal, duplicate: true } => + "Signature error: `MuSigInconsistent` at strage `Reveal` on duplicate".into(), + MuSigInconsistent { musig_stage: Reveal, duplicate: false } => + "Signature error: `MuSigInconsistent` at strage `Reveal` on not duplicate".into(), + MuSigInconsistent { musig_stage: Cosignature, duplicate: true } => + "Signature error: `MuSigInconsistent` at strage `Cosignature` on duplicate".into(), + MuSigInconsistent { musig_stage: Cosignature, duplicate: false } => + "Signature error: `MuSigInconsistent` at strage `Cosignature` on not duplicate".into(), + } +} diff --git a/substrate/core/consensus/babe/primitives/src/lib.rs b/substrate/core/consensus/babe/primitives/src/lib.rs index d169406b33..f076c3ae2a 100644 --- a/substrate/core/consensus/babe/primitives/src/lib.rs +++ b/substrate/core/consensus/babe/primitives/src/lib.rs @@ -21,7 +21,7 @@ mod digest; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use rstd::vec::Vec; use sr_primitives::ConsensusEngineId; use primitives::sr25519; diff --git a/substrate/core/consensus/babe/src/aux_schema.rs b/substrate/core/consensus/babe/src/aux_schema.rs index 91764839fb..ac90b4ce52 100644 --- a/substrate/core/consensus/babe/src/aux_schema.rs +++ b/substrate/core/consensus/babe/src/aux_schema.rs @@ -17,7 +17,7 @@ //! Schema for BABE epoch changes in the aux-db. use log::info; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use client::backend::AuxStore; use client::error::{Result as ClientResult, Error as ClientError}; @@ -32,10 +32,12 @@ fn load_decode(backend: &B, key: &[u8]) -> ClientResult> B: AuxStore, T: Decode, { - let corrupt = || ClientError::Backend(format!("BABE DB is corrupted.")).into(); + let corrupt = |e: codec::Error| { + ClientError::Backend(format!("BABE DB is corrupted. Decode error: {}", e.what())).into() + }; match backend.get_aux(key)? { None => Ok(None), - Some(t) => T::decode(&mut &t[..]).ok_or_else(corrupt).map(Some) + Some(t) => T::decode(&mut &t[..]).map(Some).map_err(corrupt) } } diff --git a/substrate/core/consensus/babe/src/lib.rs b/substrate/core/consensus/babe/src/lib.rs index 50271b0d45..e61fb04062 100644 --- a/substrate/core/consensus/babe/src/lib.rs +++ b/substrate/core/consensus/babe/src/lib.rs @@ -33,7 +33,7 @@ use sr_primitives::traits::{ }; use std::{collections::HashMap, sync::Arc, u64, fmt::{Debug, Display}, pin::Pin, time::{Instant, Duration}}; use runtime_support::serde::{Serialize, Deserialize}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use parking_lot::{Mutex, MutexGuard}; use primitives::{Blake2Hasher, H256, Pair, Public, sr25519}; use merlin::Transcript; @@ -733,7 +733,7 @@ fn epoch(client: &C, at: &BlockId) -> Result whe client .cache() .and_then(|cache| cache.get_at(&well_known_cache_keys::EPOCH, at) - .and_then(|v| Decode::decode(&mut &v[..]))) + .and_then(|v| Decode::decode(&mut &v[..]).ok())) .or_else(|| { if client.runtime_api().has_api::>(at).unwrap_or(false) { let s = BabeApi::epoch(&*client.runtime_api(), at).ok()?; @@ -856,7 +856,7 @@ fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusError> let genesis_id = BlockId::Number(Zero::zero()); let genesis_epoch: Option = cache .get_at(&well_known_cache_keys::EPOCH, &genesis_id) - .and_then(|v| Decode::decode(&mut &v[..])); + .and_then(|v| Decode::decode(&mut &v[..]).ok()); if genesis_epoch.is_some() { return Ok(()); } diff --git a/substrate/core/consensus/babe/src/tests.rs b/substrate/core/consensus/babe/src/tests.rs index f9a2360210..a0e59e3e80 100644 --- a/substrate/core/consensus/babe/src/tests.rs +++ b/substrate/core/consensus/babe/src/tests.rs @@ -165,12 +165,6 @@ impl TestNetFactory for BabeTestNet { } } -#[test] -fn can_serialize_block() { - let _ = env_logger::try_init(); - assert!(BabePreDigest::decode(&mut &b""[..]).is_none()); -} - #[test] #[should_panic] fn rejects_empty_block() { diff --git a/substrate/core/consensus/common/Cargo.toml b/substrate/core/consensus/common/Cargo.toml index c4731ce2a5..b327e9456a 100644 --- a/substrate/core/consensus/common/Cargo.toml +++ b/substrate/core/consensus/common/Cargo.toml @@ -16,7 +16,7 @@ futures-timer = "0.2.1" rstd = { package = "sr-std", path = "../../sr-std" } runtime_version = { package = "sr-version", path = "../../sr-version" } sr-primitives = { path = "../../sr-primitives" } -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } parking_lot = "0.8.0" [dev-dependencies] diff --git a/substrate/core/consensus/common/primitives/Cargo.toml b/substrate/core/consensus/common/primitives/Cargo.toml index df44db2f34..de59c3723d 100644 --- a/substrate/core/consensus/common/primitives/Cargo.toml +++ b/substrate/core/consensus/common/primitives/Cargo.toml @@ -6,7 +6,7 @@ description = "Common consensus primitives" edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" } client = { package = "substrate-client", path = "../../../client", default-features = false } sr-primitives = { path = "../../../sr-primitives", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } @@ -16,6 +16,6 @@ default = ["std"] std = [ "rstd/std", "client/std", - "parity-codec/std", + "codec/std", "sr-primitives/std" ] diff --git a/substrate/core/consensus/common/primitives/src/lib.rs b/substrate/core/consensus/common/primitives/src/lib.rs index 47c4371721..f6c1800081 100644 --- a/substrate/core/consensus/common/primitives/src/lib.rs +++ b/substrate/core/consensus/common/primitives/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use parity_codec::Codec; +use codec::Codec; use client::decl_runtime_apis; use rstd::vec::Vec; diff --git a/substrate/core/consensus/common/src/evaluation.rs b/substrate/core/consensus/common/src/evaluation.rs index 940728bc83..7a3e565aa0 100644 --- a/substrate/core/consensus/common/src/evaluation.rs +++ b/substrate/core/consensus/common/src/evaluation.rs @@ -18,7 +18,7 @@ use super::MAX_BLOCK_SIZE; -use parity_codec::Encode; +use codec::Encode; use sr_primitives::traits::{Block as BlockT, Header as HeaderT, One, CheckedConversion}; // This is just a best effort to encode the number. None indicated that it's too big to encode @@ -32,8 +32,8 @@ pub type Result = std::result::Result; #[derive(Debug, derive_more::Display)] pub enum Error { /// Proposal provided not a block. - #[display(fmt="Proposal provided not a block.")] - BadProposalFormat, + #[display(fmt="Proposal provided not a block: decoding error: {}", _0)] + BadProposalFormat(codec::Error), /// Proposal had wrong parent hash. #[display(fmt="Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got)] WrongParentHash { expected: String, got: String }, @@ -60,7 +60,7 @@ pub fn evaluate_initial( let encoded = Encode::encode(proposal); let proposal = Block::decode(&mut &encoded[..]) - .ok_or_else(|| Error::BadProposalFormat)?; + .map_err(|e| Error::BadProposalFormat(e))?; if encoded.len() > MAX_BLOCK_SIZE { return Err(Error::ProposalTooLarge(encoded.len())) diff --git a/substrate/core/consensus/rhd/Cargo.toml b/substrate/core/consensus/rhd/Cargo.toml index b973e02c60..3f6fef71a3 100644 --- a/substrate/core/consensus/rhd/Cargo.toml +++ b/substrate/core/consensus/rhd/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] derive_more = "0.14.0" futures = "0.1.17" -codec = { package = "parity-codec", version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../primitives" } consensus = { package = "substrate-consensus-common", path = "../common" } client = { package = "substrate-client", path = "../../client" } @@ -21,7 +21,7 @@ runtime_io = { package = "sr-io", path = "../../sr-io" } tokio = "0.1.7" parking_lot = "0.8.0" log = "0.4" -rhododendron = { version = "0.6.0", features = ["codec"] } +rhododendron = { version = "0.7.0", features = ["codec"] } exit-future = "0.1" [dev-dependencies] diff --git a/substrate/core/consensus/rhd/src/lib.rs b/substrate/core/consensus/rhd/src/lib.rs index 94e25dfc91..3bcd1346d4 100644 --- a/substrate/core/consensus/rhd/src/lib.rs +++ b/substrate/core/consensus/rhd/src/lib.rs @@ -40,7 +40,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{self, Instant, Duration}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use consensus::offline_tracker::OfflineTracker; use consensus::error::{ErrorKind as CommonErrorKind}; use consensus::{Authorities, BlockImport, Environment, Proposer as BaseProposer}; diff --git a/substrate/core/consensus/slots/Cargo.toml b/substrate/core/consensus/slots/Cargo.toml index 8d73c44b2b..30e3eb654c 100644 --- a/substrate/core/consensus/slots/Cargo.toml +++ b/substrate/core/consensus/slots/Cargo.toml @@ -6,7 +6,7 @@ description = "Generic slots-based utilities for consensus" edition = "2018" [dependencies] -codec = { package = "parity-codec", version = "4.1.1" } +codec = { package = "parity-scale-codec", version = "1.0.0" } client = { package = "substrate-client", path = "../../client" } primitives = { package = "substrate-primitives", path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } diff --git a/substrate/core/consensus/slots/src/aux_schema.rs b/substrate/core/consensus/slots/src/aux_schema.rs index 193c9f9b9d..1d54cb5c2e 100644 --- a/substrate/core/consensus/slots/src/aux_schema.rs +++ b/substrate/core/consensus/slots/src/aux_schema.rs @@ -37,8 +37,8 @@ fn load_decode(backend: &C, key: &[u8]) -> ClientResult> match backend.get_aux(key)? { None => Ok(None), Some(t) => T::decode(&mut &t[..]) - .ok_or_else( - || ClientError::Backend(format!("Slots DB is corrupted.")).into(), + .map_err( + |e| ClientError::Backend(format!("Slots DB is corrupted. Decode error: {}", e.what())).into(), ) .map(Some) } diff --git a/substrate/core/consensus/slots/src/lib.rs b/substrate/core/consensus/slots/src/lib.rs index ae3dd265e9..fc0134f746 100644 --- a/substrate/core/consensus/slots/src/lib.rs +++ b/substrate/core/consensus/slots/src/lib.rs @@ -188,7 +188,7 @@ impl SlotDuration { match client.get_aux(T::SLOT_KEY)? { Some(v) => ::decode(&mut &v[..]) .map(SlotDuration) - .ok_or_else(|| { + .map_err(|_| { ::client::error::Error::Backend({ error!(target: "slots", "slot duration kept in invalid format"); format!("slot duration kept in invalid format") diff --git a/substrate/core/executor/Cargo.toml b/substrate/core/executor/Cargo.toml index 1f9f3947ac..c5b296b866 100644 --- a/substrate/core/executor/Cargo.toml +++ b/substrate/core/executor/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] derive_more = "0.14.0" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } runtime_io = { package = "sr-io", path = "../sr-io" } primitives = { package = "substrate-primitives", path = "../primitives" } trie = { package = "substrate-trie", path = "../trie" } diff --git a/substrate/core/executor/src/lib.rs b/substrate/core/executor/src/lib.rs index a6147a320a..065de451c1 100644 --- a/substrate/core/executor/src/lib.rs +++ b/substrate/core/executor/src/lib.rs @@ -44,7 +44,7 @@ pub use native_executor::{with_native_environment, NativeExecutor, NativeExecuti pub use wasm_runtimes_cache::RuntimesCache; pub use state_machine::Externalities; pub use runtime_version::{RuntimeVersion, NativeVersion}; -pub use parity_codec::Codec; +pub use codec::Codec; #[doc(hidden)] pub use primitives::Blake2Hasher; diff --git a/substrate/core/executor/src/native_executor.rs b/substrate/core/executor/src/native_executor.rs index f57c331668..765b9f076e 100644 --- a/substrate/core/executor/src/native_executor.rs +++ b/substrate/core/executor/src/native_executor.rs @@ -19,7 +19,7 @@ use crate::error::{Error, Result}; use state_machine::{CodeExecutor, Externalities}; use crate::wasm_executor::WasmExecutor; use runtime_version::{NativeVersion, RuntimeVersion}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use crate::RuntimeInfo; use primitives::{Blake2Hasher, NativeOrEncoded}; use log::trace; diff --git a/substrate/core/executor/src/sandbox.rs b/substrate/core/executor/src/sandbox.rs index 1ce300c38a..6687738abc 100644 --- a/substrate/core/executor/src/sandbox.rs +++ b/substrate/core/executor/src/sandbox.rs @@ -20,7 +20,7 @@ use crate::error::{Result, Error}; use std::{collections::HashMap, rc::Rc}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use primitives::sandbox as sandbox_primitives; use wasmi::{ Externals, FuncRef, ImportResolver, MemoryInstance, MemoryRef, Module, ModuleInstance, @@ -193,7 +193,7 @@ fn trap(msg: &'static str) -> Trap { fn deserialize_result(serialized_result: &[u8]) -> std::result::Result, Trap> { use self::sandbox_primitives::{HostError, ReturnValue}; let result_val = std::result::Result::::decode(&mut &serialized_result[..]) - .ok_or_else(|| trap("Decoding Result failed!"))?; + .map_err(|_| trap("Decoding Result failed!"))?; match result_val { Ok(return_value) => Ok(match return_value { @@ -361,7 +361,7 @@ fn decode_environment_definition( memories: &[Option], ) -> std::result::Result<(Imports, GuestToSupervisorFunctionMapping), InstantiationError> { let env_def = sandbox_primitives::EnvironmentDefinition::decode(&mut &raw_env_def[..]) - .ok_or_else(|| InstantiationError::EnvironmentDefinitionCorrupted)?; + .map_err(|_| InstantiationError::EnvironmentDefinitionCorrupted)?; let mut func_map = HashMap::new(); let mut memories_map = HashMap::new(); diff --git a/substrate/core/executor/src/wasm_executor.rs b/substrate/core/executor/src/wasm_executor.rs index b776a520d7..637390b2c7 100644 --- a/substrate/core/executor/src/wasm_executor.rs +++ b/substrate/core/executor/src/wasm_executor.rs @@ -26,7 +26,7 @@ use wasmi::{ }; use state_machine::{Externalities, ChildStorageKey}; use crate::error::{Error, Result}; -use parity_codec::Encode; +use codec::Encode; use primitives::{blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, Pair}; use primitives::offchain; use primitives::hexdisplay::HexDisplay; @@ -1081,7 +1081,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, request_id: u32, written_out: *mut u32 ) -> *mut u8 => { - use parity_codec::Encode; + use codec::Encode; let headers = this.ext.offchain() .map(|api| api.http_response_headers(offchain::HttpRequestId(request_id as u16))) @@ -1172,7 +1172,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, return_val_len: usize, state: usize ) -> u32 => { - use parity_codec::{Decode, Encode}; + use codec::{Decode, Encode}; trace!(target: "sr-sandbox", "invoke, instance_idx={}", instance_idx); let export = this.memory.get(export_ptr, export_len as usize) @@ -1186,7 +1186,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, let serialized_args = this.memory.get(args_ptr, args_len as usize) .map_err(|_| "OOB while ext_sandbox_invoke: args")?; let args = Vec::::decode(&mut &serialized_args[..]) - .ok_or_else(|| "Can't decode serialized arguments for the invocation")? + .map_err(|_| "Can't decode serialized arguments for the invocation")? .into_iter() .map(Into::into) .collect::>(); @@ -1443,7 +1443,7 @@ impl WasmExecutor { mod tests { use super::*; - use parity_codec::Encode; + use codec::Encode; use state_machine::TestExternalities as CoreTestExternalities; use hex_literal::hex; diff --git a/substrate/core/executor/src/wasm_runtimes_cache.rs b/substrate/core/executor/src/wasm_runtimes_cache.rs index a1540204c7..812638126d 100644 --- a/substrate/core/executor/src/wasm_runtimes_cache.rs +++ b/substrate/core/executor/src/wasm_runtimes_cache.rs @@ -19,7 +19,7 @@ use crate::error::Error; use crate::wasm_executor::WasmExecutor; use log::{trace, warn}; -use parity_codec::Decode; +use codec::Decode; use parity_wasm::elements::{deserialize_buffer, DataSegment, Instruction, Module as RawModule}; use primitives::storage::well_known_keys; use primitives::Blake2Hasher; @@ -288,7 +288,7 @@ impl RuntimesCache { let heap_pages = ext .storage(well_known_keys::HEAP_PAGES) - .and_then(|pages| u64::decode(&mut &pages[..])) + .and_then(|pages| u64::decode(&mut &pages[..]).ok()) .or(default_heap_pages) .unwrap_or(DEFAULT_HEAP_PAGES); @@ -308,7 +308,7 @@ impl RuntimesCache { let version = wasm_executor .call_in_wasm_module(ext, &instance, "Core_version", &[]) .ok() - .and_then(|v| RuntimeVersion::decode(&mut v.as_slice())); + .and_then(|v| RuntimeVersion::decode(&mut v.as_slice()).ok()); Ok(Rc::new(CachedRuntime { instance, version, diff --git a/substrate/core/finality-grandpa/Cargo.toml b/substrate/core/finality-grandpa/Cargo.toml index 8477f75edd..04f9e7162c 100644 --- a/substrate/core/finality-grandpa/Cargo.toml +++ b/substrate/core/finality-grandpa/Cargo.toml @@ -13,7 +13,7 @@ parking_lot = "0.8.0" tokio-executor = "0.1.7" tokio-timer = "0.2.11" rand = "0.6" -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } sr-primitives = { path = "../sr-primitives" } consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" } primitives = { package = "substrate-primitives", path = "../primitives" } @@ -25,10 +25,10 @@ network = { package = "substrate-network", path = "../network" } service = { package = "substrate-service", path = "../service", optional = true } srml-finality-tracker = { path = "../../srml/finality-tracker" } fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "primitives" } -grandpa = { package = "finality-grandpa", version = "0.8.1", features = ["derive-codec"] } +grandpa = { package = "finality-grandpa", version = "0.9.0", features = ["derive-codec"] } [dev-dependencies] -grandpa = { package = "finality-grandpa", version = "0.8.1", features = ["derive-codec", "test-helpers"] } +grandpa = { package = "finality-grandpa", version = "0.9.0", features = ["derive-codec", "test-helpers"] } network = { package = "substrate-network", path = "../network", features = ["test-helpers"] } keyring = { package = "substrate-keyring", path = "../keyring" } test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client"} diff --git a/substrate/core/finality-grandpa/primitives/Cargo.toml b/substrate/core/finality-grandpa/primitives/Cargo.toml index 75e6b5f608..1c17639a2a 100644 --- a/substrate/core/finality-grandpa/primitives/Cargo.toml +++ b/substrate/core/finality-grandpa/primitives/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] client = { package = "substrate-client", path = "../../client", default-features = false } primitives = { package = "substrate-primitives", path = "../../primitives", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../../sr-primitives", default-features = false } rstd = { package = "sr-std", path = "../../sr-std", default-features = false } serde = { version = "1.0", optional = true, features = ["derive"] } @@ -17,7 +17,7 @@ default = ["std"] std = [ "primitives/std", "client/std", - "parity-codec/std", + "codec/std", "sr-primitives/std", "rstd/std", "serde", diff --git a/substrate/core/finality-grandpa/primitives/src/lib.rs b/substrate/core/finality-grandpa/primitives/src/lib.rs index b60acffc6c..25f8b802ce 100644 --- a/substrate/core/finality-grandpa/primitives/src/lib.rs +++ b/substrate/core/finality-grandpa/primitives/src/lib.rs @@ -23,7 +23,7 @@ extern crate alloc; #[cfg(feature = "std")] use serde::Serialize; -use parity_codec::{Encode, Decode, Codec}; +use codec::{Encode, Decode, Codec}; use sr_primitives::{ConsensusEngineId, traits::{DigestFor, NumberFor}}; use client::decl_runtime_apis; use rstd::vec::Vec; diff --git a/substrate/core/finality-grandpa/src/authorities.rs b/substrate/core/finality-grandpa/src/authorities.rs index 8b329d4116..27b9c57073 100644 --- a/substrate/core/finality-grandpa/src/authorities.rs +++ b/substrate/core/finality-grandpa/src/authorities.rs @@ -19,7 +19,7 @@ use fork_tree::ForkTree; use parking_lot::RwLock; use grandpa::voter_set::VoterSet; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use log::{debug, info}; use substrate_telemetry::{telemetry, CONSENSUS_INFO}; use fg_primitives::AuthorityId; @@ -403,7 +403,7 @@ pub(crate) struct PendingChange { } impl Decode for PendingChange { - fn decode(value: &mut I) -> Option { + fn decode(value: &mut I) -> Result { let next_authorities = Decode::decode(value)?; let delay = Decode::decode(value)?; let canon_height = Decode::decode(value)?; @@ -411,7 +411,7 @@ impl Decode for PendingChange { let delay_kind = DelayKind::decode(value).unwrap_or(DelayKind::Finalized); - Some(PendingChange { + Ok(PendingChange { next_authorities, delay, canon_height, diff --git a/substrate/core/finality-grandpa/src/aux_schema.rs b/substrate/core/finality-grandpa/src/aux_schema.rs index 528a221c35..5f430b17fe 100644 --- a/substrate/core/finality-grandpa/src/aux_schema.rs +++ b/substrate/core/finality-grandpa/src/aux_schema.rs @@ -18,7 +18,7 @@ use std::fmt::Debug; use std::sync::Arc; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use client::backend::AuxStore; use client::error::{Result as ClientResult, Error as ClientError}; use fork_tree::ForkTree; @@ -108,8 +108,8 @@ pub(crate) fn load_decode(backend: &B, key: &[u8]) -> Cl match backend.get_aux(key)? { None => Ok(None), Some(t) => T::decode(&mut &t[..]) - .ok_or_else( - || ClientError::Backend(format!("GRANDPA DB is corrupted.")), + .map_err( + |e| ClientError::Backend(format!("GRANDPA DB is corrupted: {}", e.what())), ) .map(Some) } diff --git a/substrate/core/finality-grandpa/src/communication/gossip.rs b/substrate/core/finality-grandpa/src/communication/gossip.rs index 3d14381e72..e51e23254c 100644 --- a/substrate/core/finality-grandpa/src/communication/gossip.rs +++ b/substrate/core/finality-grandpa/src/communication/gossip.rs @@ -85,7 +85,7 @@ use sr_primitives::traits::{NumberFor, Block as BlockT, Zero}; use network::consensus_gossip::{self as network_gossip, MessageIntent, ValidatorContext}; use network::{config::Roles, PeerId}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::ed25519::Public as AuthorityId; use substrate_telemetry::{telemetry, CONSENSUS_DEBUG}; @@ -977,10 +977,10 @@ impl GossipValidator { let action = { match GossipMessage::::decode(&mut data) { - Some(GossipMessage::VoteOrPrecommit(ref message)) + Ok(GossipMessage::VoteOrPrecommit(ref message)) => self.inner.write().validate_round_message(who, message), - Some(GossipMessage::Commit(ref message)) => self.inner.write().validate_commit_message(who, message), - Some(GossipMessage::Neighbor(update)) => { + Ok(GossipMessage::Commit(ref message)) => self.inner.write().validate_commit_message(who, message), + Ok(GossipMessage::Neighbor(update)) => { let (topics, action, catch_up, report) = self.inner.write().import_neighbor_message( who, update.into_neighbor_packet(), @@ -994,9 +994,9 @@ impl GossipValidator { peer_reply = catch_up; action } - Some(GossipMessage::CatchUp(ref message)) + Ok(GossipMessage::CatchUp(ref message)) => self.inner.write().validate_catch_up_message(who, message), - Some(GossipMessage::CatchUpRequest(request)) => { + Ok(GossipMessage::CatchUpRequest(request)) => { let (reply, action) = self.inner.write().handle_catch_up_request( who, request, @@ -1006,8 +1006,8 @@ impl GossipValidator { peer_reply = reply; action } - None => { - debug!(target: "afg", "Error decoding message"); + Err(e) => { + debug!(target: "afg", "Error decoding message: {}", e.what()); telemetry!(CONSENSUS_DEBUG; "afg.err_decoding_msg"; "" => ""); let len = std::cmp::min(i32::max_value() as usize, data.len()) as i32; @@ -1127,17 +1127,17 @@ impl network_gossip::Validator for GossipValidator let peer_best_commit = peer.view.last_commit; match GossipMessage::::decode(&mut data) { - None => false, - Some(GossipMessage::Commit(full)) => { + Err(_) => false, + Ok(GossipMessage::Commit(full)) => { // we only broadcast our best commit and only if it's // better than last received by peer. Some(full.message.target_number) == our_best_commit && Some(full.message.target_number) > peer_best_commit } - Some(GossipMessage::Neighbor(_)) => false, - Some(GossipMessage::CatchUpRequest(_)) => false, - Some(GossipMessage::CatchUp(_)) => false, - Some(GossipMessage::VoteOrPrecommit(_)) => false, // should not be the case. + Ok(GossipMessage::Neighbor(_)) => false, + Ok(GossipMessage::CatchUpRequest(_)) => false, + Ok(GossipMessage::CatchUp(_)) => false, + Ok(GossipMessage::VoteOrPrecommit(_)) => false, // should not be the case. } }) } @@ -1162,10 +1162,10 @@ impl network_gossip::Validator for GossipValidator let best_commit = local_view.last_commit; match GossipMessage::::decode(&mut data) { - None => true, - Some(GossipMessage::Commit(full)) + Err(_) => true, + Ok(GossipMessage::Commit(full)) => Some(full.message.target_number) != best_commit, - Some(_) => true, + Ok(_) => true, } }) } diff --git a/substrate/core/finality-grandpa/src/communication/mod.rs b/substrate/core/finality-grandpa/src/communication/mod.rs index e9be187eac..607dba486d 100644 --- a/substrate/core/finality-grandpa/src/communication/mod.rs +++ b/substrate/core/finality-grandpa/src/communication/mod.rs @@ -35,7 +35,7 @@ use futures::prelude::*; use futures::sync::{oneshot, mpsc}; use log::{debug, trace}; use tokio_executor::Executor; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use primitives::{ed25519, Pair}; use substrate_telemetry::{telemetry, CONSENSUS_DEBUG, CONSENSUS_INFO}; use sr_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT}; @@ -367,10 +367,10 @@ impl> NetworkBridge { let incoming = self.service.messages_for(topic) .filter_map(|notification| { let decoded = GossipMessage::::decode(&mut ¬ification.message[..]); - if decoded.is_none() { - debug!(target: "afg", "Skipping malformed message {:?}", notification); + if let Err(ref e) = decoded { + debug!(target: "afg", "Skipping malformed message {:?}: {}", notification, e); } - decoded + decoded.ok() }) .and_then(move |msg| { match msg { @@ -583,10 +583,10 @@ fn incoming_global>( .filter_map(|notification| { // this could be optimized by decoding piecewise. let decoded = GossipMessage::::decode(&mut ¬ification.message[..]); - if decoded.is_none() { - trace!(target: "afg", "Skipping malformed commit message {:?}", notification); + if let Err(ref e) = decoded { + trace!(target: "afg", "Skipping malformed commit message {:?}: {}", notification, e); } - decoded.map(move |d| (notification, d)) + decoded.map(move |d| (notification, d)).ok() }) .filter_map(move |(notification, msg)| { match msg { diff --git a/substrate/core/finality-grandpa/src/communication/periodic.rs b/substrate/core/finality-grandpa/src/communication/periodic.rs index cae42d0dc7..7265fe34a2 100644 --- a/substrate/core/finality-grandpa/src/communication/periodic.rs +++ b/substrate/core/finality-grandpa/src/communication/periodic.rs @@ -23,7 +23,7 @@ use sr_primitives::traits::{NumberFor, Block as BlockT}; use network::PeerId; use tokio_timer::Delay; use log::warn; -use parity_codec::Encode; +use codec::Encode; use std::time::{Instant, Duration}; diff --git a/substrate/core/finality-grandpa/src/communication/tests.rs b/substrate/core/finality-grandpa/src/communication/tests.rs index cfe41acb3c..f1473e9863 100644 --- a/substrate/core/finality-grandpa/src/communication/tests.rs +++ b/substrate/core/finality-grandpa/src/communication/tests.rs @@ -24,7 +24,7 @@ use network_gossip::Validator; use tokio::runtime::current_thread; use std::sync::Arc; use keyring::Ed25519Keyring; -use parity_codec::Encode; +use codec::Encode; use crate::environment::SharedVoterSetState; use super::gossip::{self, GossipValidator}; diff --git a/substrate/core/finality-grandpa/src/consensus_changes.rs b/substrate/core/finality-grandpa/src/consensus_changes.rs index 02ac951241..4d94224892 100644 --- a/substrate/core/finality-grandpa/src/consensus_changes.rs +++ b/substrate/core/finality-grandpa/src/consensus_changes.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . use std::sync::Arc; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; /// Consensus-related data changes tracker. #[derive(Clone, Debug, Encode, Decode)] diff --git a/substrate/core/finality-grandpa/src/environment.rs b/substrate/core/finality-grandpa/src/environment.rs index 3090cff386..1949fd25a1 100644 --- a/substrate/core/finality-grandpa/src/environment.rs +++ b/substrate/core/finality-grandpa/src/environment.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use log::{debug, warn, info}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use futures::prelude::*; use tokio_timer::Delay; use parking_lot::RwLock; @@ -95,8 +95,10 @@ impl Encode for CompletedRounds { } } +impl codec::EncodeLike for CompletedRounds {} + impl Decode for CompletedRounds { - fn decode(value: &mut I) -> Option { + fn decode(value: &mut I) -> Result { <(Vec>, u64, Vec)>::decode(value) .map(|(rounds, set_id, voters)| CompletedRounds { rounds: rounds.into(), diff --git a/substrate/core/finality-grandpa/src/finality_proof.rs b/substrate/core/finality-grandpa/src/finality_proof.rs index f174fb04f6..830383ffca 100644 --- a/substrate/core/finality-grandpa/src/finality_proof.rs +++ b/substrate/core/finality-grandpa/src/finality_proof.rs @@ -43,7 +43,7 @@ use client::{ light::fetcher::{FetchChecker, RemoteCallRequest}, ExecutionStrategy, NeverOffchainExt, }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use grandpa::BlockNumberOps; use sr_primitives::{Justification, generic::BlockId}; use sr_primitives::traits::{ @@ -81,8 +81,8 @@ impl, RA> AuthoritySetForFinalityProver fo ExecutionStrategy::NativeElseWasm, NeverOffchainExt::new(), ).and_then(|call_result| Decode::decode(&mut &call_result[..]) - .ok_or_else(|| ClientError::CallResultDecode( - "failed to decode GRANDPA authorities set proof".into(), + .map_err(|err| ClientError::CallResultDecode( + "failed to decode GRANDPA authorities set proof".into(), err ))) } @@ -121,8 +121,8 @@ impl AuthoritySetForFinalityChecker for Arc = Decode::decode(&mut &authorities[..]) - .ok_or_else(|| ClientError::CallResultDecode( - "failed to decode GRANDPA authorities set proof".into(), + .map_err(|err| ClientError::CallResultDecode( + "failed to decode GRANDPA authorities set proof".into(), err ))?; Ok(authorities.into_iter().collect()) }) @@ -167,8 +167,8 @@ impl network::FinalityProofProvider for FinalityProofPro request: &[u8], ) -> Result>, ClientError> { let request: FinalityProofRequest = Decode::decode(&mut &request[..]) - .ok_or_else(|| { - warn!(target: "finality", "Unable to decode finality proof request."); + .map_err(|e| { + warn!(target: "finality", "Unable to decode finality proof request: {}", e.what()); ClientError::Backend(format!("Invalid finality proof request")) })?; match request { @@ -445,7 +445,7 @@ fn do_check_finality_proof, B, J>( { // decode finality proof let proof = FinalityProof::::decode(&mut &remote_proof[..]) - .ok_or_else(|| ClientError::BadJustification("failed to decode finality proof".into()))?; + .map_err(|_| ClientError::BadJustification("failed to decode finality proof".into()))?; // empty proof can't prove anything if proof.is_empty() { @@ -500,7 +500,7 @@ fn check_finality_proof_fragment, B, J>( // verify justification using previous authorities set let (mut current_set_id, mut current_authorities) = authority_set.extract_authorities(); let justification: J = Decode::decode(&mut &proof_fragment.justification[..]) - .ok_or_else(|| ClientError::JustificationDecode)?; + .map_err(|_| ClientError::JustificationDecode)?; justification.verify(current_set_id, ¤t_authorities)?; // and now verify new authorities proof (if provided) @@ -560,7 +560,8 @@ pub(crate) trait ProvableJustification: Encode + Decode { set_id: u64, authorities: &[(AuthorityId, u64)], ) -> ClientResult { - let justification = Self::decode(&mut &**justification).ok_or(ClientError::JustificationDecode)?; + let justification = Self::decode(&mut &**justification) + .map_err(|_| ClientError::JustificationDecode)?; justification.verify(set_id, authorities)?; Ok(justification) } diff --git a/substrate/core/finality-grandpa/src/import.rs b/substrate/core/finality-grandpa/src/import.rs index 91e2b92182..4144a279c5 100644 --- a/substrate/core/finality-grandpa/src/import.rs +++ b/substrate/core/finality-grandpa/src/import.rs @@ -17,7 +17,7 @@ use std::{sync::Arc, collections::HashMap}; use log::{debug, trace, info}; -use parity_codec::Encode; +use codec::Encode; use futures::sync::mpsc; use parking_lot::RwLockWriteGuard; diff --git a/substrate/core/finality-grandpa/src/justification.rs b/substrate/core/finality-grandpa/src/justification.rs index 59a3d2166c..a6554b1e90 100644 --- a/substrate/core/finality-grandpa/src/justification.rs +++ b/substrate/core/finality-grandpa/src/justification.rs @@ -20,7 +20,7 @@ use client::{CallExecutor, Client}; use client::backend::Backend; use client::blockchain::HeaderBackend; use client::error::Error as ClientError; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use grandpa::voter_set::VoterSet; use grandpa::{Error as GrandpaError}; use sr_primitives::generic::BlockId; @@ -104,7 +104,7 @@ impl> GrandpaJustification { { let justification = GrandpaJustification::::decode(&mut &*encoded) - .ok_or(ClientError::JustificationDecode)?; + .map_err(|_| ClientError::JustificationDecode)?; if (justification.commit.target_hash, justification.commit.target_number) != finalized_target { let msg = "invalid commit target in grandpa justification".to_string(); diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index 2e688ed952..0d04e964e2 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -57,7 +57,7 @@ use log::{debug, info, warn}; use futures::sync::mpsc; use client::{BlockchainEvents, CallExecutor, Client, backend::Backend, error::Error as ClientError}; use client::blockchain::HeaderBackend; -use parity_codec::Encode; +use codec::Encode; use sr_primitives::traits::{ NumberFor, Block as BlockT, DigestFor, ProvideRuntimeApi, }; diff --git a/substrate/core/finality-grandpa/src/light_import.rs b/substrate/core/finality-grandpa/src/light_import.rs index abc98976fd..3fec523dcb 100644 --- a/substrate/core/finality-grandpa/src/light_import.rs +++ b/substrate/core/finality-grandpa/src/light_import.rs @@ -25,7 +25,7 @@ use client::{ blockchain::HeaderBackend, error::Error as ClientError, }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use consensus_common::{ import_queue::Verifier, well_known_cache_keys, BlockOrigin, BlockImport, FinalityProofImport, BlockImportParams, ImportResult, ImportedAux, diff --git a/substrate/core/finality-grandpa/src/tests.rs b/substrate/core/finality-grandpa/src/tests.rs index 797463f5de..38a5dd5441 100644 --- a/substrate/core/finality-grandpa/src/tests.rs +++ b/substrate/core/finality-grandpa/src/tests.rs @@ -34,7 +34,7 @@ use consensus_common::{BlockOrigin, ForkChoiceStrategy, ImportedAux, BlockImport use consensus_common::import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport}; use std::collections::{HashMap, HashSet}; use std::result; -use parity_codec::Decode; +use codec::Decode; use sr_primitives::traits::{ApiRef, ProvideRuntimeApi, Header as HeaderT}; use sr_primitives::generic::BlockId; use primitives::{NativeOrEncoded, ExecutionContext}; @@ -336,7 +336,7 @@ impl AuthoritySetForFinalityChecker for TestApi { proof: Vec>, ) -> Result> { Decode::decode(&mut &proof[0][..]) - .ok_or_else(|| unreachable!("incorrect value is passed as GRANDPA authorities proof")) + .map_err(|_| unreachable!("incorrect value is passed as GRANDPA authorities proof")) } } diff --git a/substrate/core/inherents/Cargo.toml b/substrate/core/inherents/Cargo.toml index 7174b7acea..f89288578a 100644 --- a/substrate/core/inherents/Cargo.toml +++ b/substrate/core/inherents/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] parking_lot = { version = "0.8.0", optional = true } rstd = { package = "sr-std", path = "../sr-std", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../sr-primitives", default-features = false } [features] @@ -15,6 +15,6 @@ default = [ "std" ] std = [ "parking_lot", "rstd/std", - "parity-codec/std", + "codec/std", "sr-primitives/std", ] diff --git a/substrate/core/inherents/src/lib.rs b/substrate/core/inherents/src/lib.rs index a5dcfdffcf..f7363b483b 100644 --- a/substrate/core/inherents/src/lib.rs +++ b/substrate/core/inherents/src/lib.rs @@ -33,7 +33,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs)] -use parity_codec as codec; use codec::{Encode, Decode}; use rstd::{collections::btree_map::{BTreeMap, IntoIter, Entry}, vec::Vec}; @@ -52,7 +51,7 @@ pub type InherentIdentifier = [u8; 8]; /// Inherent data to include in a block. #[derive(Clone, Default, Encode, Decode)] pub struct InherentData { - /// All inherent data encoded with parity-codec and an identifier. + /// All inherent data encoded with parity-scale-codec and an identifier. data: BTreeMap> } @@ -111,7 +110,7 @@ impl InherentData { match self.data.get(identifier) { Some(inherent) => I::decode(&mut &inherent[..]) - .ok_or_else(|| { + .map_err(|_| { "Could not decode requested inherent type!".into() }) .map(Some), diff --git a/substrate/core/network/Cargo.toml b/substrate/core/network/Cargo.toml index 3d687486c0..383fc29fc6 100644 --- a/substrate/core/network/Cargo.toml +++ b/substrate/core/network/Cargo.toml @@ -28,7 +28,7 @@ consensus = { package = "substrate-consensus-common", path = "../../core/consens client = { package = "substrate-client", path = "../../core/client" } sr-primitives = { path = "../../core/sr-primitives" } primitives = { package = "substrate-primitives", path = "../../core/primitives" } -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } peerset = { package = "substrate-peerset", path = "../../core/peerset" } serde = { version = "1.0.70", features = ["derive"] } serde_json = "1.0.24" diff --git a/substrate/core/network/src/config.rs b/substrate/core/network/src/config.rs index 13e9a0d3a5..c05c127d83 100644 --- a/substrate/core/network/src/config.rs +++ b/substrate/core/network/src/config.rs @@ -27,7 +27,6 @@ use crate::on_demand_layer::OnDemand; use crate::service::{ExHashT, TransactionPool}; use bitflags::bitflags; use consensus::import_queue::ImportQueue; -use parity_codec; use sr_primitives::traits::{Block as BlockT}; use std::sync::Arc; use libp2p::identity::{Keypair, secp256k1, ed25519}; @@ -109,15 +108,17 @@ impl Roles { } } -impl parity_codec::Encode for Roles { - fn encode_to(&self, dest: &mut T) { +impl codec::Encode for Roles { + fn encode_to(&self, dest: &mut T) { dest.push_byte(self.bits()) } } -impl parity_codec::Decode for Roles { - fn decode(input: &mut I) -> Option { - Self::from_bits(input.read_byte()?) +impl codec::EncodeLike for Roles {} + +impl codec::Decode for Roles { + fn decode(input: &mut I) -> Result { + Self::from_bits(input.read_byte()?).ok_or_else(|| codec::Error::from("Invalid bytes")) } } diff --git a/substrate/core/network/src/custom_proto/upgrade.rs b/substrate/core/network/src/custom_proto/upgrade.rs index 1959ca2883..ebd9c431e0 100644 --- a/substrate/core/network/src/custom_proto/upgrade.rs +++ b/substrate/core/network/src/custom_proto/upgrade.rs @@ -22,7 +22,7 @@ use libp2p::tokio_codec::Framed; use log::warn; use std::{collections::VecDeque, io, marker::PhantomData, vec::IntoIter as VecIntoIter}; use futures::{prelude::*, future, stream}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use sr_primitives::traits::Block as BlockT; use tokio_io::{AsyncRead, AsyncWrite}; use unsigned_varint::codec::UviBytes; @@ -179,7 +179,7 @@ where TSubstream: AsyncRead + AsyncWrite, B: BlockT { self.clogged_fuse = true; return Ok(Async::Ready(Some(RegisteredProtocolEvent::Clogged { messages: self.send_queue.iter() - .map(|m| Decode::decode(&mut &m[..]).ok_or(())) + .map(|m| Decode::decode(&mut &m[..])) .filter_map(Result::ok) .collect(), }))) @@ -199,9 +199,12 @@ where TSubstream: AsyncRead + AsyncWrite, B: BlockT { // Note that `inner` is wrapped in a `Fuse`, therefore we can poll it forever. match self.inner.poll()? { Async::Ready(Some(data)) => { - let message = as Decode>::decode(&mut &data[..]).ok_or(()) - .map_err(|()| { - warn!(target: "sub-libp2p", "Couldn't decode packet sent by the remote: {:?}", data); + let message = as Decode>::decode(&mut &data[..]) + .map_err(|err| { + warn!( + target: "sub-libp2p", + "Couldn't decode packet sent by the remote: {:?}: {}", data, err.what(), + ); io::ErrorKind::InvalidData })?; Ok(Async::Ready(Some(RegisteredProtocolEvent::Message(message)))) diff --git a/substrate/core/network/src/protocol/message.rs b/substrate/core/network/src/protocol/message.rs index def9d4c225..4110970f99 100644 --- a/substrate/core/network/src/protocol/message.rs +++ b/substrate/core/network/src/protocol/message.rs @@ -18,7 +18,7 @@ use bitflags::bitflags; use sr_primitives::{ConsensusEngineId, traits::{Block as BlockT, Header as HeaderT}}; -use parity_codec::{Encode, Decode, Input, Output}; +use codec::{Encode, Decode, Input, Output, Error}; pub use self::generic::{ BlockAnnounce, RemoteCallRequest, RemoteReadRequest, RemoteHeaderRequest, RemoteHeaderResponse, @@ -90,9 +90,11 @@ impl Encode for BlockAttributes { } } +impl codec::EncodeLike for BlockAttributes {} + impl Decode for BlockAttributes { - fn decode(input: &mut I) -> Option { - Self::from_bits(input.read_byte()?) + fn decode(input: &mut I) -> Result { + Self::from_bits(input.read_byte()?).ok_or_else(|| Error::from("Invalid bytes")) } } @@ -125,7 +127,7 @@ pub struct RemoteReadResponse { /// Generic types. pub mod generic { - use parity_codec::{Encode, Decode}; + use codec::{Encode, Decode}; use sr_primitives::Justification; use crate::config::Roles; use super::{ diff --git a/substrate/core/offchain/Cargo.toml b/substrate/core/offchain/Cargo.toml index 694ce38663..97a6fd3d2d 100644 --- a/substrate/core/offchain/Cargo.toml +++ b/substrate/core/offchain/Cargo.toml @@ -11,7 +11,7 @@ client = { package = "substrate-client", path = "../../core/client" } futures = "0.1.25" log = "0.4" offchain-primitives = { package = "substrate-offchain-primitives", path = "./primitives" } -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } parking_lot = "0.8.0" primitives = { package = "substrate-primitives", path = "../../core/primitives" } sr-primitives = { path = "../../core/sr-primitives" } diff --git a/substrate/core/offchain/src/api.rs b/substrate/core/offchain/src/api.rs index 8af7b333f5..8733f3699a 100644 --- a/substrate/core/offchain/src/api.rs +++ b/substrate/core/offchain/src/api.rs @@ -25,7 +25,7 @@ use client::backend::OffchainStorage; use crate::AuthorityKeyProvider; use futures::{Stream, Future, sync::mpsc}; use log::{info, debug, warn, error}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use primitives::offchain::{ Timestamp, HttpRequestId, HttpRequestStatus, HttpError, @@ -219,7 +219,7 @@ impl Api where match key { CryptoKey::LocalKey { id, kind } => { let key = self.db.get(KEYS_PREFIX, &id.encode()) - .and_then(|key| StoredKey::decode(&mut &*key)) + .and_then(|key| StoredKey::decode(&mut &*key).ok()) .ok_or(())?; if key.kind != kind { warn!( @@ -266,7 +266,7 @@ where let (id, id_encoded) = loop { let encoded = self.db.get(KEYS_PREFIX, NEXT_ID); let encoded_slice = encoded.as_ref().map(|x| x.as_slice()); - let new_id = encoded_slice.and_then(|mut x| u16::decode(&mut x)).unwrap_or_default() + let new_id = encoded_slice.and_then(|mut x| u16::decode(&mut x).ok()).unwrap_or_default() .checked_add(1) .ok_or(())?; let new_id_encoded = new_id.encode(); @@ -473,14 +473,14 @@ impl TryFrom for NetworkState { fn try_from(state: OpaqueNetworkState) -> Result { let inner_vec = state.peer_id.0; - let bytes: Vec = Decode::decode(&mut &inner_vec[..]).ok_or(())?; + let bytes: Vec = Decode::decode(&mut &inner_vec[..]).map_err(|_| ())?; let peer_id = PeerId::from_bytes(bytes).map_err(|_| ())?; let external_addresses: Result, Self::Error> = state.external_addresses .iter() .map(|enc_multiaddr| -> Result { let inner_vec = &enc_multiaddr.0; - let bytes = >::decode(&mut &inner_vec[..]).ok_or(())?; + let bytes = >::decode(&mut &inner_vec[..]).map_err(|_| ())?; let multiaddr_str = String::from_utf8(bytes).map_err(|_| ())?; let multiaddr = Multiaddr::from_str(&multiaddr_str).map_err(|_| ())?; Ok(multiaddr) @@ -548,9 +548,9 @@ impl AsyncApi { fn submit_extrinsic(&mut self, ext: Vec) { let xt = match ::Extrinsic::decode(&mut &*ext) { - Some(xt) => xt, - None => { - warn!("Unable to decode extrinsic: {:?}", ext); + Ok(xt) => xt, + Err(e) => { + warn!("Unable to decode extrinsic: {:?}: {}", ext, e.what()); return }, }; diff --git a/substrate/core/primitives/Cargo.toml b/substrate/core/primitives/Cargo.toml index d0cdf34141..c927ddfeb6 100644 --- a/substrate/core/primitives/Cargo.toml +++ b/substrate/core/primitives/Cargo.toml @@ -6,12 +6,12 @@ edition = "2018" [dependencies] rstd = { package = "sr-std", path = "../sr-std", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rustc-hex = { version = "2.0", default-features = false } serde = { version = "1.0", optional = true, features = ["derive"] } twox-hash = { version = "1.2.0", optional = true } byteorder = { version = "1.3.1", default-features = false } -primitive-types = { version = "0.4.0", default-features = false, features = ["codec"] } +primitive-types = { version = "0.5.0", default-features = false, features = ["codec"] } impl-serde = { version = "0.1", optional = true } wasmi = { version = "0.5.0", optional = true } hash-db = { version = "0.15.0", default-features = false } @@ -57,7 +57,7 @@ std = [ "primitive-types/rustc-hex", "primitive-types/libc", "impl-serde", - "parity-codec/std", + "codec/std", "hash256-std-hasher/std", "hash-db/std", "rstd/std", diff --git a/substrate/core/primitives/src/changes_trie.rs b/substrate/core/primitives/src/changes_trie.rs index eb6a75454f..fb7791f0a0 100644 --- a/substrate/core/primitives/src/changes_trie.rs +++ b/substrate/core/primitives/src/changes_trie.rs @@ -18,7 +18,7 @@ #[cfg(any(feature = "std", test))] use serde::{Serialize, Deserialize}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use num_traits::Zero; /// Substrate changes trie configuration. diff --git a/substrate/core/primitives/src/crypto.rs b/substrate/core/primitives/src/crypto.rs index 327a8a3eb1..b3469e09b8 100644 --- a/substrate/core/primitives/src/crypto.rs +++ b/substrate/core/primitives/src/crypto.rs @@ -25,7 +25,7 @@ use parking_lot::Mutex; #[cfg(feature = "std")] use rand::{RngCore, rngs::OsRng}; #[cfg(feature = "std")] -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; #[cfg(feature = "std")] use regex::Regex; #[cfg(feature = "std")] diff --git a/substrate/core/primitives/src/ed25519.rs b/substrate/core/primitives/src/ed25519.rs index 5d1fe884a5..0ff0042911 100644 --- a/substrate/core/primitives/src/ed25519.rs +++ b/substrate/core/primitives/src/ed25519.rs @@ -20,7 +20,7 @@ use crate::{hash::H256, hash::H512}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; #[cfg(feature = "std")] use blake2_rfc; diff --git a/substrate/core/primitives/src/lib.rs b/substrate/core/primitives/src/lib.rs index 4fabb04ccb..bf1911dad9 100644 --- a/substrate/core/primitives/src/lib.rs +++ b/substrate/core/primitives/src/lib.rs @@ -33,7 +33,7 @@ macro_rules! map { use rstd::prelude::*; use rstd::ops::Deref; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; #[cfg(feature = "std")] use std::borrow::Cow; #[cfg(feature = "std")] @@ -138,14 +138,14 @@ pub enum NativeOrEncoded { } #[cfg(feature = "std")] -impl ::std::fmt::Debug for NativeOrEncoded { +impl ::std::fmt::Debug for NativeOrEncoded { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { self.as_encoded().as_ref().fmt(f) } } #[cfg(feature = "std")] -impl NativeOrEncoded { +impl NativeOrEncoded { /// Return the value as the encoded format. pub fn as_encoded<'a>(&'a self) -> Cow<'a, [u8]> { match self { @@ -164,13 +164,13 @@ impl NativeOrEncoded { } #[cfg(feature = "std")] -impl PartialEq for NativeOrEncoded { +impl PartialEq for NativeOrEncoded { fn eq(&self, other: &Self) -> bool { match (self, other) { (NativeOrEncoded::Native(l), NativeOrEncoded::Native(r)) => l == r, (NativeOrEncoded::Native(n), NativeOrEncoded::Encoded(e)) | (NativeOrEncoded::Encoded(e), NativeOrEncoded::Native(n)) => - Some(n) == parity_codec::Decode::decode(&mut &e[..]).as_ref(), + Some(n) == codec::Decode::decode(&mut &e[..]).ok().as_ref(), (NativeOrEncoded::Encoded(l), NativeOrEncoded::Encoded(r)) => l == r, } } @@ -183,7 +183,7 @@ impl PartialEq for NativeOrEncoded { pub enum NeverNativeValue {} #[cfg(feature = "std")] -impl parity_codec::Encode for NeverNativeValue { +impl codec::Encode for NeverNativeValue { fn encode(&self) -> Vec { // The enum is not constructable, so this function should never be callable! unreachable!() @@ -191,8 +191,11 @@ impl parity_codec::Encode for NeverNativeValue { } #[cfg(feature = "std")] -impl parity_codec::Decode for NeverNativeValue { - fn decode(_: &mut I) -> Option { - None +impl codec::EncodeLike for NeverNativeValue {} + +#[cfg(feature = "std")] +impl codec::Decode for NeverNativeValue { + fn decode(_: &mut I) -> Result { + Err("`NeverNativeValue` should never be decoded".into()) } } diff --git a/substrate/core/primitives/src/offchain.rs b/substrate/core/primitives/src/offchain.rs index 5b6f8f5c22..a0ee1c34d1 100644 --- a/substrate/core/primitives/src/offchain.rs +++ b/substrate/core/primitives/src/offchain.rs @@ -17,7 +17,7 @@ //! Offchain workers types use crate::crypto; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use rstd::prelude::{Vec, Box}; use rstd::convert::TryFrom; @@ -397,7 +397,7 @@ pub trait Externalities { /// Initiates a http request given HTTP verb and the URL. /// - /// Meta is a future-reserved field containing additional, parity-codec encoded parameters. + /// Meta is a future-reserved field containing additional, parity-scale-codec encoded parameters. /// Returns the id of newly started request. fn http_request_start( &mut self, diff --git a/substrate/core/primitives/src/sandbox.rs b/substrate/core/primitives/src/sandbox.rs index 773a6b4893..e47a30ca5b 100644 --- a/substrate/core/primitives/src/sandbox.rs +++ b/substrate/core/primitives/src/sandbox.rs @@ -16,7 +16,7 @@ //! Definition of a sandbox environment. -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use rstd::vec::Vec; /// Error error that can be returned from host function. @@ -184,7 +184,7 @@ pub const ERR_EXECUTION: u32 = -3i32 as u32; mod tests { use super::*; use std::fmt; - use parity_codec::Codec; + use codec::Codec; fn roundtrip(s: S) { let encoded = s.encode(); diff --git a/substrate/core/primitives/src/sr25519.rs b/substrate/core/primitives/src/sr25519.rs index e01d989143..f87a0078ef 100644 --- a/substrate/core/primitives/src/sr25519.rs +++ b/substrate/core/primitives/src/sr25519.rs @@ -33,7 +33,7 @@ use bip39::{Mnemonic, Language, MnemonicType}; use crate::crypto::{Pair as TraitPair, DeriveJunction, Infallible, SecretStringError, Derive, Ss58Codec}; use crate::crypto::{key_types, KeyTypeId, Public as TraitPublic, TypedKey, UncheckedFrom}; use crate::hash::{H256, H512}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; #[cfg(feature = "std")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/substrate/core/primitives/src/uint.rs b/substrate/core/primitives/src/uint.rs index dfea51921d..b41596a910 100644 --- a/substrate/core/primitives/src/uint.rs +++ b/substrate/core/primitives/src/uint.rs @@ -21,7 +21,7 @@ pub use primitive_types::U256; #[cfg(test)] mod tests { use super::*; - use parity_codec::{Encode, Decode}; + use codec::{Encode, Decode}; use substrate_serializer as ser; macro_rules! test { @@ -78,10 +78,10 @@ mod tests { res2); assert_eq!( U256::decode(&mut &res1[..]), - Some(U256::from(120))); + Ok(U256::from(120))); assert_eq!( U256::decode(&mut &res2[..]), - Some(U256::max_value())); + Ok(U256::max_value())); } #[test] diff --git a/substrate/core/rpc/Cargo.toml b/substrate/core/rpc/Cargo.toml index a94b410775..cf129a03e6 100644 --- a/substrate/core/rpc/Cargo.toml +++ b/substrate/core/rpc/Cargo.toml @@ -14,7 +14,7 @@ jsonrpc-pubsub = "12.0.0" jsonrpc-derive = "12.0.0" log = "0.4" parking_lot = "0.8.0" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" client = { package = "substrate-client", path = "../client" } diff --git a/substrate/core/rpc/src/author/error.rs b/substrate/core/rpc/src/author/error.rs index 82ace88b84..769f111105 100644 --- a/substrate/core/rpc/src/author/error.rs +++ b/substrate/core/rpc/src/author/error.rs @@ -19,7 +19,6 @@ use client; use transaction_pool::txpool; use crate::rpc; - use crate::errors; /// Author RPC Result type. @@ -36,8 +35,8 @@ pub enum Error { #[display(fmt="Extrinsic verification error: {}", _0)] Verification(Box), /// Incorrect extrinsic format. - #[display(fmt="Invalid extrinsic format")] - BadFormat, + #[display(fmt="Invalid extrinsic format: {}", _0)] + BadFormat(codec::Error), } impl std::error::Error for Error { @@ -78,9 +77,9 @@ impl From for rpc::Error { use txpool::error::{Error as PoolError}; match e { - Error::BadFormat => rpc::Error { + Error::BadFormat(e) => rpc::Error { code: rpc::ErrorCode::ServerError(BAD_FORMAT), - message: "Extrinsic has invalid format.".into(), + message: format!("Extrinsic has invalid format: {}", e).into(), data: None, }, Error::Verification(e) => rpc::Error { diff --git a/substrate/core/rpc/src/author/mod.rs b/substrate/core/rpc/src/author/mod.rs index 4e64ff0ce2..aa238aeb70 100644 --- a/substrate/core/rpc/src/author/mod.rs +++ b/substrate/core/rpc/src/author/mod.rs @@ -30,7 +30,7 @@ use crate::subscriptions::Subscriptions; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; use log::warn; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use primitives::{Bytes, Blake2Hasher, H256}; use sr_primitives::{generic, traits}; use self::error::Result; @@ -110,7 +110,7 @@ impl AuthorApi, BlockHash

> for Author whe type Metadata = crate::metadata::Metadata; fn submit_extrinsic(&self, ext: Bytes) -> Result> { - let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::BadFormat)?; + let xt = Decode::decode(&mut &ext[..])?; let best_block_hash = self.client.info().chain.best_hash; self.pool .submit_one(&generic::BlockId::hash(best_block_hash), xt) @@ -129,7 +129,7 @@ impl AuthorApi, BlockHash

> for Author whe .map(|x| match x { hash::ExtrinsicOrHash::Hash(h) => Ok(h), hash::ExtrinsicOrHash::Extrinsic(bytes) => { - let xt = Decode::decode(&mut &bytes[..]).ok_or(error::Error::BadFormat)?; + let xt = Decode::decode(&mut &bytes[..])?; Ok(self.pool.hash_of(&xt)) }, }) @@ -146,8 +146,7 @@ impl AuthorApi, BlockHash

> for Author whe fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: Subscriber, BlockHash

>>, xt: Bytes) { let submit = || -> Result<_> { let best_block_hash = self.client.info().chain.best_hash; - let dxt = <

::Block as traits::Block>::Extrinsic::decode(&mut &xt[..]) - .ok_or(error::Error::BadFormat)?; + let dxt = <

::Block as traits::Block>::Extrinsic::decode(&mut &xt[..])?; self.pool .submit_and_watch(&generic::BlockId::hash(best_block_hash), dxt) .map_err(|e| e.into_pool_error() diff --git a/substrate/core/rpc/src/author/tests.rs b/substrate/core/rpc/src/author/tests.rs index cf320ee144..6295220820 100644 --- a/substrate/core/rpc/src/author/tests.rs +++ b/substrate/core/rpc/src/author/tests.rs @@ -18,7 +18,7 @@ use super::*; use std::sync::Arc; use assert_matches::assert_matches; -use parity_codec::Encode; +use codec::Encode; use transaction_pool::{ txpool::Pool, ChainApi, diff --git a/substrate/core/service/Cargo.toml b/substrate/core/service/Cargo.toml index 4ce3facb52..dcb47bbbfb 100644 --- a/substrate/core/service/Cargo.toml +++ b/substrate/core/service/Cargo.toml @@ -27,7 +27,7 @@ consensus_common = { package = "substrate-consensus-common", path = "../../core/ network = { package = "substrate-network", path = "../../core/network" } client = { package = "substrate-client", path = "../../core/client" } client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] } -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } substrate-executor = { path = "../../core/executor" } transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } rpc = { package = "substrate-rpc-servers", path = "../../core/rpc-servers" } diff --git a/substrate/core/service/src/chain_ops.rs b/substrate/core/service/src/chain_ops.rs index 19666c090c..c977b265bb 100644 --- a/substrate/core/service/src/chain_ops.rs +++ b/substrate/core/service/src/chain_ops.rs @@ -16,7 +16,7 @@ //! Chain utilities. -use std::{self, io::{Read, Write}}; +use std::{self, io::{Read, Write, Seek}}; use futures::prelude::*; use futures03::TryFutureExt as _; use log::{info, warn}; @@ -29,7 +29,7 @@ use network::message; use consensus_common::BlockOrigin; use crate::components::{self, Components, ServiceFactory, FactoryFullConfiguration, FactoryBlockNumber, RuntimeGenesis}; use crate::new_client; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode, IoReader}; use crate::error; use crate::chain_spec::ChainSpec; @@ -136,9 +136,9 @@ impl Link for WaitLink { pub fn import_blocks( mut config: FactoryFullConfiguration, exit: E, - mut input: R + input: R ) -> error::Result> - where F: ServiceFactory, E: Future + Send + 'static, R: Read, + where F: ServiceFactory, E: Future + Send + 'static, R: Read + Seek, { let client = new_client::(&config)?; // FIXME #1134 this shouldn't need a mutable config. @@ -155,37 +155,42 @@ pub fn import_blocks( let _ = exit_send.send(()); }); - let count: u64 = Decode::decode(&mut input).ok_or("Error reading file")?; + let mut io_reader_input = IoReader(input); + let count: u64 = Decode::decode(&mut io_reader_input) + .map_err(|e| format!("Error reading file: {}", e))?; info!("Importing {} blocks", count); let mut block_count = 0; for b in 0 .. count { if exit_recv.try_recv().is_ok() { break; } - if let Some(signed) = SignedBlock::::decode(&mut input) { - let (header, extrinsics) = signed.block.deconstruct(); - let hash = header.hash(); - let block = message::BlockData:: { - hash, - justification: signed.justification, - header: Some(header), - body: Some(extrinsics), - receipt: None, - message_queue: None - }; - // import queue handles verification and importing it into the client - queue.import_blocks(BlockOrigin::File, vec![ - IncomingBlock::{ - hash: block.hash, - header: block.header, - body: block.body, - justification: block.justification, - origin: None, - } - ]); - } else { - warn!("Error reading block data at {}.", b); - break; + match SignedBlock::::decode(&mut io_reader_input) { + Ok(signed) => { + let (header, extrinsics) = signed.block.deconstruct(); + let hash = header.hash(); + let block = message::BlockData:: { + hash, + justification: signed.justification, + header: Some(header), + body: Some(extrinsics), + receipt: None, + message_queue: None + }; + // import queue handles verification and importing it into the client + queue.import_blocks(BlockOrigin::File, vec![ + IncomingBlock:: { + hash: block.hash, + header: block.header, + body: block.body, + justification: block.justification, + origin: None, + } + ]); + } + Err(e) => { + warn!("Error reading block data at {}: {}", b, e); + break; + } } block_count = b; diff --git a/substrate/core/service/src/lib.rs b/substrate/core/service/src/lib.rs index cd904156c5..bcb5cfa3b8 100644 --- a/substrate/core/service/src/lib.rs +++ b/substrate/core/service/src/lib.rs @@ -40,7 +40,7 @@ use futures03::stream::{StreamExt as _, TryStreamExt as _}; use keystore::Store as Keystore; use network::{NetworkState, NetworkStateInfo}; use log::{log, info, warn, debug, error, Level}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use primitives::{Pair, ed25519, sr25519, crypto}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{Header, NumberFor, SaturatedConversion, Zero}; @@ -877,28 +877,31 @@ impl network::TransactionPool, ComponentBlock< } let encoded = transaction.encode(); - if let Some(uxt) = Decode::decode(&mut &encoded[..]) { - let best_block_id = self.best_block_id()?; - match self.pool.submit_one(&best_block_id, uxt) { - Ok(hash) => Some(hash), - Err(e) => match e.into_pool_error() { - Ok(txpool::error::Error::AlreadyImported(hash)) => { - hash.downcast::>().ok() - .map(|x| x.as_ref().clone()) - }, - Ok(e) => { - debug!("Error adding transaction to the pool: {:?}", e); - None - }, - Err(e) => { - debug!("Error converting pool error: {:?}", e); - None - }, + match Decode::decode(&mut &encoded[..]) { + Ok(uxt) => { + let best_block_id = self.best_block_id()?; + match self.pool.submit_one(&best_block_id, uxt) { + Ok(hash) => Some(hash), + Err(e) => match e.into_pool_error() { + Ok(txpool::error::Error::AlreadyImported(hash)) => { + hash.downcast::>().ok() + .map(|x| x.as_ref().clone()) + }, + Ok(e) => { + debug!("Error adding transaction to the pool: {:?}", e); + None + }, + Err(e) => { + debug!("Error converting pool error: {:?}", e); + None + }, + } } } - } else { - debug!("Error decoding transaction"); - None + Err(e) => { + debug!("Error decoding transaction {}", e); + None + } } } diff --git a/substrate/core/sr-api-macros/Cargo.toml b/substrate/core/sr-api-macros/Cargo.toml index aed1c022da..3301b2fdc7 100644 --- a/substrate/core/sr-api-macros/Cargo.toml +++ b/substrate/core/sr-api-macros/Cargo.toml @@ -23,7 +23,7 @@ sr-version = { path = "../sr-version" } primitives = { package = "substrate-primitives", path = "../primitives" } criterion = "0.2" consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" } -codec = { package = "parity-codec", version = "4.1.1" } +codec = { package = "parity-scale-codec", version = "1.0.0" } trybuild = "1.0" [[bench]] diff --git a/substrate/core/sr-api-macros/src/decl_runtime_apis.rs b/substrate/core/sr-api-macros/src/decl_runtime_apis.rs index c2501220b6..27f102740b 100644 --- a/substrate/core/sr-api-macros/src/decl_runtime_apis.rs +++ b/substrate/core/sr-api-macros/src/decl_runtime_apis.rs @@ -192,7 +192,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result { { ::decode( &mut &#crate_::runtime_api::Encode::encode(input)[..] - ).ok_or_else(|| error_desc) + ).map_err(|_| error_desc) } )); @@ -682,9 +682,9 @@ impl<'a> ToClientSideDecl<'a> { }, #crate_::runtime_api::NativeOrEncoded::Encoded(r) => { <#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..]) - .ok_or_else(|| + .map_err(|err| #crate_::error::Error::CallResultDecode( - #function_name + #function_name, err ).into() ) } diff --git a/substrate/core/sr-api-macros/src/impl_runtime_apis.rs b/substrate/core/sr-api-macros/src/impl_runtime_apis.rs index 530405068a..973fa0558a 100644 --- a/substrate/core/sr-api-macros/src/impl_runtime_apis.rs +++ b/substrate/core/sr-api-macros/src/impl_runtime_apis.rs @@ -77,8 +77,8 @@ fn generate_impl_call( quote!( #( let #pnames : #ptypes = match #c_iter::runtime_api::Decode::decode(&mut #input) { - Some(input) => input, - None => panic!("Bad input data provided to {}", #fn_name_str), + Ok(input) => input, + Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()), }; )* diff --git a/substrate/core/sr-io/Cargo.toml b/substrate/core/sr-io/Cargo.toml index a103245721..0e6fba5bd7 100644 --- a/substrate/core/sr-io/Cargo.toml +++ b/substrate/core/sr-io/Cargo.toml @@ -11,7 +11,7 @@ rustc_version = "0.2" [dependencies] rstd = { package = "sr-std", path = "../sr-std", default-features = false } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } -codec = { package = "parity-codec", version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } hash-db = { version = "0.15.0", default-features = false } libsecp256k1 = { version = "0.2.1", optional = true } tiny-keccak = { version = "1.4.2", optional = true } diff --git a/substrate/core/sr-io/src/lib.rs b/substrate/core/sr-io/src/lib.rs index 7729a1e573..ac4799513d 100644 --- a/substrate/core/sr-io/src/lib.rs +++ b/substrate/core/sr-io/src/lib.rs @@ -324,7 +324,7 @@ export_api! { /// Initiates a http request given HTTP verb and the URL. /// - /// Meta is a future-reserved field containing additional, parity-codec encoded parameters. + /// Meta is a future-reserved field containing additional, parity-scale-codec encoded parameters. /// Returns the id of newly started request. fn http_request_start( method: &str, diff --git a/substrate/core/sr-io/without_std.rs b/substrate/core/sr-io/without_std.rs index 861f94ced5..4dc28f0471 100644 --- a/substrate/core/sr-io/without_std.rs +++ b/substrate/core/sr-io/without_std.rs @@ -529,7 +529,7 @@ pub mod ext { /// Initiates a http request. /// - /// `meta` is parity-codec encoded additional parameters to the request (like redirection policy, + /// `meta` is parity-scale-codec encoded additional parameters to the request (like redirection policy, /// timeouts, certificates policy, etc). The format is not yet specified and the field is currently /// only reserved for future use. /// @@ -596,7 +596,7 @@ pub mod ext { /// /// # Returns /// - /// - A pointer to parity-codec encoded vector of pairs `(HeaderKey, HeaderValue)`. + /// - A pointer to parity-scale-codec encoded vector of pairs `(HeaderKey, HeaderValue)`. /// - In case invalid `id` is passed it returns a pointer to parity-encoded empty vector. fn ext_http_response_headers( id: u32, diff --git a/substrate/core/sr-primitives/Cargo.toml b/substrate/core/sr-primitives/Cargo.toml index f736df0e01..e161d5b887 100644 --- a/substrate/core/sr-primitives/Cargo.toml +++ b/substrate/core/sr-primitives/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" num-traits = { version = "0.2", default-features = false } integer-sqrt = { version = "0.1.2" } serde = { version = "1.0", optional = true, features = ["derive"] } -codec = { package = "parity-codec", version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } rstd = { package = "sr-std", path = "../sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../sr-io", default-features = false } @@ -17,7 +17,7 @@ paste = { version = "0.1"} [dev-dependencies] serde_json = "1.0" -primitive-types = "0.4" +primitive-types = "0.5.0" [features] default = ["std"] diff --git a/substrate/core/sr-primitives/src/generic/digest.rs b/substrate/core/sr-primitives/src/generic/digest.rs index 9d18f67f4c..b6d72dddf7 100644 --- a/substrate/core/sr-primitives/src/generic/digest.rs +++ b/substrate/core/sr-primitives/src/generic/digest.rs @@ -22,7 +22,7 @@ use serde::Serialize; use rstd::prelude::*; use crate::ConsensusEngineId; -use crate::codec::{Decode, Encode, Input}; +use crate::codec::{Decode, Encode, Input, Error}; /// Generic header digest. #[derive(PartialEq, Eq, Clone, Encode, Decode)] @@ -221,27 +221,29 @@ impl Encode for DigestItem { } } +impl codec::EncodeLike for DigestItem {} + impl Decode for DigestItem { #[allow(deprecated)] - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> Result { let item_type: DigestItemType = Decode::decode(input)?; match item_type { - DigestItemType::ChangesTrieRoot => Some(DigestItem::ChangesTrieRoot( + DigestItemType::ChangesTrieRoot => Ok(DigestItem::ChangesTrieRoot( Decode::decode(input)?, )), DigestItemType::PreRuntime => { let vals: (ConsensusEngineId, Vec) = Decode::decode(input)?; - Some(DigestItem::PreRuntime(vals.0, vals.1)) + Ok(DigestItem::PreRuntime(vals.0, vals.1)) }, DigestItemType::Consensus => { let vals: (ConsensusEngineId, Vec) = Decode::decode(input)?; - Some(DigestItem::Consensus(vals.0, vals.1)) + Ok(DigestItem::Consensus(vals.0, vals.1)) } DigestItemType::Seal => { let vals: (ConsensusEngineId, Vec) = Decode::decode(input)?; - Some(DigestItem::Seal(vals.0, vals.1)) + Ok(DigestItem::Seal(vals.0, vals.1)) }, - DigestItemType::Other => Some(DigestItem::Other( + DigestItemType::Other => Ok(DigestItem::Other( Decode::decode(input)?, )), } @@ -305,7 +307,7 @@ impl<'a, Hash> DigestItemRef<'a, Hash> { /// Try to match this digest item to the given opaque item identifier; if it matches, then /// try to cast to the given datatype; if that works, return it. pub fn try_to(&self, id: OpaqueDigestItemId) -> Option { - self.try_as_raw(id).and_then(|mut x| Decode::decode(&mut x)) + self.try_as_raw(id).and_then(|mut x| Decode::decode(&mut x).ok()) } } @@ -340,6 +342,8 @@ impl<'a, Hash: Encode> Encode for DigestItemRef<'a, Hash> { } } +impl<'a, Hash: Encode> codec::EncodeLike for DigestItemRef<'a, Hash> {} + #[cfg(test)] mod tests { use super::*; diff --git a/substrate/core/sr-primitives/src/generic/era.rs b/substrate/core/sr-primitives/src/generic/era.rs index c41d3eedfc..7308a8adc5 100644 --- a/substrate/core/sr-primitives/src/generic/era.rs +++ b/substrate/core/sr-primitives/src/generic/era.rs @@ -19,7 +19,7 @@ #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; -use crate::codec::{Decode, Encode, Input, Output}; +use crate::codec::{Decode, Encode, Input, Output, Error}; /// Era period pub type Period = u64; @@ -111,20 +111,22 @@ impl Encode for Era { } } +impl codec::EncodeLike for Era {} + impl Decode for Era { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> Result { let first = input.read_byte()?; if first == 0 { - Some(Era::Immortal) + Ok(Era::Immortal) } else { let encoded = first as u64 + ((input.read_byte()? as u64) << 8); let period = 2 << (encoded % (1 << 4)); let quantize_factor = (period >> 12).max(1); let phase = (encoded >> 4) * quantize_factor; if period >= 4 && phase < period { - Some(Era::Mortal(period, phase)) + Ok(Era::Mortal(period, phase)) } else { - None + Err("Invalid period and phase".into()) } } } diff --git a/substrate/core/sr-primitives/src/generic/header.rs b/substrate/core/sr-primitives/src/generic/header.rs index 66d226b2c4..e8f40bb7b6 100644 --- a/substrate/core/sr-primitives/src/generic/header.rs +++ b/substrate/core/sr-primitives/src/generic/header.rs @@ -20,7 +20,7 @@ use serde::Serialize; #[cfg(feature = "std")] use log::debug; -use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef}; +use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef, Error}; use crate::traits::{ self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay, Hash as HashT, MaybeSerializeDebug, MaybeSerializeDebugButNotDeserialize @@ -60,8 +60,8 @@ impl Decode for Header where Hash: HashT, Hash::Output: Decode, { - fn decode(input: &mut I) -> Option { - Some(Header { + fn decode(input: &mut I) -> Result { + Ok(Header { parent_hash: Decode::decode(input)?, number: <::Type>::decode(input)?.into(), state_root: Decode::decode(input)?, @@ -85,6 +85,12 @@ impl Encode for Header where } } +impl codec::EncodeLike for Header where + Number: HasCompact + Copy + Into, + Hash: HashT, + Hash::Output: Encode, +{} + impl traits::Header for Header where Number: Member + MaybeSerializeDebug + ::rstd::hash::Hash + MaybeDisplay + SimpleArithmetic + Codec + Copy + Into, Hash: HashT, diff --git a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs index b803a20397..d87c9e045f 100644 --- a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -21,7 +21,7 @@ use std::fmt; use rstd::prelude::*; use runtime_io::blake2_256; -use crate::codec::{Decode, Encode, Input}; +use crate::codec::{Decode, Encode, Input, Error}; use crate::traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic}; use super::CheckedExtrinsic; @@ -131,7 +131,7 @@ where Call: Decode, Extra: SignedExtension, { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> Result { // This is a little more complicated than usual since the binary format must be compatible // with substrate's generic `Vec` type. Basically this just means accepting that there // will be a prefix of vector length (we don't need @@ -143,10 +143,10 @@ where let is_signed = version & 0b1000_0000 != 0; let version = version & 0b0111_1111; if version != TRANSACTION_VERSION { - return None + return Err("Invalid transaction version".into()); } - Some(UncheckedExtrinsic { + Ok(UncheckedExtrinsic { signature: if is_signed { Some(Decode::decode(input)?) } else { None }, function: Decode::decode(input)?, }) @@ -245,7 +245,7 @@ mod tests { fn unsigned_codec_should_work() { let ux = Ex::new_unsigned(vec![0u8; 0]); let encoded = ux.encode(); - assert_eq!(Ex::decode(&mut &encoded[..]), Some(ux)); + assert_eq!(Ex::decode(&mut &encoded[..]), Ok(ux)); } #[test] @@ -257,7 +257,7 @@ mod tests { TestExtra ); let encoded = ux.encode(); - assert_eq!(Ex::decode(&mut &encoded[..]), Some(ux)); + assert_eq!(Ex::decode(&mut &encoded[..]), Ok(ux)); } #[test] @@ -270,7 +270,7 @@ mod tests { TestExtra ); let encoded = ux.encode(); - assert_eq!(Ex::decode(&mut &encoded[..]), Some(ux)); + assert_eq!(Ex::decode(&mut &encoded[..]), Ok(ux)); } #[test] diff --git a/substrate/core/sr-primitives/src/lib.rs b/substrate/core/sr-primitives/src/lib.rs index 08cd4d1a05..1c9def98c1 100644 --- a/substrate/core/sr-primitives/src/lib.rs +++ b/substrate/core/sr-primitives/src/lib.rs @@ -694,6 +694,8 @@ impl codec::Encode for ApplyOutcome { } } +impl codec::EncodeLike for ApplyOutcome {} + #[derive(Eq, PartialEq, Clone, Copy, Decode)] #[cfg_attr(feature = "std", derive(Debug, Serialize))] #[repr(u8)] @@ -717,6 +719,8 @@ impl codec::Encode for ApplyError { } } +impl codec::EncodeLike for ApplyError {} + /// Result from attempt to apply an extrinsic. pub type ApplyResult = Result; diff --git a/substrate/core/sr-primitives/src/testing.rs b/substrate/core/sr-primitives/src/testing.rs index 0986c4f81a..3d55e9c4b9 100644 --- a/substrate/core/sr-primitives/src/testing.rs +++ b/substrate/core/sr-primitives/src/testing.rs @@ -70,7 +70,9 @@ impl OpaqueKeys for UintAuthorityId { ) } } - fn get(&self, _: KeyTypeId) -> Option { self.0.using_encoded(|mut x| T::decode(&mut x)) } + fn get(&self, _: KeyTypeId) -> Option { + self.0.using_encoded(|mut x| T::decode(&mut x)).ok() + } } /// Digest item @@ -136,7 +138,8 @@ impl traits::Header for Header { impl<'a> Deserialize<'a> for Header { fn deserialize>(de: D) -> Result { let r = >::deserialize(de)?; - Decode::decode(&mut &r[..]).ok_or(DeError::custom("Invalid value passed into decode")) + Decode::decode(&mut &r[..]) + .map_err(|e| DeError::custom(format!("Invalid value passed into decode: {}", e.what()))) } } @@ -204,7 +207,8 @@ impl Deserialize<'a> for Block where Block: Decode { fn deserialize>(de: D) -> Result { let r = >::deserialize(de)?; - Decode::decode(&mut &r[..]).ok_or(DeError::custom("Invalid value passed into decode")) + Decode::decode(&mut &r[..]) + .map_err(|e| DeError::custom(format!("Invalid value passed into decode: {}", e.what()))) } } diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index f7d55dda79..ce67a888bc 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -1029,21 +1029,30 @@ pub trait OpaqueKeys: Clone { /// Get the raw bytes of key with key-type ID `i`. fn get_raw(&self, i: super::KeyTypeId) -> &[u8]; /// Get the decoded key with index `i`. - fn get(&self, i: super::KeyTypeId) -> Option { T::decode(&mut self.get_raw(i)) } + fn get(&self, i: super::KeyTypeId) -> Option { + T::decode(&mut self.get_raw(i)).ok() + } /// Verify a proof of ownership for the keys. fn ownership_proof_is_valid(&self, _proof: &[u8]) -> bool { true } } +/// Input that adds infinite number of zero after wrapped input. struct TrailingZeroInput<'a>(&'a [u8]); + impl<'a> codec::Input for TrailingZeroInput<'a> { - fn read(&mut self, into: &mut [u8]) -> usize { - let len = into.len().min(self.0.len()); - into[..len].copy_from_slice(&self.0[..len]); - for i in &mut into[len..] { + fn remaining_len(&mut self) -> Result, codec::Error> { + Ok(None) + } + + fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> { + let len_from_inner = into.len().min(self.0.len()); + into[..len_from_inner].copy_from_slice(&self.0[..len_from_inner]); + for i in &mut into[len_from_inner..] { *i = 0; } - self.0 = &self.0[len..]; - into.len() + self.0 = &self.0[len_from_inner..]; + + Ok(()) } } @@ -1091,7 +1100,7 @@ impl AccountIdConver x.using_encoded(|d| { if &d[0..4] != Id::TYPE_ID { return None } let mut cursor = &d[4..]; - let result = Decode::decode(&mut cursor)?; + let result = Decode::decode(&mut cursor).ok()?; if cursor.iter().all(|x| *x == 0) { Some(result) } else { @@ -1104,7 +1113,7 @@ impl AccountIdConver #[cfg(test)] mod tests { use super::AccountIdConversion; - use crate::codec::{Encode, Decode}; + use crate::codec::{Encode, Decode, Input}; #[derive(Encode, Decode, Default, PartialEq, Debug)] struct U32Value(u32); @@ -1153,6 +1162,22 @@ mod tests { let r = U16Value::try_from_account(&0x0100_c0da_f00dcafe_u64); assert!(r.is_none()); } + + #[test] + fn trailing_zero_should_work() { + let mut t = super::TrailingZeroInput(&[1, 2, 3]); + assert_eq!(t.remaining_len(), Ok(None)); + let mut buffer = [0u8; 2]; + assert_eq!(t.read(&mut buffer), Ok(())); + assert_eq!(t.remaining_len(), Ok(None)); + assert_eq!(buffer, [1, 2]); + assert_eq!(t.read(&mut buffer), Ok(())); + assert_eq!(t.remaining_len(), Ok(None)); + assert_eq!(buffer, [3, 0]); + assert_eq!(t.read(&mut buffer), Ok(())); + assert_eq!(t.remaining_len(), Ok(None)); + assert_eq!(buffer, [0, 0]); + } } /// Calls a given macro a number of times with a set of fixed params and an incrementing numeral. diff --git a/substrate/core/sr-primitives/src/transaction_validity.rs b/substrate/core/sr-primitives/src/transaction_validity.rs index a6cc43c5a3..4d5d53baf1 100644 --- a/substrate/core/sr-primitives/src/transaction_validity.rs +++ b/substrate/core/sr-primitives/src/transaction_validity.rs @@ -17,7 +17,7 @@ //! Transaction validity interface. use rstd::prelude::*; -use crate::codec::{Encode, Decode}; +use crate::codec::{Encode, Decode, Error}; use crate::traits::DispatchError; /// Priority for a transaction. Additive. Higher is better. @@ -113,9 +113,9 @@ impl ValidTransaction { } impl Decode for TransactionValidity { - fn decode(value: &mut I) -> Option { + fn decode(value: &mut I) -> Result { match value.read_byte()? { - 0 => Some(TransactionValidity::Invalid(i8::decode(value)?)), + 0 => Ok(TransactionValidity::Invalid(i8::decode(value)?)), 1 => { let priority = TransactionPriority::decode(value)?; let requires = Vec::decode(value)?; @@ -123,12 +123,12 @@ impl Decode for TransactionValidity { let longevity = TransactionLongevity::decode(value)?; let propagate = bool::decode(value).unwrap_or(true); - Some(TransactionValidity::Valid(ValidTransaction { + Ok(TransactionValidity::Valid(ValidTransaction { priority, requires, provides, longevity, propagate, })) }, - 2 => Some(TransactionValidity::Unknown(i8::decode(value)?)), - _ => None, + 2 => Ok(TransactionValidity::Unknown(i8::decode(value)?)), + _ => Err("Invalid transaction validity variant".into()), } } } @@ -143,7 +143,7 @@ mod tests { 1, 5, 0, 0, 0, 0, 0, 0, 0, 4, 16, 1, 2, 3, 4, 4, 12, 4, 5, 6, 42, 0, 0, 0, 0, 0, 0, 0 ]; - assert_eq!(TransactionValidity::decode(&mut &*old_encoding), Some(TransactionValidity::Valid(ValidTransaction { + assert_eq!(TransactionValidity::decode(&mut &*old_encoding), Ok(TransactionValidity::Valid(ValidTransaction { priority: 5, requires: vec![vec![1, 2, 3, 4]], provides: vec![vec![4, 5, 6]], @@ -169,6 +169,6 @@ mod tests { ); // decode back - assert_eq!(TransactionValidity::decode(&mut &*encoded), Some(v)); + assert_eq!(TransactionValidity::decode(&mut &*encoded), Ok(v)); } } diff --git a/substrate/core/sr-sandbox/Cargo.toml b/substrate/core/sr-sandbox/Cargo.toml index 5e3aabfd23..da80b2f213 100755 --- a/substrate/core/sr-sandbox/Cargo.toml +++ b/substrate/core/sr-sandbox/Cargo.toml @@ -12,7 +12,7 @@ rustc_version = "0.2" wasmi = { version = "0.5.0", optional = true } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } rstd = { package = "sr-std", path = "../sr-std", default-features = false } -codec = { package = "parity-codec", version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } [dev-dependencies] wabt = "~0.7.4" diff --git a/substrate/core/sr-sandbox/without_std.rs b/substrate/core/sr-sandbox/without_std.rs index 9fb255a523..ee5f7697fe 100755 --- a/substrate/core/sr-sandbox/without_std.rs +++ b/substrate/core/sr-sandbox/without_std.rs @@ -304,7 +304,7 @@ impl Instance { match result { sandbox_primitives::ERR_OK => { let return_val = sandbox_primitives::ReturnValue::decode(&mut &return_val[..]) - .ok_or(Error::Execution)?; + .map_err(|_| Error::Execution)?; Ok(return_val) } sandbox_primitives::ERR_EXECUTION => Err(Error::Execution), diff --git a/substrate/core/sr-version/Cargo.toml b/substrate/core/sr-version/Cargo.toml index e7ce3327a0..a83d1f6415 100644 --- a/substrate/core/sr-version/Cargo.toml +++ b/substrate/core/sr-version/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] impl-serde = { version = "0.1", optional = true } serde = { version = "1.0", optional = true, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../sr-std", default-features = false } sr-primitives = { path = "../sr-primitives", default-features = false } @@ -16,7 +16,7 @@ default = ["std"] std = [ "impl-serde", "serde", - "parity-codec/std", + "codec/std", "rstd/std", "sr-primitives/std", ] diff --git a/substrate/core/sr-version/src/lib.rs b/substrate/core/sr-version/src/lib.rs index 12998cecbc..cf96fe70e2 100644 --- a/substrate/core/sr-version/src/lib.rs +++ b/substrate/core/sr-version/src/lib.rs @@ -27,9 +27,9 @@ use std::collections::HashSet; #[cfg(feature = "std")] use sr_primitives::traits::RuntimeApiInfo; -use parity_codec::Encode; +use codec::Encode; #[cfg(feature = "std")] -use parity_codec::Decode; +use codec::Decode; use sr_primitives::RuntimeString; pub use sr_primitives::create_runtime_str; diff --git a/substrate/core/state-db/Cargo.toml b/substrate/core/state-db/Cargo.toml index a8dad1e84e..55d66ea5f8 100644 --- a/substrate/core/state-db/Cargo.toml +++ b/substrate/core/state-db/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" parking_lot = "0.8.0" log = "0.4" primitives = { package = "substrate-primitives", path = "../../core/primitives" } -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } [dev-dependencies] env_logger = "0.6" diff --git a/substrate/core/state-db/src/lib.rs b/substrate/core/state-db/src/lib.rs index 4434fa4ef6..43820529d4 100644 --- a/substrate/core/state-db/src/lib.rs +++ b/substrate/core/state-db/src/lib.rs @@ -35,7 +35,6 @@ mod pruning; use std::fmt; use parking_lot::RwLock; -use parity_codec as codec; use codec::Codec; use std::collections::{VecDeque, HashMap, hash_map::Entry}; use noncanonical::NonCanonicalOverlay; @@ -71,7 +70,7 @@ pub enum Error { /// Database backend error. Db(E), /// `Codec` decoding error. - Decoding, + Decoding(codec::Error), /// Trying to canonicalize invalid block. InvalidBlock, /// Trying to insert block with invalid number. @@ -82,11 +81,17 @@ pub enum Error { DiscardingPinned, } +impl From for Error { + fn from(x: codec::Error) -> Self { + Error::Decoding(x) + } +} + impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::Db(e) => e.fmt(f), - Error::Decoding => write!(f, "Error decoding slicable value"), + Error::Decoding(e) => write!(f, "Error decoding slicable value: {}", e.what()), Error::InvalidBlock => write!(f, "Trying to canonicalize invalid block"), Error::InvalidBlockNumber => write!(f, "Trying to insert block with invalid number"), Error::InvalidParent => write!(f, "Trying to insert block with unknown parent"), diff --git a/substrate/core/state-db/src/noncanonical.rs b/substrate/core/state-db/src/noncanonical.rs index 0d43389a0b..1017b8a211 100644 --- a/substrate/core/state-db/src/noncanonical.rs +++ b/substrate/core/state-db/src/noncanonical.rs @@ -23,7 +23,7 @@ use std::fmt; use std::collections::{HashMap, VecDeque, hash_map::Entry}; use super::{Error, DBValue, ChangeSet, CommitSet, MetaDb, Hash, to_meta_key}; -use crate::codec::{Encode, Decode}; +use codec::{Encode, Decode}; use log::trace; const NON_CANONICAL_JOURNAL: &[u8] = b"noncanonical_journal"; @@ -116,7 +116,7 @@ impl NonCanonicalOverlay { let last_canonicalized = db.get_meta(&to_meta_key(LAST_CANONICAL, &())) .map_err(|e| Error::Db(e))?; let last_canonicalized = match last_canonicalized { - Some(buffer) => Some(<(BlockHash, u64)>::decode(&mut buffer.as_slice()).ok_or(Error::Decoding)?), + Some(buffer) => Some(<(BlockHash, u64)>::decode(&mut buffer.as_slice())?), None => None, }; let mut levels = VecDeque::new(); @@ -134,7 +134,7 @@ impl NonCanonicalOverlay { let journal_key = to_journal_key(block, index); match db.get_meta(&journal_key).map_err(|e| Error::Db(e))? { Some(record) => { - let record: JournalRecord = Decode::decode(&mut record.as_slice()).ok_or(Error::Decoding)?; + let record: JournalRecord = Decode::decode(&mut record.as_slice())?; let inserted = record.inserted.iter().map(|(k, _)| k.clone()).collect(); let overlay = BlockOverlay { hash: record.hash.clone(), diff --git a/substrate/core/state-db/src/pruning.rs b/substrate/core/state-db/src/pruning.rs index 078745c7a2..21f472fe69 100644 --- a/substrate/core/state-db/src/pruning.rs +++ b/substrate/core/state-db/src/pruning.rs @@ -23,7 +23,7 @@ //! The changes are journaled in the DB. use std::collections::{HashMap, HashSet, VecDeque}; -use crate::codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::{CommitSet, Error, MetaDb, to_meta_key, Hash}; use log::{trace, warn}; @@ -69,7 +69,7 @@ impl RefWindow { let last_pruned = db.get_meta(&to_meta_key(LAST_PRUNED, &())) .map_err(|e| Error::Db(e))?; let pending_number: u64 = match last_pruned { - Some(buffer) => u64::decode(&mut buffer.as_slice()).ok_or(Error::Decoding)? + 1, + Some(buffer) => u64::decode(&mut buffer.as_slice())? + 1, None => 0, }; let mut block = pending_number; @@ -86,7 +86,7 @@ impl RefWindow { let journal_key = to_journal_key(block); match db.get_meta(&journal_key).map_err(|e| Error::Db(e))? { Some(record) => { - let record: JournalRecord = Decode::decode(&mut record.as_slice()).ok_or(Error::Decoding)?; + let record: JournalRecord = Decode::decode(&mut record.as_slice())?; trace!(target: "state-db", "Pruning journal entry {} ({} inserted, {} deleted)", block, record.inserted.len(), record.deleted.len()); pruning.import(&record.hash, journal_key, record.inserted.into_iter(), record.deleted); }, diff --git a/substrate/core/state-machine/Cargo.toml b/substrate/core/state-machine/Cargo.toml index c7a15bf957..bb00cfcbb7 100644 --- a/substrate/core/state-machine/Cargo.toml +++ b/substrate/core/state-machine/Cargo.toml @@ -14,7 +14,7 @@ trie-root = "0.15.0" trie = { package = "substrate-trie", path = "../trie" } primitives = { package = "substrate-primitives", path = "../primitives" } panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" } -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } num-traits = "0.2" [dev-dependencies] diff --git a/substrate/core/state-machine/src/changes_trie/build.rs b/substrate/core/state-machine/src/changes_trie/build.rs index d32d28906f..e1e3f6a808 100644 --- a/substrate/core/state-machine/src/changes_trie/build.rs +++ b/substrate/core/state-machine/src/changes_trie/build.rs @@ -18,7 +18,7 @@ use std::collections::BTreeMap; use std::collections::btree_map::Entry; -use parity_codec::Decode; +use codec::Decode; use hash_db::Hasher; use num_traits::One; use crate::backend::Backend; @@ -156,13 +156,13 @@ fn prepare_digest_input<'a, S, H, Number>( let extrinsic_prefix = ExtrinsicIndex::key_neutral_prefix(digest_build_block.clone()); trie_storage.for_keys_with_prefix(&extrinsic_prefix, |key| - if let Some(InputKey::ExtrinsicIndex::(trie_key)) = Decode::decode(&mut &key[..]) { + if let Ok(InputKey::ExtrinsicIndex::(trie_key)) = Decode::decode(&mut &key[..]) { insert_to_map(trie_key.key); }); let digest_prefix = DigestIndex::key_neutral_prefix(digest_build_block.clone()); trie_storage.for_keys_with_prefix(&digest_prefix, |key| - if let Some(InputKey::DigestIndex::(trie_key)) = Decode::decode(&mut &key[..]) { + if let Ok(InputKey::DigestIndex::(trie_key)) = Decode::decode(&mut &key[..]) { insert_to_map(trie_key.key); }); @@ -173,7 +173,7 @@ fn prepare_digest_input<'a, S, H, Number>( #[cfg(test)] mod test { - use parity_codec::Encode; + use codec::Encode; use primitives::Blake2Hasher; use primitives::storage::well_known_keys::EXTRINSIC_INDEX; use crate::backend::InMemory; diff --git a/substrate/core/state-machine/src/changes_trie/changes_iterator.rs b/substrate/core/state-machine/src/changes_trie/changes_iterator.rs index 66d09c98d4..f7342cc60f 100644 --- a/substrate/core/state-machine/src/changes_trie/changes_iterator.rs +++ b/substrate/core/state-machine/src/changes_trie/changes_iterator.rs @@ -19,7 +19,7 @@ use std::cell::RefCell; use std::collections::VecDeque; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; use num_traits::One; use trie::{Recorder, MemoryDB}; @@ -249,8 +249,7 @@ impl<'a, RS, S, H, Number> DrilldownIteratorEssence<'a, RS, S, H, Number> let extrinsics_key = ExtrinsicIndex { block: block.clone(), key: self.key.to_vec() }.encode(); let extrinsics = trie_reader(&self.storage, trie_root, &extrinsics_key); if let Some(extrinsics) = extrinsics? { - let extrinsics: Option = Decode::decode(&mut &extrinsics[..]); - if let Some(extrinsics) = extrinsics { + if let Ok(extrinsics) = ExtrinsicIndexValue::decode(&mut &extrinsics[..]) { self.extrinsics.extend(extrinsics.into_iter().rev().map(|e| (block.clone(), e))); } } @@ -259,8 +258,7 @@ impl<'a, RS, S, H, Number> DrilldownIteratorEssence<'a, RS, S, H, Number> let blocks_key = DigestIndex { block: block.clone(), key: self.key.to_vec() }.encode(); let blocks = trie_reader(&self.storage, trie_root, &blocks_key); if let Some(blocks) = blocks? { - let blocks: Option> = Decode::decode(&mut &blocks[..]); - if let Some(blocks) = blocks { + if let Ok(blocks) = >::decode(&mut &blocks[..]) { // filter level0 blocks here because we tend to use digest blocks, // AND digest block changes could also include changes for out-of-range blocks let begin = self.begin.clone(); diff --git a/substrate/core/state-machine/src/changes_trie/input.rs b/substrate/core/state-machine/src/changes_trie/input.rs index ae939c028b..8da4f1a386 100644 --- a/substrate/core/state-machine/src/changes_trie/input.rs +++ b/substrate/core/state-machine/src/changes_trie/input.rs @@ -16,7 +16,7 @@ //! Different types of changes trie input pairs. -use parity_codec::{Decode, Encode, Input, Output}; +use codec::{Decode, Encode, Input, Output, Error}; use crate::changes_trie::BlockNumber; /// Key of { changed key => set of extrinsic indices } mapping. @@ -95,6 +95,8 @@ impl Encode for ExtrinsicIndex { } } +impl codec::EncodeLike for ExtrinsicIndex {} + impl DigestIndex { pub fn key_neutral_prefix(block: Number) -> Vec { let mut prefix = vec![2]; @@ -112,18 +114,20 @@ impl Encode for DigestIndex { } } +impl codec::EncodeLike for DigestIndex {} + impl Decode for InputKey { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> Result { match input.read_byte()? { - 1 => Some(InputKey::ExtrinsicIndex(ExtrinsicIndex { + 1 => Ok(InputKey::ExtrinsicIndex(ExtrinsicIndex { block: Decode::decode(input)?, key: Decode::decode(input)?, })), - 2 => Some(InputKey::DigestIndex(DigestIndex { + 2 => Ok(InputKey::DigestIndex(DigestIndex { block: Decode::decode(input)?, key: Decode::decode(input)?, })), - _ => None, + _ => Err("Invalid input key variant".into()), } } } diff --git a/substrate/core/state-machine/src/changes_trie/mod.rs b/substrate/core/state-machine/src/changes_trie/mod.rs index 48ba9eac95..b29a515d74 100644 --- a/substrate/core/state-machine/src/changes_trie/mod.rs +++ b/substrate/core/state-machine/src/changes_trie/mod.rs @@ -49,7 +49,7 @@ pub use self::prune::{prune, oldest_non_pruned_trie}; use hash_db::{Hasher, Prefix}; use crate::backend::Backend; use num_traits::{One, Zero}; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use primitives; use crate::changes_trie::build::prepare_input; use crate::overlayed_changes::OverlayedChanges; diff --git a/substrate/core/state-machine/src/ext.rs b/substrate/core/state-machine/src/ext.rs index 7f0fa1de3f..8c54806dd9 100644 --- a/substrate/core/state-machine/src/ext.rs +++ b/substrate/core/state-machine/src/ext.rs @@ -338,7 +338,7 @@ where #[cfg(test)] mod tests { use hex_literal::hex; - use parity_codec::Encode; + use codec::Encode; use primitives::{Blake2Hasher}; use primitives::storage::well_known_keys::EXTRINSIC_INDEX; use crate::backend::InMemory; diff --git a/substrate/core/state-machine/src/lib.rs b/substrate/core/state-machine/src/lib.rs index d2ffc23b78..b98228e9b2 100644 --- a/substrate/core/state-machine/src/lib.rs +++ b/substrate/core/state-machine/src/lib.rs @@ -22,7 +22,7 @@ use std::{fmt, panic::UnwindSafe, result, marker::PhantomData}; use std::borrow::Cow; use log::warn; use hash_db::Hasher; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use primitives::{ storage::well_known_keys, NativeOrEncoded, NeverNativeValue, offchain, }; @@ -938,7 +938,7 @@ pub(crate) fn set_changes_trie_config( ) -> Result<(), Box> { let config = match config { Some(v) => Some(Decode::decode(&mut &v[..]) - .ok_or_else(|| Box::new("Failed to decode changes trie configuration".to_owned()) as Box)?), + .map_err(|_| Box::new("Failed to decode changes trie configuration".to_owned()) as Box)?), None => None, }; @@ -972,7 +972,7 @@ where #[cfg(test)] mod tests { use std::collections::HashMap; - use parity_codec::Encode; + use codec::Encode; use overlayed_changes::OverlayedValue; use super::*; use super::backend::InMemory; diff --git a/substrate/core/state-machine/src/overlayed_changes.rs b/substrate/core/state-machine/src/overlayed_changes.rs index 34bf8ca3c5..8c4160760b 100644 --- a/substrate/core/state-machine/src/overlayed_changes.rs +++ b/substrate/core/state-machine/src/overlayed_changes.rs @@ -18,7 +18,7 @@ #[cfg(test)] use std::iter::FromIterator; use std::collections::{HashMap, BTreeSet}; -use parity_codec::Decode; +use codec::Decode; use crate::changes_trie::{NO_EXTRINSIC_INDEX, Configuration as ChangesTrieConfig}; use primitives::storage::well_known_keys::EXTRINSIC_INDEX; @@ -267,7 +267,7 @@ impl OverlayedChanges { /// Inserts storage entry responsible for current extrinsic index. #[cfg(test)] pub(crate) fn set_extrinsic_index(&mut self, extrinsic_index: u32) { - use parity_codec::Encode; + use codec::Encode; self.prospective.top.insert(EXTRINSIC_INDEX.to_vec(), OverlayedValue { value: Some(extrinsic_index.encode()), extrinsics: None, @@ -284,7 +284,7 @@ impl OverlayedChanges { match self.changes_trie_config.is_some() { true => Some( self.storage(EXTRINSIC_INDEX) - .and_then(|idx| idx.and_then(|idx| Decode::decode(&mut &*idx))) + .and_then(|idx| idx.and_then(|idx| Decode::decode(&mut &*idx).ok())) .unwrap_or(NO_EXTRINSIC_INDEX)), false => None, } diff --git a/substrate/core/state-machine/src/testing.rs b/substrate/core/state-machine/src/testing.rs index 73c0b38ef4..89290a59e2 100644 --- a/substrate/core/state-machine/src/testing.rs +++ b/substrate/core/state-machine/src/testing.rs @@ -27,7 +27,7 @@ use crate::changes_trie::{ }; use primitives::offchain; use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES}; -use parity_codec::Encode; +use codec::Encode; use super::{ChildStorageKey, Externalities, OverlayedChanges}; const EXT_NOT_ALLOWED_TO_FAIL: &str = "Externalities not allowed to fail within runtime"; diff --git a/substrate/core/state-machine/src/trie_backend.rs b/substrate/core/state-machine/src/trie_backend.rs index 18c1b0eeca..739044dd50 100644 --- a/substrate/core/state-machine/src/trie_backend.rs +++ b/substrate/core/state-machine/src/trie_backend.rs @@ -194,9 +194,8 @@ impl, H: Hasher> Backend for TrieBackend where pub mod tests { use std::collections::HashSet; use primitives::{Blake2Hasher, H256}; - use parity_codec::Encode; - use trie::{TrieMut, PrefixedMemoryDB}; - use trie::trie_types::TrieDBMut; + use codec::Encode; + use trie::{TrieMut, PrefixedMemoryDB, trie_types::TrieDBMut}; use super::*; fn test_db() -> (PrefixedMemoryDB, H256) { diff --git a/substrate/core/test-client/Cargo.toml b/substrate/core/test-client/Cargo.toml index bd3b0db2ce..163cc2ab14 100644 --- a/substrate/core/test-client/Cargo.toml +++ b/substrate/core/test-client/Cargo.toml @@ -12,7 +12,7 @@ executor = { package = "substrate-executor", path = "../executor" } futures-preview = "0.3.0-alpha.17" hash-db = "0.15.0" keyring = { package = "substrate-keyring", path = "../keyring" } -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } primitives = { package = "substrate-primitives", path = "../primitives" } sr-primitives = { path = "../sr-primitives" } state_machine = { package = "substrate-state-machine", path = "../state-machine" } diff --git a/substrate/core/test-client/src/client_ext.rs b/substrate/core/test-client/src/client_ext.rs index a256dd8be5..b29a7db471 100644 --- a/substrate/core/test-client/src/client_ext.rs +++ b/substrate/core/test-client/src/client_ext.rs @@ -26,7 +26,7 @@ use sr_primitives::Justification; use sr_primitives::traits::{Block as BlockT}; use sr_primitives::generic::BlockId; use primitives::Blake2Hasher; -use parity_codec::alloc::collections::hash_map::HashMap; +use codec::alloc::collections::hash_map::HashMap; /// Extension trait for a test client. pub trait ClientExt: Sized { diff --git a/substrate/core/test-runtime/Cargo.toml b/substrate/core/test-runtime/Cargo.toml index 03ba10c5fb..03c95a5c27 100644 --- a/substrate/core/test-runtime/Cargo.toml +++ b/substrate/core/test-runtime/Cargo.toml @@ -8,7 +8,7 @@ build = "build.rs" [dependencies] log = { version = "0.4", optional = true } serde = { version = "1.0", optional = true, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } keyring = { package = "substrate-keyring", path = "../keyring", optional = true } substrate-client = { path = "../client", default-features = false } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } @@ -48,7 +48,7 @@ std = [ "serde", "substrate-client/std", "keyring", - "parity-codec/std", + "codec/std", "rstd/std", "runtime_io/std", "runtime_support/std", diff --git a/substrate/core/test-runtime/src/genesismap.rs b/substrate/core/test-runtime/src/genesismap.rs index da7d9cf4ef..8d5be8355e 100644 --- a/substrate/core/test-runtime/src/genesismap.rs +++ b/substrate/core/test-runtime/src/genesismap.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use runtime_io::{blake2_256, twox_128}; use super::{AuthorityId, AccountId, WASM_BINARY}; -use parity_codec::{Encode, KeyedVec, Joiner}; +use codec::{Encode, KeyedVec, Joiner}; use primitives::{ChangesTrieConfiguration, map, storage::well_known_keys}; use sr_primitives::traits::Block; diff --git a/substrate/core/test-runtime/src/lib.rs b/substrate/core/test-runtime/src/lib.rs index 98d2437059..6492d27bbe 100644 --- a/substrate/core/test-runtime/src/lib.rs +++ b/substrate/core/test-runtime/src/lib.rs @@ -23,7 +23,7 @@ pub mod genesismap; pub mod system; use rstd::{prelude::*, marker::PhantomData}; -use parity_codec::{Encode, Decode, Input}; +use codec::{Encode, Decode, Input, Error}; use primitives::Blake2Hasher; use trie_db::{TrieMut, Trie}; @@ -214,6 +214,8 @@ impl Encode for DecodeFails { } } +impl codec::EncodeLike for DecodeFails {} + impl DecodeFails { /// Create a new instance. pub fn new() -> DecodeFails { @@ -224,9 +226,8 @@ impl DecodeFails { } impl Decode for DecodeFails { - fn decode(_: &mut I) -> Option { - // decoding always fails - None + fn decode(_: &mut I) -> Result { + Err("DecodeFails always fails".into()) } } diff --git a/substrate/core/test-runtime/src/system.rs b/substrate/core/test-runtime/src/system.rs index 30cd105328..c108672c83 100644 --- a/substrate/core/test-runtime/src/system.rs +++ b/substrate/core/test-runtime/src/system.rs @@ -25,7 +25,7 @@ use sr_primitives::traits::{Hash as HashT, BlakeTwo256, Header as _}; use sr_primitives::generic; use sr_primitives::{ApplyError, ApplyOutcome, ApplyResult}; use sr_primitives::transaction_validity::{TransactionValidity, ValidTransaction}; -use parity_codec::{KeyedVec, Encode}; +use codec::{KeyedVec, Encode}; use super::{ AccountId, BlockNumber, Extrinsic, Transfer, H256 as Hash, Block, Header, Digest, AuthorityId }; diff --git a/substrate/core/transaction-pool/Cargo.toml b/substrate/core/transaction-pool/Cargo.toml index 6d2465922b..c18a50778d 100644 --- a/substrate/core/transaction-pool/Cargo.toml +++ b/substrate/core/transaction-pool/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" derive_more = "0.14.0" futures = "0.1" log = "0.4" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } parking_lot = "0.8.0" sr-primitives = { path = "../sr-primitives" } client = { package = "substrate-client", path = "../client" } diff --git a/substrate/core/transaction-pool/graph/Cargo.toml b/substrate/core/transaction-pool/graph/Cargo.toml index 2ecb6ab188..8010b07ac4 100644 --- a/substrate/core/transaction-pool/graph/Cargo.toml +++ b/substrate/core/transaction-pool/graph/Cargo.toml @@ -16,5 +16,5 @@ sr-primitives = { path = "../../sr-primitives" } [dev-dependencies] assert_matches = "1.3.0" env_logger = "0.6.1" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } test_runtime = { package = "substrate-test-runtime", path = "../../test-runtime" } diff --git a/substrate/core/transaction-pool/graph/src/pool.rs b/substrate/core/transaction-pool/graph/src/pool.rs index 8f76a17ed9..6eec0d222f 100644 --- a/substrate/core/transaction-pool/graph/src/pool.rs +++ b/substrate/core/transaction-pool/graph/src/pool.rs @@ -454,7 +454,7 @@ mod tests { use super::*; use sr_primitives::transaction_validity::ValidTransaction; use futures::Stream; - use parity_codec::Encode; + use codec::Encode; use test_runtime::{Block, Extrinsic, Transfer, H256, AccountId}; use assert_matches::assert_matches; use crate::watcher; diff --git a/substrate/core/transaction-pool/src/api.rs b/substrate/core/transaction-pool/src/api.rs index 668a9b8013..c0c4c787a5 100644 --- a/substrate/core/transaction-pool/src/api.rs +++ b/substrate/core/transaction-pool/src/api.rs @@ -21,7 +21,7 @@ use std::{ marker::PhantomData, }; use client::{runtime_api::TaggedTransactionQueue, blockchain::HeaderBackend}; -use parity_codec::Encode; +use codec::Encode; use txpool; use primitives::{ H256, diff --git a/substrate/core/transaction-pool/src/tests.rs b/substrate/core/transaction-pool/src/tests.rs index 7fb94936d2..71ed988e5e 100644 --- a/substrate/core/transaction-pool/src/tests.rs +++ b/substrate/core/transaction-pool/src/tests.rs @@ -17,7 +17,7 @@ use super::*; -use parity_codec::Encode; +use codec::Encode; use txpool::{self, Pool}; use test_client::{runtime::{AccountId, Block, Hash, Index, Extrinsic, Transfer}, AccountKeyring::{self, *}}; use sr_primitives::{ diff --git a/substrate/core/trie/Cargo.toml b/substrate/core/trie/Cargo.toml index 8659462bc4..82945d90f3 100644 --- a/substrate/core/trie/Cargo.toml +++ b/substrate/core/trie/Cargo.toml @@ -2,7 +2,7 @@ name = "substrate-trie" version = "2.0.0" authors = ["Parity Technologies "] -description = "Patricia trie stuff using a parity-codec node format" +description = "Patricia trie stuff using a parity-scale-codec node format" repository = "https://github.com/paritytech/parity-common" license = "GPL-3.0" edition = "2018" @@ -12,7 +12,7 @@ name = "bench" harness = false [dependencies] -codec = { package = "parity-codec", version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } rstd = { package = "sr-std", path = "../sr-std", default-features = false } hash-db = { version = "0.15.0", default-features = false } trie-db = { version = "0.15.0", default-features = false } diff --git a/substrate/core/trie/src/error.rs b/substrate/core/trie/src/error.rs index 1e386146d3..c18db37f35 100644 --- a/substrate/core/trie/src/error.rs +++ b/substrate/core/trie/src/error.rs @@ -12,22 +12,36 @@ use std::fmt; use std::error::Error as StdError; #[derive(Debug, PartialEq, Eq, Clone)] -/// Error concerning the Parity-Codec based decoder. +/// Error for trie node decoding. pub enum Error { /// Bad format. BadFormat, + /// Decoding error. + Decode(codec::Error) +} + +impl From for Error { + fn from(x: codec::Error) -> Self { + Error::Decode(x) + } } #[cfg(feature="std")] impl StdError for Error { fn description(&self) -> &str { - "codec error" + match self { + Error::BadFormat => "Bad format error", + Error::Decode(_) => "Decoding error", + } } } #[cfg(feature="std")] impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self, f) + match self { + Error::Decode(e) => write!(f, "Decode error: {}", e.what()), + Error::BadFormat => write!(f, "Bad format"), + } } } diff --git a/substrate/core/trie/src/node_codec.rs b/substrate/core/trie/src/node_codec.rs index 8c01beda6b..950f0c726f 100644 --- a/substrate/core/trie/src/node_codec.rs +++ b/substrate/core/trie/src/node_codec.rs @@ -49,7 +49,7 @@ impl NodeCodecT for NodeCodec { fn decode(data: &[u8]) -> rstd::result::Result { let input = &mut &*data; - let head = NodeHeader::decode(input).ok_or(Error::BadFormat)?; + let head = NodeHeader::decode(input)?; match head { NodeHeader::Null => Ok(Node::Empty), NodeHeader::Branch(has_value, nibble_count) => { @@ -69,7 +69,7 @@ impl NodeCodecT for NodeCodec { let bitmap_slice = take(input, BITMAP_LENGTH).ok_or(Error::BadFormat)?; let bitmap = Bitmap::decode(&bitmap_slice[..])?; let value = if has_value { - let count = >::decode(input).ok_or(Error::BadFormat)?.0 as usize; + let count = >::decode(input)?.0 as usize; Some(take(input, count).ok_or(Error::BadFormat)?) } else { None @@ -78,7 +78,7 @@ impl NodeCodecT for NodeCodec { for i in 0..nibble_ops::NIBBLE_LENGTH { if bitmap.value_at(i) { - let count = >::decode(input).ok_or(Error::BadFormat)?.0 as usize; + let count = >::decode(input)?.0 as usize; children[i] = Some(take(input, count).ok_or(Error::BadFormat)?); } } @@ -98,7 +98,7 @@ impl NodeCodecT for NodeCodec { nibble_data, nibble_ops::number_padding(nibble_count), ); - let count = >::decode(input).ok_or(Error::BadFormat)?.0 as usize; + let count = >::decode(input)?.0 as usize; Ok(Node::Leaf(nibble_slice, take(input, count).ok_or(Error::BadFormat)?)) } } @@ -229,11 +229,8 @@ const BITMAP_LENGTH: usize = 2; pub(crate) struct Bitmap(u16); impl Bitmap { - pub fn decode(data: &[u8]) -> Result { - u16::decode(&mut &data[..]) - .ok_or(Error::BadFormat) - .map(|v|Bitmap(v)) + Ok(Bitmap(u16::decode(&mut &data[..])?)) } pub fn value_at(&self, i: usize) -> bool { diff --git a/substrate/core/trie/src/node_header.rs b/substrate/core/trie/src/node_header.rs index e4c38bd075..50d3d87250 100644 --- a/substrate/core/trie/src/node_header.rs +++ b/substrate/core/trie/src/node_header.rs @@ -50,18 +50,20 @@ impl Encode for NodeHeader { } } +impl codec::EncodeLike for NodeHeader {} + impl Decode for NodeHeader { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> Result { let i = input.read_byte()?; if i == trie_constants::EMPTY_TRIE { - return Some(NodeHeader::Null); + return Ok(NodeHeader::Null); } match i & (0b11 << 6) { - trie_constants::LEAF_PREFIX_MASK => Some(NodeHeader::Leaf(decode_size(i, input)?)), - trie_constants::BRANCH_WITHOUT_MASK => Some(NodeHeader::Branch(false, decode_size(i, input)?)), - trie_constants::BRANCH_WITH_MASK => Some(NodeHeader::Branch(true, decode_size(i, input)?)), + trie_constants::LEAF_PREFIX_MASK => Ok(NodeHeader::Leaf(decode_size(i, input)?)), + trie_constants::BRANCH_WITHOUT_MASK => Ok(NodeHeader::Branch(false, decode_size(i, input)?)), + trie_constants::BRANCH_WITH_MASK => Ok(NodeHeader::Branch(true, decode_size(i, input)?)), // do not allow any special encoding - _ => None, + _ => Err("Unallowed encoding".into()), } } } @@ -103,18 +105,18 @@ fn encode_size_and_prefix(size: usize, prefix: u8, out: &mut impl Output) { } /// Decode size only from stream input and header byte. -fn decode_size(first: u8, input: &mut impl Input) -> Option { +fn decode_size(first: u8, input: &mut impl Input) -> Result { let mut result = (first & 255u8 >> 2) as usize; if result < 63 { - return Some(result); + return Ok(result); } result -= 1; while result <= trie_constants::NIBBLE_SIZE_BOUND { let n = input.read_byte()? as usize; if n < 255 { - return Some(result + n + 1); + return Ok(result + n + 1); } result += 255; } - Some(trie_constants::NIBBLE_SIZE_BOUND) + Ok(trie_constants::NIBBLE_SIZE_BOUND) } diff --git a/substrate/core/utils/fork-tree/Cargo.toml b/substrate/core/utils/fork-tree/Cargo.toml index c41914e07a..fa37161dc2 100644 --- a/substrate/core/utils/fork-tree/Cargo.toml +++ b/substrate/core/utils/fork-tree/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } diff --git a/substrate/core/utils/fork-tree/src/lib.rs b/substrate/core/utils/fork-tree/src/lib.rs index c6debe859a..5a7480e065 100644 --- a/substrate/core/utils/fork-tree/src/lib.rs +++ b/substrate/core/utils/fork-tree/src/lib.rs @@ -20,7 +20,7 @@ #![warn(missing_docs)] use std::fmt; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; /// Error occured when iterating with the tree. #[derive(Clone, Debug, PartialEq)] diff --git a/substrate/node-template/Cargo.toml b/substrate/node-template/Cargo.toml index ad626beb0b..ea48ff7f68 100644 --- a/substrate/node-template/Cargo.toml +++ b/substrate/node-template/Cargo.toml @@ -17,7 +17,7 @@ log = "0.4" tokio = "0.1" exit-future = "0.1" parking_lot = "0.8.0" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } trie-root = "0.15.0" sr-io = { path = "../core/sr-io" } substrate-cli = { path = "../core/cli" } diff --git a/substrate/node-template/runtime/Cargo.toml b/substrate/node-template/runtime/Cargo.toml index 1bde247930..878374cf6a 100644 --- a/substrate/node-template/runtime/Cargo.toml +++ b/substrate/node-template/runtime/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } safe-mix = { version = "1.0", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default_features = false } runtime-io = { package = "sr-io", path = "../../core/sr-io", default_features = false } version = { package = "sr-version", path = "../../core/sr-version", default_features = false } @@ -31,7 +31,7 @@ wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1. [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "client/std", "rstd/std", "runtime-io/std", diff --git a/substrate/node/cli/Cargo.toml b/substrate/node/cli/Cargo.toml index d3d48ebe01..f95f688ac3 100644 --- a/substrate/node/cli/Cargo.toml +++ b/substrate/node/cli/Cargo.toml @@ -12,7 +12,7 @@ tokio = "0.1.7" futures = "0.1" exit-future = "0.1" cli = { package = "substrate-cli", path = "../../core/cli" } -parity-codec = { version = "4.1.1" } +codec = { package = "parity-scale-codec", version = "1.0.0" } sr-io = { path = "../../core/sr-io" } client = { package = "substrate-client", path = "../../core/client" } primitives = { package = "substrate-primitives", path = "../../core/primitives" } diff --git a/substrate/node/cli/src/factory_impl.rs b/substrate/node/cli/src/factory_impl.rs index dffd084c5f..41ac992abb 100644 --- a/substrate/node/cli/src/factory_impl.rs +++ b/substrate/node/cli/src/factory_impl.rs @@ -21,11 +21,10 @@ use rand::{Rng, SeedableRng}; use rand::rngs::StdRng; -use parity_codec::Decode; +use codec::{Encode, Decode}; use keyring::sr25519::Keyring; use node_runtime::{Call, CheckedExtrinsic, UncheckedExtrinsic, SignedExtra, BalancesCall, ExistentialDeposit}; use primitives::{sr25519, crypto::Pair}; -use parity_codec::Encode; use sr_primitives::{generic::Era, traits::{Block as BlockT, Header as HeaderT, SignedExtension}}; use substrate_service::ServiceFactory; use transaction_factory::RuntimeAdapter; diff --git a/substrate/node/cli/src/service.rs b/substrate/node/cli/src/service.rs index 8fbd425da3..0b887bb55a 100644 --- a/substrate/node/cli/src/service.rs +++ b/substrate/node/cli/src/service.rs @@ -265,7 +265,7 @@ mod tests { use node_primitives::DigestItem; use node_runtime::{BalancesCall, Call, UncheckedExtrinsic}; use node_runtime::constants::{currency::CENTS, time::SLOT_DURATION}; - use parity_codec::{Encode, Decode}; + use codec::{Encode, Decode}; use primitives::{ crypto::Pair as CryptoPair, blake2_256, sr25519::Public as AddressPublic, H256, diff --git a/substrate/node/executor/Cargo.toml b/substrate/node/executor/Cargo.toml index 44a56ee4a6..d1886c2ab6 100644 --- a/substrate/node/executor/Cargo.toml +++ b/substrate/node/executor/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] trie-root = "0.15.0" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } runtime_io = { package = "sr-io", path = "../../core/sr-io" } state_machine = { package = "substrate-state-machine", path = "../../core/state-machine" } substrate-executor = { path = "../../core/executor" } diff --git a/substrate/node/executor/src/lib.rs b/substrate/node/executor/src/lib.rs index 572d0ca149..711fdcdb69 100644 --- a/substrate/node/executor/src/lib.rs +++ b/substrate/node/executor/src/lib.rs @@ -40,7 +40,7 @@ mod tests { use {balances, contracts, indices, staking, system, timestamp}; use runtime_io; use substrate_executor::WasmExecutor; - use parity_codec::{Encode, Decode, Joiner}; + use codec::{Encode, Decode, Joiner}; use keyring::{AccountKeyring, Ed25519Keyring, Sr25519Keyring}; use runtime_support::{Hashable, StorageValue, StorageMap, assert_eq_error_rate, traits::Currency}; use state_machine::{CodeExecutor, Externalities, TestExternalities as CoreTestExternalities}; diff --git a/substrate/node/primitives/Cargo.toml b/substrate/node/primitives/Cargo.toml index 36ea1eb414..05fb231205 100644 --- a/substrate/node/primitives/Cargo.toml +++ b/substrate/node/primitives/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -18,7 +18,7 @@ pretty_assertions = "0.5" [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "sr-primitives/std", diff --git a/substrate/node/runtime/Cargo.toml b/substrate/node/runtime/Cargo.toml index c40e6d7796..da6180889e 100644 --- a/substrate/node/runtime/Cargo.toml +++ b/substrate/node/runtime/Cargo.toml @@ -8,7 +8,7 @@ build = "build.rs" [dependencies] integer-sqrt = { version = "0.1.2" } safe-mix = { version = "1.0", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } client = { package = "substrate-client", path = "../../core/client", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } @@ -50,7 +50,7 @@ no_std = [ "contracts/core", ] std = [ - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "sr-primitives/std", diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 06285571ba..f89e1f4a86 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 129, - impl_version: 129, + impl_version: 130, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/srml/assets/Cargo.toml b/substrate/srml/assets/Cargo.toml index d1526c8be8..2badb46130 100644 --- a/substrate/srml/assets/Cargo.toml +++ b/substrate/srml/assets/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } # Needed for various traits. In our case, `OnFinalize`. sr-primitives = { path = "../../core/sr-primitives", default-features = false } # Needed for type-safe access to storage DB. @@ -23,7 +23,7 @@ runtime_io = { package = "sr-io", path = "../../core/sr-io" } default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "sr-primitives/std", "srml-support/std", "system/std", diff --git a/substrate/srml/aura/Cargo.toml b/substrate/srml/aura/Cargo.toml index 9ce3658283..6ce9c87c5c 100644 --- a/substrate/srml/aura/Cargo.toml +++ b/substrate/srml/aura/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } serde = { version = "1.0", optional = true } inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } @@ -27,7 +27,7 @@ runtime_io = { package = "sr-io", path = "../../core/sr-io" } default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "rstd/std", "srml-support/std", "sr-primitives/std", diff --git a/substrate/srml/aura/src/lib.rs b/substrate/srml/aura/src/lib.rs index 1402cb1d9e..a79b5c46a5 100644 --- a/substrate/srml/aura/src/lib.rs +++ b/substrate/srml/aura/src/lib.rs @@ -51,7 +51,7 @@ pub use timestamp; use rstd::{result, prelude::*}; -use parity_codec::Encode; +use codec::Encode; use srml_support::{decl_storage, decl_module, Parameter, storage::StorageValue, traits::Get}; use sr_primitives::{ traits::{SaturatedConversion, Saturating, Zero, One, Member, IsMember, TypedKey}, @@ -65,7 +65,7 @@ use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent use inherents::{InherentDataProviders, ProvideInherentData}; use substrate_consensus_aura_primitives::{AURA_ENGINE_ID, ConsensusLog}; #[cfg(feature = "std")] -use parity_codec::Decode; +use codec::Decode; mod mock; mod tests; @@ -138,7 +138,7 @@ impl ProvideInherentData for InherentDataProvider { } fn error_to_string(&self, error: &[u8]) -> Option { - RuntimeString::decode(&mut &error[..]).map(Into::into) + RuntimeString::decode(&mut &error[..]).map(Into::into).ok() } } diff --git a/substrate/srml/authorship/Cargo.toml b/substrate/srml/authorship/Cargo.toml index 29de88ba2c..f470675b4b 100644 --- a/substrate/srml/authorship/Cargo.toml +++ b/substrate/srml/authorship/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } srml-support = { path = "../support", default-features = false } @@ -17,7 +17,7 @@ runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "primitives/std", "sr-primitives/std", "rstd/std", diff --git a/substrate/srml/authorship/src/lib.rs b/substrate/srml/authorship/src/lib.rs index 2325dac5f3..e46e2f232d 100644 --- a/substrate/srml/authorship/src/lib.rs +++ b/substrate/srml/authorship/src/lib.rs @@ -25,7 +25,7 @@ use rstd::collections::btree_set::BTreeSet; use srml_support::{decl_module, decl_storage, for_each_tuple, StorageValue}; use srml_support::traits::{FindAuthor, VerifySeal, Get}; use srml_support::dispatch::Result as DispatchResult; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use system::ensure_none; use sr_primitives::traits::{SimpleArithmetic, Header as HeaderT, One, Zero}; use sr_primitives::weights::SimpleDispatchInfo; @@ -382,7 +382,7 @@ mod tests { { for (id, data) in digests { if id == TEST_ID { - return u64::decode(&mut &data[..]); + return u64::decode(&mut &data[..]).ok(); } } @@ -409,8 +409,8 @@ mod tests { for (id, seal) in seals { if id == TEST_ID { match u64::decode(&mut &seal[..]) { - None => return Err("wrong seal"), - Some(a) => { + Err(_) => return Err("wrong seal"), + Ok(a) => { if a != author { return Err("wrong author in seal"); } diff --git a/substrate/srml/babe/Cargo.toml b/substrate/srml/babe/Cargo.toml index ba47d8e278..2e2d3c84b0 100644 --- a/substrate/srml/babe/Cargo.toml +++ b/substrate/srml/babe/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] hex-literal = "0.2" -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } serde = { version = "1.0.93", optional = true } inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } @@ -28,7 +28,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "rstd/std", "srml-support/std", "sr-primitives/std", diff --git a/substrate/srml/babe/src/lib.rs b/substrate/srml/babe/src/lib.rs index 8e72fdffd4..02099aace8 100644 --- a/substrate/srml/babe/src/lib.rs +++ b/substrate/srml/babe/src/lib.rs @@ -28,7 +28,7 @@ use sr_primitives::{generic::DigestItem, ConsensusEngineId}; use sr_primitives::traits::{IsMember, SaturatedConversion, Saturating, RandomnessBeacon, Convert}; #[cfg(feature = "std")] use timestamp::TimestampInherentData; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; @@ -103,7 +103,7 @@ impl ProvideInherentData for InherentDataProvider { } fn error_to_string(&self, error: &[u8]) -> Option { - RuntimeString::decode(&mut &error[..]).map(Into::into) + RuntimeString::decode(&mut &error[..]).map(Into::into).ok() } } @@ -186,7 +186,7 @@ decl_module! { .iter() .filter_map(|s| s.as_pre_runtime()) .filter_map(|(id, mut data)| if id == BABE_ENGINE_ID { - RawBabePreDigest::decode(&mut data) + RawBabePreDigest::decode(&mut data).ok() } else { None }) @@ -219,7 +219,7 @@ impl FindAuthor for Module { { for (id, mut data) in digests.into_iter() { if id == BABE_ENGINE_ID { - return Some(RawBabePreDigest::decode(&mut data)?.authority_index); + return Some(RawBabePreDigest::decode(&mut data).ok()?.authority_index); } } return None; diff --git a/substrate/srml/balances/Cargo.toml b/substrate/srml/balances/Cargo.toml index f096d506a4..d3ac0c96b3 100644 --- a/substrate/srml/balances/Cargo.toml +++ b/substrate/srml/balances/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } substrate-keyring = { path = "../../core/keyring", optional = true } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -24,7 +24,7 @@ std = [ "serde", "safe-mix/std", "substrate-keyring", - "parity-codec/std", + "codec/std", "rstd/std", "srml-support/std", "sr-primitives/std", diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index bff5e90c32..b1aefccc67 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -151,7 +151,7 @@ use rstd::prelude::*; use rstd::{cmp, result, mem}; -use parity_codec::{Codec, Encode, Decode}; +use codec::{Codec, Encode, Decode}; use srml_support::{StorageValue, StorageMap, Parameter, decl_event, decl_storage, decl_module}; use srml_support::traits::{ UpdateBalanceOutcome, Currency, OnFreeBalanceZero, OnUnbalanced, diff --git a/substrate/srml/collective/Cargo.toml b/substrate/srml/collective/Cargo.toml index 83d25593e4..7aaba7c29f 100644 --- a/substrate/srml/collective/Cargo.toml +++ b/substrate/srml/collective/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } @@ -23,7 +23,7 @@ balances = { package = "srml-balances", path = "../balances" } default = ["std"] std = [ "safe-mix/std", - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "serde", diff --git a/substrate/srml/contracts/Cargo.toml b/substrate/srml/contracts/Cargo.toml index 33c32c8ea2..a013571edf 100644 --- a/substrate/srml/contracts/Cargo.toml +++ b/substrate/srml/contracts/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } pwasm-utils = { version = "0.6.1", default-features = false } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } parity-wasm = { version = "0.31", default-features = false } wasmi-validation = { version = "0.1", default-features = false } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } @@ -33,7 +33,7 @@ core = [ ] std = [ "serde", - "parity-codec/std", + "codec/std", "primitives/std", "sr-primitives/std", "runtime-io/std", diff --git a/substrate/srml/contracts/src/lib.rs b/substrate/srml/contracts/src/lib.rs index 15d7b37a45..d28ee362eb 100644 --- a/substrate/srml/contracts/src/lib.rs +++ b/substrate/srml/contracts/src/lib.rs @@ -98,7 +98,7 @@ use crate::wasm::{WasmLoader, WasmVm}; use serde::{Serialize, Deserialize}; use primitives::crypto::UncheckedFrom; use rstd::{prelude::*, marker::PhantomData}; -use parity_codec::{Codec, Encode, Decode}; +use codec::{Codec, Encode, Decode}; use runtime_io::blake2_256; use sr_primitives::traits::{ Hash, StaticLookup, Zero, MaybeSerializeDebug, Member diff --git a/substrate/srml/contracts/src/tests.rs b/substrate/srml/contracts/src/tests.rs index 5a53d8426f..80bb7af518 100644 --- a/substrate/srml/contracts/src/tests.rs +++ b/substrate/srml/contracts/src/tests.rs @@ -26,7 +26,7 @@ use crate::{ }; use assert_matches::assert_matches; use hex_literal::*; -use parity_codec::{Decode, Encode, KeyedVec}; +use codec::{Decode, Encode, KeyedVec}; use runtime_io; use runtime_io::with_externalities; use sr_primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, H256}; diff --git a/substrate/srml/contracts/src/wasm/mod.rs b/substrate/srml/contracts/src/wasm/mod.rs index 2c29b1ead1..f1db63870b 100644 --- a/substrate/srml/contracts/src/wasm/mod.rs +++ b/substrate/srml/contracts/src/wasm/mod.rs @@ -23,7 +23,7 @@ use crate::exec::{Ext, EmptyOutputBuf, VmExecResult}; use crate::gas::GasMeter; use rstd::prelude::*; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sandbox; #[macro_use] diff --git a/substrate/srml/contracts/src/wasm/runtime.rs b/substrate/srml/contracts/src/wasm/runtime.rs index 006ec5aad2..2c631d71d5 100644 --- a/substrate/srml/contracts/src/wasm/runtime.rs +++ b/substrate/srml/contracts/src/wasm/runtime.rs @@ -26,7 +26,7 @@ use sandbox; use system; use rstd::prelude::*; use rstd::mem; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use sr_primitives::traits::{Bounded, SaturatedConversion}; /// Enumerates all possible *special* trap conditions. @@ -325,12 +325,12 @@ define_env!(Env, , let callee = { let callee_buf = read_sandbox_memory(ctx, callee_ptr, callee_len)?; <::T as system::Trait>::AccountId::decode(&mut &callee_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let value = { let value_buf = read_sandbox_memory(ctx, value_ptr, value_len)?; BalanceOf::<::T>::decode(&mut &value_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let input_data = read_sandbox_memory(ctx, input_data_ptr, input_data_len)?; @@ -399,12 +399,12 @@ define_env!(Env, , ) -> u32 => { let code_hash = { let code_hash_buf = read_sandbox_memory(ctx, code_hash_ptr, code_hash_len)?; - ::T>>::decode(&mut &code_hash_buf[..]).ok_or_else(|| sandbox::HostError)? + ::T>>::decode(&mut &code_hash_buf[..]).map_err(|_| sandbox::HostError)? }; let value = { let value_buf = read_sandbox_memory(ctx, value_ptr, value_len)?; BalanceOf::<::T>::decode(&mut &value_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let input_data = read_sandbox_memory(ctx, input_data_ptr, input_data_len)?; @@ -569,7 +569,7 @@ define_env!(Env, , let call = { let call_buf = read_sandbox_memory(ctx, call_ptr, call_len)?; <<::T as Trait>::Call>::decode(&mut &call_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; // Charge gas for dispatching this call. @@ -618,12 +618,12 @@ define_env!(Env, , let dest = { let dest_buf = read_sandbox_memory(ctx, dest_ptr, dest_len)?; <::T as system::Trait>::AccountId::decode(&mut &dest_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let code_hash = { let code_hash_buf = read_sandbox_memory(ctx, code_hash_ptr, code_hash_len)?; ::T>>::decode(&mut &code_hash_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let rent_allowance = { let rent_allowance_buf = read_sandbox_memory( @@ -632,7 +632,7 @@ define_env!(Env, , rent_allowance_len )?; BalanceOf::<::T>::decode(&mut &rent_allowance_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; let delta = { // We don't use `with_capacity` here to not eagerly allocate the user specified amount @@ -717,7 +717,7 @@ define_env!(Env, , _ => { let topics_buf = read_sandbox_memory(ctx, topics_ptr, topics_len)?; Vec::::T>>::decode(&mut &topics_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? } }; @@ -757,7 +757,7 @@ define_env!(Env, , let value = { let value_buf = read_sandbox_memory(ctx, value_ptr, value_len)?; BalanceOf::<::T>::decode(&mut &value_buf[..]) - .ok_or_else(|| sandbox::HostError)? + .map_err(|_| sandbox::HostError)? }; ctx.ext.set_rent_allowance(value); diff --git a/substrate/srml/democracy/Cargo.toml b/substrate/srml/democracy/Cargo.toml index baf1488d42..b6341a8225 100644 --- a/substrate/srml/democracy/Cargo.toml +++ b/substrate/srml/democracy/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -23,7 +23,7 @@ default = ["std"] std = [ "serde", "safe-mix/std", - "parity-codec/std", + "codec/std", "rstd/std", "runtime_io/std", "srml-support/std", diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index ae53a53bb8..332ad91358 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -22,7 +22,7 @@ use rstd::prelude::*; use rstd::{result, convert::TryFrom}; use sr_primitives::traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash}; use sr_primitives::weights::SimpleDispatchInfo; -use parity_codec::{Encode, Decode, Input, Output}; +use codec::{Encode, Decode, Input, Output, Error}; use srml_support::{ decl_module, decl_storage, decl_event, ensure, StorageValue, StorageMap, Parameter, Dispatchable, IsSubType, EnumerableStorageMap, @@ -154,12 +154,15 @@ impl Encode for Vote { } } +impl codec::EncodeLike for Vote {} + impl Decode for Vote { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> core::result::Result { let b = input.read_byte()?; - Some(Vote { + Ok(Vote { aye: (b & 0b1000_0000) == 0b1000_0000, - conviction: Conviction::try_from(b & 0b0111_1111).ok()?, + conviction: Conviction::try_from(b & 0b0111_1111) + .map_err(|_| Error::from("Invalid conviction"))?, }) } } diff --git a/substrate/srml/democracy/src/vote_threshold.rs b/substrate/srml/democracy/src/vote_threshold.rs index 96e5849e43..d304c36f32 100644 --- a/substrate/srml/democracy/src/vote_threshold.rs +++ b/substrate/srml/democracy/src/vote_threshold.rs @@ -18,7 +18,7 @@ #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::traits::{Zero, IntegerSquareRoot}; use rstd::ops::{Add, Mul, Div, Rem}; diff --git a/substrate/srml/elections/Cargo.toml b/substrate/srml/elections/Cargo.toml index dc004471d5..d6043bb2d0 100644 --- a/substrate/srml/elections/Cargo.toml +++ b/substrate/srml/elections/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } @@ -23,7 +23,7 @@ balances = { package = "srml-balances", path = "../balances" } default = ["std"] std = [ "safe-mix/std", - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "serde", diff --git a/substrate/srml/elections/src/lib.rs b/substrate/srml/elections/src/lib.rs index 0e761c94c8..e8fbb75dc3 100644 --- a/substrate/srml/elections/src/lib.rs +++ b/substrate/srml/elections/src/lib.rs @@ -35,7 +35,7 @@ use srml_support::{ OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers } }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use system::{self, ensure_signed, ensure_root}; // no polynomial attacks: diff --git a/substrate/srml/example/Cargo.toml b/substrate/srml/example/Cargo.toml index 2cbd707f18..87069a487a 100644 --- a/substrate/srml/example/Cargo.toml +++ b/substrate/srml/example/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } srml-support = { path = "../support", default-features = false } system = { package = "srml-system", path = "../system", default-features = false } balances = { package = "srml-balances", path = "../balances", default-features = false } @@ -20,7 +20,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "sr-primitives/std", "srml-support/std", "system/std", diff --git a/substrate/srml/executive/Cargo.toml b/substrate/srml/executive/Cargo.toml index e732c9b636..e398a95189 100644 --- a/substrate/srml/executive/Cargo.toml +++ b/substrate/srml/executive/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -25,7 +25,7 @@ std = [ "rstd/std", "srml-support/std", "serde", - "parity-codec/std", + "codec/std", "sr-primitives/std", "runtime_io/std", "system/std", diff --git a/substrate/srml/executive/src/lib.rs b/substrate/srml/executive/src/lib.rs index 062badd932..54ea3a3f14 100644 --- a/substrate/srml/executive/src/lib.rs +++ b/substrate/srml/executive/src/lib.rs @@ -82,7 +82,7 @@ use sr_primitives::{generic::Digest, traits::{ OnInitialize, NumberFor, Block as BlockT, OffchainWorker, ValidateUnsigned }}; use srml_support::Dispatchable; -use parity_codec::{Codec, Encode}; +use codec::{Codec, Encode}; use system::{extrinsics_root, DigestOf}; use sr_primitives::{ApplyOutcome, ApplyError}; use sr_primitives::transaction_validity::TransactionValidity; diff --git a/substrate/srml/finality-tracker/Cargo.toml b/substrate/srml/finality-tracker/Cargo.toml index 3dfd453c75..65ac540b6b 100644 --- a/substrate/srml/finality-tracker/Cargo.toml +++ b/substrate/srml/finality-tracker/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", default-features = false, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -21,7 +21,7 @@ sr-io = { path = "../../core/sr-io", default-features = false } default = ["std"] std = [ "serde/std", - "parity-codec/std", + "codec/std", "rstd/std", "srml-support/std", "sr-primitives/std", diff --git a/substrate/srml/finality-tracker/src/lib.rs b/substrate/srml/finality-tracker/src/lib.rs index f0e2ae0f54..4c3d975d7e 100644 --- a/substrate/srml/finality-tracker/src/lib.rs +++ b/substrate/srml/finality-tracker/src/lib.rs @@ -25,13 +25,13 @@ use inherents::{ use srml_support::StorageValue; use sr_primitives::traits::{One, Zero, SaturatedConversion}; use rstd::{prelude::*, result, cmp, vec}; -use parity_codec::Decode; +use codec::Decode; use srml_support::{decl_module, decl_storage, for_each_tuple}; use srml_support::traits::Get; use srml_system::{ensure_none, Trait as SystemTrait}; #[cfg(feature = "std")] -use parity_codec::Encode; +use codec::Encode; /// The identifier for the `finalnum` inherent. pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"finalnum"; diff --git a/substrate/srml/generic-asset/Cargo.toml b/substrate/srml/generic-asset/Cargo.toml index 0e10e15590..65e21c3b11 100644 --- a/substrate/srml/generic-asset/Cargo.toml +++ b/substrate/srml/generic-asset/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } support = { package = "srml-support", path = "../support", default-features = false } @@ -20,7 +20,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std =[ "serde/std", - "parity-codec/std", + "codec/std", "rstd/std", "sr-primitives/std", "support/std", diff --git a/substrate/srml/generic-asset/src/lib.rs b/substrate/srml/generic-asset/src/lib.rs index 60d1f0a3ff..57369b100e 100644 --- a/substrate/srml/generic-asset/src/lib.rs +++ b/substrate/srml/generic-asset/src/lib.rs @@ -151,7 +151,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use parity_codec::{Decode, Encode, HasCompact, Input, Output}; +use codec::{Decode, Encode, HasCompact, Input, Output, Error}; use sr_primitives::traits::{ CheckedAdd, CheckedSub, MaybeSerializeDebug, Member, One, Saturating, SimpleArithmetic, Zero, Bounded @@ -284,10 +284,12 @@ impl Encode for PermissionVersions { } } +impl codec::EncodeLike for PermissionVersions {} + impl Decode for PermissionVersions { - fn decode(input: &mut I) -> Option { + fn decode(input: &mut I) -> core::result::Result { let version = PermissionVersionNumber::decode(input)?; - Some( + Ok( match version { PermissionVersionNumber::V1 => PermissionVersions::V1(Decode::decode(input)?) } @@ -484,7 +486,7 @@ decl_storage! { config.endowed_accounts.iter().for_each(|account_id| { storage.insert( >::key_for(asset_id, account_id), - ::encode(&config.initial_balance) + ::encode(&config.initial_balance) ); }); }); diff --git a/substrate/srml/grandpa/Cargo.toml b/substrate/srml/grandpa/Cargo.toml index 478cddd153..2466b8e012 100644 --- a/substrate/srml/grandpa/Cargo.toml +++ b/substrate/srml/grandpa/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } substrate-finality-grandpa-primitives = { path = "../../core/finality-grandpa/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } @@ -23,7 +23,7 @@ runtime_io = { package = "sr-io", path = "../../core/sr-io" } default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "primitives/std", "substrate-finality-grandpa-primitives/std", "rstd/std", diff --git a/substrate/srml/grandpa/src/lib.rs b/substrate/srml/grandpa/src/lib.rs index 6f1c897e53..3f4b26c17d 100644 --- a/substrate/srml/grandpa/src/lib.rs +++ b/substrate/srml/grandpa/src/lib.rs @@ -31,7 +31,7 @@ pub use substrate_finality_grandpa_primitives as fg_primitives; use rstd::prelude::*; -use parity_codec::{self as codec, Encode, Decode}; +use codec::{self as codec, Encode, Decode, Error}; use srml_support::{ decl_event, decl_storage, decl_module, dispatch::Result, storage::StorageValue }; @@ -78,11 +78,11 @@ pub struct StoredPendingChange { } impl Decode for StoredPendingChange { - fn decode(value: &mut I) -> Option { + fn decode(value: &mut I) -> core::result::Result { let old = OldStoredPendingChange::decode(value)?; let forced = >::decode(value).unwrap_or(None); - Some(StoredPendingChange { + Ok(StoredPendingChange { scheduled_at: old.scheduled_at, delay: old.delay, next_authorities: old.next_authorities, diff --git a/substrate/srml/grandpa/src/mock.rs b/substrate/srml/grandpa/src/mock.rs index 637ae7c25f..4e5d133b9e 100644 --- a/substrate/srml/grandpa/src/mock.rs +++ b/substrate/srml/grandpa/src/mock.rs @@ -22,7 +22,7 @@ use sr_primitives::{Perbill, DigestItem, traits::IdentityLookup, testing::{Heade use runtime_io; use srml_support::{impl_outer_origin, impl_outer_event, parameter_types}; use primitives::{H256, Blake2Hasher}; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use crate::{AuthorityId, GenesisConfig, Trait, Module, ConsensusLog}; use substrate_finality_grandpa_primitives::GRANDPA_ENGINE_ID; diff --git a/substrate/srml/im-online/Cargo.toml b/substrate/srml/im-online/Cargo.toml index c015e5e4c5..60be1a89c2 100644 --- a/substrate/srml/im-online/Cargo.toml +++ b/substrate/srml/im-online/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../../core/sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } @@ -18,7 +18,7 @@ system = { package = "srml-system", path = "../system", default-features = false [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "sr-primitives/std", "rstd/std", "serde", diff --git a/substrate/srml/im-online/src/lib.rs b/substrate/srml/im-online/src/lib.rs index 8254cb6078..19875d9a37 100644 --- a/substrate/srml/im-online/src/lib.rs +++ b/substrate/srml/im-online/src/lib.rs @@ -74,7 +74,7 @@ use primitives::{ offchain::StorageKind, sr25519, ed25519, }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::{ ApplyError, traits::{Member, IsMember, Extrinsic as ExtrinsicT}, transaction_validity::{TransactionValidity, TransactionLongevity, ValidTransaction}, @@ -216,7 +216,7 @@ decl_module! { // we run only when a local authority key is configured if let Ok(key) = sr_io::pubkey(CryptoKey::AuthorityKey) { let authority_id = ::AuthorityId::decode(&mut &key[..]) - .ok_or(OffchainErr::DecodeAuthorityId)?; + .map_err(|_| OffchainErr::DecodeAuthorityId)?; let network_state = sr_io::network_state().map_err(|_| OffchainErr::NetworkState)?; let heartbeat_data = Heartbeat { @@ -282,7 +282,7 @@ decl_module! { match last_gossip { Some(last) => { let worker_status: WorkerStatus = Decode::decode(&mut &last[..]) - .ok_or(OffchainErr::DecodeWorkerStatus)?; + .map_err(|_| OffchainErr::DecodeWorkerStatus)?; let was_aborted = !worker_status.done && worker_status.gossipping_at < now; diff --git a/substrate/srml/indices/Cargo.toml b/substrate/srml/indices/Cargo.toml index c500cf5f87..3cbf1d88de 100644 --- a/substrate/srml/indices/Cargo.toml +++ b/substrate/srml/indices/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } substrate-keyring = { path = "../../core/keyring", optional = true } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime-io = { package = "sr-io", path = "../../core/sr-io", default-features = false } @@ -25,7 +25,7 @@ std = [ "serde", "safe-mix/std", "substrate-keyring", - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "runtime-io/std", diff --git a/substrate/srml/indices/src/address.rs b/substrate/srml/indices/src/address.rs index c76585d216..caef4728fb 100644 --- a/substrate/srml/indices/src/address.rs +++ b/substrate/srml/indices/src/address.rs @@ -19,7 +19,8 @@ #[cfg(feature = "std")] use std::fmt; use rstd::convert::TryInto; -use crate::{Member, Decode, Encode, Input, Output}; +use crate::Member; +use codec::{Encode, Decode, Input, Output, Error}; /// An indices-aware address, which can be either a direct `AccountId` or /// an index. @@ -54,16 +55,16 @@ impl From for Address(a: T, b: T) -> Option { - if a < b { Some(b) } else { None } +fn need_more_than(a: T, b: T) -> Result { + if a < b { Ok(b) } else { Err("Invalid range".into()) } } impl Decode for Address where AccountId: Member + Decode, AccountIndex: Member + Decode + PartialOrd + Ord + From + Copy, { - fn decode(input: &mut I) -> Option { - Some(match input.read_byte()? { + fn decode(input: &mut I) -> Result { + Ok(match input.read_byte()? { x @ 0x00..=0xef => Address::Index(AccountIndex::from(x as u32)), 0xfc => Address::Index(AccountIndex::from( need_more_than(0xef, u16::decode(input)?)? as u32 @@ -75,7 +76,7 @@ impl Decode for Address where need_more_than(0xffffffffu32.into(), Decode::decode(input)?)? ), 0xff => Address::Id(Decode::decode(input)?), - _ => return None, + _ => return Err("Invalid address variant".into()), }) } } @@ -114,6 +115,11 @@ impl Encode for Address where } } +impl codec::EncodeLike for Address where + AccountId: Member + Encode, + AccountIndex: Member + Encode + PartialOrd + Ord + Copy + From + TryInto, +{} + impl Default for Address where AccountId: Member + Default, AccountIndex: Member, @@ -125,7 +131,7 @@ impl Default for Address where #[cfg(test)] mod tests { - use crate::{Encode, Decode}; + use codec::{Encode, Decode}; type Address = super::Address<[u8; 8], u32>; fn index(i: u32) -> Address { super::Address::Index(i) } @@ -135,7 +141,7 @@ mod tests { if let Some(ref a) = a { assert_eq!(d, &a.encode()[..]); } - assert_eq!(Address::decode(&mut &d[..]), a); + assert_eq!(Address::decode(&mut &d[..]).ok(), a); } #[test] diff --git a/substrate/srml/indices/src/lib.rs b/substrate/srml/indices/src/lib.rs index 0bfd6d6054..5bf838f321 100644 --- a/substrate/srml/indices/src/lib.rs +++ b/substrate/srml/indices/src/lib.rs @@ -20,7 +20,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::{prelude::*, result, marker::PhantomData, convert::TryInto}; -use parity_codec::{Encode, Decode, Codec, Input, Output}; +use codec::{Encode, Codec}; use srml_support::{StorageValue, StorageMap, Parameter, decl_module, decl_event, decl_storage}; use sr_primitives::traits::{One, SimpleArithmetic, StaticLookup, Member}; use system::{IsDeadAccount, OnNewAccount}; diff --git a/substrate/srml/metadata/Cargo.toml b/substrate/srml/metadata/Cargo.toml index cdb7a41ff8..9fc9c6e46d 100644 --- a/substrate/srml/metadata/Cargo.toml +++ b/substrate/srml/metadata/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } serde = { version = "1.0", optional = true, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } @@ -13,7 +13,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives", [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "rstd/std", "primitives/std", "serde", diff --git a/substrate/srml/metadata/src/lib.rs b/substrate/srml/metadata/src/lib.rs index f518de5057..329b543d1a 100644 --- a/substrate/srml/metadata/src/lib.rs +++ b/substrate/srml/metadata/src/lib.rs @@ -25,8 +25,8 @@ #[cfg(feature = "std")] use serde::Serialize; #[cfg(feature = "std")] -use parity_codec::{Decode, Input}; -use parity_codec::{Encode, Output}; +use codec::{Decode, Input, Error}; +use codec::{Encode, Output}; use rstd::vec::Vec; #[cfg(feature = "std")] @@ -59,11 +59,13 @@ impl Encode for DecodeDifferent where B: Encode + 'static, O: Encode } } +impl codec::EncodeLike for DecodeDifferent where B: Encode + 'static, O: Encode + 'static {} + #[cfg(feature = "std")] impl Decode for DecodeDifferent where B: 'static, O: Decode + 'static { - fn decode(input: &mut I) -> Option { - ::decode(input).and_then(|val| { - Some(DecodeDifferent::Decoded(val)) + fn decode(input: &mut I) -> Result { + ::decode(input).map(|val| { + DecodeDifferent::Decoded(val) }) } } @@ -144,6 +146,8 @@ impl Encode for FnEncode { } } +impl codec::EncodeLike for FnEncode {} + impl PartialEq for FnEncode { fn eq(&self, other: &Self) -> bool { self.0().eq(&other.0()) @@ -223,6 +227,8 @@ impl Encode for DefaultByteGetter { } } +impl codec::EncodeLike for DefaultByteGetter {} + impl PartialEq for DefaultByteGetter { fn eq(&self, other: &DefaultByteGetter) -> bool { let left = self.0.default_byte(); @@ -333,10 +339,12 @@ impl Encode for RuntimeMetadataDeprecated { fn encode_to(&self, _dest: &mut W) {} } +impl codec::EncodeLike for RuntimeMetadataDeprecated {} + #[cfg(feature = "std")] impl Decode for RuntimeMetadataDeprecated { - fn decode(_input: &mut I) -> Option { - unimplemented!() + fn decode(_input: &mut I) -> Result { + Err("Decoding is not supported".into()) } } diff --git a/substrate/srml/session/Cargo.toml b/substrate/srml/session/Cargo.toml index a5dfb713d1..66d47f4c35 100644 --- a/substrate/srml/session/Cargo.toml +++ b/substrate/srml/session/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } srml-support = { path = "../support", default-features = false } @@ -26,7 +26,7 @@ historical = ["substrate-trie"] std = [ "serde", "safe-mix/std", - "parity-codec/std", + "codec/std", "rstd/std", "srml-support/std", "sr-primitives/std", diff --git a/substrate/srml/session/src/historical.rs b/substrate/srml/session/src/historical.rs index 1e8e7faaaf..e35df3011c 100644 --- a/substrate/srml/session/src/historical.rs +++ b/substrate/srml/session/src/historical.rs @@ -26,7 +26,7 @@ //! Afterwards, the proofs can be fed to a consensus module when reporting misbehavior. use rstd::prelude::*; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::KeyTypeId; use sr_primitives::traits::{Convert, OpaqueKeys, Hash as HashT}; use srml_support::{ @@ -235,13 +235,13 @@ impl ProvingTrie { let val_idx = (key_id, key_data).using_encoded(|s| { trie.get_with(s, &mut recorder) .ok()? - .and_then(|raw| u32::decode(&mut &*raw)) + .and_then(|raw| u32::decode(&mut &*raw).ok()) })?; val_idx.using_encoded(|s| { trie.get_with(s, &mut recorder) .ok()? - .and_then(|raw| >::decode(&mut &*raw)) + .and_then(|raw| >::decode(&mut &*raw).ok()) })?; Some(recorder.drain().into_iter().map(|r| r.data).collect()) @@ -258,11 +258,11 @@ impl ProvingTrie { let trie = TrieDB::new(&self.db, &self.root).ok()?; let val_idx = (key_id, key_data).using_encoded(|s| trie.get(s)) .ok()? - .and_then(|raw| u32::decode(&mut &*raw))?; + .and_then(|raw| u32::decode(&mut &*raw).ok())?; val_idx.using_encoded(|s| trie.get(s)) .ok()? - .and_then(|raw| >::decode(&mut &*raw)) + .and_then(|raw| >::decode(&mut &*raw).ok()) } } diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index a189a91da2..8b9e8b1566 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -120,7 +120,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::{prelude::*, marker::PhantomData, ops::{Sub, Rem}}; -use parity_codec::Decode; +use codec::Decode; use sr_primitives::KeyTypeId; use sr_primitives::weights::SimpleDispatchInfo; use sr_primitives::traits::{Convert, Zero, Member, OpaqueKeys, TypedKey}; diff --git a/substrate/srml/staking/Cargo.toml b/substrate/srml/staking/Cargo.toml index 5feab0f516..5428d663f3 100644 --- a/substrate/srml/staking/Cargo.toml +++ b/substrate/srml/staking/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } substrate-keyring = { path = "../../core/keyring", optional = true } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } @@ -31,7 +31,7 @@ std = [ "serde", "safe-mix/std", "substrate-keyring", - "parity-codec/std", + "codec/std", "rstd/std", "runtime_io/std", "srml-support/std", diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index dd540e78b1..11aa4f3c7d 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -284,7 +284,7 @@ mod benches; #[cfg(feature = "std")] use runtime_io::with_storage; use rstd::{prelude::*, result, collections::btree_map::BTreeMap}; -use parity_codec::{HasCompact, Encode, Decode}; +use codec::{HasCompact, Encode, Decode}; use srml_support::{ StorageValue, StorageMap, EnumerableStorageMap, decl_module, decl_event, decl_storage, ensure, traits::{ diff --git a/substrate/srml/sudo/Cargo.toml b/substrate/srml/sudo/Cargo.toml index 6f7d290396..d0e2d5dbc5 100644 --- a/substrate/srml/sudo/Cargo.toml +++ b/substrate/srml/sudo/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } @@ -22,7 +22,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "sr-std/std", "sr-io/std", "sr-primitives/std", diff --git a/substrate/srml/support/Cargo.toml b/substrate/srml/support/Cargo.toml index 99fa2dbb38..2befc11b19 100644 --- a/substrate/srml/support/Cargo.toml +++ b/substrate/srml/support/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } -codec = { package = "parity-codec", version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } srml-metadata = { path = "../metadata", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/support/src/storage/hashed/generator.rs b/substrate/srml/support/src/storage/hashed/generator.rs index 4d367fb2a8..19c4440c85 100644 --- a/substrate/srml/support/src/storage/hashed/generator.rs +++ b/substrate/srml/support/src/storage/hashed/generator.rs @@ -208,7 +208,7 @@ pub trait StorageValue { let new_val = ::append( storage.get_raw(Self::key()).unwrap_or_default(), items, - ).ok_or_else(|| "Could not append given item")?; + ).map_err(|_| "Could not append given item")?; storage.put_raw(Self::key(), &new_val); Ok(()) } @@ -286,7 +286,7 @@ pub trait AppendableStorageMap: StorageMap::append( storage.get_raw(&k[..]).unwrap_or_default(), items, - ).ok_or_else(|| "Could not append given item")?; + ).map_err(|_| "Could not append given item")?; storage.put_raw(&k[..], &new_val); Ok(()) } diff --git a/substrate/srml/support/src/storage/unhashed/generator.rs b/substrate/srml/support/src/storage/unhashed/generator.rs index 26cb4b73e5..a5385af8fb 100644 --- a/substrate/srml/support/src/storage/unhashed/generator.rs +++ b/substrate/srml/support/src/storage/unhashed/generator.rs @@ -234,7 +234,7 @@ pub trait StorageDoubleMap::append( storage.get_raw(&key).unwrap_or_default(), items, - ).ok_or_else(|| "Could not append given item")?; + ).map_err(|_| "Could not append given item")?; storage.put_raw(&key, &new_val); Ok(()) } diff --git a/substrate/srml/support/test/Cargo.toml b/substrate/srml/support/test/Cargo.toml index a4152dae2f..fa3a04d3bc 100644 --- a/substrate/srml/support/test/Cargo.toml +++ b/substrate/srml/support/test/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", default-features = false, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } runtime_io = { package = "sr-io", path = "../../../core/sr-io", default-features = false } srml-support = { version = "2", path = "../", default-features = false } inherents = { package = "substrate-inherents", path = "../../../core/inherents", default-features = false } @@ -18,7 +18,7 @@ pretty_assertions = "0.6.1" default = ["std"] std = [ "serde/std", - "parity-codec/std", + "codec/std", "runtime_io/std", "srml-support/std", "inherents/std", diff --git a/substrate/srml/support/test/tests/final_keys.rs b/substrate/srml/support/test/tests/final_keys.rs index 54c08d5e5f..0b16db3de7 100644 --- a/substrate/srml/support/test/tests/final_keys.rs +++ b/substrate/srml/support/test/tests/final_keys.rs @@ -17,7 +17,7 @@ use runtime_io::{with_externalities, Blake2Hasher}; use srml_support::{StorageValue, StorageMap, StorageDoubleMap}; use srml_support::storage::unhashed; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; pub trait Trait { type Origin; diff --git a/substrate/srml/support/test/tests/genesisconfig.rs b/substrate/srml/support/test/tests/genesisconfig.rs index 717c7105b5..b190fa8b74 100644 --- a/substrate/srml/support/test/tests/genesisconfig.rs +++ b/substrate/srml/support/test/tests/genesisconfig.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . pub trait Trait { - type BlockNumber: parity_codec::Codec + Default; + type BlockNumber: codec::Codec + Default; type Origin; } @@ -41,4 +41,4 @@ fn init_genesis_config() { GenesisConfig:: { t: Default::default(), }; -} \ No newline at end of file +} diff --git a/substrate/srml/support/test/tests/instance.rs b/substrate/srml/support/test/tests/instance.rs index 863532ff09..f77b4a284a 100644 --- a/substrate/srml/support/test/tests/instance.rs +++ b/substrate/srml/support/test/tests/instance.rs @@ -45,7 +45,7 @@ mod module1 { type Event: From> + Into<::Event>; type Origin: From>; type SomeParameter: Get; - type GenericType: Default + Clone + parity_codec::Codec; + type GenericType: Default + Clone + codec::Codec; } srml_support::decl_module! { diff --git a/substrate/srml/system/Cargo.toml b/substrate/srml/system/Cargo.toml index 35ddfabd6e..9816555621 100644 --- a/substrate/srml/system/Cargo.toml +++ b/substrate/srml/system/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } @@ -22,7 +22,7 @@ default = ["std"] std = [ "serde", "safe-mix/std", - "parity-codec/std", + "codec/std", "primitives/std", "rstd/std", "runtime_io/std", diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index ac8357f5ca..d3a87cd38b 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -95,7 +95,7 @@ use srml_support::{ Parameter, for_each_tuple, traits::{Contains, Get} }; use safe_mix::TripletMix; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; #[cfg(any(feature = "std", test))] use runtime_io::{twox_128, TestExternalities, Blake2Hasher}; @@ -140,8 +140,8 @@ impl IsDeadAccount for () { } /// Compute the trie root of a list of extrinsics. -pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { - extrinsics_data_root::(extrinsics.iter().map(parity_codec::Encode::encode).collect()) +pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { + extrinsics_data_root::(extrinsics.iter().map(codec::Encode::encode).collect()) } /// Compute the trie root of a list of extrinsics. @@ -412,7 +412,7 @@ decl_storage! { _: &mut sr_primitives::ChildrenStorageOverlay, config: &GenesisConfig| { - use parity_codec::Encode; + use codec::Encode; storage.insert(well_known_keys::CODE.to_vec(), config.code.clone()); storage.insert(well_known_keys::EXTRINSIC_INDEX.to_vec(), 0u32.encode()); diff --git a/substrate/srml/timestamp/Cargo.toml b/substrate/srml/timestamp/Cargo.toml index 765573ce46..9b066a1505 100644 --- a/substrate/srml/timestamp/Cargo.toml +++ b/substrate/srml/timestamp/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } @@ -21,7 +21,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std = [ "inherents/std", - "parity-codec/std", + "codec/std", "rstd/std", "sr-primitives/std", "srml-support/std", diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index cc439da8ee..bc9533e6e6 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -91,9 +91,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::{result, ops::{Mul, Div}, cmp}; -use parity_codec::Encode; +use codec::Encode; #[cfg(feature = "std")] -use parity_codec::Decode; +use codec::Decode; #[cfg(feature = "std")] use inherents::ProvideInherentData; use srml_support::{StorageValue, Parameter, decl_storage, decl_module, for_each_tuple}; @@ -133,7 +133,7 @@ impl InherentError { #[cfg(feature = "std")] pub fn try_from(id: &InherentIdentifier, data: &[u8]) -> Option { if id == &INHERENT_IDENTIFIER { - ::decode(&mut &data[..]) + ::decode(&mut &data[..]).ok() } else { None } diff --git a/substrate/srml/treasury/Cargo.toml b/substrate/srml/treasury/Cargo.toml index 4314d959b3..ae2681e11b 100644 --- a/substrate/srml/treasury/Cargo.toml +++ b/substrate/srml/treasury/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } srml-support = { path = "../support", default-features = false } @@ -21,7 +21,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" default = ["std"] std = [ "serde", - "parity-codec/std", + "codec/std", "rstd/std", "sr-primitives/std", "srml-support/std", diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 702fe3048e..1cf3277199 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -80,7 +80,7 @@ use sr_primitives::traits::{ Zero, EnsureOrigin, StaticLookup, CheckedSub, CheckedMul, AccountIdConversion }; use sr_primitives::weights::SimpleDispatchInfo; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use system::ensure_signed; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; diff --git a/substrate/subkey/Cargo.toml b/substrate/subkey/Cargo.toml index 3e0079cedf..da97ace38e 100644 --- a/substrate/subkey/Cargo.toml +++ b/substrate/subkey/Cargo.toml @@ -17,7 +17,7 @@ substrate-bip39 = "0.2.2" schnorrkel = "0.1.1" hex = "0.3" hex-literal = "0.2" -parity-codec = "4.1.1" +codec = { package = "parity-scale-codec", version = "1.0.0" } system = { package = "srml-system", path = "../srml/system" } balances = { package = "srml-balances", path = "../srml/balances" } diff --git a/substrate/subkey/src/main.rs b/substrate/subkey/src/main.rs index 4a63138bf6..c123e88ec2 100644 --- a/substrate/subkey/src/main.rs +++ b/substrate/subkey/src/main.rs @@ -26,7 +26,7 @@ use primitives::{ ed25519, sr25519, hexdisplay::HexDisplay, Pair, Public, blake2_256, crypto::{Ss58Codec, set_default_ss58_version, Ss58AddressFormat} }; -use parity_codec::{Encode, Decode}; +use codec::{Encode, Decode}; use sr_primitives::generic::Era; use node_primitives::{Balance, Index, Hash}; use node_runtime::{Call, UncheckedExtrinsic, BalancesCall, Runtime}; @@ -165,7 +165,7 @@ fn execute(matches: clap::ArgMatches) where let genesis_hash: Hash = match matches.value_of("genesis").unwrap_or("alex") { "elm" => hex!["10c08714a10c7da78f40a60f6f732cf0dba97acfb5e2035445b032386157d5c3"].into(), "alex" => hex!["dcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b"].into(), - h => hex::decode(h).ok().and_then(|x| Decode::decode(&mut &x[..])) + h => hex::decode(h).ok().and_then(|x| Decode::decode(&mut &x[..]).ok()) .expect("Invalid genesis hash or unrecognised chain identifier"), }; @@ -203,12 +203,12 @@ fn execute(matches: clap::ArgMatches) where let call = matches.value_of("call") .expect("call is required; thus it can't be None; qed"); let function: Call = hex::decode(&call).ok() - .and_then(|x| Decode::decode(&mut &x[..])).unwrap(); + .and_then(|x| Decode::decode(&mut &x[..]).ok()).unwrap(); let genesis_hash: Hash = match matches.value_of("genesis").unwrap_or("alex") { "elm" => hex!["10c08714a10c7da78f40a60f6f732cf0dba97acfb5e2035445b032386157d5c3"].into(), "alex" => hex!["dcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b"].into(), - h => hex::decode(h).ok().and_then(|x| Decode::decode(&mut &x[..])) + h => hex::decode(h).ok().and_then(|x| Decode::decode(&mut &x[..]).ok()) .expect("Invalid genesis hash or unrecognised chain identifier"), }; @@ -289,7 +289,7 @@ mod tests { fn should_work() { let s = "0123456789012345678901234567890123456789012345678901234567890123"; - let d1: Hash = hex::decode(s).ok().and_then(|x| Decode::decode(&mut &x[..])).unwrap(); + let d1: Hash = hex::decode(s).ok().and_then(|x| Decode::decode(&mut &x[..]).ok()).unwrap(); let d2: Hash = { let mut gh: [u8; 32] = Default::default(); diff --git a/substrate/test-utils/transaction-factory/Cargo.toml b/substrate/test-utils/transaction-factory/Cargo.toml index 1c4cf5a5d5..f3c392c3d6 100644 --- a/substrate/test-utils/transaction-factory/Cargo.toml +++ b/substrate/test-utils/transaction-factory/Cargo.toml @@ -9,7 +9,7 @@ cli = { package = "substrate-cli", path = "../../core/cli" } client = { package = "substrate-client", path = "../../core/client" } consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } log = "0.4" -parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } substrate-service = { path = "../../core/service" } @@ -17,6 +17,6 @@ substrate-service = { path = "../../core/service" } [features] default = ["std"] std = [ - "parity-codec/std", + "codec/std", "sr-primitives/std", ] diff --git a/substrate/test-utils/transaction-factory/src/lib.rs b/substrate/test-utils/transaction-factory/src/lib.rs index 11b080f14f..ab7dfb8cea 100644 --- a/substrate/test-utils/transaction-factory/src/lib.rs +++ b/substrate/test-utils/transaction-factory/src/lib.rs @@ -33,7 +33,7 @@ use consensus_common::{ SelectChain }; use consensus_common::block_import::BlockImport; -use parity_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{ Block as BlockT, Header as HeaderT, ProvideRuntimeApi, SimpleArithmetic,