From 8bc5242c92101443224154d7521483a097312878 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 16 Oct 2018 22:47:30 +0200 Subject: [PATCH] Compact format for block number, nonce, balance (#910) * Try to make everything compact * Make `Clone` work * Fix * Move contracts and balances over to compact encoding * Session and timestamp are compact * Sataking uses compact numbers * Treasury now compact * Compact Democracy * Council is compact * Fix --- substrate/Cargo.lock | 103 ++-- substrate/core/client/Cargo.toml | 2 +- substrate/core/client/db/Cargo.toml | 4 +- substrate/core/client/src/cht.rs | 16 +- substrate/core/executor/Cargo.toml | 2 +- substrate/core/executor/wasm/Cargo.lock | 16 +- substrate/core/finality-grandpa/Cargo.toml | 2 +- substrate/core/network/Cargo.toml | 4 +- substrate/core/network/src/on_demand.rs | 2 +- substrate/core/network/src/protocol.rs | 1 + substrate/core/primitives/Cargo.toml | 4 +- substrate/core/rpc/Cargo.toml | 2 +- substrate/core/service/Cargo.toml | 2 +- substrate/core/sr-api/Cargo.toml | 2 +- substrate/core/sr-io/Cargo.toml | 2 +- substrate/core/sr-primitives/Cargo.toml | 4 +- .../core/sr-primitives/src/generic/header.rs | 14 +- .../src/generic/unchecked_extrinsic.rs | 68 ++- substrate/core/sr-primitives/src/traits.rs | 8 +- substrate/core/sr-sandbox/Cargo.toml | 2 +- substrate/core/sr-version/Cargo.toml | 4 +- substrate/core/state-db/Cargo.toml | 4 +- substrate/core/state-machine/Cargo.toml | 2 +- substrate/core/test-client/Cargo.toml | 2 +- substrate/core/test-runtime/Cargo.toml | 4 +- substrate/core/test-runtime/wasm/Cargo.lock | 25 +- substrate/core/test-runtime/wasm/Cargo.toml | 4 +- substrate/core/transaction-pool/Cargo.toml | 2 +- substrate/core/trie/Cargo.toml | 2 +- substrate/node/consensus/Cargo.toml | 2 +- substrate/node/executor/Cargo.toml | 2 +- substrate/node/executor/src/lib.rs | 22 +- substrate/node/primitives/Cargo.toml | 4 +- substrate/node/runtime/Cargo.toml | 4 +- substrate/node/runtime/src/lib.rs | 8 +- substrate/node/runtime/wasm/Cargo.lock | 51 +- substrate/node/runtime/wasm/Cargo.toml | 4 +- substrate/node/service/Cargo.toml | 2 +- substrate/node/service/src/lib.rs | 2 +- substrate/srml/balances/Cargo.toml | 4 +- substrate/srml/balances/src/lib.rs | 15 +- substrate/srml/balances/src/tests.rs | 36 +- substrate/srml/consensus/Cargo.toml | 4 +- substrate/srml/contract/Cargo.toml | 4 +- substrate/srml/contract/src/lib.rs | 22 +- substrate/srml/contract/src/tests.rs | 38 +- substrate/srml/council/Cargo.toml | 4 +- substrate/srml/council/src/motions.rs | 61 +-- substrate/srml/council/src/seats.rs | 464 +++++++++--------- substrate/srml/council/src/voting.rs | 19 +- substrate/srml/democracy/Cargo.toml | 4 +- substrate/srml/democracy/src/lib.rs | 83 ++-- substrate/srml/example/Cargo.toml | 4 +- substrate/srml/example/src/lib.rs | 2 - substrate/srml/executive/Cargo.toml | 4 +- substrate/srml/executive/src/lib.rs | 4 +- substrate/srml/metadata/Cargo.toml | 4 +- substrate/srml/session/Cargo.toml | 4 +- substrate/srml/session/src/lib.rs | 15 +- substrate/srml/staking/Cargo.toml | 4 +- substrate/srml/staking/src/lib.rs | 48 +- substrate/srml/staking/src/tests.rs | 26 +- substrate/srml/support/Cargo.toml | 4 +- substrate/srml/support/src/dispatch.rs | 2 +- substrate/srml/system/Cargo.toml | 4 +- substrate/srml/timestamp/Cargo.toml | 2 +- substrate/srml/timestamp/src/lib.rs | 15 +- substrate/srml/treasury/Cargo.toml | 4 +- substrate/srml/treasury/src/lib.rs | 75 +-- 69 files changed, 728 insertions(+), 661 deletions(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 77b992c2c7..24ab0eab93 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -585,7 +585,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -721,12 +721,12 @@ dependencies = [ [[package]] name = "hash-db" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" [[package]] name = "hash256-std-hasher" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -968,7 +968,7 @@ dependencies = [ [[package]] name = "keccak-hasher" version = "0.1.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)", @@ -1436,7 +1436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memory-db" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1610,7 +1610,7 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 0.1.0", "node-runtime 0.1.0", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rhododendron 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", @@ -1629,7 +1629,7 @@ dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 0.1.0", "node-runtime 0.1.0", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "srml-balances 0.1.0", @@ -1669,7 +1669,7 @@ dependencies = [ name = "node-primitives" version = "0.1.0" dependencies = [ - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1686,7 +1686,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 0.1.0", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.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)", @@ -1726,7 +1726,7 @@ dependencies = [ "node-network 0.1.0", "node-primitives 0.1.0", "node-runtime 0.1.0", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rhododendron 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1864,10 +1864,11 @@ dependencies = [ [[package]] name = "parity-codec" -version = "2.0.3" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2238,7 +2239,7 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2519,7 +2520,7 @@ dependencies = [ name = "sr-api" version = "0.1.0" dependencies = [ - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2532,7 +2533,7 @@ version = "0.1.0" dependencies = [ "environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -2547,7 +2548,7 @@ dependencies = [ "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2563,7 +2564,7 @@ name = "sr-sandbox" version = "0.1.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -2582,7 +2583,7 @@ dependencies = [ name = "sr-version" version = "0.1.0" dependencies = [ - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2594,7 +2595,7 @@ name = "srml-balances" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2613,7 +2614,7 @@ name = "srml-consensus" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2630,7 +2631,7 @@ name = "srml-contract" version = "0.1.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (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.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2652,7 +2653,7 @@ name = "srml-council" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2672,7 +2673,7 @@ name = "srml-democracy" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2691,7 +2692,7 @@ name = "srml-example" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2709,7 +2710,7 @@ name = "srml-executive" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2727,7 +2728,7 @@ name = "srml-session" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2747,7 +2748,7 @@ name = "srml-staking" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2771,7 +2772,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "mashup 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2787,7 +2788,7 @@ name = "srml-system" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2804,7 +2805,7 @@ name = "srml-timestamp" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", @@ -2821,7 +2822,7 @@ name = "srml-treasury" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2926,7 +2927,7 @@ dependencies = [ "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api 0.1.0", @@ -2950,7 +2951,7 @@ dependencies = [ "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", @@ -3004,7 +3005,7 @@ dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3025,7 +3026,7 @@ dependencies = [ "finality-grandpa 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "substrate-client 0.1.0", @@ -3064,7 +3065,7 @@ dependencies = [ name = "substrate-metadata" version = "0.1.0" dependencies = [ - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3080,7 +3081,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3131,7 +3132,7 @@ dependencies = [ "hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3157,7 +3158,7 @@ dependencies = [ "jsonrpc-macros 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)", "jsonrpc-pubsub 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", @@ -3200,7 +3201,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3245,7 +3246,7 @@ version = "0.1.0" dependencies = [ "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", @@ -3259,7 +3260,7 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "substrate-trie 0.4.0", @@ -3285,7 +3286,7 @@ dependencies = [ name = "substrate-test-client" version = "0.1.0" dependencies = [ - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "substrate-client 0.1.0", "substrate-executor 0.1.0", @@ -3300,7 +3301,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3334,7 +3335,7 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "substrate-client 0.1.0", @@ -3353,7 +3354,7 @@ dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.0 (git+https://github.com/paritytech/trie)", "memory-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "trie-bench 0.9.0 (git+https://github.com/paritytech/trie)", "trie-db 0.9.0 (git+https://github.com/paritytech/trie)", @@ -3728,13 +3729,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "trie-bench" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "criterion 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "keccak-hasher 0.1.0 (git+https://github.com/paritytech/trie)", "memory-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.9.0 (git+https://github.com/paritytech/trie)", "trie-root 0.9.0 (git+https://github.com/paritytech/trie)", "trie-standardmap 0.9.0 (git+https://github.com/paritytech/trie)", @@ -3743,7 +3744,7 @@ dependencies = [ [[package]] name = "trie-db" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", @@ -3754,7 +3755,7 @@ dependencies = [ [[package]] name = "trie-root" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", ] @@ -3762,7 +3763,7 @@ dependencies = [ [[package]] name = "trie-standardmap" version = "0.9.0" -source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1" +source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7" dependencies = [ "criterion 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", @@ -4289,7 +4290,7 @@ dependencies = [ "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5168b4cf41f3835e4bc6ffb32f51bc9365dc50cb351904595b3931d917fd0c" "checksum parity-codec 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bee4edfcfa19892f7178cb299a659866015dc131459865a1d808269cf7e7eb9e" -"checksum parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "63c4b16ee2b7d6aace13b09bb0d16ade6b90ef19b7ca1c6cec9b8d08b9f59ecb" +"checksum parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dca389ea5e1632c89b2ce54f7e2b4a8a8c9d278042222a91e0bf95451218cb4c" "checksum parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa42c2cb493b60b12c75b26e8c94cb734af4df4d7f2cc229dc04c1953dac189" "checksum parity-crypto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c1117f6574377d21309bfa1f7d69ff734120685d92b02c3f362b122585758840" "checksum parity-rocksdb 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd55d2d6d6000ec99f021cf52c9acc7d2a402e14f95ced4c5de230696fabe00b" diff --git a/substrate/core/client/Cargo.toml b/substrate/core/client/Cargo.toml index 2ea5df1e5d..ba457fbb9c 100644 --- a/substrate/core/client/Cargo.toml +++ b/substrate/core/client/Cargo.toml @@ -13,7 +13,7 @@ futures = "0.1.17" slog = "^2" heapsize = "0.4" substrate-consensus-rhd = { path = "../consensus/rhd" } -parity-codec = "2.0" +parity-codec = "2.1" substrate-executor = { path = "../executor" } substrate-primitives = { path = "../primitives" } sr-primitives = { path = "../sr-primitives" } diff --git a/substrate/core/client/db/Cargo.toml b/substrate/core/client/db/Cargo.toml index 0d91dd184b..4f6c785833 100644 --- a/substrate/core/client/db/Cargo.toml +++ b/substrate/core/client/db/Cargo.toml @@ -13,8 +13,8 @@ substrate-primitives = { path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } substrate-client = { path = "../../client" } substrate-state-machine = { path = "../../state-machine" } -parity-codec = "2.0" -parity-codec-derive = "2.0" +parity-codec = "2.1" +parity-codec-derive = "2.1" substrate-executor = { path = "../../executor" } substrate-state-db = { path = "../../state-db" } substrate-trie = { path = "../../trie" } diff --git a/substrate/core/client/src/cht.rs b/substrate/core/client/src/cht.rs index ead49fc728..54978b7932 100644 --- a/substrate/core/client/src/cht.rs +++ b/substrate/core/client/src/cht.rs @@ -216,8 +216,8 @@ mod tests { #[test] fn is_build_required_works() { - assert_eq!(is_build_required(SIZE, 0), None); - assert_eq!(is_build_required(SIZE, 1), None); + assert_eq!(is_build_required(SIZE, 0u64), None); + assert_eq!(is_build_required(SIZE, 1u64), None); assert_eq!(is_build_required(SIZE, SIZE), None); assert_eq!(is_build_required(SIZE, SIZE + 1), None); assert_eq!(is_build_required(SIZE, 2 * SIZE), None); @@ -228,16 +228,16 @@ mod tests { #[test] fn start_number_works() { - assert_eq!(start_number(SIZE, 0), 1); - assert_eq!(start_number(SIZE, 1), SIZE + 1); - assert_eq!(start_number(SIZE, 2), SIZE + SIZE + 1); + assert_eq!(start_number(SIZE, 0u64), 1u64); + assert_eq!(start_number(SIZE, 1u64), SIZE + 1); + assert_eq!(start_number(SIZE, 2u64), SIZE + SIZE + 1); } #[test] fn end_number_works() { - assert_eq!(end_number(SIZE, 0), SIZE); - assert_eq!(end_number(SIZE, 1), SIZE + SIZE); - assert_eq!(end_number(SIZE, 2), SIZE + SIZE + SIZE); + assert_eq!(end_number(SIZE, 0u64), SIZE); + assert_eq!(end_number(SIZE, 1u64), SIZE + SIZE); + assert_eq!(end_number(SIZE, 2u64), SIZE + SIZE + SIZE); } #[test] diff --git a/substrate/core/executor/Cargo.toml b/substrate/core/executor/Cargo.toml index 7630b91f84..a3de26a3cb 100644 --- a/substrate/core/executor/Cargo.toml +++ b/substrate/core/executor/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] error-chain = "0.12" -parity-codec = "2.0" +parity-codec = "2.1" sr-io = { path = "../sr-io" } substrate-primitives = { path = "../primitives" } substrate-trie = { path = "../trie" } diff --git a/substrate/core/executor/wasm/Cargo.lock b/substrate/core/executor/wasm/Cargo.lock index 95cd7bf2ff..691a9291a2 100644 --- a/substrate/core/executor/wasm/Cargo.lock +++ b/substrate/core/executor/wasm/Cargo.lock @@ -41,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-codec" -version = "2.0.2" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "parity-codec-derive" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -118,7 +118,7 @@ name = "sr-io" version = "0.1.0" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -128,7 +128,7 @@ dependencies = [ name = "sr-sandbox" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -150,8 +150,8 @@ dependencies = [ "fixed-hash 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec-derive 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 0.1.0", @@ -191,8 +191,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum hash-db 0.9.0 (git+https://github.com/paritytech/trie)" = "" "checksum hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" -"checksum parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df92a55cfa11e8e964e9f0e74b257e21086098d6d3e3fbb2f8fcb17bcbb8e1a1" -"checksum parity-codec-derive 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b250f2968bba91133dee9d23d2a8b7a62443cde68921f17b647fabbe3e09d67d" +"checksum parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dca389ea5e1632c89b2ce54f7e2b4a8a8c9d278042222a91e0bf95451218cb4c" +"checksum parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa42c2cb493b60b12c75b26e8c94cb734af4df4d7f2cc229dc04c1953dac189" "checksum proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ffe022fb8c8bd254524b0b3305906c1921fa37a84a644e29079a9e62200c3901" "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" diff --git a/substrate/core/finality-grandpa/Cargo.toml b/substrate/core/finality-grandpa/Cargo.toml index cc269f68a3..b507ffd6d7 100644 --- a/substrate/core/finality-grandpa/Cargo.toml +++ b/substrate/core/finality-grandpa/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] futures = "0.1.17" -parity-codec = "2.0" +parity-codec = "2.1" sr-primitives = { path = "../sr-primitives" } substrate-primitives = { path = "../primitives" } substrate-client = { path = "../client" } diff --git a/substrate/core/network/Cargo.toml b/substrate/core/network/Cargo.toml index 28330229d5..db4f6c34e2 100644 --- a/substrate/core/network/Cargo.toml +++ b/substrate/core/network/Cargo.toml @@ -19,8 +19,8 @@ rand = "0.5" substrate-primitives = { path = "../../core/primitives" } substrate-client = { path = "../../core/client" } sr-primitives = { path = "../../core/sr-primitives" } -parity-codec = "2.0" -parity-codec-derive = "2.0" +parity-codec = "2.1" +parity-codec-derive = "2.1" substrate-network-libp2p = { path = "../../core/network-libp2p" } tokio = "0.1.11" diff --git a/substrate/core/network/src/on_demand.rs b/substrate/core/network/src/on_demand.rs index f0aa86098a..399ba3f408 100644 --- a/substrate/core/network/src/on_demand.rs +++ b/substrate/core/network/src/on_demand.rs @@ -820,7 +820,7 @@ pub mod tests { }); let thread = ::std::thread::spawn(move || { let result = response.wait().unwrap(); - assert_eq!(result.hash(), "0x950856031909d22d42b7e11a837051fbde05beaa3ffb793d6e8e373c646459b1".into()); + assert_eq!(result.hash(), "0x6443a0b46e0412e626363028115a9f2cf963eeed526b8b33e5316f08b50d0dc3".into()); }); on_demand.on_remote_header_response(&mut network, 0, message::RemoteHeaderResponse { diff --git a/substrate/core/network/src/protocol.rs b/substrate/core/network/src/protocol.rs index 30ce14c8ea..b5d49272a0 100644 --- a/substrate/core/network/src/protocol.rs +++ b/substrate/core/network/src/protocol.rs @@ -416,6 +416,7 @@ impl, H: ExHashT> Protocol { } } + #[allow(dead_code)] pub fn peer_info(&self, peer: NodeIndex) -> Option> { self.context_data.peers.read().get(&peer).map(|p| { PeerInfo { diff --git a/substrate/core/primitives/Cargo.toml b/substrate/core/primitives/Cargo.toml index f09f2e486e..29914fc4ce 100644 --- a/substrate/core/primitives/Cargo.toml +++ b/substrate/core/primitives/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Parity Technologies "] [dependencies] crunchy = "0.1" sr-std = { path = "../sr-std", default-features = false } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } fixed-hash = { version = "0.2.2", default-features = false } rustc-hex = { version = "2.0", default-features = false } serde = { version = "1.0", default-features = false } diff --git a/substrate/core/rpc/Cargo.toml b/substrate/core/rpc/Cargo.toml index a846ae3605..453b288c9d 100644 --- a/substrate/core/rpc/Cargo.toml +++ b/substrate/core/rpc/Cargo.toml @@ -10,7 +10,7 @@ jsonrpc-macros = { git="https://github.com/paritytech/jsonrpc.git" } jsonrpc-pubsub = { git="https://github.com/paritytech/jsonrpc.git" } log = "0.4" parking_lot = "0.4" -parity-codec = "2.0" +parity-codec = "2.1" substrate-client = { path = "../client" } substrate-executor = { path = "../executor" } substrate-transaction-pool = { path = "../transaction-pool" } diff --git a/substrate/core/service/Cargo.toml b/substrate/core/service/Cargo.toml index a38c867f44..694cd5a553 100644 --- a/substrate/core/service/Cargo.toml +++ b/substrate/core/service/Cargo.toml @@ -23,7 +23,7 @@ substrate-primitives = { path = "../../core/primitives" } substrate-network = { path = "../../core/network" } substrate-client = { path = "../../core/client" } substrate-client-db = { path = "../../core/client/db" } -parity-codec = "2.0" +parity-codec = "2.1" substrate-executor = { path = "../../core/executor" } substrate-transaction-pool = { path = "../../core/transaction-pool" } substrate-rpc = { path = "../../core/rpc" } diff --git a/substrate/core/sr-api/Cargo.toml b/substrate/core/sr-api/Cargo.toml index 4237ae7afd..2d1197613d 100644 --- a/substrate/core/sr-api/Cargo.toml +++ b/substrate/core/sr-api/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -parity-codec = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } sr-std = { path = "../sr-std", default-features = false } sr-primitives = { path = "../sr-primitives", default-features = false } diff --git a/substrate/core/sr-io/Cargo.toml b/substrate/core/sr-io/Cargo.toml index 8b04ef35dd..39e62e7a20 100644 --- a/substrate/core/sr-io/Cargo.toml +++ b/substrate/core/sr-io/Cargo.toml @@ -10,7 +10,7 @@ rustc_version = "0.2" [dependencies] sr-std = { path = "../sr-std", default-features = false } substrate-primitives = { path = "../primitives", default-features = false } -parity-codec = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } hash-db = { git = "https://github.com/paritytech/trie", default-features = false } environmental = { version = "~1.0", optional = true } diff --git a/substrate/core/sr-primitives/Cargo.toml b/substrate/core/sr-primitives/Cargo.toml index 561552795b..0efb04f67b 100644 --- a/substrate/core/sr-primitives/Cargo.toml +++ b/substrate/core/sr-primitives/Cargo.toml @@ -8,8 +8,8 @@ num-traits = { version = "0.2", default-features = false } integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" } serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../primitives", default-features = false } sr-std = { path = "../sr-std", default-features = false } sr-io = { path = "../sr-io", default-features = false } diff --git a/substrate/core/sr-primitives/src/generic/header.rs b/substrate/core/sr-primitives/src/generic/header.rs index 6e5736908b..ff8222c59a 100644 --- a/substrate/core/sr-primitives/src/generic/header.rs +++ b/substrate/core/sr-primitives/src/generic/header.rs @@ -19,7 +19,7 @@ #[cfg(feature = "std")] use serde::{Deserialize, Deserializer}; -use codec::{Decode, Encode, Codec, Input, Output}; +use codec::{Decode, Encode, Codec, Input, Output, HasCompact}; use traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay, Hash as HashT, DigestItem as DigestItemT}; use generic::Digest; @@ -82,7 +82,7 @@ impl<'a, Number: 'a, Hash: 'a + HashT, DigestItem: 'a> Deserialize<'a> for Heade } impl Decode for Header where - Number: Decode, + Number: HasCompact, Hash: HashT, Hash::Output: Decode, DigestItem: DigestItemT + Decode, @@ -90,7 +90,7 @@ impl Decode for Header where fn decode(input: &mut I) -> Option { Some(Header { parent_hash: Decode::decode(input)?, - number: Decode::decode(input)?, + number: <::Type>::decode(input)?.into(), state_root: Decode::decode(input)?, extrinsics_root: Decode::decode(input)?, digest: Decode::decode(input)?, @@ -99,14 +99,14 @@ impl Decode for Header where } impl Encode for Header where - Number: Encode, + Number: HasCompact + Copy, Hash: HashT, Hash::Output: Encode, DigestItem: DigestItemT + Encode, { fn encode_to(&self, dest: &mut T) { dest.push(&self.parent_hash); - dest.push(&self.number); + dest.push(&<::Type>::from(self.number)); dest.push(&self.state_root); dest.push(&self.extrinsics_root); dest.push(&self.digest); @@ -114,7 +114,7 @@ impl Encode for Header where } impl traits::Header for Header where - Number: Member + ::rstd::hash::Hash + Copy + Codec + MaybeDisplay + SimpleArithmetic + Codec, + Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec, Hash: HashT, DigestItem: DigestItemT + Codec, Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec, @@ -157,7 +157,7 @@ impl traits::Header for Header Header where - Number: Member + ::rstd::hash::Hash + Copy + Codec + MaybeDisplay + SimpleArithmetic + Codec, + Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec, Hash: HashT, DigestItem: DigestItemT + Codec, Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec, diff --git a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs index 92c66799de..a37affd9ca 100644 --- a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -20,27 +20,50 @@ use std::fmt; use rstd::prelude::*; -use codec::{Decode, Encode, Input}; +use codec::{Decode, Encode, Codec, Input, HasCompact}; use traits::{self, Member, SimpleArithmetic, MaybeDisplay, Lookup}; use super::CheckedExtrinsic; +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +pub struct SignatureContent +where + Address: Codec, + Index: HasCompact + Codec, + Signature: Codec, +{ + signed: Address, + signature: Signature, + index: Index, +} + /// A extrinsic right from the external world. This is unchecked and so /// can contain a signature. #[derive(PartialEq, Eq, Clone)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct UncheckedExtrinsic { +pub struct UncheckedExtrinsic +where + Address: Codec, + Index: HasCompact + Codec, + Signature: Codec, +{ /// The signature, address and number of extrinsics have come before from /// the same signer, if this is a signed extrinsic. - pub signature: Option<(Address, Signature, Index)>, + pub signature: Option>, /// The function that should be called. pub function: Call, } -impl UncheckedExtrinsic { +impl UncheckedExtrinsic +where + Address: Codec, + Index: HasCompact + Codec, + Signature: Codec, +{ /// New instance of a signed extrinsic aka "transaction". pub fn new_signed(index: Index, function: Call, signed: Address, signature: Signature) -> Self { UncheckedExtrinsic { - signature: Some((signed, signature, index)), + signature: Some(SignatureContent{signed, signature, index}), function, } } @@ -59,13 +82,13 @@ impl UncheckedExtrinsic traits::Checkable +impl traits::Checkable for UncheckedExtrinsic where - Address: Member + MaybeDisplay, - Index: Encode + Member + MaybeDisplay + SimpleArithmetic, + Address: Member + MaybeDisplay + Codec, + Index: Member + MaybeDisplay + SimpleArithmetic + Codec, Call: Encode + Member, - Signature: Member + traits::Verify, + Signature: Member + traits::Verify + Codec, AccountId: Member + MaybeDisplay, Context: Lookup, { @@ -73,7 +96,7 @@ where fn check(self, context: &Context) -> Result { Ok(match self.signature { - Some((signed, signature, index)) => { + Some(SignatureContent{signed, signature, index}) => { let payload = (index, self.function); let signed = context.lookup(signed)?; if !::verify_encoded_lazy(&signature, &payload, &signed) { @@ -92,13 +115,8 @@ where } } -impl Decode +impl Decode for UncheckedExtrinsic -where - Address: Decode, - Signature: Decode, - Index: Decode, - Call: Decode, { fn decode(input: &mut I) -> Option { // This is a little more complicated than usual since the binary format must be compatible @@ -114,13 +132,8 @@ where } } -impl Encode +impl Encode for UncheckedExtrinsic -where - Address: Encode, - Signature: Encode, - Index: Encode, - Call: Encode, { fn encode(&self) -> Vec { super::encode_with_vec_prefix::(|v| { @@ -132,13 +145,16 @@ where /// TODO: use derive when possible. #[cfg(feature = "std")] -impl fmt::Debug for UncheckedExtrinsic where - Address: fmt::Debug, - Index: fmt::Debug, +impl fmt::Debug + for UncheckedExtrinsic +where + Address: fmt::Debug + Codec, + Index: fmt::Debug + HasCompact + Codec, + Signature: Codec, Call: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "UncheckedExtrinsic({:?}, {:?})", self.signature.as_ref().map(|x| (&x.0, &x.2)), self.function) + write!(f, "UncheckedExtrinsic({:?}, {:?})", self.signature.as_ref().map(|x| (&x.signed, &x.index)), self.function) } } diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 8f4cdf2106..24dda09345 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -23,7 +23,7 @@ use runtime_io; #[cfg(feature = "std")] use serde::{Serialize, de::DeserializeOwned}; use substrate_primitives; use substrate_primitives::Blake2Hasher; -use codec::{Codec, Encode}; +use codec::{Codec, Encode, HasCompact}; pub use integer_sqrt::IntegerSquareRoot; pub use num_traits::{Zero, One, Bounded}; pub use num_traits::ops::checked::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; @@ -160,7 +160,8 @@ pub trait SimpleArithmetic: CheckedSub + CheckedMul + CheckedDiv + - PartialOrd + Ord + PartialOrd + Ord + + HasCompact {} impl + @@ -174,7 +175,8 @@ impl + Ord + PartialOrd + Ord + + HasCompact > SimpleArithmetic for T {} /// Trait for things that can be clear (have no bits set). For numeric types, essentially the same diff --git a/substrate/core/sr-sandbox/Cargo.toml b/substrate/core/sr-sandbox/Cargo.toml index 44b7cc78ca..8cb35aed79 100755 --- a/substrate/core/sr-sandbox/Cargo.toml +++ b/substrate/core/sr-sandbox/Cargo.toml @@ -11,7 +11,7 @@ rustc_version = "0.2" wasmi = { version = "0.4.1", optional = true } substrate-primitives = { path = "../primitives", default-features = false } sr-std = { path = "../sr-std", default-features = false } -parity-codec = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } [dev-dependencies] wabt = "0.4" diff --git a/substrate/core/sr-version/Cargo.toml b/substrate/core/sr-version/Cargo.toml index 1380955800..9f3cfe7f64 100644 --- a/substrate/core/sr-version/Cargo.toml +++ b/substrate/core/sr-version/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Parity Technologies "] [dependencies] serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } sr-std = { path = "../sr-std", default-features = false } [features] diff --git a/substrate/core/state-db/Cargo.toml b/substrate/core/state-db/Cargo.toml index 627572cebc..bef12d1ae6 100644 --- a/substrate/core/state-db/Cargo.toml +++ b/substrate/core/state-db/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] parking_lot = "0.5" log = "0.4" substrate-primitives = { path = "../../core/primitives" } -parity-codec = "2.0" -parity-codec-derive = "2.0" +parity-codec = "2.1" +parity-codec-derive = "2.1" [dev-dependencies] env_logger = "0.4" diff --git a/substrate/core/state-machine/Cargo.toml b/substrate/core/state-machine/Cargo.toml index 8742c7da88..c0254116fe 100644 --- a/substrate/core/state-machine/Cargo.toml +++ b/substrate/core/state-machine/Cargo.toml @@ -14,4 +14,4 @@ trie-db = { git = "https://github.com/paritytech/trie" } trie-root = { git = "https://github.com/paritytech/trie" } substrate-trie = { path = "../trie" } substrate-primitives = { path = "../primitives" } -parity-codec = "2.0" +parity-codec = "2.1" diff --git a/substrate/core/test-client/Cargo.toml b/substrate/core/test-client/Cargo.toml index d6686134fc..a1bf2f592e 100644 --- a/substrate/core/test-client/Cargo.toml +++ b/substrate/core/test-client/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] substrate-client = { path = "../client" } -parity-codec = "2.0" +parity-codec = "2.1" substrate-executor = { path = "../executor" } substrate-keyring = { path = "../../core/keyring" } substrate-primitives = { path = "../primitives" } diff --git a/substrate/core/test-runtime/Cargo.toml b/substrate/core/test-runtime/Cargo.toml index 72370f450f..6687c019f6 100644 --- a/substrate/core/test-runtime/Cargo.toml +++ b/substrate/core/test-runtime/Cargo.toml @@ -8,8 +8,8 @@ log = { version = "0.4", optional = true } hex-literal = { version = "0.1.0", optional = true } serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-keyring = { path = "../keyring", optional = true } substrate-primitives = { path = "../primitives", default-features = false } sr-api = { path = "../sr-api", default-features = false } diff --git a/substrate/core/test-runtime/wasm/Cargo.lock b/substrate/core/test-runtime/wasm/Cargo.lock index 42513312d3..3bc67944d2 100644 --- a/substrate/core/test-runtime/wasm/Cargo.lock +++ b/substrate/core/test-runtime/wasm/Cargo.lock @@ -274,10 +274,11 @@ dependencies = [ [[package]] name = "parity-codec" -version = "2.0.2" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -468,7 +469,7 @@ dependencies = [ name = "sr-api" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -481,7 +482,7 @@ version = "0.1.0" dependencies = [ "environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -496,7 +497,7 @@ dependencies = [ "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -517,7 +518,7 @@ dependencies = [ name = "sr-version" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -530,7 +531,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", @@ -548,7 +549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "substrate-metadata" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -566,7 +567,7 @@ dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -587,7 +588,7 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "substrate-trie 0.4.0", @@ -601,7 +602,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api 0.1.0", "sr-io 0.1.0", @@ -618,7 +619,7 @@ version = "0.4.0" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "memory-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.9.0 (git+https://github.com/paritytech/trie)", "trie-root 0.9.0 (git+https://github.com/paritytech/trie)", ] @@ -778,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df92a55cfa11e8e964e9f0e74b257e21086098d6d3e3fbb2f8fcb17bcbb8e1a1" +"checksum parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dca389ea5e1632c89b2ce54f7e2b4a8a8c9d278042222a91e0bf95451218cb4c" "checksum parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa42c2cb493b60b12c75b26e8c94cb734af4df4d7f2cc229dc04c1953dac189" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" diff --git a/substrate/core/test-runtime/wasm/Cargo.toml b/substrate/core/test-runtime/wasm/Cargo.toml index ef2486c0ed..f606a6b300 100644 --- a/substrate/core/test-runtime/wasm/Cargo.toml +++ b/substrate/core/test-runtime/wasm/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Parity Technologies "] [dependencies] log = { version = "0.4", optional = true } hex-literal = { version = "0.1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../primitives", default-features = false } sr-api = { path = "../../sr-api", default-features = false } sr-std = { path = "../../sr-std", default-features = false } diff --git a/substrate/core/transaction-pool/Cargo.toml b/substrate/core/transaction-pool/Cargo.toml index 85ecd32cd2..93768f16d2 100644 --- a/substrate/core/transaction-pool/Cargo.toml +++ b/substrate/core/transaction-pool/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] error-chain = "0.12" futures = "0.1" log = "0.4" -parity-codec = "2.0" +parity-codec = "2.1" parking_lot = "0.4" sr-primitives = { path = "../sr-primitives" } substrate-client = { path = "../client" } diff --git a/substrate/core/trie/Cargo.toml b/substrate/core/trie/Cargo.toml index 6e652dfd52..955c6b95cd 100644 --- a/substrate/core/trie/Cargo.toml +++ b/substrate/core/trie/Cargo.toml @@ -11,7 +11,7 @@ name = "bench" harness = false [dependencies] -parity-codec = { version = "2.0" } +parity-codec = { version = "2.1" } hash-db = { git = "https://github.com/paritytech/trie", default-features = false } trie-db = { git = "https://github.com/paritytech/trie", optional = true } trie-root = { git = "https://github.com/paritytech/trie", default-features = false } diff --git a/substrate/node/consensus/Cargo.toml b/substrate/node/consensus/Cargo.toml index f85892633f..c45818ee07 100644 --- a/substrate/node/consensus/Cargo.toml +++ b/substrate/node/consensus/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.1.17" log = "0.4" node-primitives = { path = "../primitives" } node-runtime = { path = "../runtime" } -parity-codec = "2.0" +parity-codec = "2.1" parking_lot = "0.4" rhododendron = "0.3" sr-primitives = { path = "../../core/sr-primitives" } diff --git a/substrate/node/executor/Cargo.toml b/substrate/node/executor/Cargo.toml index 3e0b4cf30c..6cbbb2f11e 100644 --- a/substrate/node/executor/Cargo.toml +++ b/substrate/node/executor/Cargo.toml @@ -7,7 +7,7 @@ description = "Substrate node implementation in Rust." [dependencies] hex-literal = "0.1" trie-root = { git = "https://github.com/paritytech/trie" } -parity-codec = "2.0" +parity-codec = "2.1" sr-io = { path = "../../core/sr-io" } 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 f131738efb..6a2b8061c3 100644 --- a/substrate/node/executor/src/lib.rs +++ b/substrate/node/executor/src/lib.rs @@ -103,7 +103,7 @@ mod tests { fn xt() -> UncheckedExtrinsic { sign(CheckedExtrinsic { signed: Some((alice(), 0)), - function: Call::Balances(balances::Call::transfer::(bob().into(), 69)), + function: Call::Balances(balances::Call::transfer::(bob().into(), 69.into())), }) } @@ -303,11 +303,11 @@ mod tests { vec![ CheckedExtrinsic { signed: None, - function: Call::Timestamp(timestamp::Call::set(42)), + function: Call::Timestamp(timestamp::Call::set(42.into())), }, CheckedExtrinsic { signed: Some((alice(), 0)), - function: Call::Balances(balances::Call::transfer(bob().into(), 69)), + function: Call::Balances(balances::Call::transfer(bob().into(), 69.into())), }, ] ) @@ -317,20 +317,20 @@ mod tests { construct_block( 2, block1(false).1, - hex!("eef4ca8018e0511f89b7cee1e07796aa710a50accc8b1e52082d05cd8c8b6e24").into(), + hex!("788a2e8b23e4b30e1bce347ca6415fd0080e989d40741c86995b9ad539bb76b3").into(), None, vec![ CheckedExtrinsic { signed: None, - function: Call::Timestamp(timestamp::Call::set(52)), + function: Call::Timestamp(timestamp::Call::set(52.into())), }, CheckedExtrinsic { signed: Some((bob(), 0)), - function: Call::Balances(balances::Call::transfer(alice().into(), 5)), + function: Call::Balances(balances::Call::transfer(alice().into(), 5.into())), }, CheckedExtrinsic { signed: Some((alice(), 1)), - function: Call::Balances(balances::Call::transfer(bob().into(), 15)), + function: Call::Balances(balances::Call::transfer(bob().into(), 15.into())), } ] ) @@ -345,7 +345,7 @@ mod tests { vec![ CheckedExtrinsic { signed: None, - function: Call::Timestamp(timestamp::Call::set(42)), + function: Call::Timestamp(timestamp::Call::set(42.into())), }, CheckedExtrinsic { signed: Some((alice(), 0)), @@ -627,18 +627,18 @@ mod tests { vec![ CheckedExtrinsic { signed: None, - function: Call::Timestamp(timestamp::Call::set(42)), + function: Call::Timestamp(timestamp::Call::set(42.into())), }, CheckedExtrinsic { signed: Some((charlie(), 0)), function: Call::Contract( - contract::Call::create::(10, 10_000, code_ctor_transfer, Vec::new()) + contract::Call::create::(10.into(), 10_000.into(), code_ctor_transfer, Vec::new()) ), }, CheckedExtrinsic { signed: Some((charlie(), 1)), function: Call::Contract( - contract::Call::call::(addr, 10, 10_000, vec![0x00, 0x01, 0x02, 0x03]) + contract::Call::call::(addr, 10.into(), 10_000.into(), vec![0x00, 0x01, 0x02, 0x03]) ), }, ] diff --git a/substrate/node/primitives/Cargo.toml b/substrate/node/primitives/Cargo.toml index 4ad25fd7e5..a28714f6ee 100644 --- a/substrate/node/primitives/Cargo.toml +++ b/substrate/node/primitives/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Parity Technologies "] [dependencies] serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } diff --git a/substrate/node/runtime/Cargo.toml b/substrate/node/runtime/Cargo.toml index d610a02948..ac37cff456 100644 --- a/substrate/node/runtime/Cargo.toml +++ b/substrate/node/runtime/Cargo.toml @@ -9,8 +9,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false } -parity-codec = "2.0" -parity-codec-derive = "2.0" +parity-codec = "2.1" +parity-codec-derive = "2.1" sr-api = { path = "../../core/sr-api", default-features = false } sr-std = { path = "../../core/sr-std" } sr-io = { path = "../../core/sr-io" } diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 6168fb4ba8..45b5db63ad 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -284,7 +284,7 @@ impl_apis! { fn inherent_extrinsics(data: InherentData) -> Vec { let mut inherent = vec![generic::UncheckedMortalExtrinsic::new_unsigned( - Call::Timestamp(TimestampCall::set(data.timestamp)) + Call::Timestamp(TimestampCall::set(data.timestamp.into())) )]; if !data.offline_indices.is_empty() { @@ -307,9 +307,9 @@ impl_apis! { (false, Call::Timestamp(TimestampCall::set(t))) => t, _ => return Err(BlockBuilderError::Generic("No valid timestamp inherent in block".into())), }; - - if *t > data.timestamp + MAX_TIMESTAMP_DRIFT { - return Err(BlockBuilderError::TimestampInFuture(*t)) + let t = (*t).into(); + if t > data.timestamp + MAX_TIMESTAMP_DRIFT { + return Err(BlockBuilderError::TimestampInFuture(t)) } // Offline indices diff --git a/substrate/node/runtime/wasm/Cargo.lock b/substrate/node/runtime/wasm/Cargo.lock index 09affa7abd..7a655c6415 100644 --- a/substrate/node/runtime/wasm/Cargo.lock +++ b/substrate/node/runtime/wasm/Cargo.lock @@ -250,7 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "node-primitives" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -265,7 +265,7 @@ version = "0.1.0" dependencies = [ "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "node-primitives 0.1.0", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api 0.1.0", @@ -316,10 +316,11 @@ dependencies = [ [[package]] name = "parity-codec" -version = "2.0.2" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -528,7 +529,7 @@ dependencies = [ name = "sr-api" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -541,7 +542,7 @@ version = "0.1.0" dependencies = [ "environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -556,7 +557,7 @@ dependencies = [ "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -570,7 +571,7 @@ dependencies = [ name = "sr-sandbox" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (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 0.1.0", "substrate-primitives 0.1.0", @@ -588,7 +589,7 @@ dependencies = [ name = "sr-version" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -600,7 +601,7 @@ name = "srml-balances" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -619,7 +620,7 @@ name = "srml-consensus" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -635,7 +636,7 @@ dependencies = [ name = "srml-contract" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (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.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -656,7 +657,7 @@ name = "srml-council" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -676,7 +677,7 @@ name = "srml-democracy" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -695,7 +696,7 @@ name = "srml-executive" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -711,7 +712,7 @@ name = "srml-session" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -731,7 +732,7 @@ name = "srml-staking" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -755,7 +756,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", @@ -769,7 +770,7 @@ name = "srml-system" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.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.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -786,7 +787,7 @@ name = "srml-timestamp" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", @@ -803,7 +804,7 @@ name = "srml-treasury" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -834,7 +835,7 @@ dependencies = [ name = "substrate-metadata" version = "0.1.0" dependencies = [ - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -852,7 +853,7 @@ dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -873,7 +874,7 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "substrate-trie 0.4.0", @@ -887,7 +888,7 @@ version = "0.4.0" dependencies = [ "hash-db 0.9.0 (git+https://github.com/paritytech/trie)", "memory-db 0.9.0 (git+https://github.com/paritytech/trie)", - "parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.9.0 (git+https://github.com/paritytech/trie)", "trie-root 0.9.0 (git+https://github.com/paritytech/trie)", ] @@ -1047,7 +1048,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parity-codec 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df92a55cfa11e8e964e9f0e74b257e21086098d6d3e3fbb2f8fcb17bcbb8e1a1" +"checksum parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dca389ea5e1632c89b2ce54f7e2b4a8a8c9d278042222a91e0bf95451218cb4c" "checksum parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa42c2cb493b60b12c75b26e8c94cb734af4df4d7f2cc229dc04c1953dac189" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" diff --git a/substrate/node/runtime/wasm/Cargo.toml b/substrate/node/runtime/wasm/Cargo.toml index 4dfa3d3ba3..7fb33ff26b 100644 --- a/substrate/node/runtime/wasm/Cargo.toml +++ b/substrate/node/runtime/wasm/Cargo.toml @@ -9,8 +9,8 @@ crate-type = ["cdylib"] [dependencies] integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" } safe-mix = { version = "1.0", default-features = false} -parity-codec-derive = { version = "2.0" } -parity-codec = { version = "2.0", default-features = false } +parity-codec-derive = { version = "2.1" } +parity-codec = { version = "2.1", default-features = false } substrate-primitives = { path = "../../../core/primitives", default-features = false } sr-api = { path = "../../../core/sr-api", default-features = false } sr-std = { path = "../../../core/sr-std", default-features = false } diff --git a/substrate/node/service/Cargo.toml b/substrate/node/service/Cargo.toml index f341aaa4c9..2ef8ae5a12 100644 --- a/substrate/node/service/Cargo.toml +++ b/substrate/node/service/Cargo.toml @@ -13,7 +13,7 @@ node-executor = { path = "../executor" } node-network = { path = "../network" } node-primitives = { path = "../primitives" } node-runtime = { path = "../runtime" } -parity-codec = { version = "2.0" } +parity-codec = { version = "2.1" } parking_lot = "0.4" slog = "^2" sr-io = { path = "../../core/sr-io" } diff --git a/substrate/node/service/src/lib.rs b/substrate/node/service/src/lib.rs index d966f40bf5..dc799ba4dd 100644 --- a/substrate/node/service/src/lib.rs +++ b/substrate/node/service/src/lib.rs @@ -249,7 +249,7 @@ mod tests { } }; let extrinsic_factory = |service: &::FullService| { - let payload = (0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69)), Era::immortal(), service.client().genesis_hash()); + let payload = (0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())), Era::immortal(), service.client().genesis_hash()); let signature = alice.sign(&payload.encode()).into(); let id = alice.public().0.into(); let xt = UncheckedExtrinsic { diff --git a/substrate/srml/balances/Cargo.toml b/substrate/srml/balances/Cargo.toml index c734f0af0c..769e801ca9 100644 --- a/substrate/srml/balances/Cargo.toml +++ b/substrate/srml/balances/Cargo.toml @@ -8,8 +8,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-keyring = { path = "../../core/keyring", optional = true } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index bf497bd181..50c9b27d76 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -41,7 +41,7 @@ extern crate substrate_primitives; use rstd::prelude::*; use rstd::{cmp, result}; -use codec::{Encode, Decode, Codec, Input, Output}; +use codec::{Encode, Decode, Codec, Input, Output, HasCompact}; use runtime_support::{StorageValue, StorageMap, Parameter}; use runtime_support::dispatch::Result; use primitives::traits::{Zero, One, SimpleArithmetic, OnFinalise, MakePayment, @@ -125,8 +125,8 @@ pub trait Trait: system::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn transfer(origin, dest: RawAddress, value: T::Balance) -> Result; - fn set_balance(who: RawAddress, free: T::Balance, reserved: T::Balance) -> Result; + fn transfer(origin, dest: RawAddress, value: ::Type) -> Result; + fn set_balance(who: RawAddress, free: ::Type, reserved: ::Type) -> Result; } } @@ -288,10 +288,11 @@ impl Module { // PUBLIC DISPATCH /// Transfer some liquid free balance to another staker. - pub fn transfer(origin: T::Origin, dest: Address, value: T::Balance) -> Result { + pub fn transfer(origin: T::Origin, dest: Address, value: ::Type) -> Result { let transactor = ensure_signed(origin)?; let dest = Self::lookup(dest)?; + let value = value.into(); let from_balance = Self::free_balance(&transactor); let to_balance = Self::free_balance(&dest); let would_create = to_balance.is_zero(); @@ -328,10 +329,10 @@ impl Module { } /// Set the balances of a given account. - fn set_balance(who: Address, free: T::Balance, reserved: T::Balance) -> Result { + fn set_balance(who: Address, free: ::Type, reserved: ::Type) -> Result { let who = Self::lookup(who)?; - Self::set_free_balance(&who, free); - Self::set_reserved_balance(&who, reserved); + Self::set_free_balance(&who, free.into()); + Self::set_reserved_balance(&who, reserved.into()); Ok(()) } diff --git a/substrate/srml/balances/src/tests.rs b/substrate/srml/balances/src/tests.rs index 801a6d30a9..b9c5b85902 100644 --- a/substrate/srml/balances/src/tests.rs +++ b/substrate/srml/balances/src/tests.rs @@ -58,7 +58,7 @@ fn default_indexing_on_new_accounts_should_work() { .build(), || { assert_eq!(Balances::lookup_index(4), None); - assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10)); + assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10.into())); assert_eq!(Balances::lookup_index(4), Some(5)); }, ); @@ -75,7 +75,7 @@ fn default_indexing_on_new_accounts_should_work2() { || { assert_eq!(Balances::lookup_index(4), None); // account 1 has 256 * 10 = 2560, account 5 is not exist, ext_deposit is 10, value is 10 - assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10)); + assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10.into())); assert_eq!(Balances::lookup_index(4), Some(5)); assert_eq!(Balances::free_balance(&1), 256 * 10 - 10 - 50); // 10 is value, 50 is creation_free @@ -95,7 +95,7 @@ fn default_indexing_on_new_accounts_should_not_work2() { assert_eq!(Balances::lookup_index(4), None); // account 1 has 256 * 10 = 2560, account 5 is not exist, ext_deposit is 10, value is 9, not satisfies for ext_deposit assert_noop!( - Balances::transfer(Some(1).into(), 5.into(), 9), + Balances::transfer(Some(1).into(), 5.into(), 9.into()), "value too low to create account" ); assert_eq!(Balances::lookup_index(4), None); // account 5 should not exist @@ -116,7 +116,7 @@ fn dust_account_removal_should_work() { assert_eq!(System::account_nonce(&2), 1); assert_eq!(Balances::total_balance(&2), 256 * 20); - assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 10 + 1)); // index 1 (account 2) becomes zombie + assert_ok!(Balances::transfer(Some(2).into(), 5.into(), (256 * 10 + 1).into())); // index 1 (account 2) becomes zombie assert_eq!(Balances::total_balance(&2), 0); assert_eq!(Balances::total_balance(&5), 256 * 10 + 1); assert_eq!(System::account_nonce(&2), 0); @@ -136,7 +136,7 @@ fn dust_account_removal_should_work2() { System::inc_account_nonce(&2); assert_eq!(System::account_nonce(&2), 1); assert_eq!(Balances::total_balance(&2), 256 * 20); - assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 10)); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit) + assert_ok!(Balances::transfer(Some(2).into(), 5.into(), (256 * 10).into())); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit) assert_eq!(Balances::total_balance(&2), 0); assert_eq!(Balances::total_balance(&5), 256 * 10); assert_eq!(System::account_nonce(&2), 0); @@ -156,10 +156,10 @@ fn reclaim_indexing_on_new_accounts_should_work() { assert_eq!(Balances::lookup_index(4), None); assert_eq!(Balances::total_balance(&2), 256 * 20); - assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 20)); // account 2 becomes zombie freeing index 1 for reclaim) + assert_ok!(Balances::transfer(Some(2).into(), 5.into(), (256 * 20).into())); // account 2 becomes zombie freeing index 1 for reclaim) assert_eq!(Balances::total_balance(&2), 0); - assert_ok!(Balances::transfer(Some(5).into(), 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1. + assert_ok!(Balances::transfer(Some(5).into(), 6.into(), (256 * 1 + 0x69).into())); // account 6 takes index 1. assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(6)); }, @@ -178,10 +178,10 @@ fn reclaim_indexing_on_new_accounts_should_work2() { assert_eq!(Balances::lookup_index(4), None); assert_eq!(Balances::total_balance(&2), 256 * 20); - assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 20 - 50)); // account 2 becomes zombie freeing index 1 for reclaim) 50 is creation fee + assert_ok!(Balances::transfer(Some(2).into(), 5.into(), (256 * 20 - 50).into())); // account 2 becomes zombie freeing index 1 for reclaim) 50 is creation fee assert_eq!(Balances::total_balance(&2), 0); - assert_ok!(Balances::transfer(Some(5).into(), 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1. + assert_ok!(Balances::transfer(Some(5).into(), 6.into(), (256 * 1 + 0x69).into())); // account 6 takes index 1. assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(6)); }, @@ -206,7 +206,7 @@ fn reserved_balance_should_prevent_reclaim_count() { assert_eq!(Balances::total_balance(&2), 256 * 19 + 1); // reserve still exists. assert_eq!(System::account_nonce(&2), 1); - assert_ok!(Balances::transfer(Some(4).into(), 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5. + assert_ok!(Balances::transfer(Some(4).into(), 5.into(), (256 * 1 + 0x69).into())); // account 4 tries to take index 1 for account 5. assert_eq!(Balances::total_balance(&5), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(2)); // but fails. assert_eq!(System::account_nonce(&2), 1); @@ -215,7 +215,7 @@ fn reserved_balance_should_prevent_reclaim_count() { assert_eq!(Balances::total_balance(&2), 0); // "free" account deleted." assert_eq!(System::account_nonce(&2), 0); - assert_ok!(Balances::transfer(Some(4).into(), 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6. + assert_ok!(Balances::transfer(Some(4).into(), 6.into(), (256 * 1 + 0x69).into())); // account 4 tries to take index 1 again for account 6. assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(6)); // and succeeds. }, @@ -240,7 +240,7 @@ fn reserved_balance_should_prevent_reclaim_count2() { assert_eq!(Balances::total_balance(&2), 256 * 19 + 1); // reserve still exists. assert_eq!(System::account_nonce(&2), 1); - assert_ok!(Balances::transfer(Some(4).into(), 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5. + assert_ok!(Balances::transfer(Some(4).into(), 5.into(), (256 * 1 + 0x69).into())); // account 4 tries to take index 1 for account 5. assert_eq!(Balances::total_balance(&5), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(2)); // but fails. assert_eq!(System::account_nonce(&2), 1); @@ -249,7 +249,7 @@ fn reserved_balance_should_prevent_reclaim_count2() { assert_eq!(Balances::total_balance(&2), 0); // "free" account deleted." assert_eq!(System::account_nonce(&2), 0); - assert_ok!(Balances::transfer(Some(4).into(), 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6. + assert_ok!(Balances::transfer(Some(4).into(), 6.into(), (256 * 1 + 0x69).into())); // account 4 tries to take index 1 again for account 6. assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69); assert_eq!(Balances::lookup_index(1), Some(6)); // and succeeds. }, @@ -274,7 +274,7 @@ fn balance_transfer_works() { with_externalities(&mut ExtBuilder::default().build(), || { Balances::set_free_balance(&1, 111); Balances::increase_total_stake_by(111); - assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 69)); + assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 69.into())); assert_eq!(Balances::total_balance(&1), 42); assert_eq!(Balances::total_balance(&2), 69); }); @@ -302,7 +302,7 @@ fn balance_transfer_when_reserved_should_not_work() { with_externalities(&mut ExtBuilder::default().build(), || { Balances::set_free_balance(&1, 111); assert_ok!(Balances::reserve(&1, 69)); - assert_noop!(Balances::transfer(Some(1).into(), 2.into(), 69), "balance too low to send value"); + assert_noop!(Balances::transfer(Some(1).into(), 2.into(), 69.into()), "balance too low to send value"); }); } @@ -433,7 +433,7 @@ fn transferring_too_high_value_should_not_panic() { >::insert(2, 1); assert_err!( - Balances::transfer(Some(1).into(), 2.into(), u64::max_value()), + Balances::transfer(Some(1).into(), 2.into(), u64::max_value().into()), "destination balance too high to receive value" ); @@ -461,7 +461,7 @@ fn account_removal_on_free_too_low() { // Transfer funds from account 1 of such amount that after this transfer // the balance of account 1 will be below the exsistential threshold. // This should lead to the removal of all balance of this account. - assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 20)); + assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 20.into())); // Verify free balance removal of account 1. assert_eq!(Balances::free_balance(&1), 0); @@ -481,7 +481,7 @@ fn transfer_overflow_isnt_exploitable() { let evil_value = u64::max_value() - 49; assert_err!( - Balances::transfer(Some(1).into(), 5.into(), evil_value), + Balances::transfer(Some(1).into(), 5.into(), evil_value.into()), "got overflow after adding a fee to value" ); } diff --git a/substrate/srml/consensus/Cargo.toml b/substrate/srml/consensus/Cargo.toml index 8e38d2a8f4..c7bbfe03f6 100644 --- a/substrate/srml/consensus/Cargo.toml +++ b/substrate/srml/consensus/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/contract/Cargo.toml b/substrate/srml/contract/Cargo.toml index 197dcf3f17..51a0b172db 100644 --- a/substrate/srml/contract/Cargo.toml +++ b/substrate/srml/contract/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } pwasm-utils = { version = "0.3", default-features = false } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } parity-wasm = { version = "0.31", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } diff --git a/substrate/srml/contract/src/lib.rs b/substrate/srml/contract/src/lib.rs index bef16e29f3..6c2c3b6df0 100644 --- a/substrate/srml/contract/src/lib.rs +++ b/substrate/srml/contract/src/lib.rs @@ -102,7 +102,7 @@ use double_map::StorageDoubleMap; use rstd::prelude::*; use rstd::marker::PhantomData; -use codec::Codec; +use codec::{Codec, HasCompact}; use runtime_primitives::traits::{Hash, As, SimpleArithmetic, OnFinalise}; use runtime_support::dispatch::Result; use runtime_support::{Parameter, StorageMap, StorageValue}; @@ -155,15 +155,15 @@ decl_module! { fn call( origin, dest: T::AccountId, - value: T::Balance, - gas_limit: T::Gas, + value: ::Type, + gas_limit: ::Type, data: Vec ) -> Result; fn create( origin, - value: T::Balance, - gas_limit: T::Gas, + value: ::Type, + gas_limit: ::Type, init_code: Vec, data: Vec ) -> Result; @@ -227,11 +227,13 @@ impl Module { fn call( origin: ::Origin, dest: T::AccountId, - value: T::Balance, - gas_limit: T::Gas, + value: ::Type, + gas_limit: ::Type, data: Vec, ) -> Result { let origin = ensure_signed(origin)?; + let value = value.into(); + let gas_limit = gas_limit.into(); // Pay for the gas upfront. // @@ -277,12 +279,14 @@ impl Module { /// upon any message received by this account. fn create( origin: ::Origin, - endowment: T::Balance, - gas_limit: T::Gas, + endowment: ::Type, + gas_limit: ::Type, ctor_code: Vec, data: Vec, ) -> Result { let origin = ensure_signed(origin)?; + let endowment = endowment.into(); + let gas_limit = gas_limit.into(); // Pay for the gas upfront. // diff --git a/substrate/srml/contract/src/tests.rs b/substrate/srml/contract/src/tests.rs index 6bbb6cd11e..f48769c978 100644 --- a/substrate/srml/contract/src/tests.rs +++ b/substrate/srml/contract/src/tests.rs @@ -199,7 +199,7 @@ fn contract_transfer() { Balances::set_free_balance(&1, 11); Balances::increase_total_stake_by(11); - assert_ok!(Contract::call(Origin::signed(0), 1, 3, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 3.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -257,7 +257,7 @@ fn contract_transfer_to_death() { Balances::increase_total_stake_by(6); >::insert(1, b"foo".to_vec(), b"1".to_vec()); - assert_ok!(Contract::call(Origin::signed(0), 1, 0, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 0.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -290,7 +290,7 @@ fn contract_transfer_takes_creation_fee() { Balances::set_free_balance(&1, 11); Balances::increase_total_stake_by(11); - assert_ok!(Contract::call(Origin::signed(0), 1, 3, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 3.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -331,7 +331,7 @@ fn contract_transfer_takes_transfer_fee() { // is charged (and creation fee is not). Balances::set_free_balance(&CONTRACT_SHOULD_TRANSFER_TO, 25); - assert_ok!(Contract::call(Origin::signed(0), 1, 3, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 3.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -368,7 +368,7 @@ fn contract_transfer_oog() { Balances::set_free_balance(&1, 11); Balances::increase_total_stake_by(11); - assert_ok!(Contract::call(Origin::signed(0), 1, 3, 135 + 135 + 7, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 3.into(), (135 + 135 + 7).into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -407,7 +407,7 @@ fn contract_transfer_max_depth() { Balances::set_free_balance(&CONTRACT_SHOULD_TRANSFER_TO, 11); Balances::increase_total_stake_by(11); - assert_ok!(Contract::call(Origin::signed(0), CONTRACT_SHOULD_TRANSFER_TO, 3, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), CONTRACT_SHOULD_TRANSFER_TO, 3.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -519,7 +519,7 @@ fn contract_create() { >::insert(1, code_create.to_vec()); // When invoked, the contract at address `1` must create a contract with 'transfer' code. - assert_ok!(Contract::call(Origin::signed(0), 1, 11, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 11.into(), 100_000.into(), Vec::new())); let derived_address = ::DetermineContractAddress::contract_address_for( &code_ctor_transfer, @@ -560,7 +560,7 @@ fn contract_create() { ]); // Initiate transfer to the newly created contract. - assert_ok!(Contract::call(Origin::signed(0), derived_address, 22, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), derived_address, 22.into(), 100_000.into(), Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -594,8 +594,8 @@ fn top_level_create() { assert_ok!(Contract::create( Origin::signed(0), - 11, - 100_000, + 11.into(), + 100_000.into(), code_ctor_transfer.clone(), Vec::new(), )); @@ -639,7 +639,7 @@ fn refunds_unused_gas() { Balances::set_free_balance(&0, 100_000_000); Balances::increase_total_stake_by(100_000_000); - assert_ok!(Contract::call(Origin::signed(0), 1, 0, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 0.into(), 100_000.into(), Vec::new())); assert_eq!(Balances::free_balance(&0), 100_000_000 - 4 - (2 * 135)); }); @@ -653,7 +653,7 @@ fn call_with_zero_value() { Balances::set_free_balance(&0, 100_000_000); Balances::increase_total_stake_by(100_000_000); - assert_ok!(Contract::call(Origin::signed(0), 1, 0, 100_000, Vec::new())); + assert_ok!(Contract::call(Origin::signed(0), 1, 0.into(), 100_000.into(), Vec::new())); assert_eq!(Balances::free_balance(&0), 100_000_000 - (2 * 135)); }); @@ -667,7 +667,7 @@ fn create_with_zero_endowment() { Balances::set_free_balance(&0, 100_000_000); Balances::increase_total_stake_by(100_000_000); - assert_ok!(Contract::create(Origin::signed(0), 0, 100_000, code_nop, Vec::new())); + assert_ok!(Contract::create(Origin::signed(0), 0.into(), 100_000.into(), code_nop, Vec::new())); assert_eq!( Balances::free_balance(&0), @@ -700,7 +700,7 @@ fn account_removal_removes_storage() { // the balance of account 1 is will be below than exsistential threshold. // // This should lead to the removal of all storage associated with this account. - assert_ok!(Balances::transfer(Origin::signed(1), 2.into(), 20)); + assert_ok!(Balances::transfer(Origin::signed(1), 2.into(), 20.into())); // Verify that all entries from account 1 is removed, while // entries from account 2 is in place. @@ -740,7 +740,7 @@ fn top_level_call_refunds_even_if_fails() { Balances::increase_total_stake_by(100_000_000); assert_err!( - Contract::call(Origin::signed(0), 1, 0, 100_000, Vec::new()), + Contract::call(Origin::signed(0), 1, 0.into(), 100_000.into(), Vec::new()), "vm execute returned error while call" ); @@ -773,19 +773,19 @@ fn block_gas_limit() { // Spend 50_000 units of gas (OOG). assert_err!( - Contract::call(Origin::signed(0), 1, 0, 50_000, Vec::new()), + Contract::call(Origin::signed(0), 1, 0.into(), 50_000.into(), Vec::new()), "vm execute returned error while call" ); // Ensure we can't spend more gas than available in block gas limit. assert_err!( - Contract::call(Origin::signed(0), 1, 0, 50_001, Vec::new()), + Contract::call(Origin::signed(0), 1, 0.into(), 50_001.into(), Vec::new()), "block gas limit is reached" ); // However, we can spend another 50_000 assert_err!( - Contract::call(Origin::signed(0), 1, 0, 50_000, Vec::new()), + Contract::call(Origin::signed(0), 1, 0.into(), 50_000.into(), Vec::new()), "vm execute returned error while call" ); }, @@ -858,7 +858,7 @@ fn input_data() { Balances::set_free_balance(&0, 100_000_000); Balances::increase_total_stake_by(100_000_000); - assert_ok!(Contract::call(Origin::signed(0), 1, 0, 50_000, vec![0, 1, 2, 3])); + assert_ok!(Contract::call(Origin::signed(0), 1, 0.into(), 50_000.into(), vec![0, 1, 2, 3])); // all asserts are made within contract code itself. }, diff --git a/substrate/srml/council/Cargo.toml b/substrate/srml/council/Cargo.toml index 9f851f41fd..39cd73e96c 100644 --- a/substrate/srml/council/Cargo.toml +++ b/substrate/srml/council/Cargo.toml @@ -8,8 +8,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/council/src/motions.rs b/substrate/srml/council/src/motions.rs index 418576dd26..ab6ea5f4ef 100644 --- a/substrate/srml/council/src/motions.rs +++ b/substrate/srml/council/src/motions.rs @@ -18,6 +18,7 @@ use rstd::prelude::*; use rstd::result; +use codec::Compact; use substrate_primitives::u32_trait::Value as U32; use primitives::traits::{Hash, EnsureOrigin, MaybeSerializeDebug, OnFinalise}; use srml_support::dispatch::{Result, Dispatchable, Parameter}; @@ -67,8 +68,8 @@ decl_event!( decl_module! { #[cfg_attr(feature = "std", serde(bound(deserialize = "::Proposal: ::serde::de::DeserializeOwned")))] pub struct Module for enum Call where origin: ::Origin { - fn propose(origin, threshold: u32, proposal: Box<::Proposal>) -> Result; - fn vote(origin, proposal: T::Hash, index: ProposalIndex, approve: bool) -> Result; + fn propose(origin, threshold: Compact, proposal: Box<::Proposal>) -> Result; + fn vote(origin, proposal: T::Hash, index: Compact, approve: bool) -> Result; } } @@ -102,8 +103,9 @@ impl Module { } // Dispatch - fn propose(origin: ::Origin, threshold: u32, proposal: Box<::Proposal>) -> Result { + fn propose(origin: ::Origin, threshold: Compact, proposal: Box<::Proposal>) -> Result { let who = ensure_signed(origin)?; + let threshold = threshold.into(); ensure!(Self::is_councillor(&who), "proposer not on council"); @@ -126,8 +128,9 @@ impl Module { Ok(()) } - fn vote(origin: ::Origin, proposal: T::Hash, index: ProposalIndex, approve: bool) -> Result { + fn vote(origin: ::Origin, proposal: T::Hash, index: Compact, approve: bool) -> Result { let who = ensure_signed(origin)?; + let index = index.into(); ensure!(Self::is_councillor(&who), "voter not on council"); @@ -236,7 +239,7 @@ mod tests { } fn set_balance_proposal(value: u64) -> Call { - Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value, 0)) + Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value.into(), 0.into())) } #[test] @@ -245,7 +248,7 @@ mod tests { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone()))); assert_eq!(CouncilMotions::proposals(), vec![hash]); assert_eq!(CouncilMotions::proposal_of(&hash), Some(proposal)); assert_eq!(CouncilMotions::voting(&hash), Some((0, 3, vec![1], Vec::::new()))); @@ -253,7 +256,7 @@ mod tests { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), 3)) + event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), 3)) } ]); }); @@ -264,7 +267,7 @@ mod tests { with_externalities(&mut new_test_ext(true), || { System::set_block_number(1); let proposal = set_balance_proposal(42); - assert_noop!(CouncilMotions::propose(Origin::signed(42), 3, Box::new(proposal.clone())), "proposer not on council"); + assert_noop!(CouncilMotions::propose(Origin::signed(42), 3.into(), Box::new(proposal.clone())), "proposer not on council"); }); } @@ -274,8 +277,8 @@ mod tests { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); - assert_noop!(CouncilMotions::vote(Origin::signed(42), hash.clone(), 0, true), "voter not on council"); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone()))); + assert_noop!(CouncilMotions::vote(Origin::signed(42), hash.clone(), 0.into(), true), "voter not on council"); }); } @@ -285,8 +288,8 @@ mod tests { System::set_block_number(3); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); - assert_noop!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 1, true), "mismatched index"); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone()))); + assert_noop!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 1.into(), true), "mismatched index"); }); } @@ -296,21 +299,21 @@ mod tests { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 2.into(), Box::new(proposal.clone()))); assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, vec![1], Vec::::new()))); - assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, true), "duplicate vote ignored"); - assert_ok!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false)); + assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), true), "duplicate vote ignored"); + assert_ok!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), false)); assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, Vec::::new(), vec![1]))); - assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false), "duplicate vote ignored"); + assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), false), "duplicate vote ignored"); assert_eq!(System::events(), vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), 2)) + event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), 2)) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Voted(1, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), false, 0, 1)) + event: OuterEvent::motions(RawEvent::Voted(1, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), false, 0, 1)) } ]); }); @@ -322,21 +325,21 @@ mod tests { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); - assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, false)); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0.into(), false)); assert_eq!(System::events(), vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), 3)) + event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), 3)) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Voted(2, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), false, 1, 1)) + event: OuterEvent::motions(RawEvent::Voted(2, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), false, 1, 1)) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Disapproved(hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into())) + event: OuterEvent::motions(RawEvent::Disapproved(hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into())) } ]); }); @@ -348,25 +351,25 @@ mod tests { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); - assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone()))); - assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, true)); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 2.into(), Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0.into(), true)); assert_eq!(System::events(), vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), 2)) + event: OuterEvent::motions(RawEvent::Proposed(1, 0, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), 2)) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Voted(2, hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), true, 2, 0)) + event: OuterEvent::motions(RawEvent::Voted(2, hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), true, 2, 0)) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Approved(hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into())) + event: OuterEvent::motions(RawEvent::Approved(hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into())) }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: OuterEvent::motions(RawEvent::Executed(hex!["a900ca23832b1f42a5d4af5d0ece88da63fbb4049cc00bac3f741eabb5a79c45"].into(), false)) + event: OuterEvent::motions(RawEvent::Executed(hex!["35282aeb9f95795dc1be91b748cec2d210338f2c9c1a85d98e7a3619b6187d22"].into(), false)) } ]); }); diff --git a/substrate/srml/council/src/seats.rs b/substrate/srml/council/src/seats.rs index 8e01dc1054..42c3858efb 100644 --- a/substrate/srml/council/src/seats.rs +++ b/substrate/srml/council/src/seats.rs @@ -17,6 +17,7 @@ //! Council system: Handles the voting in and maintenance of council members. use rstd::prelude::*; +use codec::{Compact, HasCompact}; use primitives::traits::{Zero, One, As, OnFinalise}; use runtime_io::print; use srml_support::{StorageValue, StorageMap, dispatch::Result}; @@ -86,16 +87,16 @@ pub trait Trait: democracy::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn set_approvals(origin, votes: Vec, index: VoteIndex) -> Result; - fn reap_inactive_voter(origin, reporter_index: u32, who: Address, who_index: u32, assumed_vote_index: VoteIndex) -> Result; - fn retract_voter(origin, index: u32) -> Result; - fn submit_candidacy(origin, slot: u32) -> Result; - fn present_winner(origin, candidate: Address, total: T::Balance, index: VoteIndex) -> Result; + fn set_approvals(origin, votes: Vec, index: Compact) -> Result; + fn reap_inactive_voter(origin, reporter_index: Compact, who: Address, who_index: Compact, assumed_vote_index: Compact) -> Result; + fn retract_voter(origin, index: Compact) -> Result; + fn submit_candidacy(origin, slot: Compact) -> Result; + fn present_winner(origin, candidate: Address, total: ::Type, index: Compact) -> Result; - fn set_desired_seats(count: u32) -> Result; + fn set_desired_seats(count: Compact) -> Result; fn remove_member(who: Address) -> Result; - fn set_presentation_duration(count: T::BlockNumber) -> Result; - fn set_term_duration(count: T::BlockNumber) -> Result; + fn set_presentation_duration(count: ::Type) -> Result; + fn set_term_duration(count: ::Type) -> Result; } } @@ -227,8 +228,9 @@ impl Module { /// Set candidate approvals. Approval slots stay valid as long as candidates in those slots /// are registered. - fn set_approvals(origin: T::Origin, votes: Vec, index: VoteIndex) -> Result { + fn set_approvals(origin: T::Origin, votes: Vec, index: Compact) -> Result { let who = ensure_signed(origin)?; + let index: VoteIndex = index.into(); ensure!(!Self::presentation_active(), "no approval changes during presentation period"); ensure!(index == Self::vote_index(), "incorrect vote index"); @@ -255,12 +257,13 @@ impl Module { /// May be called by anyone. Returns the voter deposit to `signed`. fn reap_inactive_voter( origin: T::Origin, - reporter_index: u32, + reporter_index: Compact, who: Address, - who_index: u32, - assumed_vote_index: VoteIndex + who_index: Compact, + assumed_vote_index: Compact ) -> Result { let reporter = ensure_signed(origin)?; + let assumed_vote_index: VoteIndex = assumed_vote_index.into(); let who = >::lookup(who)?; ensure!(!Self::presentation_active(), "cannot reap during presentation period"); @@ -269,7 +272,9 @@ impl Module { ensure!(assumed_vote_index == Self::vote_index(), "vote index not current"); ensure!(last_active < assumed_vote_index - Self::inactivity_grace_period(), "cannot reap during grace perid"); let voters = Self::voters(); + let reporter_index: u32 = reporter_index.into(); let reporter_index = reporter_index as usize; + let who_index: u32 = who_index.into(); let who_index = who_index as usize; ensure!(reporter_index < voters.len() && voters[reporter_index] == reporter, "bad reporter index"); ensure!(who_index < voters.len() && voters[who_index] == who, "bad target index"); @@ -302,12 +307,13 @@ impl Module { } /// Remove a voter. All votes are cancelled and the voter deposit is returned. - fn retract_voter(origin: T::Origin, index: u32) -> Result { + fn retract_voter(origin: T::Origin, index: Compact) -> Result { let who = ensure_signed(origin)?; ensure!(!Self::presentation_active(), "cannot retract when presenting"); ensure!(>::exists(&who), "cannot retract non-voter"); let voters = Self::voters(); + let index: u32 = index.into(); let index = index as usize; ensure!(index < voters.len(), "retraction index invalid"); ensure!(voters[index] == who, "retraction index mismatch"); @@ -320,10 +326,11 @@ impl Module { /// Submit oneself for candidacy. /// /// Account must have enough transferrable funds in it to pay the bond. - fn submit_candidacy(origin: T::Origin, slot: u32) -> Result { + fn submit_candidacy(origin: T::Origin, slot: Compact) -> Result { let who = ensure_signed(origin)?; ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission"); + let slot: u32 = slot.into(); let slot = slot as usize; let count = Self::candidate_count() as usize; let candidates = Self::candidates(); @@ -354,10 +361,12 @@ impl Module { fn present_winner( origin: T::Origin, candidate: Address, - total: T::Balance, - index: VoteIndex + total: ::Type, + index: Compact ) -> Result { let who = ensure_signed(origin)?; + let total = total.into(); + let index: VoteIndex = index.into(); let candidate = >::lookup(candidate)?; ensure!(index == Self::vote_index(), "index not current"); @@ -404,7 +413,8 @@ impl Module { /// Set the desired member count; if lower than the current count, then seats will not be up /// election when they expire. If more, then a new vote will be started if one is not already /// in progress. - fn set_desired_seats(count: u32) -> Result { + fn set_desired_seats(count: Compact) -> Result { + let count: u32 = count.into(); >::put(count); Ok(()) } @@ -424,15 +434,15 @@ impl Module { /// Set the presentation duration. If there is currently a vote being presented for, will /// invoke `finalise_vote`. - fn set_presentation_duration(count: T::BlockNumber) -> Result { - >::put(count); + fn set_presentation_duration(count: ::Type) -> Result { + >::put(count.into()); Ok(()) } /// Set the presentation duration. If there is current a vote being presented for, will /// invoke `finalise_vote`. - fn set_term_duration(count: T::BlockNumber) -> Result { - >::put(count); + fn set_term_duration(count: ::Type) -> Result { + >::put(count.into()); Ok(()) } @@ -606,14 +616,14 @@ mod tests { assert_eq!(Council::is_a_candidate(&1), false); assert_eq!(Council::is_a_candidate(&2), false); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); assert_eq!(Council::candidates(), vec![1]); assert_eq!(Council::candidate_reg_info(1), Some((0, 0))); assert_eq!(Council::candidate_reg_info(2), None); assert_eq!(Council::is_a_candidate(&1), true); assert_eq!(Council::is_a_candidate(&2), false); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); assert_eq!(Council::candidates(), vec![1, 2]); assert_eq!(Council::candidate_reg_info(1), Some((0, 0))); assert_eq!(Council::candidate_reg_info(2), Some((0, 1))); @@ -640,10 +650,10 @@ mod tests { System::set_block_number(1); assert_eq!(Council::candidates(), vec![0, 0, 1]); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); assert_eq!(Council::candidates(), vec![0, 2, 1]); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into())); assert_eq!(Council::candidates(), vec![3, 2, 1]); }); } @@ -656,10 +666,10 @@ mod tests { System::set_block_number(1); assert_eq!(Council::candidates(), vec![0, 0, 1]); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); assert_eq!(Council::candidates(), vec![2, 0, 1]); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1.into())); assert_eq!(Council::candidates(), vec![2, 3, 1]); }); } @@ -668,7 +678,7 @@ mod tests { fn candidate_submission_not_using_free_slot_should_not_work() { with_externalities(&mut new_test_ext_with_candidate_holes(), || { System::set_block_number(1); - assert_noop!(Council::submit_candidacy(Origin::signed(4), 3), "invalid candidate slot"); + assert_noop!(Council::submit_candidacy(Origin::signed(4), 3.into()), "invalid candidate slot"); }); } @@ -677,7 +687,7 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); - assert_noop!(Council::submit_candidacy(Origin::signed(1), 1), "invalid candidate slot"); + assert_noop!(Council::submit_candidacy(Origin::signed(1), 1.into()), "invalid candidate slot"); }); } @@ -686,9 +696,9 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); assert_eq!(Council::candidates(), vec![1]); - assert_noop!(Council::submit_candidacy(Origin::signed(2), 0), "invalid candidate slot"); + assert_noop!(Council::submit_candidacy(Origin::signed(2), 0.into()), "invalid candidate slot"); }); } @@ -697,9 +707,9 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); assert_eq!(Council::candidates(), vec![1]); - assert_noop!(Council::submit_candidacy(Origin::signed(1), 1), "duplicate candidate submission"); + assert_noop!(Council::submit_candidacy(Origin::signed(1), 1.into()), "duplicate candidate submission"); }); } @@ -708,7 +718,7 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); - assert_noop!(Council::submit_candidacy(Origin::signed(7), 0), "candidate has not enough funds"); + assert_noop!(Council::submit_candidacy(Origin::signed(7), 0.into()), "candidate has not enough funds"); }); } @@ -717,20 +727,20 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0.into())); assert_eq!(Council::approvals_of(1), vec![true]); assert_eq!(Council::approvals_of(4), vec![true]); assert_eq!(Council::voters(), vec![1, 4]); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0.into())); assert_eq!(Council::approvals_of(1), vec![true]); assert_eq!(Council::approvals_of(4), vec![true]); @@ -746,14 +756,14 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0.into())); assert_eq!(Council::approvals_of(4), vec![true]); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0.into())); assert_eq!(Council::approvals_of(4), vec![true, false, true]); }); @@ -764,14 +774,14 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0.into())); assert_eq!(Council::voters(), vec![1, 2, 3, 4]); assert_eq!(Council::approvals_of(1), vec![true]); @@ -779,7 +789,7 @@ mod tests { assert_eq!(Council::approvals_of(3), vec![false, true, true]); assert_eq!(Council::approvals_of(4), vec![true, false, true]); - assert_ok!(Council::retract_voter(Origin::signed(1), 0)); + assert_ok!(Council::retract_voter(Origin::signed(1), 0.into())); assert_eq!(Council::voters(), vec![4, 2, 3]); assert_eq!(Council::approvals_of(1), Vec::::new()); @@ -787,7 +797,7 @@ mod tests { assert_eq!(Council::approvals_of(3), vec![false, true, true]); assert_eq!(Council::approvals_of(4), vec![true, false, true]); - assert_ok!(Council::retract_voter(Origin::signed(2), 1)); + assert_ok!(Council::retract_voter(Origin::signed(2), 1.into())); assert_eq!(Council::voters(), vec![4, 3]); assert_eq!(Council::approvals_of(1), Vec::::new()); @@ -795,7 +805,7 @@ mod tests { assert_eq!(Council::approvals_of(3), vec![false, true, true]); assert_eq!(Council::approvals_of(4), vec![true, false, true]); - assert_ok!(Council::retract_voter(Origin::signed(3), 1)); + assert_ok!(Council::retract_voter(Origin::signed(3), 1.into())); assert_eq!(Council::voters(), vec![4]); assert_eq!(Council::approvals_of(1), Vec::::new()); @@ -809,11 +819,11 @@ mod tests { fn invalid_retraction_index_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_eq!(Council::voters(), vec![1, 2]); - assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index mismatch"); + assert_noop!(Council::retract_voter(Origin::signed(1), 1.into()), "retraction index mismatch"); }); } @@ -821,9 +831,9 @@ mod tests { fn overflow_retraction_index_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index invalid"); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into())); + assert_noop!(Council::retract_voter(Origin::signed(1), 1.into()), "retraction index invalid"); }); } @@ -831,9 +841,9 @@ mod tests { fn non_voter_retraction_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(1); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_noop!(Council::retract_voter(Origin::signed(2), 0), "cannot retract non-voter"); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into())); + assert_noop!(Council::retract_voter(Origin::signed(2), 0.into()), "cannot retract non-voter"); }); } @@ -843,10 +853,10 @@ mod tests { System::set_block_number(4); assert!(!Council::presentation_active()); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into())); assert_eq!(Council::voters(), vec![2, 5]); assert_eq!(Council::approvals_of(2), vec![true, false]); assert_eq!(Council::approvals_of(5), vec![false, true]); @@ -854,8 +864,8 @@ mod tests { System::set_block_number(6); assert!(Council::presentation_active()); - assert_eq!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0), Ok(())); - assert_eq!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into()), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into()), Ok(())); assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (0, 0), (20, 2), (50, 5)])); assert_ok!(Council::end_block(System::block_number())); @@ -877,16 +887,16 @@ mod tests { assert!(Balances::can_slash(&4, 10)); System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); - assert_eq!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0), Err("duplicate presentation")); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); + assert_eq!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into()), Err("duplicate presentation")); assert_ok!(Council::end_block(System::block_number())); assert_eq!(Council::active_council(), vec![(5, 11), (2, 11)]); @@ -898,27 +908,27 @@ mod tests { fn retracting_inactive_voter_should_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert_ok!(Council::reap_inactive_voter(Origin::signed(5), - Council::voters().iter().position(|&i| i == 5).unwrap() as u32, - 2.into(), Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2 + (Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(), + 2.into(), (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into() )); assert_eq!(Council::voters(), vec![5]); @@ -932,21 +942,21 @@ mod tests { fn presenting_for_double_election_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(())); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_eq!(Council::submit_candidacy(Origin::signed(2), 0.into()), Ok(())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(())); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1)); + assert_eq!(Council::submit_candidacy(Origin::signed(2), 0.into()), Ok(())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20, 1), "candidate must not form a duplicated member if elected"); + assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 1.into()), "candidate must not form a duplicated member if elected"); }); } @@ -954,30 +964,30 @@ mod tests { fn retracting_inactive_voter_with_other_candidates_in_slots_should_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(11); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); assert_ok!(Council::reap_inactive_voter(Origin::signed(5), - Council::voters().iter().position(|&i| i == 5).unwrap() as u32, - 2.into(), Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2 + (Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(), + 2.into(), (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into() )); assert_eq!(Council::voters(), vec![5]); @@ -991,27 +1001,27 @@ mod tests { fn retracting_inactive_voter_with_bad_reporter_index_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert_noop!(Council::reap_inactive_voter(Origin::signed(2), - 42, - 2.into(), Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2 + 42.into(), + 2.into(), (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into() ), "bad reporter index"); }); } @@ -1020,27 +1030,27 @@ mod tests { fn retracting_inactive_voter_with_bad_target_index_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert_noop!(Council::reap_inactive_voter(Origin::signed(2), - Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2.into(), 42, - 2 + (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into(), 42.into(), + 2.into() ), "bad target index"); }); } @@ -1049,36 +1059,36 @@ mod tests { fn attempting_to_retract_active_voter_should_slash_reporter() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); - assert_ok!(Council::submit_candidacy(Origin::signed(4), 2)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 3)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 2.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 3.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::set_desired_seats(3)); + assert_ok!(Council::set_desired_seats(3.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 1)); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 1.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert_ok!(Council::reap_inactive_voter(Origin::signed(4), - Council::voters().iter().position(|&i| i == 4).unwrap() as u32, - 2.into(), Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2 + (Council::voters().iter().position(|&i| i == 4).unwrap() as u32).into(), + 2.into(), (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into() )); assert_eq!(Council::voters(), vec![2, 3, 5]); @@ -1091,27 +1101,27 @@ mod tests { fn attempting_to_retract_inactive_voter_by_nonvoter_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert_noop!(Council::reap_inactive_voter(Origin::signed(4), - 0, - 2.into(), Council::voters().iter().position(|&i| i == 2).unwrap() as u32, - 2 + 0.into(), + 2.into(), (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2.into() ), "reporter must be a voter"); }); } @@ -1120,24 +1130,24 @@ mod tests { fn presenting_loser_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); - assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0), "candidate not worthy of leaderboard"); + assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); + assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into()), "candidate not worthy of leaderboard"); }); } @@ -1145,24 +1155,24 @@ mod tests { fn presenting_loser_first_should_not_matter() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); assert_eq!(Council::leaderboard(), Some(vec![ (30, 3), @@ -1178,7 +1188,7 @@ mod tests { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); assert!(!Council::presentation_active()); - assert_noop!(Council::present_winner(Origin::signed(5), 5.into(), 1, 0), "cannot present outside of presentation period"); + assert_noop!(Council::present_winner(Origin::signed(5), 5.into(), 1.into(), 0.into()), "cannot present outside of presentation period"); }); } @@ -1186,14 +1196,14 @@ mod tests { fn present_with_invalid_vote_index_should_not_work() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20, 1), "index not current"); + assert_noop!(Council::present_winner(Origin::signed(4), 2.into(), 20.into(), 1.into()), "index not current"); }); } @@ -1203,16 +1213,16 @@ mod tests { System::set_block_number(4); assert!(!Council::presentation_active()); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); assert_eq!(Balances::free_balance(&1), 1); assert_eq!(Balances::reserved_balance(&1), 9); - assert_noop!(Council::present_winner(Origin::signed(1), 1.into(), 20, 0), "presenter must have sufficient slashable funds"); + assert_noop!(Council::present_winner(Origin::signed(1), 1.into(), 20.into(), 0.into()), "presenter must have sufficient slashable funds"); }); } @@ -1223,14 +1233,14 @@ mod tests { assert!(!Council::presentation_active()); assert_eq!(Balances::total_balance(&4), 40); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_err!(Council::present_winner(Origin::signed(4), 2.into(), 80, 0), "incorrect total"); + assert_err!(Council::present_winner(Origin::signed(4), 2.into(), 80.into(), 0.into()), "incorrect total"); assert_eq!(Balances::total_balance(&4), 38); }); @@ -1242,31 +1252,31 @@ mod tests { System::set_block_number(4); assert!(!Council::presentation_active()); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); assert!(Council::presentation_active()); - assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60.into(), 0.into())); assert_eq!(Council::leaderboard(), Some(vec![ (0, 0), (0, 0), (0, 0), (60, 1) ])); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); assert_eq!(Council::leaderboard(), Some(vec![ (30, 3), (40, 4), @@ -1299,33 +1309,33 @@ mod tests { fn second_tally_should_use_runners_up() { with_externalities(&mut new_test_ext(false), || { System::set_block_number(4); - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into())); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into())); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into())); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into())); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into())); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into())); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 0)); - assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50, 0)); + assert_ok!(Council::present_winner(Origin::signed(4), 1.into(), 60.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 30.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 0.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 5.into(), 50.into(), 0.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1)); - assert_ok!(Council::set_desired_seats(3)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1.into())); + assert_ok!(Council::set_desired_seats(3.into())); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 90, 1)); - assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 3.into(), 90.into(), 1.into())); + assert_ok!(Council::present_winner(Origin::signed(4), 4.into(), 40.into(), 1.into())); assert_ok!(Council::end_block(System::block_number())); assert!(!Council::presentation_active()); diff --git a/substrate/srml/council/src/voting.rs b/substrate/srml/council/src/voting.rs index 21ee647bb1..094066327c 100644 --- a/substrate/srml/council/src/voting.rs +++ b/substrate/srml/council/src/voting.rs @@ -18,6 +18,7 @@ use rstd::prelude::*; use rstd::borrow::Borrow; +use codec::HasCompact; use primitives::traits::{OnFinalise, Hash, As}; use runtime_io::print; use srml_support::dispatch::Result; @@ -36,8 +37,8 @@ decl_module! { fn vote(origin, proposal: T::Hash, approve: bool) -> Result; fn veto(origin, proposal_hash: T::Hash) -> Result; - fn set_cooloff_period(blocks: T::BlockNumber) -> Result; - fn set_voting_period(blocks: T::BlockNumber) -> Result; + fn set_cooloff_period(blocks: ::Type) -> Result; + fn set_voting_period(blocks: ::Type) -> Result; } } @@ -153,13 +154,13 @@ impl Module { Ok(()) } - fn set_cooloff_period(blocks: T::BlockNumber) -> Result { - >::put(blocks); + fn set_cooloff_period(blocks: ::Type) -> Result { + >::put(blocks.into()); Ok(()) } - fn set_voting_period(blocks: T::BlockNumber) -> Result { - >::put(blocks); + fn set_voting_period(blocks: ::Type) -> Result { + >::put(blocks.into()); Ok(()) } @@ -209,7 +210,7 @@ impl Module { if let Some(&democracy::Call::cancel_referendum(ref_index)) = IsSubType::>::is_aux_sub_type(&proposal) { Self::deposit_event(RawEvent::TallyCancelation(proposal_hash, tally.0, tally.1, tally.2)); if let (_, 0, 0) = tally { - >::internal_cancel_referendum(ref_index); + >::internal_cancel_referendum(ref_index.into()); } } else { Self::deposit_event(RawEvent::TallyReferendum(proposal_hash.clone(), tally.0, tally.1, tally.2)); @@ -264,11 +265,11 @@ mod tests { } fn set_balance_proposal(value: u64) -> Call { - Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value, 0)) + Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value.into(), 0.into())) } fn cancel_referendum_proposal(id: u32) -> Call { - Call::Democracy(democracy::Call::cancel_referendum(id)) + Call::Democracy(democracy::Call::cancel_referendum(id.into())) } #[test] diff --git a/substrate/srml/democracy/Cargo.toml b/substrate/srml/democracy/Cargo.toml index 908c5392df..c037a4b219 100644 --- a/substrate/srml/democracy/Cargo.toml +++ b/substrate/srml/democracy/Cargo.toml @@ -8,8 +8,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index 7d1b48b39d..f5c3153251 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -40,6 +40,7 @@ extern crate srml_system as system; use rstd::prelude::*; use rstd::result; +use codec::{HasCompact, Compact}; use primitives::traits::{Zero, OnFinalise, As, MaybeSerializeDebug}; use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType}; use srml_support::dispatch::Result; @@ -61,12 +62,12 @@ pub trait Trait: balances::Trait + Sized { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn propose(origin, proposal: Box, value: T::Balance) -> Result; - fn second(origin, proposal: PropIndex) -> Result; - fn vote(origin, ref_index: ReferendumIndex, approve_proposal: bool) -> Result; + fn propose(origin, proposal: Box, value: ::Type) -> Result; + fn second(origin, proposal: Compact) -> Result; + fn vote(origin, ref_index: Compact, approve_proposal: bool) -> Result; fn start_referendum(proposal: Box, vote_threshold: VoteThreshold) -> Result; - fn cancel_referendum(ref_index: ReferendumIndex) -> Result; + fn cancel_referendum(ref_index: Compact) -> Result; } } @@ -164,8 +165,10 @@ impl Module { // dispatching. /// Propose a sensitive action to be taken. - fn propose(origin: T::Origin, proposal: Box, value: T::Balance) -> Result { + fn propose(origin: T::Origin, proposal: Box, value: ::Type) -> Result { let who = ensure_signed(origin)?; + let value = value.into(); + ensure!(value >= Self::minimum_deposit(), "value too low"); >::reserve(&who, value) .map_err(|_| "proposer's balance too low")?; @@ -181,8 +184,9 @@ impl Module { } /// Propose a sensitive action to be taken. - fn second(origin: T::Origin, proposal: PropIndex) -> Result { + fn second(origin: T::Origin, proposal: Compact) -> Result { let who = ensure_signed(origin)?; + let proposal: PropIndex = proposal.into(); let mut deposit = Self::deposit_of(proposal) .ok_or("can only second an existing proposal")?; >::reserve(&who, deposit.0) @@ -194,8 +198,9 @@ impl Module { /// Vote in a referendum. If `approve_proposal` is true, the vote is to enact the proposal; /// false would be a vote to keep the status quo. - fn vote(origin: T::Origin, ref_index: ReferendumIndex, approve_proposal: bool) -> Result { + fn vote(origin: T::Origin, ref_index: Compact, approve_proposal: bool) -> Result { let who = ensure_signed(origin)?; + let ref_index = ref_index.into(); ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); ensure!(!>::total_balance(&who).is_zero(), "transactor must have balance to signal approval."); @@ -216,8 +221,8 @@ impl Module { } /// Remove a referendum. - fn cancel_referendum(ref_index: ReferendumIndex) -> Result { - Self::clear_referendum(ref_index); + fn cancel_referendum(ref_index: Compact) -> Result { + Self::clear_referendum(ref_index.into()); Ok(()) } @@ -394,11 +399,11 @@ mod tests { } fn set_balance_proposal(value: u64) -> Call { - Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value, 0)) + Call::Balances(balances::Call::set_balance(balances::address::Address::Id(42), value.into(), 0.into())) } fn propose_set_balance(who: u64, value: u64, locked: u64) -> super::Result { - Democracy::propose(Origin::signed(who), Box::new(set_balance_proposal(value)), locked) + Democracy::propose(Origin::signed(who), Box::new(set_balance_proposal(value)), locked.into()) } #[test] @@ -423,7 +428,7 @@ mod tests { System::set_block_number(2); let r = 0; - assert_ok!(Democracy::vote(Origin::signed(1), r, true)); + assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); assert_eq!(Democracy::referendum_count(), 1); assert_eq!(Democracy::voters_for(r), vec![1]); @@ -441,10 +446,10 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); assert_ok!(propose_set_balance(1, 2, 5)); - assert_ok!(Democracy::second(Origin::signed(2), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); + assert_ok!(Democracy::second(Origin::signed(2), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); assert_eq!(Balances::free_balance(&1), 5); assert_eq!(Balances::free_balance(&2), 15); assert_eq!(Balances::free_balance(&5), 35); @@ -456,10 +461,10 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); assert_ok!(propose_set_balance(1, 2, 5)); - assert_ok!(Democracy::second(Origin::signed(2), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); - assert_ok!(Democracy::second(Origin::signed(5), 0)); + assert_ok!(Democracy::second(Origin::signed(2), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); + assert_ok!(Democracy::second(Origin::signed(5), 0.into())); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); assert_eq!(Balances::free_balance(&1), 10); assert_eq!(Balances::free_balance(&2), 20); @@ -488,7 +493,7 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); assert_ok!(propose_set_balance(2, 2, 11)); - assert_noop!(Democracy::second(Origin::signed(1), 0), "seconder\'s balance too low"); + assert_noop!(Democracy::second(Origin::signed(1), 0.into()), "seconder\'s balance too low"); }); } @@ -502,17 +507,17 @@ mod tests { assert_eq!(Democracy::end_block(System::block_number()), Ok(())); System::set_block_number(1); - assert_ok!(Democracy::vote(Origin::signed(1), 0, true)); + assert_ok!(Democracy::vote(Origin::signed(1), 0.into(), true)); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); assert_eq!(Balances::free_balance(&42), 4); System::set_block_number(2); - assert_ok!(Democracy::vote(Origin::signed(1), 1, true)); + assert_ok!(Democracy::vote(Origin::signed(1), 1.into(), true)); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); assert_eq!(Balances::free_balance(&42), 3); System::set_block_number(3); - assert_ok!(Democracy::vote(Origin::signed(1), 2, true)); + assert_ok!(Democracy::vote(Origin::signed(1), 2.into(), true)); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); }); } @@ -522,7 +527,7 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, true)); + assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), Some(true)); @@ -539,8 +544,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, true)); - assert_ok!(Democracy::cancel_referendum(r)); + assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); + assert_ok!(Democracy::cancel_referendum(r.into())); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); @@ -553,7 +558,7 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, false)); + assert_ok!(Democracy::vote(Origin::signed(1), r.into(), false)); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), Some(false)); @@ -570,12 +575,12 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, true)); - assert_ok!(Democracy::vote(Origin::signed(2), r, false)); - assert_ok!(Democracy::vote(Origin::signed(3), r, false)); - assert_ok!(Democracy::vote(Origin::signed(4), r, true)); - assert_ok!(Democracy::vote(Origin::signed(5), r, false)); - assert_ok!(Democracy::vote(Origin::signed(6), r, true)); + assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); + assert_ok!(Democracy::vote(Origin::signed(2), r.into(), false)); + assert_ok!(Democracy::vote(Origin::signed(3), r.into(), false)); + assert_ok!(Democracy::vote(Origin::signed(4), r.into(), true)); + assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false)); + assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true)); assert_eq!(Democracy::tally(r), (110, 100)); @@ -590,8 +595,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(5), r, false)); - assert_ok!(Democracy::vote(Origin::signed(6), r, true)); + assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false)); + assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true)); assert_eq!(Democracy::tally(r), (60, 50)); @@ -609,9 +614,9 @@ mod tests { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(4), r, true)); - assert_ok!(Democracy::vote(Origin::signed(5), r, false)); - assert_ok!(Democracy::vote(Origin::signed(6), r, true)); + assert_ok!(Democracy::vote(Origin::signed(4), r.into(), true)); + assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false)); + assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true)); assert_eq!(Democracy::tally(r), (100, 50)); diff --git a/substrate/srml/example/Cargo.toml b/substrate/srml/example/Cargo.toml index b69484eb17..ae2174ca23 100644 --- a/substrate/srml/example/Cargo.toml +++ b/substrate/srml/example/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index 87cfa4f198..8952893540 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -109,8 +109,6 @@ decl_module! { /// world. fn accumulate_dummy(origin, increase_by: T::Balance) -> Result; - fn accumulate_foo(origin, increase_by: T::Balance) -> Result; - /// A privileged call; in this case it resets our dummy value to something new. fn set_dummy(new_dummy: T::Balance) -> Result; } diff --git a/substrate/srml/executive/Cargo.toml b/substrate/srml/executive/Cargo.toml index 05951363ee..33cd0432e0 100644 --- a/substrate/srml/executive/Cargo.toml +++ b/substrate/srml/executive/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } 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 } diff --git a/substrate/srml/executive/src/lib.rs b/substrate/srml/executive/src/lib.rs index faebde9b50..49daf95fa5 100644 --- a/substrate/srml/executive/src/lib.rs +++ b/substrate/srml/executive/src/lib.rs @@ -332,7 +332,7 @@ mod tests { creation_fee: 0, reclaim_rebate: 0, }.build_storage().unwrap()); - let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2.into(), 69)); + let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2.into(), 69.into())); let mut t = runtime_io::TestExternalities::::new(t); with_externalities(&mut t, || { Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), @@ -402,7 +402,7 @@ mod tests { #[test] fn bad_extrinsic_not_inserted() { let mut t = new_test_ext(); - let xt = primitives::testing::TestXt(Some(1), 42, Call::transfer(33.into(), 69)); + let xt = primitives::testing::TestXt(Some(1), 42, Call::transfer(33.into(), 69.into())); with_externalities(&mut t, || { Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default())); assert!(Executive::apply_extrinsic(xt).is_err()); diff --git a/substrate/srml/metadata/Cargo.toml b/substrate/srml/metadata/Cargo.toml index 5666268dc4..2e113ab6f0 100644 --- a/substrate/srml/metadata/Cargo.toml +++ b/substrate/srml/metadata/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "^2.0.1", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } diff --git a/substrate/srml/session/Cargo.toml b/substrate/srml/session/Cargo.toml index 0d57726f96..c006eff0a4 100644 --- a/substrate/srml/session/Cargo.toml +++ b/substrate/srml/session/Cargo.toml @@ -9,8 +9,8 @@ serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} substrate-primitives = { path = "../../core/primitives", default-features = false } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } 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 } diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index 3648db2ee3..087e37ecfe 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -43,6 +43,7 @@ extern crate srml_timestamp as timestamp; use rstd::prelude::*; use primitives::traits::{As, Zero, One, OnFinalise, Convert}; +use codec::HasCompact; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; use system::ensure_signed; @@ -68,7 +69,7 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin { fn set_key(origin, key: T::SessionKey) -> Result; - fn set_length(new: T::BlockNumber) -> Result; + fn set_length(new: ::Type) -> Result; fn force_new_session(apply_rewards: bool) -> Result; } } @@ -133,8 +134,8 @@ impl Module { } /// Set a new session length. Won't kick in until the next session change (at current length). - fn set_length(new: T::BlockNumber) -> Result { - >::put(new); + fn set_length(new: ::Type) -> Result { + >::put(new.into()); Ok(()) } @@ -309,7 +310,7 @@ mod tests { fn should_work_with_early_exit() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - assert_ok!(Session::set_length(10)); + assert_ok!(Session::set_length(10.into())); assert_eq!(Session::blocks_remaining(), 1); Session::check_rotate_session(1); @@ -344,14 +345,14 @@ mod tests { with_externalities(&mut new_test_ext(), || { // Block 1: Change to length 3; no visible change. System::set_block_number(1); - assert_ok!(Session::set_length(3)); + assert_ok!(Session::set_length(3.into())); Session::check_rotate_session(1); assert_eq!(Session::length(), 2); assert_eq!(Session::current_index(), 0); // Block 2: Length now changed to 3. Index incremented. System::set_block_number(2); - assert_ok!(Session::set_length(3)); + assert_ok!(Session::set_length(3.into())); Session::check_rotate_session(2); assert_eq!(Session::length(), 3); assert_eq!(Session::current_index(), 1); @@ -364,7 +365,7 @@ mod tests { // Block 4: Change to length 2; no visible change. System::set_block_number(4); - assert_ok!(Session::set_length(2)); + assert_ok!(Session::set_length(2.into())); Session::check_rotate_session(4); assert_eq!(Session::length(), 3); assert_eq!(Session::current_index(), 1); diff --git a/substrate/srml/staking/Cargo.toml b/substrate/srml/staking/Cargo.toml index 3542f7cb70..7a1f4ef4eb 100644 --- a/substrate/srml/staking/Cargo.toml +++ b/substrate/srml/staking/Cargo.toml @@ -8,8 +8,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-keyring = { path = "../../core/keyring", optional = true } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index 01d2ae630d..6b47e01c33 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -51,6 +51,7 @@ extern crate srml_timestamp as timestamp; use rstd::prelude::*; use rstd::cmp; +use codec::{HasCompact, Compact}; use runtime_support::{Parameter, StorageValue, StorageMap}; use runtime_support::dispatch::Result; use session::OnSessionChange; @@ -75,14 +76,16 @@ pub enum LockStatus { /// Preference of what happens on a slash event. #[derive(PartialEq, Eq, Clone, Encode, Decode)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] -pub struct ValidatorPrefs { +pub struct ValidatorPrefs { // TODO: @bkchr shouldn't need this Copy but derive(Encode) breaks otherwise /// Validator should ensure this many more slashes than is necessary before being unstaked. + #[codec(compact)] pub unstake_threshold: u32, // Reward that validator takes up-front; only the rest is split between themselves and nominators. + #[codec(encoded_as = "::Type")] pub validator_payment: Balance, } -impl Default for ValidatorPrefs { +impl Default for ValidatorPrefs { fn default() -> Self { ValidatorPrefs { unstake_threshold: 3, @@ -103,16 +106,16 @@ decl_module! { #[cfg_attr(feature = "std", serde(bound(deserialize = "T::Balance: ::serde::de::DeserializeOwned")))] pub struct Module for enum Call where origin: T::Origin { fn stake(origin) -> Result; - fn unstake(origin, intentions_index: u32) -> Result; + fn unstake(origin, intentions_index: Compact) -> Result; fn nominate(origin, target: Address) -> Result; - fn unnominate(origin, target_index: u32) -> Result; - fn register_preferences(origin, intentions_index: u32, prefs: ValidatorPrefs) -> Result; + fn unnominate(origin, target_index: Compact) -> Result; + fn register_preferences(origin, intentions_index: Compact, prefs: ValidatorPrefs) -> Result; - fn set_sessions_per_era(new: T::BlockNumber) -> Result; - fn set_bonding_duration(new: T::BlockNumber) -> Result; - fn set_validator_count(new: u32) -> Result; + fn set_sessions_per_era(new: ::Type) -> Result; + fn set_bonding_duration(new: ::Type) -> Result; + fn set_validator_count(new: Compact) -> Result; fn force_new_era(apply_rewards: bool) -> Result; - fn set_offline_slash_grace(new: u32) -> Result; + fn set_offline_slash_grace(new: Compact) -> Result; } } @@ -243,8 +246,9 @@ impl Module { /// Retract the desire to stake for the transactor. /// /// Effects will be felt at the beginning of the next era. - fn unstake(origin: T::Origin, intentions_index: u32) -> Result { + fn unstake(origin: T::Origin, intentions_index: Compact) -> Result { let who = ensure_signed(origin)?; + let intentions_index: u32 = intentions_index.into(); // unstake fails in degenerate case of having too few existing staked parties if Self::intentions().len() <= Self::minimum_validator_count() as usize { return Err("cannot unstake when there are too few staked participants") @@ -275,8 +279,9 @@ impl Module { /// Will panic if called when source isn't currently nominating target. /// Updates Nominating, NominatorsFor and NominationBalance. - fn unnominate(origin: T::Origin, target_index: u32) -> Result { + fn unnominate(origin: T::Origin, target_index: Compact) -> Result { let source = ensure_signed(origin)?; + let target_index: u32 = target_index.into(); let target_index = target_index as usize; let target = >::get(&source).ok_or("Account must be nominating")?; @@ -305,10 +310,11 @@ impl Module { /// An error (no-op) if `Self::intentions()[intentions_index] != origin`. fn register_preferences( origin: T::Origin, - intentions_index: u32, + intentions_index: Compact, prefs: ValidatorPrefs ) -> Result { let who = ensure_signed(origin)?; + let intentions_index: u32 = intentions_index.into(); if Self::intentions().get(intentions_index as usize) != Some(&who) { return Err("Invalid index") @@ -322,20 +328,21 @@ impl Module { // PRIV DISPATCH /// Set the number of sessions in an era. - fn set_sessions_per_era(new: T::BlockNumber) -> Result { - >::put(&new); + fn set_sessions_per_era(new: ::Type) -> Result { + >::put(new.into()); Ok(()) } /// The length of the bonding duration in eras. - fn set_bonding_duration(new: T::BlockNumber) -> Result { - >::put(&new); + fn set_bonding_duration(new: ::Type) -> Result { + >::put(new.into()); Ok(()) } /// The length of a staking era in sessions. - fn set_validator_count(new: u32) -> Result { - >::put(&new); + fn set_validator_count(new: Compact) -> Result { + let new: u32 = new.into(); + >::put(new); Ok(()) } @@ -353,8 +360,9 @@ impl Module { /// Set the offline slash grace period. - fn set_offline_slash_grace(new: u32) -> Result { - >::put(&new); + fn set_offline_slash_grace(new: Compact) -> Result { + let new: u32 = new.into(); + >::put(new); Ok(()) } diff --git a/substrate/srml/staking/src/tests.rs b/substrate/srml/staking/src/tests.rs index 596b95d759..67e793f7bc 100644 --- a/substrate/srml/staking/src/tests.rs +++ b/substrate/srml/staking/src/tests.rs @@ -75,7 +75,7 @@ fn note_offline_grace_should_work() { with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || { Balances::set_free_balance(&10, 70); Balances::set_free_balance(&20, 70); - assert_ok!(Staking::set_offline_slash_grace(1)); + assert_ok!(Staking::set_offline_slash_grace(1.into())); assert_eq!(Staking::offline_slash_grace(), 1); assert_eq!(Staking::slash_count(&10), 0); @@ -130,7 +130,7 @@ fn note_offline_auto_unstake_session_change_should_work() { with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || { Balances::set_free_balance(&10, 7000); Balances::set_free_balance(&20, 7000); - assert_ok!(Staking::register_preferences(Origin::signed(10), 0, ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 })); + assert_ok!(Staking::register_preferences(Origin::signed(10), 0.into(), ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 })); assert_eq!(Staking::intentions(), vec![10, 20]); @@ -236,7 +236,7 @@ fn staking_should_work() { assert_eq!(Staking::validator_count(), 2); assert_eq!(Session::validators(), vec![10, 20]); - assert_ok!(Staking::set_bonding_duration(2)); + assert_ok!(Staking::set_bonding_duration(2.into())); assert_eq!(Staking::bonding_duration(), 2); // Block 1: Add three validators. No obvious change. @@ -257,7 +257,7 @@ fn staking_should_work() { // Block 3: Unstake highest, introduce another staker. No change yet. System::set_block_number(3); assert_ok!(Staking::stake(Origin::signed(3))); - assert_ok!(Staking::unstake(Origin::signed(4), Staking::intentions().iter().position(|&x| x == 4).unwrap() as u32)); + assert_ok!(Staking::unstake(Origin::signed(4), (Staking::intentions().iter().position(|&x| x == 4).unwrap() as u32).into())); assert_eq!(Staking::current_era(), 1); Session::check_rotate_session(System::block_number()); @@ -269,7 +269,7 @@ fn staking_should_work() { // Block 5: Transfer stake from highest to lowest. No change yet. System::set_block_number(5); - assert_ok!(Balances::transfer(Origin::signed(4), 1.into(), 40)); + assert_ok!(Balances::transfer(Origin::signed(4), 1.into(), 40.into())); Session::check_rotate_session(System::block_number()); // Block 6: Lowest now validator. @@ -279,7 +279,7 @@ fn staking_should_work() { // Block 7: Unstake three. No change yet. System::set_block_number(7); - assert_ok!(Staking::unstake(Origin::signed(3), Staking::intentions().iter().position(|&x| x == 3).unwrap() as u32)); + assert_ok!(Staking::unstake(Origin::signed(3), (Staking::intentions().iter().position(|&x| x == 3).unwrap() as u32).into())); Session::check_rotate_session(System::block_number()); assert_eq!(Session::validators(), vec![1, 3]); @@ -312,7 +312,7 @@ fn nominating_and_rewards_should_work() { assert_eq!(Balances::total_balance(&4), 40); System::set_block_number(2); - assert_ok!(Staking::unnominate(Origin::signed(4), 0)); + assert_ok!(Staking::unnominate(Origin::signed(4), 0.into())); Session::check_rotate_session(System::block_number()); assert_eq!(Staking::current_era(), 2); assert_eq!(Session::validators(), vec![3, 2]); @@ -323,7 +323,7 @@ fn nominating_and_rewards_should_work() { System::set_block_number(3); assert_ok!(Staking::stake(Origin::signed(4))); - assert_ok!(Staking::unstake(Origin::signed(3), Staking::intentions().iter().position(|&x| x == 3).unwrap() as u32)); + assert_ok!(Staking::unstake(Origin::signed(3), (Staking::intentions().iter().position(|&x| x == 3).unwrap() as u32).into())); assert_ok!(Staking::nominate(Origin::signed(3), 1.into())); Session::check_rotate_session(System::block_number()); assert_eq!(Session::validators(), vec![1, 4]); @@ -355,7 +355,11 @@ fn rewards_with_off_the_table_should_work() { assert_eq!(Balances::total_balance(&3), 30); System::set_block_number(2); - assert_ok!(Staking::register_preferences(Origin::signed(1), Staking::intentions().into_iter().position(|i| i == 1).unwrap() as u32, ValidatorPrefs { unstake_threshold: 3, validator_payment: 4 })); + assert_ok!(Staking::register_preferences( + Origin::signed(1), + (Staking::intentions().into_iter().position(|i| i == 1).unwrap() as u32).into(), + ValidatorPrefs { unstake_threshold: 3, validator_payment: 4 } + )); Session::check_rotate_session(System::block_number()); assert_eq!(Balances::total_balance(&1), 22); assert_eq!(Balances::total_balance(&2), 37); @@ -441,7 +445,7 @@ fn staking_eras_work() { // Block 3: Schedule an era length change; no visible changes. System::set_block_number(3); - assert_ok!(Staking::set_sessions_per_era(3)); + assert_ok!(Staking::set_sessions_per_era(3.into())); Session::check_rotate_session(System::block_number()); assert_eq!(Session::current_index(), 3); assert_eq!(Staking::sessions_per_era(), 2); @@ -487,7 +491,7 @@ fn staking_balance_transfer_when_bonded_should_not_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { Balances::set_free_balance(&1, 111); assert_ok!(Staking::stake(Origin::signed(1))); - assert_noop!(Balances::transfer(Origin::signed(1), 2.into(), 69), "cannot transfer illiquid funds"); + assert_noop!(Balances::transfer(Origin::signed(1), 2.into(), 69.into()), "cannot transfer illiquid funds"); }); } diff --git a/substrate/srml/support/Cargo.toml b/substrate/srml/support/Cargo.toml index 65251221cb..f1254a538d 100644 --- a/substrate/srml/support/Cargo.toml +++ b/substrate/srml/support/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] hex-literal = { version = "0.1.0", optional = true } serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } substrate-metadata = { path = "../metadata", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } @@ -16,7 +16,7 @@ mashup = "0.1.7" [dev-dependencies] pretty_assertions = "0.5.1" -parity-codec-derive = { version = "2.0" } +parity-codec-derive = { version = "2.1" } [features] default = ["std"] diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index ecca471e5f..a413f06b0f 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -218,7 +218,7 @@ macro_rules! decl_module { match *self { $( $call_type::$fn_name( $( ref $param_name ),* ) => - $call_type::$fn_name( $( $param_name.clone() ),* ) + $call_type::$fn_name( $( (*$param_name).clone() ),* ) ,)* _ => unreachable!(), } diff --git a/substrate/srml/system/Cargo.toml b/substrate/srml/system/Cargo.toml index 25633abe41..c4bde66fc8 100644 --- a/substrate/srml/system/Cargo.toml +++ b/substrate/srml/system/Cargo.toml @@ -8,8 +8,8 @@ hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/timestamp/Cargo.toml b/substrate/srml/timestamp/Cargo.toml index 13f6ccd5a6..3b06f6c39a 100644 --- a/substrate/srml/timestamp/Cargo.toml +++ b/substrate/srml/timestamp/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index 0b55cc6882..6d64800189 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -51,6 +51,7 @@ extern crate srml_system as system; extern crate srml_consensus as consensus; extern crate parity_codec as codec; +use codec::HasCompact; use runtime_support::{StorageValue, Parameter}; use runtime_support::dispatch::Result; use runtime_primitives::traits::{As, OnFinalise, SimpleArithmetic, Zero}; @@ -68,7 +69,7 @@ pub trait Trait: consensus::Trait + system::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn set(origin, now: T::Moment) -> Result; + fn set(origin, now: ::Type) -> Result; } } @@ -102,8 +103,10 @@ impl Module { /// if this call hasn't been invoked by that time. /// /// The timestamp should be greater than the previous one by the amount specified by `block_period`. - fn set(origin: T::Origin, now: T::Moment) -> Result { + fn set(origin: T::Origin, now: ::Type) -> Result { ensure_inherent(origin)?; + let now = now.into(); + assert!(!::DidUpdate::exists(), "Timestamp must be updated only once in the block"); assert!( >::extrinsic_index() == Some(T::TIMESTAMP_SET_POSITION), @@ -179,7 +182,7 @@ mod tests { with_externalities(&mut TestExternalities::new(t), || { Timestamp::set_timestamp(42); - assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT)); + assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT)); assert_eq!(Timestamp::now(), 69); }); } @@ -192,8 +195,8 @@ mod tests { with_externalities(&mut TestExternalities::new(t), || { Timestamp::set_timestamp(42); - assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT)); - let _ = Timestamp::dispatch(Call::set(70), Origin::INHERENT); + assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT)); + let _ = Timestamp::dispatch(Call::set(70.into()), Origin::INHERENT); }); } @@ -205,7 +208,7 @@ mod tests { with_externalities(&mut TestExternalities::new(t), || { Timestamp::set_timestamp(42); - let _ = Timestamp::dispatch(Call::set(46), Origin::INHERENT); + let _ = Timestamp::dispatch(Call::set(46.into()), Origin::INHERENT); }); } } diff --git a/substrate/srml/treasury/Cargo.toml b/substrate/srml/treasury/Cargo.toml index 752daa2147..32621e1561 100644 --- a/substrate/srml/treasury/Cargo.toml +++ b/substrate/srml/treasury/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Parity Technologies "] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } serde_derive = { version = "1.0", optional = true } -parity-codec = { version = "2.0", default-features = false } -parity-codec-derive = { version = "2.0", default-features = false } +parity-codec = { version = "2.1", default-features = false } +parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 6ad8d48509..ae8aa9ceec 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -29,6 +29,8 @@ extern crate sr_io as runtime_io; #[cfg(feature = "std")] #[macro_use] extern crate serde_derive; +#[cfg(feature = "std")] +extern crate serde; #[macro_use] extern crate parity_codec_derive; @@ -44,7 +46,8 @@ use rstd::prelude::*; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; use runtime_primitives::{Permill, traits::{OnFinalise, Zero, EnsureOrigin}}; -use balances::OnDilution; +use codec::{HasCompact, Compact}; +use balances::{OnDilution, address::Address}; use system::ensure_signed; /// Our module's configuration trait. All our types and consts go in here. If the @@ -73,20 +76,20 @@ decl_module! { // Put forward a suggestion for spending. A deposit proportional to the value // is reserved and slashed if the proposal is rejected. It is returned once the // proposal is awarded. - fn propose_spend(origin, value: T::Balance, beneficiary: T::AccountId) -> Result; + fn propose_spend(origin, value: ::Type, beneficiary: Address) -> Result; // Set the balance of funds available to spend. - fn set_pot(new_pot: T::Balance) -> Result; + fn set_pot(new_pot: ::Type) -> Result; // (Re-)configure this module. - fn configure(proposal_bond: Permill, proposal_bond_minimum: T::Balance, spend_period: T::BlockNumber, burn: Permill) -> Result; + fn configure(proposal_bond: Permill, proposal_bond_minimum: ::Type, spend_period: ::Type, burn: Permill) -> Result; // Reject a proposed spend. The original deposit will be slashed. - fn reject_proposal(origin, roposal_id: ProposalIndex) -> Result; + fn reject_proposal(origin, roposal_id: Compact) -> Result; // Approve a proposal. At a later time, the proposal will be allocated to the beneficiary // and the original deposit will be returned. - fn approve_proposal(origin, proposal_id: ProposalIndex) -> Result; + fn approve_proposal(origin, proposal_id: Compact) -> Result; } } @@ -157,8 +160,10 @@ impl Module { // Implement Calls and add public immutables and private mutables. - fn propose_spend(origin: T::Origin, value: T::Balance, beneficiary: T::AccountId) -> Result { + fn propose_spend(origin: T::Origin, value: ::Type, beneficiary: Address) -> Result { let proposer = ensure_signed(origin)?; + let beneficiary = >::lookup(beneficiary)?; + let value = value.into(); let bond = Self::calculate_bond(value); >::reserve(&proposer, bond) @@ -173,8 +178,9 @@ impl Module { Ok(()) } - fn reject_proposal(origin: T::Origin, proposal_id: ProposalIndex) -> Result { + fn reject_proposal(origin: T::Origin, proposal_id: Compact) -> Result { T::RejectOrigin::ensure_origin(origin)?; + let proposal_id: ProposalIndex = proposal_id.into(); let proposal = >::take(proposal_id).ok_or("No proposal at that index")?; @@ -184,8 +190,9 @@ impl Module { Ok(()) } - fn approve_proposal(origin: T::Origin, proposal_id: ProposalIndex) -> Result { + fn approve_proposal(origin: T::Origin, proposal_id: Compact) -> Result { T::ApproveOrigin::ensure_origin(origin)?; + let proposal_id = proposal_id.into(); ensure!(>::exists(proposal_id), "No proposal at that index"); @@ -194,9 +201,9 @@ impl Module { Ok(()) } - fn set_pot(new_pot: T::Balance) -> Result { + fn set_pot(new_pot: ::Type) -> Result { // Put the new value into storage. - >::put(new_pot); + >::put(new_pot.into()); // All good. Ok(()) @@ -204,13 +211,13 @@ impl Module { fn configure( proposal_bond: Permill, - proposal_bond_minimum: T::Balance, - spend_period: T::BlockNumber, + proposal_bond_minimum: ::Type, + spend_period: ::Type, burn: Permill ) -> Result { >::put(proposal_bond); - >::put(proposal_bond_minimum); - >::put(spend_period); + >::put(proposal_bond_minimum.into()); + >::put(spend_period.into()); >::put(burn); Ok(()) } @@ -373,7 +380,7 @@ mod tests { #[test] fn spend_proposal_takes_min_deposit() { with_externalities(&mut new_test_ext(), || { - assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 1.into(), Address::Id(3))); assert_eq!(Balances::free_balance(&0), 99); assert_eq!(Balances::reserved_balance(&0), 1); }); @@ -382,7 +389,7 @@ mod tests { #[test] fn spend_proposal_takes_proportional_deposit() { with_externalities(&mut new_test_ext(), || { - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); assert_eq!(Balances::free_balance(&0), 95); assert_eq!(Balances::reserved_balance(&0), 5); }); @@ -391,7 +398,7 @@ mod tests { #[test] fn spend_proposal_fails_when_proposer_poor() { with_externalities(&mut new_test_ext(), || { - assert_noop!(Treasury::propose_spend(Origin::signed(2), 100, 3), "Proposer's balance too low"); + assert_noop!(Treasury::propose_spend(Origin::signed(2), 100.into(), Address::Id(3)), "Proposer's balance too low"); }); } @@ -400,8 +407,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); - assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); + assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into())); >::on_finalise(1); assert_eq!(Balances::free_balance(&3), 0); @@ -424,8 +431,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); - assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); + assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into())); >::on_finalise(2); assert_eq!(Balances::free_balance(&3), 0); @@ -438,23 +445,23 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); - assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); - assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0), "No proposal at that index"); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); + assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into())); + assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0.into()), "No proposal at that index"); }); } #[test] fn reject_non_existant_spend_proposal_fails() { with_externalities(&mut new_test_ext(), || { - assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0), "No proposal at that index"); + assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0.into()), "No proposal at that index"); }); } #[test] fn accept_non_existant_spend_proposal_fails() { with_externalities(&mut new_test_ext(), || { - assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0), "No proposal at that index"); + assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0.into()), "No proposal at that index"); }); } @@ -463,9 +470,9 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); - assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); - assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0), "No proposal at that index"); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); + assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into())); + assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0.into()), "No proposal at that index"); }); } @@ -474,8 +481,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); - assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), Address::Id(3))); + assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into())); >::on_finalise(2); assert_eq!(Balances::free_balance(&3), 100); @@ -488,8 +495,8 @@ mod tests { with_externalities(&mut new_test_ext(), || { Treasury::on_dilution(100, 100); - assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3)); - assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); + assert_ok!(Treasury::propose_spend(Origin::signed(0), 150.into(), Address::Id(3))); + assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into())); >::on_finalise(2); assert_eq!(Treasury::pot(), 100);