diff --git a/Cargo.toml b/Cargo.toml
index b4c53a03b0..1ed86c0e54 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,7 +18,7 @@ jsonrpc-core-client = { version = "14.0", features = ["ws"] }
num-traits = { version = "0.2", default-features = false }
serde = { version = "1.0", features = ["derive"] }
url = "1.7"
-parity-scale-codec = { version = "1.1", default-features = false, features = ["derive", "full"] }
+codec = { package = "parity-scale-codec", version = "1.1", default-features = false, features = ["derive", "full"] }
frame-metadata = { git = "https://github.com/paritytech/substrate/", package = "frame-metadata" }
frame-support = { git = "https://github.com/paritytech/substrate/", package = "frame-support" }
@@ -28,10 +28,10 @@ frame-system = { git = "https://github.com/paritytech/substrate/", package = "fr
pallet-balances = { git = "https://github.com/paritytech/substrate/", package = "pallet-balances" }
pallet-contracts = { git = "https://github.com/paritytech/substrate/", package = "pallet-contracts" }
pallet-indices = { git = "https://github.com/paritytech/substrate/", package = "pallet-indices" }
-substrate-rpc-api = { git = "https://github.com/paritytech/substrate/", package = "sc-rpc-api" }
+sc-rpc-api = { git = "https://github.com/paritytech/substrate/", package = "sc-rpc-api" }
sp-rpc = { git = "https://github.com/paritytech/substrate/", package = "sp-rpc" }
sp-core = { git = "https://github.com/paritytech/substrate/", package = "sp-core" }
-txpool-api = { git = "https://github.com/paritytech/substrate/", package = "sp-transaction-pool" }
+sp-transaction-pool = { git = "https://github.com/paritytech/substrate/", package = "sp-transaction-pool" }
[dev-dependencies]
env_logger = "0.7"
diff --git a/src/codec.rs b/src/codec.rs
deleted file mode 100644
index 9f9727bcec..0000000000
--- a/src/codec.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
-// This file is part of substrate-subxt.
-//
-// subxt is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// subxt is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with substrate-subxt. If not, see .
-
-use parity_scale_codec::Encode;
-
-#[derive(Clone)]
-pub struct Encoded(pub Vec);
-
-impl Encode for Encoded {
- fn encode(&self) -> Vec {
- self.0.to_owned()
- }
-}
diff --git a/src/error.rs b/src/error.rs
index 731cc8a58f..00a3c809c6 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -15,8 +15,8 @@
// along with substrate-subxt. If not, see .
use jsonrpc_core_client::RpcError;
-use sp_runtime::transaction_validity::TransactionValidityError;
use sp_core::crypto::SecretStringError;
+use sp_runtime::transaction_validity::TransactionValidityError;
use crate::{
events::EventsError,
@@ -31,7 +31,7 @@ pub enum Error {
Io(#[from] std::io::Error),
/// Codec error.
#[error("Scale codec error: {0}")]
- Codec(#[from] parity_scale_codec::Error),
+ Codec(#[from] codec::Error),
/// Rpc error.
#[error("Rpc error: {0}")]
Rpc(RpcError),
diff --git a/src/events.rs b/src/events.rs
index b8c7a7df84..e01649693d 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -26,7 +26,7 @@ use std::{
},
};
-use parity_scale_codec::{
+use codec::{
Codec,
Compact,
Decode,
@@ -231,7 +231,11 @@ impl EventsDecoder {
} else {
let event_variant = input.read_byte()? as u8;
let event_metadata = module.event(event_variant)?;
- log::debug!("decoding event '{}::{}'", module.name(), event_metadata.name);
+ log::debug!(
+ "decoding event '{}::{}'",
+ module.name(),
+ event_metadata.name
+ );
let mut event_data = Vec::::new();
self.decode_raw_bytes(
diff --git a/src/extrinsic.rs b/src/extrinsic.rs
index adf864b809..4c51aca9ec 100644
--- a/src/extrinsic.rs
+++ b/src/extrinsic.rs
@@ -16,12 +16,13 @@
use std::marker::PhantomData;
-use parity_scale_codec::{
+use codec::{
Codec,
Decode,
Encode,
};
+use sp_core::Pair;
use sp_runtime::{
generic::{
Era,
@@ -35,7 +36,6 @@ use sp_runtime::{
},
transaction_validity::TransactionValidityError,
};
-use sp_core::Pair;
use crate::frame::{
balances::Balances,
diff --git a/src/frame/balances.rs b/src/frame/balances.rs
index f79fe5feef..84c273779d 100644
--- a/src/frame/balances.rs
+++ b/src/frame/balances.rs
@@ -22,17 +22,13 @@ use futures::future::{
self,
Future,
};
-use parity_scale_codec::{
- Codec,
- Encode,
-};
+use frame_support::Parameter;
use sp_runtime::traits::{
MaybeSerialize,
Member,
SimpleArithmetic,
};
-use frame_support::Parameter;
use crate::{
error::Error,
@@ -49,7 +45,7 @@ pub trait Balances: System {
type Balance: Parameter
+ Member
+ SimpleArithmetic
- + Codec
+ + codec::Codec
+ Default
+ Copy
+ MaybeSerialize
@@ -118,7 +114,7 @@ const MODULE: &str = "Balances";
const TRANSFER: &str = "transfer";
/// Arguments for transferring a balance
-#[derive(Encode)]
+#[derive(codec::Encode)]
pub struct TransferArgs {
to: ::Address,
#[codec(compact)]
diff --git a/src/frame/contracts.rs b/src/frame/contracts.rs
index 613a74a4bd..21c9b076d0 100644
--- a/src/frame/contracts.rs
+++ b/src/frame/contracts.rs
@@ -16,13 +16,12 @@
//! Implements support for the pallet_contracts module.
-use parity_scale_codec::Encode;
-
use crate::frame::{
balances::Balances,
system::System,
Call,
};
+use codec::Encode;
const MODULE: &str = "Contracts";
const PUT_CODE: &str = "put_code";
diff --git a/src/frame/mod.rs b/src/frame/mod.rs
index d5fc55a336..7d753dbded 100644
--- a/src/frame/mod.rs
+++ b/src/frame/mod.rs
@@ -16,7 +16,7 @@
//! Implements support for built-in runtime modules.
-use parity_scale_codec::Encode;
+use codec::Encode;
pub mod balances;
pub mod contracts;
diff --git a/src/frame/system.rs b/src/frame/system.rs
index da0c7541ee..36beaefae5 100644
--- a/src/frame/system.rs
+++ b/src/frame/system.rs
@@ -18,13 +18,14 @@
use std::fmt::Debug;
+use codec::Codec;
use futures::future::{
self,
Future,
};
-use parity_scale_codec::Codec;
use serde::de::DeserializeOwned;
+use frame_support::Parameter;
use sp_runtime::traits::{
Bounded,
CheckEqual,
@@ -38,7 +39,6 @@ use sp_runtime::traits::{
SimpleBitOps,
StaticLookup,
};
-use frame_support::Parameter;
use crate::{
error::Error,
@@ -170,7 +170,7 @@ pub fn set_code(code: Vec) -> Call {
}
/// Event for the System module.
-#[derive(Clone, Debug, parity_scale_codec::Decode)]
+#[derive(Clone, Debug, codec::Decode)]
pub enum SystemEvent {
/// An extrinsic completed successfully.
ExtrinsicSuccess(frame_support::weights::DispatchInfo),
diff --git a/src/lib.rs b/src/lib.rs
index 47a8ce3987..e2f283f9b9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -26,6 +26,11 @@ use std::{
marker::PhantomData,
};
+use codec::{
+ Codec,
+ Decode,
+ Encode,
+};
use futures::future::{
self,
Either,
@@ -33,10 +38,12 @@ use futures::future::{
IntoFuture,
};
use jsonrpc_core_client::transports::ws;
-use parity_scale_codec::{
- Codec,
- Decode,
- Encode,
+use sp_core::{
+ storage::{
+ StorageChangeSet,
+ StorageKey,
+ },
+ Pair,
};
use sp_runtime::{
generic::UncheckedExtrinsic,
@@ -47,16 +54,8 @@ use sp_runtime::{
MultiSignature,
};
use sp_version::RuntimeVersion;
-use sp_core::{
- storage::{
- StorageChangeSet,
- StorageKey,
- },
- Pair,
-};
use url::Url;
-mod codec;
mod error;
mod events;
mod extrinsic;
@@ -65,8 +64,14 @@ mod metadata;
mod rpc;
mod runtimes;
+pub use self::{
+ error::Error,
+ events::RawEvent,
+ frame::*,
+ rpc::ExtrinsicSuccess,
+ runtimes::*,
+};
use self::{
- codec::Encoded,
events::EventsDecoder,
extrinsic::{
DefaultExtra,
@@ -88,13 +93,6 @@ use self::{
Rpc,
},
};
-pub use self::{
- error::Error,
- events::RawEvent,
- frame::*,
- rpc::ExtrinsicSuccess,
- runtimes::*,
-};
fn connect(url: &Url) -> impl Future- , Error = Error> {
ws::connect(url).map_err(Into::into)
@@ -331,7 +329,7 @@ where
Error,
>
where
- C: parity_scale_codec::Encode,
+ C: codec::Encode,
{
let signer = self.signer.clone();
let account_nonce = self.nonce;
@@ -390,13 +388,24 @@ where
}
}
+/// Wraps an already encoded byte vector, prevents being encoded as a raw byte vector as part of
+/// the transaction payload
+#[derive(Clone)]
+pub struct Encoded(pub Vec);
+
+impl codec::Encode for Encoded {
+ fn encode(&self) -> Vec {
+ self.0.to_owned()
+ }
+}
+
#[cfg(test)]
mod tests {
- use futures::stream::Stream;
- use parity_scale_codec::Encode;
+ use codec::Encode;
use frame_support::StorageMap;
- use sp_keyring::AccountKeyring;
+ use futures::stream::Stream;
use sp_core::storage::StorageKey;
+ use sp_keyring::AccountKeyring;
use super::*;
use crate::{
diff --git a/src/metadata.rs b/src/metadata.rs
index 88046a9f0b..5055c9f367 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -21,7 +21,7 @@ use std::{
str::FromStr,
};
-use parity_scale_codec::{
+use codec::{
Decode,
Encode,
};
@@ -37,7 +37,7 @@ use frame_metadata::{
};
use sp_core::storage::StorageKey;
-use crate::codec::Encoded;
+use crate::Encoded;
#[derive(Debug, thiserror::Error)]
pub enum MetadataError {
@@ -236,12 +236,8 @@ impl StorageMap {
bytes.extend(&sp_core::twox_128(&self.storage_prefix)[..]);
let encoded_key = key.encode();
let hash = match self.hasher {
- StorageHasher::Blake2_128 => {
- sp_core::blake2_128(&encoded_key).to_vec()
- }
- StorageHasher::Blake2_256 => {
- sp_core::blake2_256(&encoded_key).to_vec()
- }
+ StorageHasher::Blake2_128 => sp_core::blake2_128(&encoded_key).to_vec(),
+ StorageHasher::Blake2_256 => sp_core::blake2_256(&encoded_key).to_vec(),
StorageHasher::Twox128 => sp_core::twox_128(&encoded_key).to_vec(),
StorageHasher::Twox256 => sp_core::twox_256(&encoded_key).to_vec(),
StorageHasher::Twox64Concat => sp_core::twox_64(&encoded_key).to_vec(),
@@ -360,7 +356,11 @@ impl TryFrom for Metadata {
let module_prefix = convert(storage.prefix)?;
for entry in convert(storage.entries)?.into_iter() {
let storage_prefix = convert(entry.name.clone())?;
- let entry = convert_entry(module_prefix.clone(), storage_prefix.clone(), entry)?;
+ let entry = convert_entry(
+ module_prefix.clone(),
+ storage_prefix.clone(),
+ entry,
+ )?;
storage_map.insert(storage_prefix, entry);
}
}
diff --git a/src/rpc.rs b/src/rpc.rs
index 5f8869a7df..8473c19f67 100644
--- a/src/rpc.rs
+++ b/src/rpc.rs
@@ -16,6 +16,11 @@
use std::convert::TryInto;
+use codec::{
+ Decode,
+ Encode,
+ Error as CodecError,
+};
use futures::{
future::{
self,
@@ -32,14 +37,25 @@ use jsonrpc_core_client::{
TypedSubscriptionStream,
};
use num_traits::bounds::Bounded;
-use parity_scale_codec::{
- Decode,
- Encode,
- Error as CodecError,
-};
-use frame_system::Phase;
use frame_metadata::RuntimeMetadataPrefixed;
+use frame_system::Phase;
+use sc_rpc_api::{
+ author::AuthorClient,
+ chain::ChainClient,
+ state::StateClient,
+};
+use sp_core::{
+ storage::{
+ StorageChangeSet,
+ StorageKey,
+ },
+ twox_128,
+};
+use sp_rpc::{
+ list::ListOrValue,
+ number::NumberOrHex,
+};
use sp_runtime::{
generic::{
Block,
@@ -48,24 +64,8 @@ use sp_runtime::{
traits::Hash,
OpaqueExtrinsic,
};
+use sp_transaction_pool::TransactionStatus;
use sp_version::RuntimeVersion;
-use sp_core::{
- storage::{
- StorageChangeSet,
- StorageKey,
- },
- twox_128,
-};
-use substrate_rpc_api::{
- author::AuthorClient,
- chain::ChainClient,
- state::StateClient,
-};
-use sp_rpc::{
- list::ListOrValue,
- number::NumberOrHex,
-};
-use txpool_api::TransactionStatus;
use crate::{
error::Error,
@@ -132,12 +132,12 @@ impl Rpc {
.block_hash(Some(ListOrValue::Value(NumberOrHex::Number(block_zero))))
.map_err(Into::into)
.and_then(|list_or_value| {
- future::result(
- match list_or_value {
- ListOrValue::Value(genesis_hash) => genesis_hash.ok_or_else(|| "Genesis hash not found".into()),
- ListOrValue::List(_) => Err("Expected a Value, got a List".into()),
+ future::result(match list_or_value {
+ ListOrValue::Value(genesis_hash) => {
+ genesis_hash.ok_or_else(|| "Genesis hash not found".into())
}
- )
+ ListOrValue::List(_) => Err("Expected a Value, got a List".into()),
+ })
})
}
@@ -274,15 +274,21 @@ impl Rpc {
log::info!("received status {:?}", status);
match status {
// ignore in progress extrinsic for now
- TransactionStatus::Future | TransactionStatus::Ready | TransactionStatus::Broadcast(_) => {
- None
+ TransactionStatus::Future
+ | TransactionStatus::Ready
+ | TransactionStatus::Broadcast(_) => None,
+ TransactionStatus::Finalized(block_hash) => {
+ Some(Ok(block_hash))
}
- TransactionStatus::Finalized(block_hash) => Some(Ok(block_hash)),
TransactionStatus::Usurped(_) => {
Some(Err("Extrinsic Usurped".into()))
}
- TransactionStatus::Dropped => Some(Err("Extrinsic Dropped".into())),
- TransactionStatus::Invalid => Some(Err("Extrinsic Invalid".into())),
+ TransactionStatus::Dropped => {
+ Some(Err("Extrinsic Dropped".into()))
+ }
+ TransactionStatus::Invalid => {
+ Some(Err("Extrinsic Invalid".into()))
+ }
}
})
.into_future()