Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pallet_identity to the runtime #211

Merged
merged 7 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use fs_node_runtime::{
AccountId, AuraConfig, pallet_roles, BalancesConfig, CouncilConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
SystemConfig,RoleModuleConfig, NftModuleConfig, WASM_BINARY,
pallet_roles, AccountId, AuraConfig, BalancesConfig, CouncilConfig, GenesisConfig,
GrandpaConfig, NftModuleConfig, RoleModuleConfig, Signature, SudoConfig, SystemConfig,
WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -156,9 +157,13 @@ fn testnet_genesis(
key: Some(root_key),
},
transaction_payment: Default::default(),

role_module: RoleModuleConfig {
new_admin: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
representatives: vec![
get_account_id_from_seed::<sr25519::Public>("Gabriel"),
get_account_id_from_seed::<sr25519::Public>("Henry"),
],
},
nft_module: NftModuleConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
Expand Down
17 changes: 5 additions & 12 deletions pallets/bidding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,7 @@ fn process_onboarded_assets_should_succeed() {

events.pop();

let event = events
.pop()
.expect("Expected at least one EventRecord to be found")
.event;
let event = events.pop().expect("Expected at least one EventRecord to be found").event;
cuteolaf marked this conversation as resolved.
Show resolved Hide resolved

// check that the event has been raised
assert_eq!(
Expand All @@ -718,10 +715,9 @@ fn process_onboarded_assets_should_succeed() {
))
);

assert_eq!(
pallet_onboarding::Houses::<Test>::get(collection_id, item_id).unwrap().status,
crate::Onboarding::AssetStatus::FINALISING
);
let asset = pallet_onboarding::Houses::<Test>::get(collection_id, item_id).unwrap();

assert_eq!(asset.status, crate::Onboarding::AssetStatus::FINALISING);
});
}

Expand Down Expand Up @@ -863,10 +859,7 @@ fn process_finalised_assets_should_succeed() {

events.pop();

let mut event = events
.pop()
.expect("Expected at least one EventRecord to be found")
.event;
let mut event = events.pop().expect("Expected at least one EventRecord to be found").event;

// check that the event has been raised
assert_eq!(
Expand Down
19 changes: 17 additions & 2 deletions pallets/roles/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,24 @@ impl<T: Config> Pallet<T> {
ensure!(&account != id, Error::<T>::AlreadyWaiting);
}
}
ensure!(!RepApprovalList::<T>::contains_key(&account),Error::<T>::AlreadyWaiting);

ensure!(!RepApprovalList::<T>::contains_key(&account), Error::<T>::AlreadyWaiting);

Ok(())
}

pub fn init_representatives(representatives: Vec<AccountIdOf<T>>) {
let now = <frame_system::Pallet<T>>::block_number();
for account in representatives.into_iter() {
AccountsRolesLog::<T>::insert(&account, Accounts::REPRESENTATIVE);
RepresentativeLog::<T>::insert(
&account,
Representative::<T> {
account_id: account.clone(),
age: now,
activated: true,
assets_accounts: vec![],
},
);
}
}
}
5 changes: 4 additions & 1 deletion pallets/roles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ pub mod pallet {
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub new_admin: Option<T::AccountId>,
pub representatives: Vec<T::AccountId>,
}
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { new_admin: Default::default() }
Self { new_admin: Default::default(), representatives: vec![] }
}
}

Expand All @@ -198,6 +199,8 @@ pub mod pallet {
let origin = T::Origin::from(RawOrigin::Signed(servicer0.clone())); //Origin
let source = T::Lookup::unlookup(servicer0); //Source
crate::Pallet::<T>::set_manager(origin, source).ok();

crate::Pallet::<T>::init_representatives(self.representatives.clone());
}
}

Expand Down
8 changes: 6 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }

