Update to parity-scale-codec (#3232)

* WIP: update codec

* WIP

* compiling

* WIP

* rename parity-scale-codec to codec

* WIP

* fix

* remove old comments

* use published crates

* fix expected error msg

* bump version

* fmt and fix

* remove old comment

* fix wrong decoding impl

* implement encode like for structures

* undo removal of old pending changes

* trailingzeroinput

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* update codec

* fmt

* version is 1.0.0

* show more error

* fmt
This commit is contained in:
thiolliere
2019-08-06 19:36:23 +02:00
committed by Bastian Köcher
parent a0d442333f
commit 4ed67e03a4
211 changed files with 867 additions and 682 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ futures-timer = "0.2.1"
rstd = { package = "sr-std", path = "../../sr-std" }
runtime_version = { package = "sr-version", path = "../../sr-version" }
sr-primitives = { path = "../../sr-primitives" }
parity-codec = { version = "4.1.1", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
parking_lot = "0.8.0"
[dev-dependencies]
@@ -6,7 +6,7 @@ description = "Common consensus primitives"
edition = "2018"
[dependencies]
parity-codec = { version = "4.1.1", default-features = false }
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
client = { package = "substrate-client", path = "../../../client", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
@@ -16,6 +16,6 @@ default = ["std"]
std = [
"rstd/std",
"client/std",
"parity-codec/std",
"codec/std",
"sr-primitives/std"
]
@@ -18,7 +18,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use parity_codec::Codec;
use codec::Codec;
use client::decl_runtime_apis;
use rstd::vec::Vec;
@@ -18,7 +18,7 @@
use super::MAX_BLOCK_SIZE;
use parity_codec::Encode;
use codec::Encode;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, One, CheckedConversion};
// This is just a best effort to encode the number. None indicated that it's too big to encode
@@ -32,8 +32,8 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, derive_more::Display)]
pub enum Error {
/// Proposal provided not a block.
#[display(fmt="Proposal provided not a block.")]
BadProposalFormat,
#[display(fmt="Proposal provided not a block: decoding error: {}", _0)]
BadProposalFormat(codec::Error),
/// Proposal had wrong parent hash.
#[display(fmt="Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got)]
WrongParentHash { expected: String, got: String },
@@ -60,7 +60,7 @@ pub fn evaluate_initial<Block: BlockT>(
let encoded = Encode::encode(proposal);
let proposal = Block::decode(&mut &encoded[..])
.ok_or_else(|| Error::BadProposalFormat)?;
.map_err(|e| Error::BadProposalFormat(e))?;
if encoded.len() > MAX_BLOCK_SIZE {
return Err(Error::ProposalTooLarge(encoded.len()))