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
@@ -43,7 +43,7 @@ use client::{
light::fetcher::{FetchChecker, RemoteCallRequest},
ExecutionStrategy, NeverOffchainExt,
};
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use grandpa::BlockNumberOps;
use sr_primitives::{Justification, generic::BlockId};
use sr_primitives::traits::{
@@ -81,8 +81,8 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> AuthoritySetForFinalityProver<Block> fo
ExecutionStrategy::NativeElseWasm,
NeverOffchainExt::new(),
).and_then(|call_result| Decode::decode(&mut &call_result[..])
.ok_or_else(|| ClientError::CallResultDecode(
"failed to decode GRANDPA authorities set proof".into(),
.map_err(|err| ClientError::CallResultDecode(
"failed to decode GRANDPA authorities set proof".into(), err
)))
}
@@ -121,8 +121,8 @@ impl<Block: BlockT> AuthoritySetForFinalityChecker<Block> for Arc<dyn FetchCheck
self.check_execution_proof(&request, proof)
.and_then(|authorities| {
let authorities: Vec<(AuthorityId, u64)> = Decode::decode(&mut &authorities[..])
.ok_or_else(|| ClientError::CallResultDecode(
"failed to decode GRANDPA authorities set proof".into(),
.map_err(|err| ClientError::CallResultDecode(
"failed to decode GRANDPA authorities set proof".into(), err
))?;
Ok(authorities.into_iter().collect())
})
@@ -167,8 +167,8 @@ impl<B, E, Block, RA> network::FinalityProofProvider<Block> for FinalityProofPro
request: &[u8],
) -> Result<Option<Vec<u8>>, ClientError> {
let request: FinalityProofRequest<Block::Hash> = Decode::decode(&mut &request[..])
.ok_or_else(|| {
warn!(target: "finality", "Unable to decode finality proof request.");
.map_err(|e| {
warn!(target: "finality", "Unable to decode finality proof request: {}", e.what());
ClientError::Backend(format!("Invalid finality proof request"))
})?;
match request {
@@ -445,7 +445,7 @@ fn do_check_finality_proof<Block: BlockT<Hash=H256>, B, J>(
{
// decode finality proof
let proof = FinalityProof::<Block::Header>::decode(&mut &remote_proof[..])
.ok_or_else(|| ClientError::BadJustification("failed to decode finality proof".into()))?;
.map_err(|_| ClientError::BadJustification("failed to decode finality proof".into()))?;
// empty proof can't prove anything
if proof.is_empty() {
@@ -500,7 +500,7 @@ fn check_finality_proof_fragment<Block: BlockT<Hash=H256>, B, J>(
// verify justification using previous authorities set
let (mut current_set_id, mut current_authorities) = authority_set.extract_authorities();
let justification: J = Decode::decode(&mut &proof_fragment.justification[..])
.ok_or_else(|| ClientError::JustificationDecode)?;
.map_err(|_| ClientError::JustificationDecode)?;
justification.verify(current_set_id, &current_authorities)?;
// and now verify new authorities proof (if provided)
@@ -560,7 +560,8 @@ pub(crate) trait ProvableJustification<Header: HeaderT>: Encode + Decode {
set_id: u64,
authorities: &[(AuthorityId, u64)],
) -> ClientResult<Self> {
let justification = Self::decode(&mut &**justification).ok_or(ClientError::JustificationDecode)?;
let justification = Self::decode(&mut &**justification)
.map_err(|_| ClientError::JustificationDecode)?;
justification.verify(set_id, authorities)?;
Ok(justification)
}