# Used for the node template's RPCs
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" }
Expand Down Expand Up @@ -110,6 +111,7 @@ std = [
"pallet-scheduler/std",
"pallet-preimage/std",
"pallet-treasury/std",
"pallet-identity/std",
"pallet-roles/std",
"pallet-housing_fund/std",
"pallet-nft/std",
Expand All @@ -132,12 +134,13 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-roles/runtime-benchmarks",
"pallet-housing_fund/runtime-benchmarks",
"pallet-nft/runtime-benchmarks",
"pallet-voting/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-onboarding/runtime-benchmarks",
"pallet-share_distributor/runtime-benchmarks",
"pallet-bidding/runtime-benchmarks",
Expand All @@ -156,11 +159,12 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"pallet-identity/try-runtime",
"pallet-roles/try-runtime",
"pallet-housing_fund/try-runtime",
"pallet-nft/try-runtime",
"pallet-voting/try-runtime",
"pallet-utility/try-runtime",
"pallet-onboarding/try-runtime",
"pallet-share_distributor/try-runtime",
"pallet-bidding/try-runtime",
Expand Down
47 changes: 35 additions & 12 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ use frame_system::{
EnsureRoot, EnsureSigned,
};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_democracy;
use pallet_nft::NftPermissions;
pub use pallet_nft::{self, Acc, CollectionId, ItemId, NftPermission};
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};
pub use pallet_democracy;
use pallet_nft::NftPermissions;
pub use pallet_nft::{self, Acc, CollectionId, ItemId, NftPermission};

pub use pallet_asset_management;
pub use pallet_bidding;
pub use pallet_housing_fund;
pub use pallet_onboarding;
/// Import the template pallet.
pub use pallet_roles;
pub use pallet_housing_fund;
pub use pallet_share_distributor;
cuteolaf marked this conversation as resolved.
Show resolved Hide resolved
pub use pallet_utility;
pub use pallet_voting;
pub use pallet_onboarding;
pub use pallet_share_distributor;
pub use pallet_bidding;
pub use pallet_asset_management;
// flag add pallet use

/// An index to a block.
Expand Down Expand Up @@ -125,8 +125,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};



/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand All @@ -141,7 +139,6 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);


parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;
Expand Down Expand Up @@ -328,14 +325,38 @@ impl pallet_uniques::Config for Runtime {
type Locker = ();
}

parameter_types! {
pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain
pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain
pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain
pub const MaxAdditionalFields: u32 = 100;
pub const MaxRegistrars: u32 = 1;
pub const MaxSubAccounts: u32 = 100;
}

impl pallet_identity::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
type FieldDeposit = FieldDeposit;
type MaxRegistrars = MaxRegistrars;
type ForceOrigin = EnsureRoot<AccountId>;
type RegistrarOrigin = EnsureRoot<AccountId>;
type MaxAdditionalFields = MaxAdditionalFields;
type MaxSubAccounts = MaxSubAccounts;
type Slashed = Treasury;
type SubAccountDeposit = SubAccountDeposit;
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MaxMembers:u32 =200;
}
/// Configure the pallet-roles in pallets/roles.
impl pallet_roles::Config for Runtime {
type Event = Event;
type Currency = Balances;
type WeightInfo = pallet_roles::weights::SubstrateWeight<Runtime>;
type WeightInfo = pallet_roles::weights::SubstrateWeight<Runtime>;
type MaxMembers = MaxMembers;
}

Expand Down Expand Up @@ -643,6 +664,7 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment,
Uniques: pallet_uniques,
Sudo: pallet_sudo,
Identity: pallet_identity,
RoleModule: pallet_roles,
HousingFundModule: pallet_housing_fund,
NftModule: pallet_nft,
Expand Down Expand Up @@ -707,6 +729,7 @@ mod benches {
[pallet_nft, NftModule]
[pallet_onboarding, OnboardingModule]
[pallet_share_distributor,ShareDistributor]
[pallet_identity, Identity]
//[pallet_asset_management, AssetManagementModule]
// flag add pallet bench_macro
);
Expand Down