mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +00:00
Refactor sr_primitives. (#3214)
* refactor sr_primitives. * Fix try build error. * Line-width * Ui test. * Final fixes. * Fix build again. * bring back ui test. * Fix unsigned import. * Another ui fix. * Also refactor substrate-primitives * Fix benchmarks. * Fix doc test. * fix doc tests
This commit is contained in:
committed by
Bastian Köcher
parent
cf80af9255
commit
79feb23a22
@@ -9,7 +9,7 @@ num-traits = { version = "0.2", default-features = false }
|
||||
integer-sqrt = { version = "0.1.2" }
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-codec", version = "4.1.1", default-features = false, features = ["derive"] }
|
||||
substrate-primitives = { path = "../primitives", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
|
||||
log = { version = "0.4", optional = true }
|
||||
@@ -28,5 +28,5 @@ std = [
|
||||
"rstd/std",
|
||||
"runtime_io/std",
|
||||
"codec/std",
|
||||
"substrate-primitives/std",
|
||||
"primitives/std",
|
||||
]
|
||||
|
||||
@@ -105,7 +105,7 @@ pub enum DigestItem<Hash> {
|
||||
impl<Hash: Encode> ::serde::Serialize for DigestItem<Hash> {
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
self.using_encoded(|bytes| {
|
||||
::substrate_primitives::bytes::serialize(bytes, seq)
|
||||
::primitives::bytes::serialize(bytes, seq)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ pub struct Header<Number: Copy + Into<u128>, Hash: HashT> {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn serialize_number<S, T: Copy + Into<u128>>(val: &T, s: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
use substrate_primitives::uint::U256;
|
||||
use primitives::uint::U256;
|
||||
let v: u128 = (*val).into();
|
||||
let lower = U256::from(v as u64);
|
||||
let upper = U256::from(v.rotate_left(64) as u64) << 64;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Tests for the generic implementations of Extrinsic/Header/Block.
|
||||
|
||||
use crate::codec::{Decode, Encode};
|
||||
use substrate_primitives::H256;
|
||||
use primitives::H256;
|
||||
use super::DigestItem;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -35,7 +35,7 @@ pub use paste;
|
||||
pub use runtime_io::{StorageOverlay, ChildrenStorageOverlay};
|
||||
|
||||
use rstd::{prelude::*, ops, convert::TryInto};
|
||||
use substrate_primitives::{crypto, ed25519, sr25519, hash::{H256, H512}};
|
||||
use primitives::{crypto, ed25519, sr25519, hash::{H256, H512}};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -52,7 +52,7 @@ pub mod transaction_validity;
|
||||
pub use generic::{DigestItem, Digest};
|
||||
|
||||
/// Re-export this since it's part of the API of this crate.
|
||||
pub use substrate_primitives::crypto::{key_types, KeyTypeId};
|
||||
pub use primitives::crypto::{key_types, KeyTypeId};
|
||||
|
||||
/// A message indicating an invalid signature in extrinsic.
|
||||
pub const BAD_SIGNATURE: &str = "bad signature in extrinsic";
|
||||
@@ -868,14 +868,14 @@ pub struct OpaqueExtrinsic(pub Vec<u8>);
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for OpaqueExtrinsic {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(fmt, "{}", substrate_primitives::hexdisplay::HexDisplay::from(&self.0))
|
||||
write!(fmt, "{}", primitives::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl ::serde::Serialize for OpaqueExtrinsic {
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
codec::Encode::using_encoded(&self.0, |bytes| ::substrate_primitives::bytes::serialize(bytes, seq))
|
||||
codec::Encode::using_encoded(&self.0, |bytes| ::primitives::bytes::serialize(bytes, seq))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ use crate::traits::{
|
||||
};
|
||||
use crate::{generic, KeyTypeId};
|
||||
use crate::weights::{GetDispatchInfo, DispatchInfo};
|
||||
pub use substrate_primitives::H256;
|
||||
use substrate_primitives::U256;
|
||||
use substrate_primitives::ed25519::{Public as AuthorityId};
|
||||
pub use primitives::H256;
|
||||
use primitives::U256;
|
||||
use primitives::ed25519::{Public as AuthorityId};
|
||||
use crate::transaction_validity::TransactionValidity;
|
||||
|
||||
/// Authority Id
|
||||
|
||||
@@ -21,12 +21,12 @@ use rstd::{self, result, marker::PhantomData, convert::{TryFrom, TryInto}};
|
||||
use runtime_io;
|
||||
#[cfg(feature = "std")] use std::fmt::{Debug, Display};
|
||||
#[cfg(feature = "std")] use serde::{Serialize, Deserialize, de::DeserializeOwned};
|
||||
use substrate_primitives::{self, Hasher, Blake2Hasher};
|
||||
use primitives::{self, Hasher, Blake2Hasher};
|
||||
use crate::codec::{Codec, Encode, Decode, HasCompact};
|
||||
use crate::transaction_validity::{ValidTransaction, TransactionValidity};
|
||||
use crate::generic::{Digest, DigestItem};
|
||||
use crate::weights::DispatchInfo;
|
||||
pub use substrate_primitives::crypto::TypedKey;
|
||||
pub use primitives::crypto::TypedKey;
|
||||
pub use integer_sqrt::IntegerSquareRoot;
|
||||
pub use num_traits::{
|
||||
Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv,
|
||||
@@ -57,15 +57,15 @@ pub trait Verify {
|
||||
fn verify<L: Lazy<[u8]>>(&self, msg: L, signer: &Self::Signer) -> bool;
|
||||
}
|
||||
|
||||
impl Verify for substrate_primitives::ed25519::Signature {
|
||||
type Signer = substrate_primitives::ed25519::Public;
|
||||
impl Verify for primitives::ed25519::Signature {
|
||||
type Signer = primitives::ed25519::Public;
|
||||
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &Self::Signer) -> bool {
|
||||
runtime_io::ed25519_verify(self.as_ref(), msg.get(), signer)
|
||||
}
|
||||
}
|
||||
|
||||
impl Verify for substrate_primitives::sr25519::Signature {
|
||||
type Signer = substrate_primitives::sr25519::Public;
|
||||
impl Verify for primitives::sr25519::Signature {
|
||||
type Signer = primitives::sr25519::Public;
|
||||
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &Self::Signer) -> bool {
|
||||
runtime_io::sr25519_verify(self.as_ref(), msg.get(), signer)
|
||||
}
|
||||
@@ -458,7 +458,7 @@ pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // Stup
|
||||
pub struct BlakeTwo256;
|
||||
|
||||
impl Hash for BlakeTwo256 {
|
||||
type Output = substrate_primitives::H256;
|
||||
type Output = primitives::H256;
|
||||
type Hasher = Blake2Hasher;
|
||||
fn hash(s: &[u8]) -> Self::Output {
|
||||
runtime_io::blake2_256(s).into()
|
||||
@@ -493,10 +493,10 @@ pub trait CheckEqual {
|
||||
fn check_equal(&self, other: &Self);
|
||||
}
|
||||
|
||||
impl CheckEqual for substrate_primitives::H256 {
|
||||
impl CheckEqual for primitives::H256 {
|
||||
#[cfg(feature = "std")]
|
||||
fn check_equal(&self, other: &Self) {
|
||||
use substrate_primitives::hexdisplay::HexDisplay;
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
if self != other {
|
||||
println!("Hash: given={}, expected={}", HexDisplay::from(self.as_fixed_bytes()), HexDisplay::from(other.as_fixed_bytes()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user