Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
Prev Previous commit
Next Next commit
Merge branch 'master' into td-pubsub
  • Loading branch information
tomusdrw committed Apr 13, 2018
commit af88a13f6dcc8a19e50f6dcc4cce05f63589e023
6 changes: 3 additions & 3 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
};
let client = Arc::new(client::new_in_mem(executor, prepare_genesis)?);

let handler = rpc::rpc_handler(client, client, DummyPool);
let handler = || rpc::rpc_handler(client.clone(), client.clone(), DummyPool);
let http_address = "127.0.0.1:9933".parse().unwrap();
let http_server = rpc::start_http(&http_address, handler)?;
let http_server = rpc::start_http(&http_address, handler())?;
let ws_address = "127.0.0.1:9944".parse().unwrap();
let ws_server = rpc::start_ws(&ws_address, handler)?;
let ws_server = rpc::start_ws(&ws_address, handler())?;

if let Some(_) = matches.subcommand_matches("validator") {
info!("Starting validator.");
Expand Down
24 changes: 16 additions & 8 deletions substrate/rpc/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ build_rpc_trait! {
#[rpc(name = "chain_getHeader")]
fn header(&self, block::HeaderHash) -> Result<Option<block::Header>>;

#[pubsub(name = "chain_newHeader")] {
/// Get hash of the head.
#[rpc(name = "chain_getHead")]
fn head(&self) -> Result<block::HeaderHash>;

#[pubsub(name = "chain_newHead")] {
/// Hello subscription
#[rpc(name = "subscribe_newHeader")]
fn subscribe(&self, Self::Metadata, pubsub::Subscriber<block::Header>);
#[rpc(name = "subscribe_newHead")]
fn subscribe_new_head(&self, Self::Metadata, pubsub::Subscriber<block::Header>);

/// Unsubscribe from hello subscription.
#[rpc(name = "unsubscribe_newHeader")]
fn unsubscribe(&self, SubscriptionId) -> RpcResult<bool>;
#[rpc(name = "unsubscribe_newHead")]
fn unsubscribe_new_head(&self, SubscriptionId) -> RpcResult<bool>;
}
}
}

impl<B, E> ChainApi for Arc<client::Client<B, E>> where
impl<B, E> ChainApi for Arc<Client<B, E>> where
B: client::backend::Backend + Send + Sync + 'static,
E: state_machine::CodeExecutor + Send + Sync + 'static,
client::error::Error: From<<<B as client::backend::Backend>::State as state_machine::backend::Backend>::Error>,
Expand All @@ -65,11 +69,15 @@ impl<B, E> ChainApi for Arc<client::Client<B, E>> where
client::Client::header(self, &block::Id::Hash(hash)).chain_err(|| "Blockchain error")
}

fn subscribe(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber<block::Header>) {
fn head(&self) -> Result<block::HeaderHash> {
Ok(client::Client::info(self).chain_err(|| "Blockchain error")?.chain.best_hash)
}

fn subscribe_new_head(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber<block::Header>) {

}

fn unsubscribe(&self, id: SubscriptionId) -> RpcResult<bool> {
fn unsubscribe_new_head(&self, id: SubscriptionId) -> RpcResult<bool> {
unimplemented!()
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.