Skip to content

Commit

Permalink
Remove duplicate substrate types (scs#580)
Browse files Browse the repository at this point in the history
* remove types and cargo update

* cargo fmt

* remove traits.rs

* update ac_primitives import

* make all config types pub

* cargo ftm
  • Loading branch information
haerdib authored Jun 8, 2023
1 parent b16b2c5 commit f11729e
Show file tree
Hide file tree
Showing 21 changed files with 513 additions and 1,405 deletions.
824 changes: 440 additions & 384 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ tungstenite = { version = "0.18.0", optional = true, features = ["native-tls"] }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }

# Substrate no_std dependencies
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-storage = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }

# substrate std / wasm only
frame-support = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand Down Expand Up @@ -103,6 +105,8 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-runtime-interface/std",
"sp-storage/std",
"sp-version/std",
# substrate std
"frame-support",
# local deps
Expand Down
11 changes: 4 additions & 7 deletions node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ serde = { version = "1.0.136", features = ["derive"], default-features = false }
serde_json = { version = "1.0.79", default-features = false, features = ["alloc"] }

# substrate
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-storage = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }

# need to add this for `no_std`
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate.git", features = ["full_crypto"], branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

# local
ac-primitives = { path = "../primitives", default-features = false }

[features]
default = ["std"]
# To support `no_std` builds in non-32 bit environments.
Expand All @@ -54,8 +52,7 @@ std = [
# no_std support
"sp-application-crypto/std",
"sp-runtime-interface/std",
# local
"ac-primitives/std",
"sp-storage/std",
]
# Enable import of test_utils also outside of crate (feature test does not allow to do so).
mocks = []
2 changes: 1 addition & 1 deletion node-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
//! This file is mostly subxt.
use crate::{alloc::borrow::ToOwned, storage::GetStorageTypes, Encoded};
use ac_primitives::StorageKey;
use codec::{Decode, Encode, Error as CodecError};
use frame_metadata::{
PalletConstantMetadata, RuntimeMetadata, RuntimeMetadataLastVersion, RuntimeMetadataPrefixed,
StorageEntryMetadata, META_RESERVED,
};
use scale_info::{form::PortableForm, PortableRegistry, Type};
use sp_storage::StorageKey;

#[cfg(feature = "std")]
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion node-api/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//! For querying runtime storage.
use crate::metadata::MetadataError;
use ac_primitives::StorageKey;
use alloc::{borrow::ToOwned, vec::Vec};
use codec::Encode;
use core::marker::PhantomData;
use frame_metadata::{StorageEntryMetadata, StorageEntryType, StorageHasher};
use scale_info::form::PortableForm;
use sp_storage::StorageKey;

#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct StorageValue {
Expand Down
12 changes: 6 additions & 6 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# substrate no_std
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core-hashing = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-staking = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-weights = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
# need to add this for the app_crypto macro
sp-application-crypto = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }

Expand Down Expand Up @@ -58,7 +58,7 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"sp-version/std",
# app_crypto macro
"sp-weights/std",
"sp-application-crypto/std",
# substrate std
"frame-system",
Expand Down
14 changes: 8 additions & 6 deletions primitives/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
//! This file is mostly subxt:
//! https://github.com/paritytech/subxt/blob/ce0a82e3227efb0eae131f025da5f839d9623e15/subxt/src/config/mod.rs
use core::{fmt::Debug, marker::PhantomData};

use codec::{Decode, Encode, FullCodec};
use core::{fmt::Debug, marker::PhantomData};
use serde::{de::DeserializeOwned, Serialize};
use sp_core::Pair;
use sp_runtime::traits::{AtLeast32Bit, AtLeast32BitUnsigned, MaybeSerializeDeserialize};
use sp_runtime::traits::{
AtLeast32Bit, AtLeast32BitUnsigned, Block, Hash as HashTrait, Header as HeaderTrait,
MaybeSerializeDeserialize,
};

use crate::{extrinsic_params, Block, Hasher, Header, SignExtrinsic};
use crate::{extrinsic_params, SignExtrinsic};

pub use polkadot::*;
pub use substrate_kitchensink::*;
Expand Down Expand Up @@ -72,11 +74,11 @@ pub trait Config {
type Signature: Debug + Encode + From<<Self::CryptoKey as Pair>::Signature>;

/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hasher: Debug + Hasher<Output = Self::Hash>;
type Hasher: Debug + HashTrait<Output = Self::Hash>;

/// The block header.
type Header: Debug
+ Header<Number = Self::BlockNumber, Hasher = Self::Hasher>
+ HeaderTrait<Number = Self::BlockNumber, Hashing = Self::Hasher>
+ Send
+ DeserializeOwned;

Expand Down
12 changes: 5 additions & 7 deletions primitives/src/config/substrate_kitchensink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
//! https://github.com/paritytech/subxt/blob/ce0a82e3227efb0eae131f025da5f839d9623e15/subxt/src/config/substrate.rs
use crate::{
config::Config, types::AccountData, AssetTip, BlakeTwo256, ExtrinsicSigner,
GenericExtrinsicParams, SubstrateBlock, SubstrateHeader, SubstrateOpaqueExtrinsic,
config::Config, sr25519, types::AccountData, AccountId32, AssetTip, BlakeTwo256, Block,
ExtrinsicSigner, GenericExtrinsicParams, Header, MultiAddress, MultiSignature, OpaqueExtrinsic,
H256,
};
use codec::{Decode, Encode};
use core::fmt::Debug;
pub use primitive_types::{H256, U256};
use sp_core::sr25519;
use sp_runtime::{AccountId32, MultiAddress, MultiSignature};

/// Default set of commonly used types by Substrate kitchensink runtime.
#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
Expand All @@ -29,12 +27,12 @@ impl Config for SubstrateKitchensinkConfig {
type Address = MultiAddress<Self::AccountId, u32>;
type Signature = MultiSignature;
type Hasher = BlakeTwo256;
type Header = SubstrateHeader<Self::BlockNumber, BlakeTwo256>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type AccountData = AccountData<Self::Balance>;
type ExtrinsicParams = AssetTipExtrinsicParams<Self>;
type CryptoKey = sr25519::Pair;
type ExtrinsicSigner = ExtrinsicSigner<Self>;
type Block = SubstrateBlock<Self::Header, SubstrateOpaqueExtrinsic>;
type Block = Block<Self::Header, OpaqueExtrinsic>;
type Balance = u128;
type ContractCurrency = u128;
type StakingBalance = u128;
Expand Down
18 changes: 14 additions & 4 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ pub use config::*;
pub use extrinsics::*;
pub use rpc_numbers::*;
pub use rpc_params::*;
pub use serde_impls::*;
pub use traits::*;
pub use types::*;

pub mod config;
pub mod extrinsics;
pub mod rpc_numbers;
pub mod rpc_params;
pub mod serde_impls;
pub mod traits;
pub mod types;

// Re-export substrate types for easy import on user side.
pub use sp_core::{
sr25519,
storage::{StorageChangeSet, StorageData, StorageKey},
Bytes, H256,
};
pub use sp_runtime::{
generic::{Block, Digest, DigestItem, Header, SignedBlock},
traits::{BlakeTwo256, Block as BlockTrait, Hash as HashTrait, Header as HeaderTrait},
AccountId32, ConsensusEngineId, Justifications, MultiAddress, MultiSignature, OpaqueExtrinsic,
};
pub use sp_version::RuntimeVersion;
pub use sp_weights::Weight;
Loading

0 comments on commit f11729e

Please sign in to comment.