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
7 changes: 4 additions & 3 deletions substrate/bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
use grandpa_primitives::AuthorityId as GrandpaId;
use kitchensink_runtime::{
constants::currency::*, wasm_binary_unwrap, BabeConfig, BalancesConfig, Block, CouncilConfig,
DemocracyConfig, ElectionsConfig, ImOnlineConfig, IndicesConfig, MaxNominations,
NominationPoolsConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, TechnicalCommitteeConfig,
DemocracyConfig, ElectionsConfig, IdentityConfig, ImOnlineConfig, IndicesConfig,
MaxNominations, NominationPoolsConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus,
StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down Expand Up @@ -315,6 +315,7 @@ pub fn testnet_genesis(
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
},
identity: IdentityConfig { registrars: vec![] },
indices: IndicesConfig { indices: vec![] },
session: SessionConfig {
keys: initial_authorities
Expand Down
5 changes: 3 additions & 2 deletions substrate/bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use crate::keyring::*;
use kitchensink_runtime::{
constants::currency::*, wasm_binary_unwrap, AccountId, AssetsConfig, BabeConfig,
BalancesConfig, GluttonConfig, GrandpaConfig, IndicesConfig, RuntimeGenesisConfig,
SessionConfig, SocietyConfig, StakerStatus, StakingConfig, SystemConfig,
BalancesConfig, GluttonConfig, GrandpaConfig, IdentityConfig, IndicesConfig,
RuntimeGenesisConfig, SessionConfig, SocietyConfig, StakerStatus, StakingConfig, SystemConfig,
BABE_GENESIS_EPOCH_CONFIG,
};
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
Expand Down Expand Up @@ -52,6 +52,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Run
code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()),
..Default::default()
},
identity: IdentityConfig { registrars: vec![] },
indices: IndicesConfig { indices: vec![] },
balances: BalancesConfig { balances: endowed },
session: SessionConfig {
Expand Down
50 changes: 50 additions & 0 deletions substrate/frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup
#[frame_support::pallet]
pub mod pallet {
use super::*;
use enumflags2::BitFlags;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

Expand Down Expand Up @@ -201,6 +202,55 @@ pub mod pallet {
ValueQuery,
>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub registrars: Vec<(T::AccountId, Vec<(T::AccountId, BoundedVec<u8, ConstU32<32>>)>)>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub registrars: Vec<(T::AccountId, Vec<(T::AccountId, BoundedVec<u8, ConstU32<32>>)>)>,
pub registrars: Vec<T::AccountId>,
pub identities: Vec<(T::AccountId, BoundedVec<u8, ConstU32<32>>)>,

}

impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { registrars: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
for (registrar, identities) in &self.registrars {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genesis config should just include identities in this case

<Registrars<T>>::put(
BoundedVec::try_from(vec![Some(RegistrarInfo {
account: registrar.clone(),
fee: Zero::zero(),
fields: IdentityFields(<BitFlags<IdentityField>>::all()),
})])
.unwrap(),
);
for (account, name) in identities {
let judgements =
BoundedVec::try_from(vec![(0, Judgement::KnownGood); 1]).unwrap();
<IdentityOf<T>>::insert(
account,
Registration {
info: IdentityInfo {
display: Data::Raw(name.clone()),
twitter: Data::None,
riot: Data::None,
email: Data::None,
pgp_fingerprint: None,
image: Data::None,
legal: Data::None,
web: Data::None,
additional: BoundedVec::default(),
},
judgements,
deposit: Zero::zero(),
},
);
}
}
}
}

#[pallet::error]
pub enum Error<T> {
/// Too many subs-accounts.
Expand Down
32 changes: 32 additions & 0 deletions substrate/frame/identity/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,35 @@ fn test_has_identity() {
));
});
}

#[test]
fn test_genesis_config_should_register_identities() {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_identity::GenesisConfig::<Test> {
registrars: vec![(
0,
vec![
(1, BoundedVec::try_from("One".to_string().as_bytes().to_vec()).unwrap()),
(2, BoundedVec::try_from("Two".to_string().as_bytes().to_vec()).unwrap()),
(3, BoundedVec::try_from("Three".to_string().as_bytes().to_vec()).unwrap()),
],
)],
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext: sp_io::TestExternalities = t.into();
ext.execute_with(|| {
assert_eq!(
Identity::identity(1).unwrap().info.display,
Data::Raw(b"One".to_vec().try_into().unwrap())
);
assert_eq!(
Identity::identity(2).unwrap().info.display,
Data::Raw(b"Two".to_vec().try_into().unwrap())
);
assert_eq!(
Identity::identity(3).unwrap().info.display,
Data::Raw(b"Three".to_vec().try_into().unwrap())
);
});
}