mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Update substrate and codec crate aliases (#54)
* Replace substrate crate aliases with actual crate names * Alias parity-scale-codec to just codec, like in substrate * Format code
This commit is contained in:
+3
-3
@@ -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"
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
use parity_scale_codec::Encode;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Encoded(pub Vec<u8>);
|
||||
|
||||
impl Encode for Encoded {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.0.to_owned()
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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),
|
||||
|
||||
+6
-2
@@ -26,7 +26,7 @@ use std::{
|
||||
},
|
||||
};
|
||||
|
||||
use parity_scale_codec::{
|
||||
use codec::{
|
||||
Codec,
|
||||
Compact,
|
||||
Decode,
|
||||
@@ -231,7 +231,11 @@ impl<T: System + Balances + 'static> EventsDecoder<T> {
|
||||
} 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::<u8>::new();
|
||||
self.decode_raw_bytes(
|
||||
|
||||
+2
-2
@@ -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,
|
||||
|
||||
@@ -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<T: Balances> {
|
||||
to: <T as System>::Address,
|
||||
#[codec(compact)]
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+3
-3
@@ -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<u8>) -> Call<SetCode> {
|
||||
}
|
||||
|
||||
/// 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),
|
||||
|
||||
+33
-24
@@ -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<T: System>(url: &Url) -> impl Future<Item = Rpc<T>, 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<u8>);
|
||||
|
||||
impl codec::Encode for Encoded {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
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::{
|
||||
|
||||
+9
-9
@@ -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<K: Encode, V: Decode + Clone> StorageMap<K, V> {
|
||||
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<RuntimeMetadataPrefixed> 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);
|
||||
}
|
||||
}
|
||||
|
||||
+39
-33
@@ -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<T: System> Rpc<T> {
|
||||
.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<T: System + Balances + 'static> Rpc<T> {
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user