Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cumulus/parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ use frame_support::parameter_types;
use grandpa::AuthorityId as GrandpaId;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_core::{
crypto::{CryptoType, Pair},
sr25519,
storage::Storage,
};
use sp_runtime::{
traits::{AccountIdConversion, IdentifyAccount, Verify},
BuildStorage, MultiSignature,
Expand Down Expand Up @@ -71,18 +75,18 @@ parameter_types! {
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
pub fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Helper function to generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T>(seed)).into_account()
}

pub fn get_host_config() -> HostConfiguration<BlockNumber> {
Expand Down
14 changes: 7 additions & 7 deletions cumulus/polkadot-parachain/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use parachains_common::{AccountId, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};
use sp_core::crypto::{CryptoType, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod asset_hubs;
Expand Down Expand Up @@ -56,25 +56,25 @@ impl Extensions {
pub type GenericChainSpec = sc_service::GenericChainSpec<(), Extensions>;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
pub fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

type AccountPublic = <Signature as Verify>::Signer;

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T>(seed)).into_account()
}

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain in tuple format.
pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> <AuraId::Pair as Pair>::Public {
pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}
15 changes: 7 additions & 8 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use cumulus_primitives_core::{
};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
use sc_rpc::DenyUnsafe;
use sp_core::Pair;

use jsonrpsee::RpcModule;

Expand All @@ -57,7 +56,7 @@ use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, Ta
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::{ApiExt, ConstructRuntimeApi, ProvideRuntimeApi};
use sp_consensus_aura::AuraApi;
use sp_core::traits::SpawnEssentialNamed;
use sp_core::{crypto::CryptoType, traits::SpawnEssentialNamed};
use sp_keystore::KeystorePtr;
use sp_runtime::{
app_crypto::AppCrypto,
Expand Down Expand Up @@ -636,8 +635,8 @@ where
+ sp_api::ApiExt<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as Pair>::Public>,
<<AuraId as AppCrypto>::Pair as Pair>::Signature:
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as CryptoType>::Public>,
<<AuraId as AppCrypto>::Pair as CryptoType>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{
let verifier_client = client.clone();
Expand Down Expand Up @@ -810,10 +809,10 @@ where
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as Pair>::Public>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as CryptoType>::Public>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
<<AuraId as AppCrypto>::Pair as Pair>::Signature:
<<AuraId as AppCrypto>::Pair as CryptoType>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{
start_node_impl::<RuntimeApi, _, _, _>(
Expand Down Expand Up @@ -958,11 +957,11 @@ where
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as Pair>::Public>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as CryptoType>::Public>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>,
<<AuraId as AppCrypto>::Pair as Pair>::Signature:
<<AuraId as AppCrypto>::Pair as CryptoType>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{
start_node_impl::<RuntimeApi, _, _, _>(
Expand Down
15 changes: 9 additions & 6 deletions cumulus/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ use cumulus_test_runtime::{AccountId, RuntimeGenesisConfig, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_core::{
crypto::{CryptoType, Pair},
sr25519,
};
use sp_runtime::traits::{IdentifyAccount, Verify};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
pub fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}
Expand All @@ -52,11 +55,11 @@ impl Extensions {
type AccountPublic = <Signature as Verify>::Signer;

/// Helper function to generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T::Public>(seed)).into_account()
}

/// Get the chain spec for a specific parachain ID.
Expand Down
13 changes: 8 additions & 5 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ pub use frame_system::{Config as SystemConfig, Pallet as SystemPallet};
pub use pallet_balances::AccountData;
pub use pallet_message_queue;
pub use sp_arithmetic::traits::Bounded;
pub use sp_core::{parameter_types, sr25519, storage::Storage, Pair};
pub use sp_core::{
crypto::{CryptoType, Pair},
parameter_types, sr25519,
storage::Storage,
};
pub use sp_crypto_hashing::blake2_256;
pub use sp_io::TestExternalities;
pub use sp_runtime::BoundedSlice;
Expand Down Expand Up @@ -1586,13 +1590,12 @@ pub mod helpers {
}

/// Helper function to generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: sp_core::Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
sp_runtime::MultiSigner:
From<<<TPublic as sp_runtime::CryptoType>::Pair as sp_core::Pair>::Public>,
sp_runtime::MultiSigner: From<T::Public>,
{
use sp_runtime::traits::IdentifyAccount;
let pubkey = TPublic::Pair::from_string(&format!("//{}", seed), None)
let pubkey = T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public();
sp_runtime::MultiSigner::from(pubkey).into_account()
Expand Down
15 changes: 9 additions & 6 deletions polkadot/node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use sc_chain_spec::ChainSpecExtension;
#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
use sc_chain_spec::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_core::{
crypto::{CryptoType, Pair},
sr25519,
};
use sp_runtime::traits::IdentifyAccount;
#[cfg(feature = "westend-native")]
use sp_runtime::Perbill;
Expand Down Expand Up @@ -720,18 +723,18 @@ pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
pub fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T>(seed)).into_account()
}

/// Helper function to generate stash, controller and session key from seed
Expand Down
15 changes: 9 additions & 6 deletions polkadot/runtime/common/src/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ where
mod tests {
use super::*;

use sp_core::{crypto::AccountId32, ed25519, Pair, Public, H256};
use sp_core::{
crypto::{AccountId32, CryptoType, Pair},
ed25519, H256,
};
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use crate::purchase;
Expand Down Expand Up @@ -625,18 +628,18 @@ mod tests {
type AccountPublic = <MultiSignature as Verify>::Signer;

/// Helper function to generate a crypto pair from seed
fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Helper function to generate an account ID from seed
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T::Public>(seed)).into_account()
}

fn alice() -> AccountId {
Expand Down
15 changes: 9 additions & 6 deletions substrate/bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use sc_telemetry::TelemetryEndpoints;
use serde::{Deserialize, Serialize};
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_core::{
crypto::{CryptoType, Pair, UncheckedInto},
sr25519,
};
use sp_mixnet::types::AuthorityId as MixnetId;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Expand Down Expand Up @@ -245,18 +248,18 @@ pub fn staging_testnet_config() -> ChainSpec {
}

/// Helper function to generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
pub fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Helper function to generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
pub fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T>(seed)).into_account()
}

/// Helper function to generate stash, controller and session key from seed.
Expand Down
16 changes: 10 additions & 6 deletions substrate/bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ use sc_executor::{WasmExecutionMethod, WasmtimeInstantiationStrategy};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_consensus::BlockOrigin;
use sp_core::{ed25519, sr25519, traits::SpawnNamed, Pair, Public};
use sp_core::{
crypto::{CryptoType, Pair},
ed25519, sr25519,
traits::SpawnNamed,
};
use sp_crypto_hashing::blake2_256;
use sp_inherents::InherentData;
use sp_runtime::{
Expand Down Expand Up @@ -628,17 +632,17 @@ pub struct BenchContext {

type AccountPublic = <Signature as Verify>::Signer;

fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
fn get_from_seed<T: CryptoType>(seed: &str) -> T::Public {
T::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
fn get_account_id_from_seed<T: CryptoType>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
AccountPublic: From<T::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_from_seed::<T>(seed)).into_account()
}

impl BenchContext {
Expand Down
9 changes: 4 additions & 5 deletions substrate/client/cli/src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ use crate::{
use serde_json::json;
use sp_core::{
crypto::{
unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec,
Zeroize,
unwrap_or_default_ss58_version, CryptoType, ExposeSecret, Pair, SecretString,
Ss58AddressFormat, Ss58Codec, Zeroize,
},
hexdisplay::HexDisplay,
Pair,
};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
use std::path::PathBuf;

/// Public key type for Runtime
pub type PublicFor<P> = <P as sp_core::Pair>::Public;
pub type PublicFor<P> = <P as CryptoType>::Public;
/// Seed type for Runtime
pub type SeedFor<P> = <P as sp_core::Pair>::Seed;
pub type SeedFor<P> = <P as Pair>::Seed;

/// helper method to fetch uri from `Option<String>` either as a file or read from stdin
pub fn read_uri(uri: Option<&String>) -> error::Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus::{BlockOrigin, Environment, Error as ConsensusError, Proposer, SelectChain};
use sp_consensus_slots::Slot;
use sp_core::crypto::Pair;
use sp_core::crypto::{CryptoType, Pair};
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, Header, Member, NumberFor};
Expand All @@ -70,7 +70,7 @@ pub use sp_consensus_aura::{

const LOG_TARGET: &str = "aura";

type AuthorityId<P> = <P as Pair>::Public;
type AuthorityId<P> = <P as CryptoType>::Public;

/// Run `AURA` in a compatibility mode.
///
Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/application-crypto/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

//! Bandersnatch VRF application crypto types.

use crate::{KeyTypeId, RuntimePublic};
use crate::{KeyTypeId, RuntimePublic, Vec};

pub use sp_core::bandersnatch::*;
use sp_std::vec::Vec;

mod app {
crate::app_crypto!(super, sp_core::testing::BANDERSNATCH);
Expand Down
Loading