Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP
Forked at: 53e8ec2
Parent branch: origin/cecton-the-revenge-of-the-cli
  • Loading branch information
cecton committed Apr 7, 2020
commit c79cc3a1c62b4b4eb6ea63ae4e7b322af7a2e60a
17 changes: 17 additions & 0 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

#![allow(unused_imports)]

use crate::error::Error;
use futures::Future;
use std::pin::Pin;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::NumberFor;
use std::io::{Read, Write, Seek};
use sp_runtime::traits::Block as BlockT;
use sc_executor::NativeExecutionDispatch;

/*
use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm};
use crate::{TaskManagerBuilder, start_rpc_servers, build_network_future, TransactionPoolAdapter};
use crate::status_sinks;
Expand Down Expand Up @@ -656,7 +668,9 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
})
}
}
*/

/*
/// Implemented on `ServiceBuilder`. Allows running block commands, such as import/export/validate
/// components to the builder.
pub trait ServiceBuilderCommand {
Expand Down Expand Up @@ -692,7 +706,9 @@ pub trait ServiceBuilderCommand {
block: BlockId<Self::Block>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
}
*/

/*
impl<TBl, TRtApi, TBackend, TExec, TSc, TImpQu, TExPool, TRpc>
ServiceBuilder<
TBl,
Expand Down Expand Up @@ -1168,3 +1184,4 @@ ServiceBuilder<
})
}
}
*/
59 changes: 27 additions & 32 deletions client/service/src/chain_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

//! Chain utilities.

#![allow(unused_imports)]

use crate::error;
use crate::builder::{ServiceBuilderCommand, ServiceBuilder};
//use crate::builder::{ServiceBuilderCommand, ServiceBuilder};
use crate::error::Error;
use sc_chain_spec::ChainSpec;
use log::{warn, info};
Expand All @@ -36,32 +38,25 @@ use sc_executor::{NativeExecutor, NativeExecutionDispatch};

use std::{io::{Read, Write, Seek}, pin::Pin};
use sc_client_api::BlockBackend;
use std::sync::Arc;

/// Build a chain spec json
pub fn build_spec(spec: &dyn ChainSpec, raw: bool) -> error::Result<String> {
Ok(spec.as_json(raw)?)
}

impl<
TBl, TRtApi, TBackend,
TExecDisp, TFchr, TSc, TImpQu, TFprb, TFpp,
TExPool, TRpc, Backend
> ServiceBuilderCommand for ServiceBuilder<
TBl, TRtApi,
Client<TBackend, LocalCallExecutor<TBackend, NativeExecutor<TExecDisp>>, TBl, TRtApi>,
TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend
> where
TBl: BlockT,
TBackend: 'static + sc_client_api::backend::Backend<TBl> + Send,
TExecDisp: 'static + NativeExecutionDispatch,
TImpQu: 'static + ImportQueue<TBl>,
TRtApi: 'static + Send + Sync,
pub trait ServiceBuilderCommand<B, BA, CE, IQ>: Sized
where
B: BlockT,
BA: sc_client_api::backend::Backend<B> + 'static,
CE: sc_client_api::call_executor::CallExecutor<B> + Send + Sync + 'static,
IQ: ImportQueue<B> + Sync + 'static,
{
type Block = TBl;
type NativeDispatch = TExecDisp;
fn client(&self) -> Arc<Client<BA, CE, B, ()>>;
fn import_queue(&mut self) -> &mut IQ;

fn import_blocks(
self,
&'static mut self,
input: impl Read + Seek + Send + 'static,
force: bool,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> {
Expand Down Expand Up @@ -98,8 +93,8 @@ impl<
}
}

let client = self.client;
let mut queue = self.import_queue;
let client = self.client();
let mut queue = self.import_queue();

let mut io_reader_input = IoReader(input);
let mut count = None::<u64>;
Expand Down Expand Up @@ -133,13 +128,13 @@ impl<

// Read blocks from the input.
if read_block_count < count {
match SignedBlock::<Self::Block>::decode(&mut io_reader_input) {
match SignedBlock::<B>::decode(&mut io_reader_input) {
Ok(signed) => {
let (header, extrinsics) = signed.block.deconstruct();
let hash = header.hash();
// import queue handles verification and importing it into the client
queue.import_blocks(BlockOrigin::File, vec![
IncomingBlock::<Self::Block> {
IncomingBlock::<B> {
hash,
header: Some(header),
body: Some(extrinsics),
Expand Down Expand Up @@ -197,13 +192,13 @@ impl<
}

fn export_blocks(
self,
&'static self,
mut output: impl Write + 'static,
from: NumberFor<TBl>,
to: Option<NumberFor<TBl>>,
from: NumberFor<B>,
to: Option<NumberFor<B>>,
binary: bool
) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
let client = self.client;
let client = self.client();
let mut block = from;

let last = match to {
Expand Down Expand Up @@ -267,10 +262,10 @@ impl<

fn revert_chain(
&self,
blocks: NumberFor<TBl>
blocks: NumberFor<B>
) -> Result<(), Error> {
let reverted = self.client.revert(blocks)?;
let info = self.client.chain_info();
let reverted = self.client().revert(blocks)?;
let info = self.client().chain_info();

if reverted.is_zero() {
info!("There aren't any non-finalized blocks to revert.");
Expand All @@ -281,10 +276,10 @@ impl<
}

fn check_block(
self,
block_id: BlockId<TBl>
&'static mut self,
block_id: BlockId<B>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> {
match self.client.block(&block_id) {
match self.client().block(&block_id) {
Ok(Some(block)) => {
let mut buf = Vec::new();
1u64.encode_to(&mut buf);
Expand Down
2 changes: 2 additions & 0 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ use parity_util_mem::MallocSizeOf;
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};

pub use self::error::Error;
/*
pub use self::builder::{
new_full_client,
ServiceBuilder, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend,
TFullCallExecutor, TLightCallExecutor,
};
pub use config::{Configuration, Role, PruningMode, DatabaseConfig};
*/
pub use sc_chain_spec::{
ChainSpec, GenericChainSpec, Properties, RuntimeGenesis, Extension as ChainSpecExtension,
NoExtension,
Expand Down