mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
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:
committed by
Bastian Köcher
parent
a0d442333f
commit
4ed67e03a4
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Chain utilities.
|
||||
|
||||
use std::{self, io::{Read, Write}};
|
||||
use std::{self, io::{Read, Write, Seek}};
|
||||
use futures::prelude::*;
|
||||
use futures03::TryFutureExt as _;
|
||||
use log::{info, warn};
|
||||
@@ -29,7 +29,7 @@ use network::message;
|
||||
use consensus_common::BlockOrigin;
|
||||
use crate::components::{self, Components, ServiceFactory, FactoryFullConfiguration, FactoryBlockNumber, RuntimeGenesis};
|
||||
use crate::new_client;
|
||||
use parity_codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode, IoReader};
|
||||
use crate::error;
|
||||
use crate::chain_spec::ChainSpec;
|
||||
|
||||
@@ -136,9 +136,9 @@ impl<B: Block> Link<B> for WaitLink {
|
||||
pub fn import_blocks<F, E, R>(
|
||||
mut config: FactoryFullConfiguration<F>,
|
||||
exit: E,
|
||||
mut input: R
|
||||
input: R
|
||||
) -> error::Result<impl Future<Item = (), Error = ()>>
|
||||
where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read,
|
||||
where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read + Seek,
|
||||
{
|
||||
let client = new_client::<F>(&config)?;
|
||||
// FIXME #1134 this shouldn't need a mutable config.
|
||||
@@ -155,37 +155,42 @@ pub fn import_blocks<F, E, R>(
|
||||
let _ = exit_send.send(());
|
||||
});
|
||||
|
||||
let count: u64 = Decode::decode(&mut input).ok_or("Error reading file")?;
|
||||
let mut io_reader_input = IoReader(input);
|
||||
let count: u64 = Decode::decode(&mut io_reader_input)
|
||||
.map_err(|e| format!("Error reading file: {}", e))?;
|
||||
info!("Importing {} blocks", count);
|
||||
let mut block_count = 0;
|
||||
for b in 0 .. count {
|
||||
if exit_recv.try_recv().is_ok() {
|
||||
break;
|
||||
}
|
||||
if let Some(signed) = SignedBlock::<F::Block>::decode(&mut input) {
|
||||
let (header, extrinsics) = signed.block.deconstruct();
|
||||
let hash = header.hash();
|
||||
let block = message::BlockData::<F::Block> {
|
||||
hash,
|
||||
justification: signed.justification,
|
||||
header: Some(header),
|
||||
body: Some(extrinsics),
|
||||
receipt: None,
|
||||
message_queue: None
|
||||
};
|
||||
// import queue handles verification and importing it into the client
|
||||
queue.import_blocks(BlockOrigin::File, vec![
|
||||
IncomingBlock::<F::Block>{
|
||||
hash: block.hash,
|
||||
header: block.header,
|
||||
body: block.body,
|
||||
justification: block.justification,
|
||||
origin: None,
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
warn!("Error reading block data at {}.", b);
|
||||
break;
|
||||
match SignedBlock::<F::Block>::decode(&mut io_reader_input) {
|
||||
Ok(signed) => {
|
||||
let (header, extrinsics) = signed.block.deconstruct();
|
||||
let hash = header.hash();
|
||||
let block = message::BlockData::<F::Block> {
|
||||
hash,
|
||||
justification: signed.justification,
|
||||
header: Some(header),
|
||||
body: Some(extrinsics),
|
||||
receipt: None,
|
||||
message_queue: None
|
||||
};
|
||||
// import queue handles verification and importing it into the client
|
||||
queue.import_blocks(BlockOrigin::File, vec![
|
||||
IncomingBlock::<F::Block> {
|
||||
hash: block.hash,
|
||||
header: block.header,
|
||||
body: block.body,
|
||||
justification: block.justification,
|
||||
origin: None,
|
||||
}
|
||||
]);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Error reading block data at {}: {}", b, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
block_count = b;
|
||||
|
||||
@@ -40,7 +40,7 @@ use futures03::stream::{StreamExt as _, TryStreamExt as _};
|
||||
use keystore::Store as Keystore;
|
||||
use network::{NetworkState, NetworkStateInfo};
|
||||
use log::{log, info, warn, debug, error, Level};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use primitives::{Pair, ed25519, sr25519, crypto};
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{Header, NumberFor, SaturatedConversion, Zero};
|
||||
@@ -877,28 +877,31 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
|
||||
}
|
||||
|
||||
let encoded = transaction.encode();
|
||||
if let Some(uxt) = Decode::decode(&mut &encoded[..]) {
|
||||
let best_block_id = self.best_block_id()?;
|
||||
match self.pool.submit_one(&best_block_id, uxt) {
|
||||
Ok(hash) => Some(hash),
|
||||
Err(e) => match e.into_pool_error() {
|
||||
Ok(txpool::error::Error::AlreadyImported(hash)) => {
|
||||
hash.downcast::<ComponentExHash<C>>().ok()
|
||||
.map(|x| x.as_ref().clone())
|
||||
},
|
||||
Ok(e) => {
|
||||
debug!("Error adding transaction to the pool: {:?}", e);
|
||||
None
|
||||
},
|
||||
Err(e) => {
|
||||
debug!("Error converting pool error: {:?}", e);
|
||||
None
|
||||
},
|
||||
match Decode::decode(&mut &encoded[..]) {
|
||||
Ok(uxt) => {
|
||||
let best_block_id = self.best_block_id()?;
|
||||
match self.pool.submit_one(&best_block_id, uxt) {
|
||||
Ok(hash) => Some(hash),
|
||||
Err(e) => match e.into_pool_error() {
|
||||
Ok(txpool::error::Error::AlreadyImported(hash)) => {
|
||||
hash.downcast::<ComponentExHash<C>>().ok()
|
||||
.map(|x| x.as_ref().clone())
|
||||
},
|
||||
Ok(e) => {
|
||||
debug!("Error adding transaction to the pool: {:?}", e);
|
||||
None
|
||||
},
|
||||
Err(e) => {
|
||||
debug!("Error converting pool error: {:?}", e);
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug!("Error decoding transaction");
|
||||
None
|
||||
Err(e) => {
|
||||
debug!("Error decoding transaction {}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user