Transaction queue integration + submission RPC (#99)

* Implement transaction queue RPC.

* whitespace

* Support without_std env in environmental!  (#110)

* Make environmental crate support without_std env.

* Small doc fixes.

* Remove dead code.
This commit is contained in:
Gav Wood
2018-04-09 16:28:06 +02:00
committed by GitHub
parent 0e442f06e1
commit 68273405a2
7 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -118,7 +118,7 @@ pub fn run<I, T>(args: I, exit: mpsc::Receiver<()>) -> error::Result<()> where
let rpc_port: u16 = port.parse().expect("Invalid RPC port value specified."); let rpc_port: u16 = port.parse().expect("Invalid RPC port value specified.");
address.set_port(rpc_port); address.set_port(rpc_port);
} }
let handler = rpc::rpc_handler(service.client()); let handler = rpc::rpc_handler(service.client(), service.transaction_pool());
let _server = rpc::start_http(&address, handler)?; let _server = rpc::start_http(&address, handler)?;
exit.recv().ok(); exit.recv().ok();
@@ -150,6 +150,7 @@ fn default_base_path() -> PathBuf {
&app_info, &app_info,
).expect("app directories exist on all supported platforms; qed") ).expect("app directories exist on all supported platforms; qed")
} }
fn init_logger(pattern: &str) { fn init_logger(pattern: &str) {
let mut builder = env_logger::LogBuilder::new(); let mut builder = env_logger::LogBuilder::new();
// Disable info logging by default for some modules: // Disable info logging by default for some modules:
+4
View File
@@ -570,9 +570,13 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
} }
let polkadot_block = block_builder.bake(); let polkadot_block = block_builder.bake();
info!("Proposing block [number: {}; extrinsics: [{}], parent_hash: {}]", polkadot_block.header.number, polkadot_block.extrinsics.len(), polkadot_block.header.parent_hash);
let substrate_block = Slicable::decode(&mut polkadot_block.encode().as_slice()) let substrate_block = Slicable::decode(&mut polkadot_block.encode().as_slice())
.expect("polkadot blocks defined to serialize to substrate blocks correctly; qed"); .expect("polkadot blocks defined to serialize to substrate blocks correctly; qed");
assert!(evaluate_proposal(&substrate_block, &*self.client, current_timestamp(), &self.parent_hash, &self.parent_id).is_ok());
Ok(substrate_block) Ok(substrate_block)
} }
Binary file not shown.
+2
View File
@@ -9,6 +9,8 @@ error-chain = "0.11"
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
substrate-client = { path = "../../substrate/client" }
substrate-rpc = { path = "../../substrate/rpc" }
substrate-primitives = { path = "../../substrate/primitives" } substrate-primitives = { path = "../../substrate/primitives" }
substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" } substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" }
substrate-codec = { path = "../../substrate/codec" } substrate-codec = { path = "../../substrate/codec" }
+13
View File
@@ -17,6 +17,7 @@
extern crate ed25519; extern crate ed25519;
extern crate ethereum_types; extern crate ethereum_types;
extern crate substrate_codec as codec; extern crate substrate_codec as codec;
extern crate substrate_rpc;
extern crate substrate_primitives as substrate_primitives; extern crate substrate_primitives as substrate_primitives;
extern crate substrate_runtime_primitives as substrate_runtime_primitives; extern crate substrate_runtime_primitives as substrate_runtime_primitives;
extern crate polkadot_runtime as runtime; extern crate polkadot_runtime as runtime;
@@ -31,8 +32,10 @@ use std::collections::HashMap;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::sync::Arc; use std::sync::Arc;
use codec::Slicable;
use polkadot_api::PolkadotApi; use polkadot_api::PolkadotApi;
use primitives::{AccountId, Timestamp}; use primitives::{AccountId, Timestamp};
use substrate_primitives::block::Extrinsic;
use runtime::{Block, UncheckedExtrinsic, TimestampCall, Call}; use runtime::{Block, UncheckedExtrinsic, TimestampCall, Call};
use substrate_runtime_primitives::traits::Checkable; use substrate_runtime_primitives::traits::Checkable;
use transaction_pool::{Pool, Readiness}; use transaction_pool::{Pool, Readiness};
@@ -371,6 +374,16 @@ impl TransactionPool {
} }
} }
impl substrate_rpc::author::AsyncAuthorApi for TransactionPool {
fn submit_extrinsic(&mut self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> {
self.import(xt
.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?)
.map(|_| ())
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into())
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
} }