Migrate network, primitives and rpc to the 2018 edition (#1710)

This commit is contained in:
Stanislav Tkach
2019-02-06 20:07:48 +02:00
committed by Gav Wood
parent 3a4dda7beb
commit e60be1ad12
43 changed files with 203 additions and 278 deletions
+3 -2
View File
@@ -16,11 +16,12 @@
//! Authoring RPC module errors.
use error_chain::*;
use client;
use transaction_pool::txpool;
use rpc;
use crate::rpc;
use errors;
use crate::errors;
error_chain! {
links {
+8 -7
View File
@@ -18,8 +18,9 @@
use std::sync::Arc;
use log::warn;
use client::{self, Client};
use codec::{Encode, Decode};
use parity_codec::{Encode, Decode};
use transaction_pool::{
txpool::{
ChainApi as PoolChainApi,
@@ -33,9 +34,9 @@ use transaction_pool::{
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use primitives::{Bytes, Blake2Hasher, H256};
use rpc::futures::{Sink, Stream, Future};
use crate::rpc::futures::{Sink, Stream, Future};
use runtime_primitives::{generic, traits};
use subscriptions::Subscriptions;
use crate::subscriptions::Subscriptions;
pub mod error;
@@ -52,7 +53,7 @@ pub trait AuthorApi<Hash, BlockHash> {
/// Submit hex-encoded extrinsic for inclusion in block.
#[rpc(name = "author_submitExtrinsic")]
fn submit_extrinsic(&self, Bytes) -> Result<Hash>;
fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash>;
/// Returns all pending extrinsics, potentially grouped by sender.
#[rpc(name = "author_pendingExtrinsics")]
@@ -60,11 +61,11 @@ pub trait AuthorApi<Hash, BlockHash> {
/// Submit an extrinsic to watch.
#[pubsub(subscription = "author_extrinsicUpdate", subscribe, name = "author_submitAndWatchExtrinsic")]
fn watch_extrinsic(&self, Self::Metadata, Subscriber<Status<Hash, BlockHash>>, Bytes);
fn watch_extrinsic(&self, metadata: Self::Metadata, subscriber: Subscriber<Status<Hash, BlockHash>>, bytes: Bytes);
/// Unsubscribe from extrinsic watching.
#[pubsub(subscription = "author_extrinsicUpdate", unsubscribe, name = "author_unwatchExtrinsic")]
fn unwatch_extrinsic(&self, Option<Self::Metadata>, SubscriptionId) -> Result<bool>;
fn unwatch_extrinsic(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> Result<bool>;
}
/// Authoring API
@@ -100,7 +101,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
P::Error: 'static,
RA: Send + Sync + 'static
{
type Metadata = ::metadata::Metadata;
type Metadata = crate::metadata::Metadata;
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?;
+3 -1
View File
@@ -17,7 +17,9 @@
use super::*;
use std::sync::Arc;
use codec::Encode;
use hex_literal::{hex, hex_impl};
use assert_matches::assert_matches;
use parity_codec::Encode;
use transaction_pool::{
txpool::Pool,
ChainApi,
+3 -3
View File
@@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use error_chain::*;
use client;
use rpc;
use errors;
use crate::rpc;
use crate::errors;
error_chain! {
links {
+12 -11
View File
@@ -18,16 +18,17 @@
use std::sync::Arc;
use log::warn;
use client::{self, Client, BlockchainEvents};
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use primitives::{H256, Blake2Hasher};
use rpc::Result as RpcResult;
use rpc::futures::{stream, Future, Sink, Stream};
use crate::rpc::Result as RpcResult;
use crate::rpc::futures::{stream, Future, Sink, Stream};
use runtime_primitives::generic::{BlockId, SignedBlock};
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
use subscriptions::Subscriptions;
use crate::subscriptions::Subscriptions;
mod error;
#[cfg(test)]
@@ -44,17 +45,17 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
/// Get header of a relay chain block.
#[rpc(name = "chain_getHeader")]
fn header(&self, Option<Hash>) -> Result<Option<Header>>;
fn header(&self, hash: Option<Hash>) -> Result<Option<Header>>;
/// Get header and body of a relay chain block.
#[rpc(name = "chain_getBlock")]
fn block(&self, Option<Hash>) -> Result<Option<SignedBlock>>;
fn block(&self, hash: Option<Hash>) -> Result<Option<SignedBlock>>;
/// Get hash of the n-th block in the canon chain.
///
/// By default returns latest block hash.
#[rpc(name = "chain_getBlockHash", alias("chain_getHead"))]
fn block_hash(&self, Option<number::NumberOrHex<Number>>) -> Result<Option<Hash>>;
fn block_hash(&self, hash: Option<number::NumberOrHex<Number>>) -> Result<Option<Hash>>;
/// Get hash of the last finalised block in the canon chain.
#[rpc(name = "chain_getFinalisedHead")]
@@ -67,7 +68,7 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
name = "chain_subscribeNewHead",
alias("subscribe_newHead")
)]
fn subscribe_new_head(&self, Self::Metadata, Subscriber<Header>);
fn subscribe_new_head(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
/// Unsubscribe from new head subscription.
#[pubsub(
@@ -76,7 +77,7 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
name = "chain_unsubscribeNewHead",
alias("unsubscribe_newHead")
)]
fn unsubscribe_new_head(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_new_head(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
/// New head subscription
#[pubsub(
@@ -84,7 +85,7 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
subscribe,
name = "chain_subscribeFinalisedHeads"
)]
fn subscribe_finalised_heads(&self, Self::Metadata, Subscriber<Header>);
fn subscribe_finalised_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
/// Unsubscribe from new head subscription.
#[pubsub(
@@ -92,7 +93,7 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
unsubscribe,
name = "chain_unsubscribeFinalisedHeads"
)]
fn unsubscribe_finalised_heads(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_finalised_heads(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
}
/// Chain API with subscriptions support.
@@ -169,7 +170,7 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
E: client::CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static,
RA: Send + Sync + 'static
{
type Metadata = ::metadata::Metadata;
type Metadata = crate::metadata::Metadata;
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>> {
let hash = self.unwrap_or_best(hash)?;
+1
View File
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use serde_derive::Deserialize;
use primitives::U256;
use runtime_primitives::traits;
+1
View File
@@ -15,6 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use assert_matches::assert_matches;
use test_client::{self, TestClient};
use test_client::runtime::{H256, Block, Header};
use consensus::BlockOrigin;
+2 -1
View File
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use rpc;
use crate::rpc;
use log::warn;
pub fn unimplemented() -> rpc::Error {
rpc::Error {
+2 -35
View File
@@ -18,41 +18,6 @@
#![warn(missing_docs)]
extern crate jsonrpc_core as rpc;
extern crate jsonrpc_pubsub;
extern crate jsonrpc_derive;
extern crate parity_codec as codec;
extern crate parking_lot;
extern crate serde;
extern crate serde_json;
extern crate sr_primitives as runtime_primitives;
extern crate sr_version as runtime_version;
extern crate substrate_client as client;
extern crate substrate_network as network;
extern crate substrate_primitives as primitives;
extern crate substrate_transaction_pool as transaction_pool;
extern crate tokio;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
#[macro_use]
extern crate assert_matches;
#[cfg(test)]
#[macro_use]
extern crate hex_literal;
#[cfg(test)]
extern crate substrate_test_client as test_client;
#[cfg(test)]
extern crate substrate_consensus_common as consensus;
#[cfg(test)]
extern crate rustc_hex;
mod errors;
mod helpers;
mod subscriptions;
@@ -64,3 +29,5 @@ pub mod chain;
pub mod metadata;
pub mod state;
pub mod system;
use jsonrpc_core as rpc;
+2 -2
View File
@@ -18,7 +18,7 @@
use std::sync::Arc;
use jsonrpc_pubsub::{Session, PubSubMetadata};
use rpc::futures::sync::mpsc;
use crate::rpc::futures::sync::mpsc;
/// RPC Metadata.
///
@@ -30,7 +30,7 @@ pub struct Metadata {
session: Option<Arc<Session>>,
}
impl ::rpc::Metadata for Metadata {}
impl crate::rpc::Metadata for Metadata {}
impl PubSubMetadata for Metadata {
fn session(&self) -> Option<Arc<Session>> {
self.session.clone()
+3 -3
View File
@@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use error_chain::*;
use client;
use rpc;
use errors;
use crate::rpc;
use crate::errors;
error_chain! {
links {
+19 -17
View File
@@ -22,19 +22,21 @@ use std::{
sync::Arc,
};
use error_chain::bail;
use log::{warn, trace};
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use primitives::{H256, Blake2Hasher, Bytes};
use primitives::hexdisplay::HexDisplay;
use primitives::storage::{self, StorageKey, StorageData, StorageChangeSet};
use rpc::Result as RpcResult;
use rpc::futures::{stream, Future, Sink, Stream};
use crate::rpc::Result as RpcResult;
use crate::rpc::futures::{stream, Future, Sink, Stream};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{Block as BlockT, Header, ProvideRuntimeApi, As, NumberFor};
use runtime_version::RuntimeVersion;
use subscriptions::Subscriptions;
use crate::subscriptions::Subscriptions;
mod error;
#[cfg(test)]
@@ -50,38 +52,38 @@ pub trait StateApi<Hash> {
/// Call a contract at a block's state.
#[rpc(name = "state_call", alias("state_callAt"))]
fn call(&self, String, Bytes, Option<Hash>) -> Result<Bytes>;
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> Result<Bytes>;
/// Returns the keys with prefix, leave empty to get all the keys
#[rpc(name = "state_getKeys")]
fn storage_keys(&self, StorageKey, Option<Hash>) -> Result<Vec<StorageKey>>;
fn storage_keys(&self, key: StorageKey, hash: Option<Hash>) -> Result<Vec<StorageKey>>;
/// Returns a storage entry at a specific block's state.
#[rpc(name = "state_getStorage", alias("state_getStorageAt"))]
fn storage(&self, StorageKey, Option<Hash>) -> Result<Option<StorageData>>;
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<StorageData>>;
/// Returns the hash of a storage entry at a block's state.
#[rpc(name = "state_getStorageHash", alias("state_getStorageHashAt"))]
fn storage_hash(&self, StorageKey, Option<Hash>) -> Result<Option<Hash>>;
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<Hash>>;
/// Returns the size of a storage entry at a block's state.
#[rpc(name = "state_getStorageSize", alias("state_getStorageSizeAt"))]
fn storage_size(&self, StorageKey, Option<Hash>) -> Result<Option<u64>>;
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<u64>>;
/// Returns the runtime metadata as an opaque blob.
#[rpc(name = "state_getMetadata")]
fn metadata(&self, Option<Hash>) -> Result<Bytes>;
fn metadata(&self, hash: Option<Hash>) -> Result<Bytes>;
/// Get the runtime version.
#[rpc(name = "state_getRuntimeVersion", alias("chain_getRuntimeVersion"))]
fn runtime_version(&self, Option<Hash>) -> Result<RuntimeVersion>;
fn runtime_version(&self, hash: Option<Hash>) -> Result<RuntimeVersion>;
/// Query historical storage entries (by key) starting from a block given as the second parameter.
///
/// NOTE This first returned result contains the initial state of storage for all keys.
/// Subsequent values in the vector represent changes to the previous state (diffs).
#[rpc(name = "state_queryStorage")]
fn query_storage(&self, Vec<StorageKey>, Hash, Option<Hash>) -> Result<Vec<StorageChangeSet<Hash>>>;
fn query_storage(&self, keys: Vec<StorageKey>, block: Hash, hash: Option<Hash>) -> Result<Vec<StorageChangeSet<Hash>>>;
/// New runtime version subscription
#[pubsub(
@@ -90,7 +92,7 @@ pub trait StateApi<Hash> {
name = "state_subscribeRuntimeVersion",
alias("chain_subscribeRuntimeVersion")
)]
fn subscribe_runtime_version(&self, Self::Metadata, Subscriber<RuntimeVersion>);
fn subscribe_runtime_version(&self, metadata: Self::Metadata, subscriber: Subscriber<RuntimeVersion>);
/// Unsubscribe from runtime version subscription
#[pubsub(
@@ -99,15 +101,15 @@ pub trait StateApi<Hash> {
name = "state_unsubscribeRuntimeVersion",
alias("chain_unsubscribeRuntimeVersion")
)]
fn unsubscribe_runtime_version(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_runtime_version(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
/// New storage subscription
#[pubsub(subscription = "state_storage", subscribe, name = "state_subscribeStorage")]
fn subscribe_storage(&self, Self::Metadata, Subscriber<StorageChangeSet<Hash>>, Option<Vec<StorageKey>>);
fn subscribe_storage(&self, metadata: Self::Metadata, subscriber: Subscriber<StorageChangeSet<Hash>>, keys: Option<Vec<StorageKey>>);
/// Unsubscribe from storage subscription
#[pubsub(subscription = "state_storage", unsubscribe, name = "state_unsubscribeStorage")]
fn unsubscribe_storage(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_storage(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
}
/// State API with subscriptions support.
@@ -274,7 +276,7 @@ impl<B, E, Block, RA> State<B, E, Block, RA> where
E: CallExecutor<Block, Blake2Hasher>,
{
fn unwrap_or_best(&self, hash: Option<Block::Hash>) -> Result<Block::Hash> {
::helpers::unwrap_or_else(|| Ok(self.client.info()?.chain.best_hash), hash)
crate::helpers::unwrap_or_else(|| Ok(self.client.info()?.chain.best_hash), hash)
}
}
@@ -286,7 +288,7 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
Client<B, E, Block, RA>: ProvideRuntimeApi,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api: Metadata<Block>
{
type Metadata = ::metadata::Metadata;
type Metadata = crate::metadata::Metadata;
fn call(&self, method: String, data: Bytes, block: Option<Block::Hash>) -> Result<Bytes> {
let block = self.unwrap_or_best(block)?;
+1
View File
@@ -17,6 +17,7 @@
use super::*;
use self::error::{Error, ErrorKind};
use assert_matches::assert_matches;
use consensus::BlockOrigin;
use rustc_hex::FromHex;
use test_client::{self, runtime, keyring::Keyring, TestClient, BlockBuilderExt};
+3 -2
View File
@@ -17,10 +17,11 @@
use std::collections::HashMap;
use std::sync::{Arc, atomic::{self, AtomicUsize}};
use log::warn;
use jsonrpc_pubsub::{SubscriptionId, typed::{Sink, Subscriber}};
use parking_lot::Mutex;
use rpc::futures::sync::oneshot;
use rpc::futures::{Future, future};
use crate::rpc::futures::sync::oneshot;
use crate::rpc::futures::{Future, future};
use tokio::runtime::TaskExecutor;
type Id = u64;
+4 -3
View File
@@ -16,10 +16,11 @@
//! System RPC module errors.
use rpc;
use error_chain::*;
use errors;
use system::helpers::Health;
use crate::rpc;
use crate::errors;
use crate::system::helpers::Health;
error_chain! {
errors {
+1
View File
@@ -19,6 +19,7 @@ use super::*;
use network::{self, SyncState, SyncStatus, ProtocolStatus, NodeIndex, PeerId, PeerInfo as NetworkPeerInfo, PublicKey};
use network::config::Roles;
use test_client::runtime::Block;
use assert_matches::assert_matches;
#[derive(Default)]
struct Status {