mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Reorganising the repository - external renames and moves (#4074)
* Adding first rough ouline of the repository structure * Remove old CI stuff * add title * formatting fixes * move node-exits job's script to scripts dir * Move docs into subdir * move to bin * move maintainence scripts, configs and helpers into its own dir * add .local to ignore * move core->client * start up 'test' area * move test client * move test runtime * make test move compile * Add dependencies rule enforcement. * Fix indexing. * Update docs to reflect latest changes * Moving /srml->/paint * update docs * move client/sr-* -> primitives/ * clean old readme * remove old broken code in rhd * update lock * Step 1. * starting to untangle client * Fix after merge. * start splitting out client interfaces * move children and blockchain interfaces * Move trie and state-machine to primitives. * Fix WASM builds. * fixing broken imports * more interface moves * move backend and light to interfaces * move CallExecutor * move cli off client * moving around more interfaces * re-add consensus crates into the mix * fix subkey path * relieve client from executor * starting to pull out client from grandpa * move is_decendent_of out of client * grandpa still depends on client directly * lemme tests pass * rename srml->paint * Make it compile. * rename interfaces->client-api * Move keyring to primitives. * fixup libp2p dep * fix broken use * allow dependency enforcement to fail * move fork-tree * Moving wasm-builder * make env * move build-script-utils * fixup broken crate depdencies and names * fix imports for authority discovery * fix typo * update cargo.lock * fixing imports * Fix paths and add missing crates * re-add missing crates
This commit is contained in:
committed by
Bastian Köcher
parent
becc3b0a4f
commit
60e5011c72
@@ -0,0 +1,209 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
use std::{collections::HashMap, ops::Deref};
|
||||
use lazy_static::lazy_static;
|
||||
use primitives::{ed25519::{Pair, Public, Signature}, Pair as PairT, Public as PublicT, H256};
|
||||
pub use primitives::ed25519;
|
||||
use sr_primitives::AccountId32;
|
||||
|
||||
/// Set of test accounts.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum_macros::Display, strum_macros::EnumIter)]
|
||||
pub enum Keyring {
|
||||
Alice,
|
||||
Bob,
|
||||
Charlie,
|
||||
Dave,
|
||||
Eve,
|
||||
Ferdie,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
impl Keyring {
|
||||
pub fn from_public(who: &Public) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &Public::from(k) == who)
|
||||
}
|
||||
|
||||
pub fn from_account_id(who: &AccountId32) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &k.to_account_id() == who)
|
||||
}
|
||||
|
||||
pub fn from_raw_public(who: [u8; 32]) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who))
|
||||
}
|
||||
|
||||
pub fn to_raw_public(self) -> [u8; 32] {
|
||||
*Public::from(self).as_array_ref()
|
||||
}
|
||||
|
||||
pub fn from_h256_public(who: H256) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who.into()))
|
||||
}
|
||||
|
||||
pub fn to_h256_public(self) -> H256 {
|
||||
Public::from(self).as_array_ref().into()
|
||||
}
|
||||
|
||||
pub fn to_raw_public_vec(self) -> Vec<u8> {
|
||||
Public::from(self).to_raw_vec()
|
||||
}
|
||||
|
||||
pub fn to_account_id(self) -> AccountId32 {
|
||||
self.to_raw_public().into()
|
||||
}
|
||||
|
||||
pub fn sign(self, msg: &[u8]) -> Signature {
|
||||
Pair::from(self).sign(msg)
|
||||
}
|
||||
|
||||
pub fn pair(self) -> Pair {
|
||||
Pair::from_string(&format!("//{}", <&'static str>::from(self)), None)
|
||||
.expect("static values are known good; qed")
|
||||
}
|
||||
|
||||
/// Returns an iterator over all test accounts.
|
||||
pub fn iter() -> impl Iterator<Item=Keyring> {
|
||||
<Self as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
|
||||
pub fn public(self) -> Public {
|
||||
self.pair().public()
|
||||
}
|
||||
|
||||
pub fn to_seed(self) -> String {
|
||||
format!("//{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static str {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => "Alice",
|
||||
Keyring::Bob => "Bob",
|
||||
Keyring::Charlie => "Charlie",
|
||||
Keyring::Dave => "Dave",
|
||||
Keyring::Eve => "Eve",
|
||||
Keyring::Ferdie => "Ferdie",
|
||||
Keyring::One => "One",
|
||||
Keyring::Two => "Two",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for sr_primitives::MultiSigner {
|
||||
fn from(x: Keyring) -> Self {
|
||||
sr_primitives::MultiSigner::Ed25519(x.into())
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PRIVATE_KEYS: HashMap<Keyring, Pair> = {
|
||||
Keyring::iter().map(|i| (i, i.pair())).collect()
|
||||
};
|
||||
|
||||
static ref PUBLIC_KEYS: HashMap<Keyring, Public> = {
|
||||
PRIVATE_KEYS.iter().map(|(&name, pair)| (name, pair.public())).collect()
|
||||
};
|
||||
}
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for AccountId32 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.to_account_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Pair {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.pair()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
*(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for H256 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8; 32]> for Keyring {
|
||||
fn as_ref(&self) -> &[u8; 32] {
|
||||
(*PUBLIC_KEYS).get(self).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Public> for Keyring {
|
||||
fn as_ref(&self) -> &Public {
|
||||
(*PUBLIC_KEYS).get(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Keyring {
|
||||
type Target = [u8; 32];
|
||||
fn deref(&self) -> &[u8; 32] {
|
||||
(*PUBLIC_KEYS).get(self).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use primitives::{ed25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
assert!(
|
||||
Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Alice.public(),
|
||||
)
|
||||
);
|
||||
assert!(
|
||||
!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Bob!",
|
||||
&Keyring::Alice.public(),
|
||||
)
|
||||
);
|
||||
assert!(
|
||||
!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Bob.public(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
/// Test account crypto for sr25519.
|
||||
pub mod sr25519;
|
||||
|
||||
/// Test account crypto for ed25519.
|
||||
pub mod ed25519;
|
||||
|
||||
/// Convenience export: Sr25519's Keyring is exposed as `AccountKeyring`,
|
||||
/// since it tends to be used for accounts (although it may also be used
|
||||
/// by authorities).
|
||||
pub use sr25519::Keyring as AccountKeyring;
|
||||
|
||||
pub use ed25519::Keyring as Ed25519Keyring;
|
||||
pub use sr25519::Keyring as Sr25519Keyring;
|
||||
|
||||
pub mod test {
|
||||
/// The keyring for use with accounts when using the test runtime.
|
||||
pub use super::ed25519::Keyring as AccountKeyring;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use lazy_static::lazy_static;
|
||||
use primitives::{sr25519::{Pair, Public, Signature}, Pair as PairT, Public as PublicT, H256};
|
||||
pub use primitives::sr25519;
|
||||
use sr_primitives::AccountId32;
|
||||
|
||||
/// Set of test accounts.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum_macros::Display, strum_macros::EnumIter)]
|
||||
pub enum Keyring {
|
||||
Alice,
|
||||
Bob,
|
||||
Charlie,
|
||||
Dave,
|
||||
Eve,
|
||||
Ferdie,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
impl Keyring {
|
||||
pub fn from_public(who: &Public) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &Public::from(k) == who)
|
||||
}
|
||||
|
||||
pub fn from_account_id(who: &AccountId32) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &k.to_account_id() == who)
|
||||
}
|
||||
|
||||
pub fn from_raw_public(who: [u8; 32]) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who))
|
||||
}
|
||||
|
||||
pub fn to_raw_public(self) -> [u8; 32] {
|
||||
*Public::from(self).as_array_ref()
|
||||
}
|
||||
|
||||
pub fn from_h256_public(who: H256) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who.into()))
|
||||
}
|
||||
|
||||
pub fn to_h256_public(self) -> H256 {
|
||||
Public::from(self).as_array_ref().into()
|
||||
}
|
||||
|
||||
pub fn to_raw_public_vec(self) -> Vec<u8> {
|
||||
Public::from(self).to_raw_vec()
|
||||
}
|
||||
|
||||
pub fn to_account_id(self) -> AccountId32 {
|
||||
self.to_raw_public().into()
|
||||
}
|
||||
|
||||
pub fn sign(self, msg: &[u8]) -> Signature {
|
||||
Pair::from(self).sign(msg)
|
||||
}
|
||||
|
||||
pub fn pair(self) -> Pair {
|
||||
Pair::from_string(&format!("//{}", <&'static str>::from(self)), None)
|
||||
.expect("static values are known good; qed")
|
||||
}
|
||||
|
||||
/// Returns an iterator over all test accounts.
|
||||
pub fn iter() -> impl Iterator<Item=Keyring> {
|
||||
<Self as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
|
||||
pub fn public(self) -> Public {
|
||||
self.pair().public()
|
||||
}
|
||||
|
||||
pub fn to_seed(self) -> String {
|
||||
format!("//{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static str {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => "Alice",
|
||||
Keyring::Bob => "Bob",
|
||||
Keyring::Charlie => "Charlie",
|
||||
Keyring::Dave => "Dave",
|
||||
Keyring::Eve => "Eve",
|
||||
Keyring::Ferdie => "Ferdie",
|
||||
Keyring::One => "One",
|
||||
Keyring::Two => "Two",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for sr_primitives::MultiSigner {
|
||||
fn from(x: Keyring) -> Self {
|
||||
sr_primitives::MultiSigner::Sr25519(x.into())
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PRIVATE_KEYS: HashMap<Keyring, Pair> = {
|
||||
Keyring::iter().map(|i| (i, i.pair())).collect()
|
||||
};
|
||||
|
||||
static ref PUBLIC_KEYS: HashMap<Keyring, Public> = {
|
||||
PRIVATE_KEYS.iter().map(|(&name, pair)| (name, pair.public())).collect()
|
||||
};
|
||||
}
|
||||
|
||||
impl From<Keyring> for AccountId32 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.to_account_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Pair {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.pair()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
*(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for H256 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8; 32]> for Keyring {
|
||||
fn as_ref(&self) -> &[u8; 32] {
|
||||
(*PUBLIC_KEYS).get(self).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Public> for Keyring {
|
||||
fn as_ref(&self) -> &Public {
|
||||
(*PUBLIC_KEYS).get(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Keyring {
|
||||
type Target = [u8; 32];
|
||||
fn deref(&self) -> &[u8; 32] {
|
||||
(*PUBLIC_KEYS).get(self).unwrap().as_array_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use primitives::{sr25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
assert!(
|
||||
Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Alice.public(),
|
||||
)
|
||||
);
|
||||
assert!(
|
||||
!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Bob!",
|
||||
&Keyring::Alice.public(),
|
||||
)
|
||||
);
|
||||
assert!(
|
||||
!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Bob.public(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user