Skip to content
Snippets Groups Projects
Commit 61e079dc authored by Wei Tang's avatar Wei Tang
Browse files

Define a service!

parent d36dfe5a
Branches
No related merge requests found
......@@ -1991,10 +1991,15 @@ dependencies = [
name = "shasper-service"
version = "0.1.0"
dependencies = [
"shasper-executor 0.1.0",
"shasper-network 0.1.0",
"shasper-runtime 0.1.0",
"shasper-transaction-pool 0.1.0",
"sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)",
"substrate-client 0.1.0 (git+https://github.com/paritytech/substrate)",
"substrate-primitives 0.1.0 (git+https://github.com/paritytech/substrate)",
"substrate-service 0.3.0 (git+https://github.com/paritytech/substrate)",
"tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......
......@@ -4,7 +4,12 @@ version = "0.1.0"
authors = ["Parity Team <admin@parity.io>"]
[dependencies]
tokio = "0.1.7"
shasper-runtime = { path = "../runtime" }
shasper-network = { path = "../network" }
shasper-executor = { path = "../executor" }
shasper-transaction-pool = { path = "../transaction-pool" }
sr-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-service = { git = "https://github.com/paritytech/substrate" }
extern crate shasper_runtime as runtime;
extern crate shasper_network as network;
extern crate shasper_executor as executor;
extern crate shasper_transaction_pool as transaction_pool;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_primitives as primitives;
extern crate substrate_client as client;
extern crate substrate_service as service;
extern crate tokio;
use runtime::Block;
use primitives::Blake2Hasher;
use network::Protocol;
use primitives::H256;
use transaction_pool::TransactionPool;
use service::TransactionPoolOptions;
use runtime_primitives::StorageMap;
use tokio::runtime::TaskExecutor;
pub trait Components: service::Components {
type Backend: 'static + client::backend::Backend<Block, Blake2Hasher>;
type Executor: 'static + client::CallExecutor<Block, Blake2Hasher> + Send + Sync;
}
use std::sync::Arc;
/// All configuration for the node.
pub type Configuration = service::FactoryFullConfiguration<Factory>;
pub struct Factory;
impl service::ServiceFactory for Factory {
type Block = Block;
type ExtrinsicHash = H256;
type NetworkProtocol = Protocol;
type RuntimeDispatch = executor::Executor;
type FullTransactionPoolApi = transaction_pool::ChainApi;
type LightTransactionPoolApi = transaction_pool::ChainApi;
type Genesis = StorageMap;
type Configuration = ();
type FullService = Service<service::FullComponents<Self>>;
type LightService = Service<service::LightComponents<Self>>;
fn build_full_transaction_pool(config: TransactionPoolOptions, _client: Arc<service::FullClient<Self>>)
-> Result<TransactionPool, service::Error>
{
Ok(TransactionPool::new(config, transaction_pool::ChainApi))
}
fn build_light_transaction_pool(config: TransactionPoolOptions, _client: Arc<service::LightClient<Self>>)
-> Result<TransactionPool, service::Error>
{
Ok(TransactionPool::new(config, transaction_pool::ChainApi))
}
fn build_network_protocol(_config: &Configuration)
-> Result<Protocol, service::Error>
{
Ok(Protocol::new())
}
fn new_light(config: Configuration, executor: TaskExecutor)
-> Result<Service<service::LightComponents<Factory>>, service::Error>
{
Ok(Service(service::Service::<service::LightComponents<Factory>>::new(config, executor.clone())?))
}
fn new_full(config: Configuration, executor: TaskExecutor)
-> Result<Service<service::FullComponents<Factory>>, service::Error>
{
Ok(Service(service::Service::<service::FullComponents<Factory>>::new(config, executor.clone())?))
}
}
pub struct Service<C: service::Components>(service::Service<C>);
impl<C: service::Components> ::std::ops::Deref for Service<C> {
type Target = service::Service<C>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
......@@ -10,6 +10,8 @@ use transaction_pool::scoring::{Change, Choice};
use std::cmp::Ordering;
pub type TransactionPool = transaction_pool::Pool<ChainApi>;
#[derive(Debug, Clone)]
pub struct Verified {
pub extrinsic: Extrinsic,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment