difftreelog
feat(identity) fork + publicize private fields
in: master
14 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4026,7 +4026,7 @@
"pallet-elections-phragmen",
"pallet-fast-unstake",
"pallet-grandpa",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36)",
"pallet-im-online",
"pallet-indices",
"pallet-membership",
@@ -5322,7 +5322,7 @@
"pallet-evm-transaction-payment",
"pallet-foreign-assets",
"pallet-fungible",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev",
"pallet-inflation",
"pallet-maintenance",
"pallet-nonfungible",
@@ -5777,7 +5777,7 @@
[[package]]
name = "pallet-collator-selection"
-version = "3.0.0"
+version = "4.0.0"
dependencies = [
"frame-benchmarking",
"frame-support",
@@ -5885,6 +5885,7 @@
"frame-support",
"frame-system",
"pallet-evm",
+ "pallet-identity 4.0.0-dev",
"parity-scale-codec 3.2.1",
"scale-info",
"sp-core",
@@ -6184,6 +6185,23 @@
[[package]]
name = "pallet-identity"
version = "4.0.0-dev"
+dependencies = [
+ "enumflags2",
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "pallet-balances",
+ "parity-scale-codec 3.2.1",
+ "scale-info",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
+name = "pallet-identity"
+version = "4.0.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"enumflags2",
@@ -8137,7 +8155,7 @@
"pallet-elections-phragmen",
"pallet-fast-unstake",
"pallet-grandpa",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36)",
"pallet-im-online",
"pallet-indices",
"pallet-membership",
@@ -8912,7 +8930,7 @@
"pallet-evm-transaction-payment",
"pallet-foreign-assets",
"pallet-fungible",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev",
"pallet-inflation",
"pallet-maintenance",
"pallet-nonfungible",
@@ -9353,7 +9371,7 @@
"pallet-democracy",
"pallet-elections-phragmen",
"pallet-grandpa",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36)",
"pallet-im-online",
"pallet-indices",
"pallet-membership",
@@ -13144,7 +13162,7 @@
"pallet-evm-transaction-payment",
"pallet-foreign-assets",
"pallet-fungible",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev",
"pallet-inflation",
"pallet-maintenance",
"pallet-nonfungible",
@@ -13789,7 +13807,7 @@
"pallet-elections-phragmen",
"pallet-fast-unstake",
"pallet-grandpa",
- "pallet-identity",
+ "pallet-identity 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36)",
"pallet-im-online",
"pallet-indices",
"pallet-membership",
pallets/collator-selection/Cargo.tomldiffbeforeafterboth--- a/pallets/collator-selection/Cargo.toml
+++ b/pallets/collator-selection/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "pallet-collator-selection"
-version = "3.0.0"
+version = "4.0.0"
description = "Simple staking pallet with a fixed stake."
-authors = ["Unique Network <support@uniquenetwork.io>"]
+authors = ["Parity Technologies <admin@parity.io>", "Unique Network <support@uniquenetwork.io>"]
edition = "2021"
homepage = "https://unique.network"
repository = "https://github.com/UniqueNetwork/unique-chain"
pallets/data-management/Cargo.tomldiffbeforeafterboth--- a/pallets/data-management/Cargo.toml
+++ b/pallets/data-management/Cargo.toml
@@ -16,6 +16,7 @@
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+pallet-identity = { default-features = false, path = "../identity" }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }
fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }
pallets/data-management/src/lib.rsdiffbeforeafterboth--- a/pallets/data-management/src/lib.rs
+++ b/pallets/data-management/src/lib.rs
@@ -34,9 +34,10 @@
use sp_std::vec::Vec;
use super::weights::WeightInfo;
use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};
+ use pallet_identity::Registration;
#[pallet::config]
- pub trait Config: frame_system::Config + pallet_evm::Config {
+ pub trait Config: frame_system::Config + pallet_evm::Config + pallet_identity::Config {
/// Weights
type WeightInfo: WeightInfo;
/// The overarching event type.
@@ -149,6 +150,23 @@
}
Ok(())
}
+
+ /// Insert or remove identities.
+ #[pallet::call_index(5)]
+ #[pallet::weight(<SelfWeightOf<T>>::insert_events(identities.len() as u32))] // todo:collator weight
+ pub fn insert_identities(
+ origin: OriginFor<T>,
+ identities: Vec<(
+ T::AccountId,
+ Option<Registration<pallet_identity::BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields>>,
+ )>,
+ ) -> DispatchResult {
+ ensure_root(origin)?;
+ for identity in identities {
+ <pallet_identity::IdentityOf<T>>::set(identity.0, identity.1);
+ }
+ Ok(())
+ }
}
/// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration
pallets/identity/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/Cargo.toml
@@ -0,0 +1,47 @@
+[package]
+name = "pallet-identity"
+version = "4.0.0-dev"
+authors = ["Parity Technologies <admin@parity.io>", "Unique Network <support@uniquenetwork.io>"]
+edition = "2021"
+license = "Apache-2.0"
+homepage = "https://substrate.io"
+repository = "https://github.com/paritytech/substrate/"
+description = "FRAME identity management pallet"
+readme = "README.md"
+
+[package.metadata.docs.rs]
+targets = ["x86_64-unknown-linux-gnu"]
+
+[dependencies]
+codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
+enumflags2 = { version = "0.7.4" }
+scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-io = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+
+[dev-dependencies]
+pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+
+[features]
+default = ["std"]
+std = [
+ "codec/std",
+ "frame-benchmarking?/std",
+ "frame-support/std",
+ "frame-system/std",
+ "scale-info/std",
+ "sp-io/std",
+ "sp-runtime/std",
+ "sp-std/std",
+]
+runtime-benchmarks = [
+ "frame-benchmarking/runtime-benchmarks",
+ "frame-support/runtime-benchmarks",
+ "frame-system/runtime-benchmarks",
+]
+try-runtime = ["frame-support/try-runtime"]
pallets/identity/README.mddiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/README.md
@@ -0,0 +1,56 @@
+# Identity Module
+
+- [`identity::Config`](https://docs.rs/pallet-identity/latest/pallet_identity/trait.Config.html)
+- [`Call`](https://docs.rs/pallet-identity/latest/pallet_identity/enum.Call.html)
+
+## Overview
+
+A federated naming system, allowing for multiple registrars to be added from a specified origin.
+Registrars can set a fee to provide identity-verification service. Anyone can put forth a
+proposed identity for a fixed deposit and ask for review by any number of registrars (paying
+each of their fees). Registrar judgements are given as an `enum`, allowing for sophisticated,
+multi-tier opinions.
+
+Some judgements are identified as *sticky*, which means they cannot be removed except by
+complete removal of the identity, or by the registrar. Judgements are allowed to represent a
+portion of funds that have been reserved for the registrar.
+
+A super-user can remove accounts and in doing so, slash the deposit.
+
+All accounts may also have a limited number of sub-accounts which may be specified by the owner;
+by definition, these have equivalent ownership and each has an individual name.
+
+The number of registrars should be limited, and the deposit made sufficiently large, to ensure
+no state-bloat attack is viable.
+
+## Interface
+
+### Dispatchable Functions
+
+#### For general users
+* `set_identity` - Set the associated identity of an account; a small deposit is reserved if not
+ already taken.
+* `clear_identity` - Remove an account's associated identity; the deposit is returned.
+* `request_judgement` - Request a judgement from a registrar, paying a fee.
+* `cancel_request` - Cancel the previous request for a judgement.
+
+#### For general users with sub-identities
+* `set_subs` - Set the sub-accounts of an identity.
+* `add_sub` - Add a sub-identity to an identity.
+* `remove_sub` - Remove a sub-identity of an identity.
+* `rename_sub` - Rename a sub-identity of an identity.
+* `quit_sub` - Remove a sub-identity of an identity (called by the sub-identity).
+
+#### For registrars
+* `set_fee` - Set the fee required to be paid for a judgement to be given by the registrar.
+* `set_fields` - Set the fields that a registrar cares about in their judgements.
+* `provide_judgement` - Provide a judgement to an identity.
+
+#### For super-users
+* `add_registrar` - Add a new registrar to the system.
+* `kill_identity` - Forcibly remove the associated identity; the deposit is lost.
+
+[`Call`]: ./enum.Call.html
+[`Config`]: ./trait.Config.html
+
+License: Apache-2.0
pallets/identity/src/benchmarking.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/src/benchmarking.rs
@@ -0,0 +1,462 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network 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.
+
+// Unique Network 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 Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+// Original license:
+// This file is part of Substrate.
+
+// Copyright (C) 2020-2022 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Identity pallet benchmarking.
+
+#![cfg(feature = "runtime-benchmarks")]
+
+use super::*;
+
+use crate::Pallet as Identity;
+use frame_benchmarking::{account, benchmarks, whitelisted_caller};
+use frame_support::{
+ ensure,
+ traits::{EnsureOrigin, Get},
+};
+use frame_system::RawOrigin;
+use sp_runtime::traits::Bounded;
+
+const SEED: u32 = 0;
+
+fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
+ frame_system::Pallet::<T>::assert_last_event(generic_event.into());
+}
+
+// Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields.
+fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {
+ for i in 0..r {
+ let registrar: T::AccountId = account("registrar", i, SEED);
+ let registrar_lookup = T::Lookup::unlookup(registrar.clone());
+ let _ = T::Currency::make_free_balance_be(®istrar, BalanceOf::<T>::max_value());
+ let registrar_origin = T::RegistrarOrigin::successful_origin();
+ Identity::<T>::add_registrar(registrar_origin, registrar_lookup)?;
+ Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?;
+ let fields =
+ IdentityFields(
+ IdentityField::Display |
+ IdentityField::Legal | IdentityField::Web |
+ IdentityField::Riot | IdentityField::Email |
+ IdentityField::PgpFingerprint |
+ IdentityField::Image | IdentityField::Twitter,
+ );
+ Identity::<T>::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?;
+ }
+
+ assert_eq!(Registrars::<T>::get().len(), r as usize);
+ Ok(())
+}
+
+// Create `s` sub-accounts for the identity of `who` and return them.
+// Each will have 32 bytes of raw data added to it.
+fn create_sub_accounts<T: Config>(
+ who: &T::AccountId,
+ s: u32,
+) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
+ let mut subs = Vec::new();
+ let who_origin = RawOrigin::Signed(who.clone());
+ let data = Data::Raw(vec![0; 32].try_into().unwrap());
+
+ for i in 0..s {
+ let sub_account = account("sub", i, SEED);
+ subs.push((sub_account, data.clone()));
+ }
+
+ // Set identity so `set_subs` does not fail.
+ if IdentityOf::<T>::get(who).is_none() {
+ let _ = T::Currency::make_free_balance_be(who, BalanceOf::<T>::max_value() / 2u32.into());
+ let info = create_identity_info::<T>(1);
+ Identity::<T>::set_identity(who_origin.into(), Box::new(info))?;
+ }
+
+ Ok(subs)
+}
+
+// Adds `s` sub-accounts to the identity of `who`. Each will have 32 bytes of raw data added to it.
+// This additionally returns the vector of sub-accounts so it can be modified if needed.
+fn add_sub_accounts<T: Config>(
+ who: &T::AccountId,
+ s: u32,
+) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
+ let who_origin = RawOrigin::Signed(who.clone());
+ let subs = create_sub_accounts::<T>(who, s)?;
+
+ Identity::<T>::set_subs(who_origin.into(), subs.clone())?;
+
+ Ok(subs)
+}
+
+// This creates an `IdentityInfo` object with `num_fields` extra fields.
+// All data is pre-populated with some arbitrary bytes.
+fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo<T::MaxAdditionalFields> {
+ let data = Data::Raw(vec![0; 32].try_into().unwrap());
+
+ IdentityInfo {
+ additional: vec![(data.clone(), data.clone()); num_fields as usize].try_into().unwrap(),
+ display: data.clone(),
+ legal: data.clone(),
+ web: data.clone(),
+ riot: data.clone(),
+ email: data.clone(),
+ pgp_fingerprint: Some([0; 20]),
+ image: data.clone(),
+ twitter: data,
+ }
+}
+
+benchmarks! {
+ add_registrar {
+ let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+ ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
+ let origin = T::RegistrarOrigin::successful_origin();
+ let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
+ }: _<T::RuntimeOrigin>(origin, account)
+ verify {
+ ensure!(Registrars::<T>::get().len() as u32 == r + 1, "Registrars not added.");
+ }
+
+ set_identity {
+ let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
+ let x in 0 .. T::MaxAdditionalFields::get();
+ let caller = {
+ // The target user
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_lookup = T::Lookup::unlookup(caller.clone());
+ let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ // Add an initial identity
+ let initial_info = create_identity_info::<T>(1);
+ Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?;
+
+ // User requests judgement from all the registrars, and they approve
+ for i in 0..r {
+ let registrar: T::AccountId = account("registrar", i, SEED);
+ let registrar_lookup = T::Lookup::unlookup(registrar.clone());
+ let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
+ let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
+
+ Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
+ Identity::<T>::provide_judgement(
+ RawOrigin::Signed(registrar).into(),
+ i,
+ caller_lookup.clone(),
+ Judgement::Reasonable,
+ T::Hashing::hash_of(&initial_info),
+ )?;
+ }
+ caller
+ };
+ }: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x)))
+ verify {
+ assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into());
+ }
+
+ // We need to split `set_subs` into two benchmarks to accurately isolate the potential
+ // writes caused by new or old sub accounts. The actual weight should simply be
+ // the sum of these two weights.
+ set_subs_new {
+ let caller: T::AccountId = whitelisted_caller();
+ // Create a new subs vec with s sub accounts
+ let s in 0 .. T::MaxSubAccounts::get() => ();
+ let subs = create_sub_accounts::<T>(&caller, s)?;
+ ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Caller already has subs");
+ }: set_subs(RawOrigin::Signed(caller.clone()), subs)
+ verify {
+ ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not added");
+ }
+
+ set_subs_old {
+ let caller: T::AccountId = whitelisted_caller();
+ // Give them p many previous sub accounts.
+ let p in 0 .. T::MaxSubAccounts::get() => {
+ let _ = add_sub_accounts::<T>(&caller, p)?;
+ };
+ // Remove all subs.
+ let subs = create_sub_accounts::<T>(&caller, 0)?;
+ ensure!(
+ SubsOf::<T>::get(&caller).1.len() as u32 == p,
+ "Caller does have subs",
+ );
+ }: set_subs(RawOrigin::Signed(caller.clone()), subs)
+ verify {
+ ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Subs not removed");
+ }
+
+ clear_identity {
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
+ let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
+ let s in 0 .. T::MaxSubAccounts::get() => {
+ // Give them s many sub accounts
+ let caller: T::AccountId = whitelisted_caller();
+ let _ = add_sub_accounts::<T>(&caller, s)?;
+ };
+ let x in 0 .. T::MaxAdditionalFields::get();
+
+ // Create their main identity with x additional fields
+ let info = create_identity_info::<T>(x);
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
+ Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?;
+
+ // User requests judgement from all the registrars, and they approve
+ for i in 0..r {
+ let registrar: T::AccountId = account("registrar", i, SEED);
+ let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
+ let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
+
+ Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
+ Identity::<T>::provide_judgement(
+ RawOrigin::Signed(registrar).into(),
+ i,
+ caller_lookup.clone(),
+ Judgement::Reasonable,
+ T::Hashing::hash_of(&info),
+ )?;
+ }
+ ensure!(IdentityOf::<T>::contains_key(&caller), "Identity does not exist.");
+ }: _(RawOrigin::Signed(caller.clone()))
+ verify {
+ ensure!(!IdentityOf::<T>::contains_key(&caller), "Identity not cleared.");
+ }
+
+ request_judgement {
+ let caller: T::AccountId = whitelisted_caller();
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
+ let x in 0 .. T::MaxAdditionalFields::get() => {
+ // Create their main identity with x additional fields
+ let info = create_identity_info::<T>(x);
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
+ Identity::<T>::set_identity(caller_origin, Box::new(info))?;
+ };
+ }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
+ verify {
+ assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into());
+ }
+
+ cancel_request {
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
+ let x in 0 .. T::MaxAdditionalFields::get() => {
+ // Create their main identity with x additional fields
+ let info = create_identity_info::<T>(x);
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
+ Identity::<T>::set_identity(caller_origin, Box::new(info))?;
+ };
+
+ Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;
+ }: _(RawOrigin::Signed(caller.clone()), r - 1)
+ verify {
+ assert_last_event::<T>(Event::<T>::JudgementUnrequested { who: caller, registrar_index: r-1 }.into());
+ }
+
+ set_fee {
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_lookup = T::Lookup::unlookup(caller.clone());
+
+ let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+
+ let registrar_origin = T::RegistrarOrigin::successful_origin();
+ Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set.");
+ }: _(RawOrigin::Signed(caller), r, 100u32.into())
+ verify {
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().fee == 100u32.into(), "Fee not changed.");
+ }
+
+ set_account_id {
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_lookup = T::Lookup::unlookup(caller.clone());
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+
+ let registrar_origin = T::RegistrarOrigin::successful_origin();
+ Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
+ let new_account = T::Lookup::unlookup(account("new", 0, SEED));
+ }: _(RawOrigin::Signed(caller), r, new_account)
+ verify {
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed.");
+ }
+
+ set_fields {
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_lookup = T::Lookup::unlookup(caller.clone());
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+
+ let registrar_origin = T::RegistrarOrigin::successful_origin();
+ Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
+ let fields = IdentityFields(
+ IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot
+ | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter
+ );
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set.");
+ }: _(RawOrigin::Signed(caller), r, fields)
+ verify {
+ let registrars = Registrars::<T>::get();
+ ensure!(registrars[r as usize].as_ref().unwrap().fields != Default::default(), "fields not set.");
+ }
+
+ provide_judgement {
+ // The user
+ let user: T::AccountId = account("user", r, SEED);
+ let user_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
+ let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
+ let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
+
+ let caller: T::AccountId = whitelisted_caller();
+ let caller_lookup = T::Lookup::unlookup(caller.clone());
+ let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
+
+ let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+ let x in 0 .. T::MaxAdditionalFields::get();
+
+ let info = create_identity_info::<T>(x);
+ let info_hash = T::Hashing::hash_of(&info);
+ Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?;
+
+ let registrar_origin = T::RegistrarOrigin::successful_origin();
+ Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
+ Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;
+ }: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash)
+ verify {
+ assert_last_event::<T>(Event::<T>::JudgementGiven { target: user, registrar_index: r }.into())
+ }
+
+ kill_identity {
+ let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
+ let s in 0 .. T::MaxSubAccounts::get();
+ let x in 0 .. T::MaxAdditionalFields::get();
+
+ let target: T::AccountId = account("target", 0, SEED);
+ let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into();
+ let target_lookup = T::Lookup::unlookup(target.clone());
+ let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
+
+ let info = create_identity_info::<T>(x);
+ Identity::<T>::set_identity(target_origin.clone(), Box::new(info.clone()))?;
+ let _ = add_sub_accounts::<T>(&target, s)?;
+
+ // User requests judgement from all the registrars, and they approve
+ for i in 0..r {
+ let registrar: T::AccountId = account("registrar", i, SEED);
+ let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
+ let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
+
+ Identity::<T>::request_judgement(target_origin.clone(), i, 10u32.into())?;
+ Identity::<T>::provide_judgement(
+ RawOrigin::Signed(registrar).into(),
+ i,
+ target_lookup.clone(),
+ Judgement::Reasonable,
+ T::Hashing::hash_of(&info),
+ )?;
+ }
+ ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");
+ let origin = T::ForceOrigin::successful_origin();
+ }: _<T::RuntimeOrigin>(origin, target_lookup)
+ verify {
+ ensure!(!IdentityOf::<T>::contains_key(&target), "Identity not removed");
+ }
+
+ add_sub {
+ let s in 0 .. T::MaxSubAccounts::get() - 1;
+
+ let caller: T::AccountId = whitelisted_caller();
+ let _ = add_sub_accounts::<T>(&caller, s)?;
+ let sub = account("new_sub", 0, SEED);
+ let data = Data::Raw(vec![0; 32].try_into().unwrap());
+ ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not set.");
+ }: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data)
+ verify {
+ ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s + 1, "Subs not added.");
+ }
+
+ rename_sub {
+ let s in 1 .. T::MaxSubAccounts::get();
+
+ let caller: T::AccountId = whitelisted_caller();
+ let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
+ let data = Data::Raw(vec![1; 32].try_into().unwrap());
+ ensure!(SuperOf::<T>::get(&sub).unwrap().1 != data, "data already set");
+ }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone())
+ verify {
+ ensure!(SuperOf::<T>::get(&sub).unwrap().1 == data, "data not set");
+ }
+
+ remove_sub {
+ let s in 1 .. T::MaxSubAccounts::get();
+
+ let caller: T::AccountId = whitelisted_caller();
+ let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
+ ensure!(SuperOf::<T>::contains_key(&sub), "Sub doesn't exists");
+ }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()))
+ verify {
+ ensure!(!SuperOf::<T>::contains_key(&sub), "Sub not removed");
+ }
+
+ quit_sub {
+ let s in 0 .. T::MaxSubAccounts::get() - 1;
+
+ let caller: T::AccountId = whitelisted_caller();
+ let sup = account("super", 0, SEED);
+ let _ = add_sub_accounts::<T>(&sup, s)?;
+ let sup_origin = RawOrigin::Signed(sup).into();
+ Identity::<T>::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32].try_into().unwrap()))?;
+ ensure!(SuperOf::<T>::contains_key(&caller), "Sub doesn't exists");
+ }: _(RawOrigin::Signed(caller.clone()))
+ verify {
+ ensure!(!SuperOf::<T>::contains_key(&caller), "Sub not removed");
+ }
+
+ impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test);
+}
pallets/identity/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435//! # Identity Pallet36//!37//! - [`Config`]38//! - [`Call`]39//!40//! ## Overview41//!42//! A federated naming system, allowing for multiple registrars to be added from a specified origin.43//! Registrars can set a fee to provide identity-verification service. Anyone can put forth a44//! proposed identity for a fixed deposit and ask for review by any number of registrars (paying45//! each of their fees). Registrar judgements are given as an `enum`, allowing for sophisticated,46//! multi-tier opinions.47//!48//! Some judgements are identified as *sticky*, which means they cannot be removed except by49//! complete removal of the identity, or by the registrar. Judgements are allowed to represent a50//! portion of funds that have been reserved for the registrar.51//!52//! A super-user can remove accounts and in doing so, slash the deposit.53//!54//! All accounts may also have a limited number of sub-accounts which may be specified by the owner;55//! by definition, these have equivalent ownership and each has an individual name.56//!57//! The number of registrars should be limited, and the deposit made sufficiently large, to ensure58//! no state-bloat attack is viable.59//!60//! ## Interface61//!62//! ### Dispatchable Functions63//!64//! #### For general users65//! * `set_identity` - Set the associated identity of an account; a small deposit is reserved if not66//! already taken.67//! * `clear_identity` - Remove an account's associated identity; the deposit is returned.68//! * `request_judgement` - Request a judgement from a registrar, paying a fee.69//! * `cancel_request` - Cancel the previous request for a judgement.70//!71//! #### For general users with sub-identities72//! * `set_subs` - Set the sub-accounts of an identity.73//! * `add_sub` - Add a sub-identity to an identity.74//! * `remove_sub` - Remove a sub-identity of an identity.75//! * `rename_sub` - Rename a sub-identity of an identity.76//! * `quit_sub` - Remove a sub-identity of an identity (called by the sub-identity).77//!78//! #### For registrars79//! * `set_fee` - Set the fee required to be paid for a judgement to be given by the registrar.80//! * `set_fields` - Set the fields that a registrar cares about in their judgements.81//! * `provide_judgement` - Provide a judgement to an identity.82//!83//! #### For super-users84//! * `add_registrar` - Add a new registrar to the system.85//! * `kill_identity` - Forcibly remove the associated identity; the deposit is lost.86//!87//! [`Call`]: ./enum.Call.html88//! [`Config`]: ./trait.Config.html8990#![cfg_attr(not(feature = "std"), no_std)]9192mod benchmarking;93#[cfg(test)]94mod tests;95mod types;96pub mod weights;9798use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency};99use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero};100use sp_std::prelude::*;101pub use weights::WeightInfo;102103pub use pallet::*;104pub use types::{105 Data, IdentityField, IdentityFields, IdentityInfo, Judgement, RegistrarIndex, RegistrarInfo,106 Registration,107};108109pub type BalanceOf<T> =110 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;111type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<112 <T as frame_system::Config>::AccountId,113>>::NegativeImbalance;114type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;115116#[frame_support::pallet]117pub mod pallet {118 use super::*;119 use frame_support::pallet_prelude::*;120 use frame_system::pallet_prelude::*;121122 #[pallet::config]123 pub trait Config: frame_system::Config {124 /// The overarching event type.125 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;126127 /// The currency trait.128 type Currency: ReservableCurrency<Self::AccountId>;129130 /// The amount held on deposit for a registered identity131 #[pallet::constant]132 type BasicDeposit: Get<BalanceOf<Self>>;133134 /// The amount held on deposit per additional field for a registered identity.135 #[pallet::constant]136 type FieldDeposit: Get<BalanceOf<Self>>;137138 /// The amount held on deposit for a registered subaccount. This should account for the fact139 /// that one storage item's value will increase by the size of an account ID, and there will140 /// be another trie item whose value is the size of an account ID plus 32 bytes.141 #[pallet::constant]142 type SubAccountDeposit: Get<BalanceOf<Self>>;143144 /// The maximum number of sub-accounts allowed per identified account.145 #[pallet::constant]146 type MaxSubAccounts: Get<u32>;147148 /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O149 /// required to access an identity, but can be pretty high.150 #[pallet::constant]151 type MaxAdditionalFields: Get<u32>;152153 /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity154 /// of, e.g., updating judgements.155 #[pallet::constant]156 type MaxRegistrars: Get<u32>;157158 /// What to do with slashed funds.159 type Slashed: OnUnbalanced<NegativeImbalanceOf<Self>>;160161 /// The origin which may forcibly set or remove a name. Root can always do this.162 type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;163164 /// The origin which may add or remove registrars. Root can always do this.165 type RegistrarOrigin: EnsureOrigin<Self::RuntimeOrigin>;166167 /// Weight information for extrinsics in this pallet.168 type WeightInfo: WeightInfo;169 }170171 #[pallet::pallet]172 #[pallet::generate_store(pub(super) trait Store)]173 pub struct Pallet<T>(_);174175 /// Information that is pertinent to identify the entity behind an account.176 ///177 /// TWOX-NOTE: OK ― `AccountId` is a secure hash.178 #[pallet::storage]179 #[pallet::getter(fn identity)]180 pub type IdentityOf<T: Config> = StorageMap<181 _,182 Twox64Concat,183 T::AccountId,184 Registration<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields>,185 OptionQuery,186 >;187188 /// The super-identity of an alternative "sub" identity together with its name, within that189 /// context. If the account is not some other account's sub-identity, then just `None`.190 #[pallet::storage]191 #[pallet::getter(fn super_of)]192 pub(super) type SuperOf<T: Config> =193 StorageMap<_, Blake2_128Concat, T::AccountId, (T::AccountId, Data), OptionQuery>;194195 /// Alternative "sub" identities of this account.196 ///197 /// The first item is the deposit, the second is a vector of the accounts.198 ///199 /// TWOX-NOTE: OK ― `AccountId` is a secure hash.200 #[pallet::storage]201 #[pallet::getter(fn subs_of)]202 pub(super) type SubsOf<T: Config> = StorageMap<203 _,204 Twox64Concat,205 T::AccountId,206 (BalanceOf<T>, BoundedVec<T::AccountId, T::MaxSubAccounts>),207 ValueQuery,208 >;209210 /// The set of registrars. Not expected to get very big as can only be added through a211 /// special origin (likely a council motion).212 ///213 /// The index into this can be cast to `RegistrarIndex` to get a valid value.214 #[pallet::storage]215 #[pallet::getter(fn registrars)]216 pub(super) type Registrars<T: Config> = StorageValue<217 _,218 BoundedVec<Option<RegistrarInfo<BalanceOf<T>, T::AccountId>>, T::MaxRegistrars>,219 ValueQuery,220 >;221222 #[pallet::error]223 pub enum Error<T> {224 /// Too many subs-accounts.225 TooManySubAccounts,226 /// Account isn't found.227 NotFound,228 /// Account isn't named.229 NotNamed,230 /// Empty index.231 EmptyIndex,232 /// Fee is changed.233 FeeChanged,234 /// No identity found.235 NoIdentity,236 /// Sticky judgement.237 StickyJudgement,238 /// Judgement given.239 JudgementGiven,240 /// Invalid judgement.241 InvalidJudgement,242 /// The index is invalid.243 InvalidIndex,244 /// The target is invalid.245 InvalidTarget,246 /// Too many additional fields.247 TooManyFields,248 /// Maximum amount of registrars reached. Cannot add any more.249 TooManyRegistrars,250 /// Account ID is already named.251 AlreadyClaimed,252 /// Sender is not a sub-account.253 NotSub,254 /// Sub-account isn't owned by sender.255 NotOwned,256 /// The provided judgement was for a different identity.257 JudgementForDifferentIdentity,258 /// Error that occurs when there is an issue paying for judgement.259 JudgementPaymentFailed,260 }261262 #[pallet::event]263 #[pallet::generate_deposit(pub(super) fn deposit_event)]264 pub enum Event<T: Config> {265 /// A name was set or reset (which will remove all judgements).266 IdentitySet { who: T::AccountId },267 /// A name was cleared, and the given balance returned.268 IdentityCleared { who: T::AccountId, deposit: BalanceOf<T> },269 /// A name was removed and the given balance slashed.270 IdentityKilled { who: T::AccountId, deposit: BalanceOf<T> },271 /// A judgement was asked from a registrar.272 JudgementRequested { who: T::AccountId, registrar_index: RegistrarIndex },273 /// A judgement request was retracted.274 JudgementUnrequested { who: T::AccountId, registrar_index: RegistrarIndex },275 /// A judgement was given by a registrar.276 JudgementGiven { target: T::AccountId, registrar_index: RegistrarIndex },277 /// A registrar was added.278 RegistrarAdded { registrar_index: RegistrarIndex },279 /// A sub-identity was added to an identity and the deposit paid.280 SubIdentityAdded { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },281 /// A sub-identity was removed from an identity and the deposit freed.282 SubIdentityRemoved { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },283 /// A sub-identity was cleared, and the given deposit repatriated from the284 /// main identity account to the sub-identity account.285 SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },286 }287288 #[pallet::call]289 /// Identity pallet declaration.290 impl<T: Config> Pallet<T> {291 /// Add a registrar to the system.292 ///293 /// The dispatch origin for this call must be `T::RegistrarOrigin`.294 ///295 /// - `account`: the account of the registrar.296 ///297 /// Emits `RegistrarAdded` if successful.298 ///299 /// # <weight>300 /// - `O(R)` where `R` registrar-count (governance-bounded and code-bounded).301 /// - One storage mutation (codec `O(R)`).302 /// - One event.303 /// # </weight>304 #[pallet::call_index(0)]305 #[pallet::weight(T::WeightInfo::add_registrar(T::MaxRegistrars::get()))]306 pub fn add_registrar(307 origin: OriginFor<T>,308 account: AccountIdLookupOf<T>,309 ) -> DispatchResultWithPostInfo {310 T::RegistrarOrigin::ensure_origin(origin)?;311 let account = T::Lookup::lookup(account)?;312313 let (i, registrar_count) = <Registrars<T>>::try_mutate(314 |registrars| -> Result<(RegistrarIndex, usize), DispatchError> {315 registrars316 .try_push(Some(RegistrarInfo {317 account,318 fee: Zero::zero(),319 fields: Default::default(),320 }))321 .map_err(|_| Error::<T>::TooManyRegistrars)?;322 Ok(((registrars.len() - 1) as RegistrarIndex, registrars.len()))323 },324 )?;325326 Self::deposit_event(Event::RegistrarAdded { registrar_index: i });327328 Ok(Some(T::WeightInfo::add_registrar(registrar_count as u32)).into())329 }330331 /// Set an account's identity information and reserve the appropriate deposit.332 ///333 /// If the account already has identity information, the deposit is taken as part payment334 /// for the new deposit.335 ///336 /// The dispatch origin for this call must be _Signed_.337 ///338 /// - `info`: The identity information.339 ///340 /// Emits `IdentitySet` if successful.341 ///342 /// # <weight>343 /// - `O(X + X' + R)`344 /// - where `X` additional-field-count (deposit-bounded and code-bounded)345 /// - where `R` judgements-count (registrar-count-bounded)346 /// - One balance reserve operation.347 /// - One storage mutation (codec-read `O(X' + R)`, codec-write `O(X + R)`).348 /// - One event.349 /// # </weight>350 #[pallet::call_index(1)]351 #[pallet::weight( T::WeightInfo::set_identity(352 T::MaxRegistrars::get(), // R353 T::MaxAdditionalFields::get(), // X354 ))]355 pub fn set_identity(356 origin: OriginFor<T>,357 info: Box<IdentityInfo<T::MaxAdditionalFields>>,358 ) -> DispatchResultWithPostInfo {359 let sender = ensure_signed(origin)?;360 let extra_fields = info.additional.len() as u32;361 ensure!(extra_fields <= T::MaxAdditionalFields::get(), Error::<T>::TooManyFields);362 let fd = <BalanceOf<T>>::from(extra_fields) * T::FieldDeposit::get();363364 let mut id = match <IdentityOf<T>>::get(&sender) {365 Some(mut id) => {366 // Only keep non-positive judgements.367 id.judgements.retain(|j| j.1.is_sticky());368 id.info = *info;369 id370 },371 None => Registration {372 info: *info,373 judgements: BoundedVec::default(),374 deposit: Zero::zero(),375 },376 };377378 let old_deposit = id.deposit;379 id.deposit = T::BasicDeposit::get() + fd;380 if id.deposit > old_deposit {381 T::Currency::reserve(&sender, id.deposit - old_deposit)?;382 }383 if old_deposit > id.deposit {384 let err_amount = T::Currency::unreserve(&sender, old_deposit - id.deposit);385 debug_assert!(err_amount.is_zero());386 }387388 let judgements = id.judgements.len();389 <IdentityOf<T>>::insert(&sender, id);390 Self::deposit_event(Event::IdentitySet { who: sender });391392 Ok(Some(T::WeightInfo::set_identity(393 judgements as u32, // R394 extra_fields, // X395 ))396 .into())397 }398399 /// Set the sub-accounts of the sender.400 ///401 /// Payment: Any aggregate balance reserved by previous `set_subs` calls will be returned402 /// and an amount `SubAccountDeposit` will be reserved for each item in `subs`.403 ///404 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered405 /// identity.406 ///407 /// - `subs`: The identity's (new) sub-accounts.408 ///409 /// # <weight>410 /// - `O(P + S)`411 /// - where `P` old-subs-count (hard- and deposit-bounded).412 /// - where `S` subs-count (hard- and deposit-bounded).413 /// - At most one balance operations.414 /// - DB:415 /// - `P + S` storage mutations (codec complexity `O(1)`)416 /// - One storage read (codec complexity `O(P)`).417 /// - One storage write (codec complexity `O(S)`).418 /// - One storage-exists (`IdentityOf::contains_key`).419 /// # </weight>420 // TODO: This whole extrinsic screams "not optimized". For example we could421 // filter any overlap between new and old subs, and avoid reading/writing422 // to those values... We could also ideally avoid needing to write to423 // N storage items for N sub accounts. Right now the weight on this function424 // is a large overestimate due to the fact that it could potentially write425 // to 2 x T::MaxSubAccounts::get().426 #[pallet::call_index(2)]427 #[pallet::weight(T::WeightInfo::set_subs_old(T::MaxSubAccounts::get()) // P: Assume max sub accounts removed.428 .saturating_add(T::WeightInfo::set_subs_new(subs.len() as u32)) // S: Assume all subs are new.429 )]430 pub fn set_subs(431 origin: OriginFor<T>,432 subs: Vec<(T::AccountId, Data)>,433 ) -> DispatchResultWithPostInfo {434 let sender = ensure_signed(origin)?;435 ensure!(<IdentityOf<T>>::contains_key(&sender), Error::<T>::NotFound);436 ensure!(437 subs.len() <= T::MaxSubAccounts::get() as usize,438 Error::<T>::TooManySubAccounts439 );440441 let (old_deposit, old_ids) = <SubsOf<T>>::get(&sender);442 let new_deposit = T::SubAccountDeposit::get() * <BalanceOf<T>>::from(subs.len() as u32);443444 let not_other_sub =445 subs.iter().filter_map(|i| SuperOf::<T>::get(&i.0)).all(|i| i.0 == sender);446 ensure!(not_other_sub, Error::<T>::AlreadyClaimed);447448 if old_deposit < new_deposit {449 T::Currency::reserve(&sender, new_deposit - old_deposit)?;450 } else if old_deposit > new_deposit {451 let err_amount = T::Currency::unreserve(&sender, old_deposit - new_deposit);452 debug_assert!(err_amount.is_zero());453 }454 // do nothing if they're equal.455456 for s in old_ids.iter() {457 <SuperOf<T>>::remove(s);458 }459 let mut ids = BoundedVec::<T::AccountId, T::MaxSubAccounts>::default();460 for (id, name) in subs {461 <SuperOf<T>>::insert(&id, (sender.clone(), name));462 ids.try_push(id).expect("subs length is less than T::MaxSubAccounts; qed");463 }464 let new_subs = ids.len();465466 if ids.is_empty() {467 <SubsOf<T>>::remove(&sender);468 } else {469 <SubsOf<T>>::insert(&sender, (new_deposit, ids));470 }471472 Ok(Some(473 T::WeightInfo::set_subs_old(old_ids.len() as u32) // P: Real number of old accounts removed.474 // S: New subs added475 .saturating_add(T::WeightInfo::set_subs_new(new_subs as u32)),476 )477 .into())478 }479480 /// Clear an account's identity info and all sub-accounts and return all deposits.481 ///482 /// Payment: All reserved balances on the account are returned.483 ///484 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered485 /// identity.486 ///487 /// Emits `IdentityCleared` if successful.488 ///489 /// # <weight>490 /// - `O(R + S + X)`491 /// - where `R` registrar-count (governance-bounded).492 /// - where `S` subs-count (hard- and deposit-bounded).493 /// - where `X` additional-field-count (deposit-bounded and code-bounded).494 /// - One balance-unreserve operation.495 /// - `2` storage reads and `S + 2` storage deletions.496 /// - One event.497 /// # </weight>498 #[pallet::call_index(3)]499 #[pallet::weight(T::WeightInfo::clear_identity(500 T::MaxRegistrars::get(), // R501 T::MaxSubAccounts::get(), // S502 T::MaxAdditionalFields::get(), // X503 ))]504 pub fn clear_identity(origin: OriginFor<T>) -> DispatchResultWithPostInfo {505 let sender = ensure_signed(origin)?;506507 let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&sender);508 let id = <IdentityOf<T>>::take(&sender).ok_or(Error::<T>::NotNamed)?;509 let deposit = id.total_deposit() + subs_deposit;510 for sub in sub_ids.iter() {511 <SuperOf<T>>::remove(sub);512 }513514 let err_amount = T::Currency::unreserve(&sender, deposit);515 debug_assert!(err_amount.is_zero());516517 Self::deposit_event(Event::IdentityCleared { who: sender, deposit });518519 Ok(Some(T::WeightInfo::clear_identity(520 id.judgements.len() as u32, // R521 sub_ids.len() as u32, // S522 id.info.additional.len() as u32, // X523 ))524 .into())525 }526527 /// Request a judgement from a registrar.528 ///529 /// Payment: At most `max_fee` will be reserved for payment to the registrar if judgement530 /// given.531 ///532 /// The dispatch origin for this call must be _Signed_ and the sender must have a533 /// registered identity.534 ///535 /// - `reg_index`: The index of the registrar whose judgement is requested.536 /// - `max_fee`: The maximum fee that may be paid. This should just be auto-populated as:537 ///538 /// ```nocompile539 /// Self::registrars().get(reg_index).unwrap().fee540 /// ```541 ///542 /// Emits `JudgementRequested` if successful.543 ///544 /// # <weight>545 /// - `O(R + X)`.546 /// - One balance-reserve operation.547 /// - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`.548 /// - One event.549 /// # </weight>550 #[pallet::call_index(4)]551 #[pallet::weight(T::WeightInfo::request_judgement(552 T::MaxRegistrars::get(), // R553 T::MaxAdditionalFields::get(), // X554 ))]555 pub fn request_judgement(556 origin: OriginFor<T>,557 #[pallet::compact] reg_index: RegistrarIndex,558 #[pallet::compact] max_fee: BalanceOf<T>,559 ) -> DispatchResultWithPostInfo {560 let sender = ensure_signed(origin)?;561 let registrars = <Registrars<T>>::get();562 let registrar = registrars563 .get(reg_index as usize)564 .and_then(Option::as_ref)565 .ok_or(Error::<T>::EmptyIndex)?;566 ensure!(max_fee >= registrar.fee, Error::<T>::FeeChanged);567 let mut id = <IdentityOf<T>>::get(&sender).ok_or(Error::<T>::NoIdentity)?;568569 let item = (reg_index, Judgement::FeePaid(registrar.fee));570 match id.judgements.binary_search_by_key(®_index, |x| x.0) {571 Ok(i) =>572 if id.judgements[i].1.is_sticky() {573 return Err(Error::<T>::StickyJudgement.into())574 } else {575 id.judgements[i] = item576 },577 Err(i) =>578 id.judgements.try_insert(i, item).map_err(|_| Error::<T>::TooManyRegistrars)?,579 }580581 T::Currency::reserve(&sender, registrar.fee)?;582583 let judgements = id.judgements.len();584 let extra_fields = id.info.additional.len();585 <IdentityOf<T>>::insert(&sender, id);586587 Self::deposit_event(Event::JudgementRequested {588 who: sender,589 registrar_index: reg_index,590 });591592 Ok(Some(T::WeightInfo::request_judgement(judgements as u32, extra_fields as u32))593 .into())594 }595596 /// Cancel a previous request.597 ///598 /// Payment: A previously reserved deposit is returned on success.599 ///600 /// The dispatch origin for this call must be _Signed_ and the sender must have a601 /// registered identity.602 ///603 /// - `reg_index`: The index of the registrar whose judgement is no longer requested.604 ///605 /// Emits `JudgementUnrequested` if successful.606 ///607 /// # <weight>608 /// - `O(R + X)`.609 /// - One balance-reserve operation.610 /// - One storage mutation `O(R + X)`.611 /// - One event612 /// # </weight>613 #[pallet::call_index(5)]614 #[pallet::weight(T::WeightInfo::cancel_request(615 T::MaxRegistrars::get(), // R616 T::MaxAdditionalFields::get(), // X617 ))]618 pub fn cancel_request(619 origin: OriginFor<T>,620 reg_index: RegistrarIndex,621 ) -> DispatchResultWithPostInfo {622 let sender = ensure_signed(origin)?;623 let mut id = <IdentityOf<T>>::get(&sender).ok_or(Error::<T>::NoIdentity)?;624625 let pos = id626 .judgements627 .binary_search_by_key(®_index, |x| x.0)628 .map_err(|_| Error::<T>::NotFound)?;629 let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 {630 fee631 } else {632 return Err(Error::<T>::JudgementGiven.into())633 };634635 let err_amount = T::Currency::unreserve(&sender, fee);636 debug_assert!(err_amount.is_zero());637 let judgements = id.judgements.len();638 let extra_fields = id.info.additional.len();639 <IdentityOf<T>>::insert(&sender, id);640641 Self::deposit_event(Event::JudgementUnrequested {642 who: sender,643 registrar_index: reg_index,644 });645646 Ok(Some(T::WeightInfo::cancel_request(judgements as u32, extra_fields as u32)).into())647 }648649 /// Set the fee required for a judgement to be requested from a registrar.650 ///651 /// The dispatch origin for this call must be _Signed_ and the sender must be the account652 /// of the registrar whose index is `index`.653 ///654 /// - `index`: the index of the registrar whose fee is to be set.655 /// - `fee`: the new fee.656 ///657 /// # <weight>658 /// - `O(R)`.659 /// - One storage mutation `O(R)`.660 /// - Benchmark: 7.315 + R * 0.329 µs (min squares analysis)661 /// # </weight>662 #[pallet::call_index(6)]663 #[pallet::weight(T::WeightInfo::set_fee(T::MaxRegistrars::get()))] // R664 pub fn set_fee(665 origin: OriginFor<T>,666 #[pallet::compact] index: RegistrarIndex,667 #[pallet::compact] fee: BalanceOf<T>,668 ) -> DispatchResultWithPostInfo {669 let who = ensure_signed(origin)?;670671 let registrars = <Registrars<T>>::mutate(|rs| -> Result<usize, DispatchError> {672 rs.get_mut(index as usize)673 .and_then(|x| x.as_mut())674 .and_then(|r| {675 if r.account == who {676 r.fee = fee;677 Some(())678 } else {679 None680 }681 })682 .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?;683 Ok(rs.len())684 })?;685 Ok(Some(T::WeightInfo::set_fee(registrars as u32)).into()) // R686 }687688 /// Change the account associated with a registrar.689 ///690 /// The dispatch origin for this call must be _Signed_ and the sender must be the account691 /// of the registrar whose index is `index`.692 ///693 /// - `index`: the index of the registrar whose fee is to be set.694 /// - `new`: the new account ID.695 ///696 /// # <weight>697 /// - `O(R)`.698 /// - One storage mutation `O(R)`.699 /// - Benchmark: 8.823 + R * 0.32 µs (min squares analysis)700 /// # </weight>701 #[pallet::call_index(7)]702 #[pallet::weight(T::WeightInfo::set_account_id(T::MaxRegistrars::get()))] // R703 pub fn set_account_id(704 origin: OriginFor<T>,705 #[pallet::compact] index: RegistrarIndex,706 new: AccountIdLookupOf<T>,707 ) -> DispatchResultWithPostInfo {708 let who = ensure_signed(origin)?;709 let new = T::Lookup::lookup(new)?;710711 let registrars = <Registrars<T>>::mutate(|rs| -> Result<usize, DispatchError> {712 rs.get_mut(index as usize)713 .and_then(|x| x.as_mut())714 .and_then(|r| {715 if r.account == who {716 r.account = new;717 Some(())718 } else {719 None720 }721 })722 .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?;723 Ok(rs.len())724 })?;725 Ok(Some(T::WeightInfo::set_account_id(registrars as u32)).into()) // R726 }727728 /// Set the field information for a registrar.729 ///730 /// The dispatch origin for this call must be _Signed_ and the sender must be the account731 /// of the registrar whose index is `index`.732 ///733 /// - `index`: the index of the registrar whose fee is to be set.734 /// - `fields`: the fields that the registrar concerns themselves with.735 ///736 /// # <weight>737 /// - `O(R)`.738 /// - One storage mutation `O(R)`.739 /// - Benchmark: 7.464 + R * 0.325 µs (min squares analysis)740 /// # </weight>741 #[pallet::call_index(8)]742 #[pallet::weight(T::WeightInfo::set_fields(T::MaxRegistrars::get()))] // R743 pub fn set_fields(744 origin: OriginFor<T>,745 #[pallet::compact] index: RegistrarIndex,746 fields: IdentityFields,747 ) -> DispatchResultWithPostInfo {748 let who = ensure_signed(origin)?;749750 let registrars = <Registrars<T>>::mutate(|rs| -> Result<usize, DispatchError> {751 rs.get_mut(index as usize)752 .and_then(|x| x.as_mut())753 .and_then(|r| {754 if r.account == who {755 r.fields = fields;756 Some(())757 } else {758 None759 }760 })761 .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?;762 Ok(rs.len())763 })?;764 Ok(Some(T::WeightInfo::set_fields(765 registrars as u32, // R766 ))767 .into())768 }769770 /// Provide a judgement for an account's identity.771 ///772 /// The dispatch origin for this call must be _Signed_ and the sender must be the account773 /// of the registrar whose index is `reg_index`.774 ///775 /// - `reg_index`: the index of the registrar whose judgement is being made.776 /// - `target`: the account whose identity the judgement is upon. This must be an account777 /// with a registered identity.778 /// - `judgement`: the judgement of the registrar of index `reg_index` about `target`.779 /// - `identity`: The hash of the [`IdentityInfo`] for that the judgement is provided.780 ///781 /// Emits `JudgementGiven` if successful.782 ///783 /// # <weight>784 /// - `O(R + X)`.785 /// - One balance-transfer operation.786 /// - Up to one account-lookup operation.787 /// - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`.788 /// - One event.789 /// # </weight>790 #[pallet::call_index(9)]791 #[pallet::weight(T::WeightInfo::provide_judgement(792 T::MaxRegistrars::get(), // R793 T::MaxAdditionalFields::get(), // X794 ))]795 pub fn provide_judgement(796 origin: OriginFor<T>,797 #[pallet::compact] reg_index: RegistrarIndex,798 target: AccountIdLookupOf<T>,799 judgement: Judgement<BalanceOf<T>>,800 identity: T::Hash,801 ) -> DispatchResultWithPostInfo {802 let sender = ensure_signed(origin)?;803 let target = T::Lookup::lookup(target)?;804 ensure!(!judgement.has_deposit(), Error::<T>::InvalidJudgement);805 <Registrars<T>>::get()806 .get(reg_index as usize)807 .and_then(Option::as_ref)808 .filter(|r| r.account == sender)809 .ok_or(Error::<T>::InvalidIndex)?;810 let mut id = <IdentityOf<T>>::get(&target).ok_or(Error::<T>::InvalidTarget)?;811812 if T::Hashing::hash_of(&id.info) != identity {813 return Err(Error::<T>::JudgementForDifferentIdentity.into())814 }815816 let item = (reg_index, judgement);817 match id.judgements.binary_search_by_key(®_index, |x| x.0) {818 Ok(position) => {819 if let Judgement::FeePaid(fee) = id.judgements[position].1 {820 T::Currency::repatriate_reserved(821 &target,822 &sender,823 fee,824 BalanceStatus::Free,825 )826 .map_err(|_| Error::<T>::JudgementPaymentFailed)?;827 }828 id.judgements[position] = item829 },830 Err(position) => id831 .judgements832 .try_insert(position, item)833 .map_err(|_| Error::<T>::TooManyRegistrars)?,834 }835836 let judgements = id.judgements.len();837 let extra_fields = id.info.additional.len();838 <IdentityOf<T>>::insert(&target, id);839 Self::deposit_event(Event::JudgementGiven { target, registrar_index: reg_index });840841 Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, extra_fields as u32))842 .into())843 }844845 /// Remove an account's identity and sub-account information and slash the deposits.846 ///847 /// Payment: Reserved balances from `set_subs` and `set_identity` are slashed and handled by848 /// `Slash`. Verification request deposits are not returned; they should be cancelled849 /// manually using `cancel_request`.850 ///851 /// The dispatch origin for this call must match `T::ForceOrigin`.852 ///853 /// - `target`: the account whose identity the judgement is upon. This must be an account854 /// with a registered identity.855 ///856 /// Emits `IdentityKilled` if successful.857 ///858 /// # <weight>859 /// - `O(R + S + X)`.860 /// - One balance-reserve operation.861 /// - `S + 2` storage mutations.862 /// - One event.863 /// # </weight>864 #[pallet::call_index(10)]865 #[pallet::weight(T::WeightInfo::kill_identity(866 T::MaxRegistrars::get(), // R867 T::MaxSubAccounts::get(), // S868 T::MaxAdditionalFields::get(), // X869 ))]870 pub fn kill_identity(871 origin: OriginFor<T>,872 target: AccountIdLookupOf<T>,873 ) -> DispatchResultWithPostInfo {874 T::ForceOrigin::ensure_origin(origin)?;875876 // Figure out who we're meant to be clearing.877 let target = T::Lookup::lookup(target)?;878 // Grab their deposit (and check that they have one).879 let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&target);880 let id = <IdentityOf<T>>::take(&target).ok_or(Error::<T>::NotNamed)?;881 let deposit = id.total_deposit() + subs_deposit;882 for sub in sub_ids.iter() {883 <SuperOf<T>>::remove(sub);884 }885 // Slash their deposit from them.886 T::Slashed::on_unbalanced(T::Currency::slash_reserved(&target, deposit).0);887888 Self::deposit_event(Event::IdentityKilled { who: target, deposit });889890 Ok(Some(T::WeightInfo::kill_identity(891 id.judgements.len() as u32, // R892 sub_ids.len() as u32, // S893 id.info.additional.len() as u32, // X894 ))895 .into())896 }897898 /// Add the given account to the sender's subs.899 ///900 /// Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated901 /// to the sender.902 ///903 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered904 /// sub identity of `sub`.905 #[pallet::call_index(11)]906 #[pallet::weight(T::WeightInfo::add_sub(T::MaxSubAccounts::get()))]907 pub fn add_sub(908 origin: OriginFor<T>,909 sub: AccountIdLookupOf<T>,910 data: Data,911 ) -> DispatchResult {912 let sender = ensure_signed(origin)?;913 let sub = T::Lookup::lookup(sub)?;914 ensure!(IdentityOf::<T>::contains_key(&sender), Error::<T>::NoIdentity);915916 // Check if it's already claimed as sub-identity.917 ensure!(!SuperOf::<T>::contains_key(&sub), Error::<T>::AlreadyClaimed);918919 SubsOf::<T>::try_mutate(&sender, |(ref mut subs_deposit, ref mut sub_ids)| {920 // Ensure there is space and that the deposit is paid.921 ensure!(922 sub_ids.len() < T::MaxSubAccounts::get() as usize,923 Error::<T>::TooManySubAccounts924 );925 let deposit = T::SubAccountDeposit::get();926 T::Currency::reserve(&sender, deposit)?;927928 SuperOf::<T>::insert(&sub, (sender.clone(), data));929 sub_ids.try_push(sub.clone()).expect("sub ids length checked above; qed");930 *subs_deposit = subs_deposit.saturating_add(deposit);931932 Self::deposit_event(Event::SubIdentityAdded { sub, main: sender.clone(), deposit });933 Ok(())934 })935 }936937 /// Alter the associated name of the given sub-account.938 ///939 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered940 /// sub identity of `sub`.941 #[pallet::call_index(12)]942 #[pallet::weight(T::WeightInfo::rename_sub(T::MaxSubAccounts::get()))]943 pub fn rename_sub(944 origin: OriginFor<T>,945 sub: AccountIdLookupOf<T>,946 data: Data,947 ) -> DispatchResult {948 let sender = ensure_signed(origin)?;949 let sub = T::Lookup::lookup(sub)?;950 ensure!(IdentityOf::<T>::contains_key(&sender), Error::<T>::NoIdentity);951 ensure!(SuperOf::<T>::get(&sub).map_or(false, |x| x.0 == sender), Error::<T>::NotOwned);952 SuperOf::<T>::insert(&sub, (sender, data));953 Ok(())954 }955956 /// Remove the given account from the sender's subs.957 ///958 /// Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated959 /// to the sender.960 ///961 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered962 /// sub identity of `sub`.963 #[pallet::call_index(13)]964 #[pallet::weight(T::WeightInfo::remove_sub(T::MaxSubAccounts::get()))]965 pub fn remove_sub(origin: OriginFor<T>, sub: AccountIdLookupOf<T>) -> DispatchResult {966 let sender = ensure_signed(origin)?;967 ensure!(IdentityOf::<T>::contains_key(&sender), Error::<T>::NoIdentity);968 let sub = T::Lookup::lookup(sub)?;969 let (sup, _) = SuperOf::<T>::get(&sub).ok_or(Error::<T>::NotSub)?;970 ensure!(sup == sender, Error::<T>::NotOwned);971 SuperOf::<T>::remove(&sub);972 SubsOf::<T>::mutate(&sup, |(ref mut subs_deposit, ref mut sub_ids)| {973 sub_ids.retain(|x| x != &sub);974 let deposit = T::SubAccountDeposit::get().min(*subs_deposit);975 *subs_deposit -= deposit;976 let err_amount = T::Currency::unreserve(&sender, deposit);977 debug_assert!(err_amount.is_zero());978 Self::deposit_event(Event::SubIdentityRemoved { sub, main: sender, deposit });979 });980 Ok(())981 }982983 /// Remove the sender as a sub-account.984 ///985 /// Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated986 /// to the sender (*not* the original depositor).987 ///988 /// The dispatch origin for this call must be _Signed_ and the sender must have a registered989 /// super-identity.990 ///991 /// NOTE: This should not normally be used, but is provided in the case that the non-992 /// controller of an account is maliciously registered as a sub-account.993 #[pallet::call_index(14)]994 #[pallet::weight(T::WeightInfo::quit_sub(T::MaxSubAccounts::get()))]995 pub fn quit_sub(origin: OriginFor<T>) -> DispatchResult {996 let sender = ensure_signed(origin)?;997 let (sup, _) = SuperOf::<T>::take(&sender).ok_or(Error::<T>::NotSub)?;998 SubsOf::<T>::mutate(&sup, |(ref mut subs_deposit, ref mut sub_ids)| {999 sub_ids.retain(|x| x != &sender);1000 let deposit = T::SubAccountDeposit::get().min(*subs_deposit);1001 *subs_deposit -= deposit;1002 let _ =1003 T::Currency::repatriate_reserved(&sup, &sender, deposit, BalanceStatus::Free);1004 Self::deposit_event(Event::SubIdentityRevoked {1005 sub: sender,1006 main: sup.clone(),1007 deposit,1008 });1009 });1010 Ok(())1011 }1012 }1013}10141015impl<T: Config> Pallet<T> {1016 /// Get the subs of an account.1017 pub fn subs(who: &T::AccountId) -> Vec<(T::AccountId, Data)> {1018 SubsOf::<T>::get(who)1019 .11020 .into_iter()1021 .filter_map(|a| SuperOf::<T>::get(&a).map(|x| (a, x.1)))1022 .collect()1023 }10241025 /// Check if the account has corresponding identity information by the identity field.1026 pub fn has_identity(who: &T::AccountId, fields: u64) -> bool {1027 IdentityOf::<T>::get(who)1028 .map_or(false, |registration| (registration.info.fields().0.bits() & fields) == fields)1029 }1030}pallets/identity/src/tests.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/src/tests.rs
@@ -0,0 +1,643 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network 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.
+
+// Unique Network 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 Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+// Original license:
+// This file is part of Substrate.
+
+// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Tests for Identity Pallet
+
+use super::*;
+use crate as pallet_identity;
+
+use codec::{Decode, Encode};
+use frame_support::{
+ assert_noop, assert_ok, ord_parameter_types, parameter_types,
+ traits::{ConstU32, ConstU64, EitherOfDiverse},
+ BoundedVec,
+};
+use frame_system::{EnsureRoot, EnsureSignedBy};
+use sp_core::H256;
+use sp_runtime::{
+ testing::Header,
+ traits::{BadOrigin, BlakeTwo256, IdentityLookup},
+};
+
+type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
+type Block = frame_system::mocking::MockBlock<Test>;
+
+frame_support::construct_runtime!(
+ pub enum Test where
+ Block = Block,
+ NodeBlock = Block,
+ UncheckedExtrinsic = UncheckedExtrinsic,
+ {
+ System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
+ Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
+ Identity: pallet_identity::{Pallet, Call, Storage, Event<T>},
+ }
+);
+
+parameter_types! {
+ pub BlockWeights: frame_system::limits::BlockWeights =
+ frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
+}
+impl frame_system::Config for Test {
+ type BaseCallFilter = frame_support::traits::Everything;
+ type BlockWeights = ();
+ type BlockLength = ();
+ type RuntimeOrigin = RuntimeOrigin;
+ type Index = u64;
+ type BlockNumber = u64;
+ type Hash = H256;
+ type RuntimeCall = RuntimeCall;
+ type Hashing = BlakeTwo256;
+ type AccountId = u64;
+ type Lookup = IdentityLookup<Self::AccountId>;
+ type Header = Header;
+ type RuntimeEvent = RuntimeEvent;
+ type BlockHashCount = ConstU64<250>;
+ type DbWeight = ();
+ type Version = ();
+ type PalletInfo = PalletInfo;
+ type AccountData = pallet_balances::AccountData<u64>;
+ type OnNewAccount = ();
+ type OnKilledAccount = ();
+ type SystemWeightInfo = ();
+ type SS58Prefix = ();
+ type OnSetCode = ();
+ type MaxConsumers = ConstU32<16>;
+}
+
+impl pallet_balances::Config for Test {
+ type Balance = u64;
+ type RuntimeEvent = RuntimeEvent;
+ type DustRemoval = ();
+ type ExistentialDeposit = ConstU64<1>;
+ type AccountStore = System;
+ type MaxLocks = ();
+ type MaxReserves = ();
+ type ReserveIdentifier = [u8; 8];
+ type WeightInfo = ();
+}
+
+parameter_types! {
+ pub const MaxAdditionalFields: u32 = 2;
+ pub const MaxRegistrars: u32 = 20;
+}
+
+ord_parameter_types! {
+ pub const One: u64 = 1;
+ pub const Two: u64 = 2;
+}
+type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
+type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;
+impl pallet_identity::Config for Test {
+ type RuntimeEvent = RuntimeEvent;
+ type Currency = Balances;
+ type Slashed = ();
+ type BasicDeposit = ConstU64<10>;
+ type FieldDeposit = ConstU64<10>;
+ type SubAccountDeposit = ConstU64<10>;
+ type MaxSubAccounts = ConstU32<2>;
+ type MaxAdditionalFields = MaxAdditionalFields;
+ type MaxRegistrars = MaxRegistrars;
+ type RegistrarOrigin = EnsureOneOrRoot;
+ type ForceOrigin = EnsureTwoOrRoot;
+ type WeightInfo = ();
+}
+
+pub fn new_test_ext() -> sp_io::TestExternalities {
+ let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
+ pallet_balances::GenesisConfig::<Test> {
+ balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],
+ }
+ .assimilate_storage(&mut t)
+ .unwrap();
+ t.into()
+}
+
+fn ten() -> IdentityInfo<MaxAdditionalFields> {
+ IdentityInfo {
+ display: Data::Raw(b"ten".to_vec().try_into().unwrap()),
+ legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),
+ ..Default::default()
+ }
+}
+
+fn twenty() -> IdentityInfo<MaxAdditionalFields> {
+ IdentityInfo {
+ display: Data::Raw(b"twenty".to_vec().try_into().unwrap()),
+ legal: Data::Raw(b"The Right Ordinal Twenty, Esq.".to_vec().try_into().unwrap()),
+ ..Default::default()
+ }
+}
+
+#[test]
+fn editing_subaccounts_should_work() {
+ new_test_ext().execute_with(|| {
+ let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());
+
+ assert_noop!(
+ Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),
+ Error::<Test>::NoIdentity
+ );
+
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+
+ // first sub account
+ assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
+ assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
+ assert_eq!(Balances::free_balance(10), 80);
+
+ // second sub account
+ assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));
+ assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
+ assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
+ assert_eq!(Balances::free_balance(10), 70);
+
+ // third sub account is too many
+ assert_noop!(
+ Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),
+ Error::<Test>::TooManySubAccounts
+ );
+
+ // rename first sub account
+ assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));
+ assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));
+ assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
+ assert_eq!(Balances::free_balance(10), 70);
+
+ // remove first sub account
+ assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));
+ assert_eq!(SuperOf::<Test>::get(1), None);
+ assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
+ assert_eq!(Balances::free_balance(10), 80);
+
+ // add third sub account
+ assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));
+ assert_eq!(SuperOf::<Test>::get(1), None);
+ assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
+ assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));
+ assert_eq!(Balances::free_balance(10), 70);
+ });
+}
+
+#[test]
+fn resolving_subaccount_ownership_works() {
+ new_test_ext().execute_with(|| {
+ let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());
+
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty())));
+
+ // 10 claims 1 as a subaccount
+ assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
+ assert_eq!(Balances::free_balance(1), 10);
+ assert_eq!(Balances::free_balance(10), 80);
+ assert_eq!(Balances::reserved_balance(10), 20);
+ // 20 cannot claim 1 now
+ assert_noop!(
+ Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),
+ Error::<Test>::AlreadyClaimed
+ );
+ // 1 wants to be with 20 so it quits from 10
+ assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));
+ // 1 gets the 10 that 10 paid.
+ assert_eq!(Balances::free_balance(1), 20);
+ assert_eq!(Balances::free_balance(10), 80);
+ assert_eq!(Balances::reserved_balance(10), 10);
+ // 20 can claim 1 now
+ assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));
+ });
+}
+
+#[test]
+fn trailing_zeros_decodes_into_default_data() {
+ let encoded = Data::Raw(b"Hello".to_vec().try_into().unwrap()).encode();
+ assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err());
+ let input = &mut &encoded[..];
+ let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap();
+ assert_eq!(a, Data::Raw(b"Hello".to_vec().try_into().unwrap()));
+ assert_eq!(b, Data::None);
+}
+
+#[test]
+fn adding_registrar_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);
+ assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));
+ assert_eq!(
+ Identity::registrars(),
+ vec![Some(RegistrarInfo { account: 3, fee: 10, fields })]
+ );
+ });
+}
+
+#[test]
+fn amount_of_registrars_is_limited() {
+ new_test_ext().execute_with(|| {
+ for i in 1..MaxRegistrars::get() + 1 {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));
+ }
+ let last_registrar = MaxRegistrars::get() as u64 + 1;
+ assert_noop!(
+ Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),
+ Error::<Test>::TooManyRegistrars
+ );
+ });
+}
+
+#[test]
+fn registration_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ let mut three_fields = ten();
+ three_fields.additional.try_push(Default::default()).unwrap();
+ three_fields.additional.try_push(Default::default()).unwrap();
+ assert!(three_fields.additional.try_push(Default::default()).is_err());
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_eq!(Identity::identity(10).unwrap().info, ten());
+ assert_eq!(Balances::free_balance(10), 90);
+ assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
+ assert_eq!(Balances::free_balance(10), 100);
+ assert_noop!(Identity::clear_identity(RuntimeOrigin::signed(10)), Error::<Test>::NotNamed);
+ });
+}
+
+#[test]
+fn uninvited_judgement_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ H256::random()
+ ),
+ Error::<Test>::InvalidIndex
+ );
+
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ H256::random()
+ ),
+ Error::<Test>::InvalidTarget
+ );
+
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ H256::random()
+ ),
+ Error::<Test>::JudgementForDifferentIdentity
+ );
+
+ let identity_hash = BlakeTwo256::hash_of(&ten());
+
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(10),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ identity_hash
+ ),
+ Error::<Test>::InvalidIndex
+ );
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::FeePaid(1),
+ identity_hash
+ ),
+ Error::<Test>::InvalidJudgement
+ );
+
+ assert_ok!(Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ identity_hash
+ ));
+ assert_eq!(Identity::identity(10).unwrap().judgements, vec![(0, Judgement::Reasonable)]);
+ });
+}
+
+#[test]
+fn clearing_judgement_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ BlakeTwo256::hash_of(&ten())
+ ));
+ assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
+ assert_eq!(Identity::identity(10), None);
+ });
+}
+
+#[test]
+fn killing_slashing_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_noop!(Identity::kill_identity(RuntimeOrigin::signed(1), 10), BadOrigin);
+ assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
+ assert_eq!(Identity::identity(10), None);
+ assert_eq!(Balances::free_balance(10), 90);
+ assert_noop!(
+ Identity::kill_identity(RuntimeOrigin::signed(2), 10),
+ Error::<Test>::NotNamed
+ );
+ });
+}
+
+#[test]
+fn setting_subaccounts_should_work() {
+ new_test_ext().execute_with(|| {
+ let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];
+ assert_noop!(
+ Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),
+ Error::<Test>::NotFound
+ );
+
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
+ assert_eq!(Balances::free_balance(10), 80);
+ assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));
+ assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
+
+ // push another item and re-set it.
+ subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));
+ assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
+ assert_eq!(Balances::free_balance(10), 70);
+ assert_eq!(Identity::subs_of(10), (20, vec![20, 30].try_into().unwrap()));
+ assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
+ assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap()))));
+
+ // switch out one of the items and re-set.
+ subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));
+ assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
+ assert_eq!(Balances::free_balance(10), 70); // no change in the balance
+ assert_eq!(Identity::subs_of(10), (20, vec![40, 30].try_into().unwrap()));
+ assert_eq!(Identity::super_of(20), None);
+ assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap()))));
+ assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1].try_into().unwrap()))));
+
+ // clear
+ assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));
+ assert_eq!(Balances::free_balance(10), 90);
+ assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));
+ assert_eq!(Identity::super_of(30), None);
+ assert_eq!(Identity::super_of(40), None);
+
+ subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));
+ assert_noop!(
+ Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),
+ Error::<Test>::TooManySubAccounts
+ );
+ });
+}
+
+#[test]
+fn clearing_account_should_remove_subaccounts_and_refund() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::set_subs(
+ RuntimeOrigin::signed(10),
+ vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
+ ));
+ assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
+ assert_eq!(Balances::free_balance(10), 100);
+ assert!(Identity::super_of(20).is_none());
+ });
+}
+
+#[test]
+fn killing_account_should_remove_subaccounts_and_not_refund() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::set_subs(
+ RuntimeOrigin::signed(10),
+ vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
+ ));
+ assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
+ assert_eq!(Balances::free_balance(10), 80);
+ assert!(Identity::super_of(20).is_none());
+ });
+}
+
+#[test]
+fn cancelling_requested_judgement_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ assert_noop!(
+ Identity::cancel_request(RuntimeOrigin::signed(10), 0),
+ Error::<Test>::NoIdentity
+ );
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
+ assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));
+ assert_eq!(Balances::free_balance(10), 90);
+ assert_noop!(
+ Identity::cancel_request(RuntimeOrigin::signed(10), 0),
+ Error::<Test>::NotFound
+ );
+
+ assert_ok!(Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Reasonable,
+ BlakeTwo256::hash_of(&ten())
+ ));
+ assert_noop!(
+ Identity::cancel_request(RuntimeOrigin::signed(10), 0),
+ Error::<Test>::JudgementGiven
+ );
+ });
+}
+
+#[test]
+fn requesting_judgement_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_noop!(
+ Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),
+ Error::<Test>::FeeChanged
+ );
+ assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
+ // 10 for the judgement request, 10 for the identity.
+ assert_eq!(Balances::free_balance(10), 80);
+
+ // Re-requesting won't work as we already paid.
+ assert_noop!(
+ Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),
+ Error::<Test>::StickyJudgement
+ );
+ assert_ok!(Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Erroneous,
+ BlakeTwo256::hash_of(&ten())
+ ));
+ // Registrar got their payment now.
+ assert_eq!(Balances::free_balance(3), 20);
+
+ // Re-requesting still won't work as it's erroneous.
+ assert_noop!(
+ Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),
+ Error::<Test>::StickyJudgement
+ );
+
+ // Requesting from a second registrar still works.
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));
+ assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 1, 10));
+
+ // Re-requesting after the judgement has been reduced works.
+ assert_ok!(Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::OutOfDate,
+ BlakeTwo256::hash_of(&ten())
+ ));
+ assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
+ });
+}
+
+#[test]
+fn provide_judgement_should_return_judgement_payment_failed_error() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
+ // 10 for the judgement request, 10 for the identity.
+ assert_eq!(Balances::free_balance(10), 80);
+
+ // This forces judgement payment failed error
+ Balances::make_free_balance_be(&3, 0);
+ assert_noop!(
+ Identity::provide_judgement(
+ RuntimeOrigin::signed(3),
+ 0,
+ 10,
+ Judgement::Erroneous,
+ BlakeTwo256::hash_of(&ten())
+ ),
+ Error::<Test>::JudgementPaymentFailed
+ );
+ });
+}
+
+#[test]
+fn field_deposit_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
+ assert_ok!(Identity::set_identity(
+ RuntimeOrigin::signed(10),
+ Box::new(IdentityInfo {
+ additional: vec![
+ (
+ Data::Raw(b"number".to_vec().try_into().unwrap()),
+ Data::Raw(10u32.encode().try_into().unwrap())
+ ),
+ (
+ Data::Raw(b"text".to_vec().try_into().unwrap()),
+ Data::Raw(b"10".to_vec().try_into().unwrap())
+ ),
+ ]
+ .try_into()
+ .unwrap(),
+ ..Default::default()
+ })
+ ));
+ assert_eq!(Balances::free_balance(10), 70);
+ });
+}
+
+#[test]
+fn setting_account_id_should_work() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
+ // account 4 cannot change the first registrar's identity since it's owned by 3.
+ assert_noop!(
+ Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),
+ Error::<Test>::InvalidIndex
+ );
+ // account 3 can, because that's the registrar's current account.
+ assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));
+ // account 4 can now, because that's their new ID.
+ assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));
+ });
+}
+
+#[test]
+fn test_has_identity() {
+ new_test_ext().execute_with(|| {
+ assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
+ assert!(Identity::has_identity(&10, IdentityField::Display as u64));
+ assert!(Identity::has_identity(&10, IdentityField::Legal as u64));
+ assert!(Identity::has_identity(
+ &10,
+ IdentityField::Display as u64 | IdentityField::Legal as u64
+ ));
+ assert!(!Identity::has_identity(
+ &10,
+ IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64
+ ));
+ });
+}
pallets/identity/src/types.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/src/types.rs
@@ -0,0 +1,518 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network 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.
+
+// Unique Network 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 Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+// Original license:
+// This file is part of Substrate.
+
+// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+use super::*;
+use codec::{Decode, Encode, MaxEncodedLen};
+use enumflags2::{bitflags, BitFlags};
+use frame_support::{
+ traits::{ConstU32, Get},
+ BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound,
+};
+use scale_info::{
+ build::{Fields, Variants},
+ meta_type, Path, Type, TypeInfo, TypeParameter,
+};
+use sp_runtime::{traits::Zero, RuntimeDebug};
+use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*};
+
+/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
+/// than 32-bytes then it will be truncated when encoding.
+///
+/// Can also be `None`.
+#[derive(Clone, Eq, PartialEq, RuntimeDebug, MaxEncodedLen)]
+pub enum Data {
+ /// No data here.
+ None,
+ /// The data is stored directly.
+ Raw(BoundedVec<u8, ConstU32<32>>),
+ /// Only the Blake2 hash of the data is stored. The preimage of the hash may be retrieved
+ /// through some hash-lookup service.
+ BlakeTwo256([u8; 32]),
+ /// Only the SHA2-256 hash of the data is stored. The preimage of the hash may be retrieved
+ /// through some hash-lookup service.
+ Sha256([u8; 32]),
+ /// Only the Keccak-256 hash of the data is stored. The preimage of the hash may be retrieved
+ /// through some hash-lookup service.
+ Keccak256([u8; 32]),
+ /// Only the SHA3-256 hash of the data is stored. The preimage of the hash may be retrieved
+ /// through some hash-lookup service.
+ ShaThree256([u8; 32]),
+}
+
+impl Data {
+ pub fn is_none(&self) -> bool {
+ self == &Data::None
+ }
+}
+
+impl Decode for Data {
+ fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
+ let b = input.read_byte()?;
+ Ok(match b {
+ 0 => Data::None,
+ n @ 1..=33 => {
+ let mut r: BoundedVec<_, _> = vec![0u8; n as usize - 1]
+ .try_into()
+ .expect("bound checked in match arm condition; qed");
+ input.read(&mut r[..])?;
+ Data::Raw(r)
+ },
+ 34 => Data::BlakeTwo256(<[u8; 32]>::decode(input)?),
+ 35 => Data::Sha256(<[u8; 32]>::decode(input)?),
+ 36 => Data::Keccak256(<[u8; 32]>::decode(input)?),
+ 37 => Data::ShaThree256(<[u8; 32]>::decode(input)?),
+ _ => return Err(codec::Error::from("invalid leading byte")),
+ })
+ }
+}
+
+impl Encode for Data {
+ fn encode(&self) -> Vec<u8> {
+ match self {
+ Data::None => vec![0u8; 1],
+ Data::Raw(ref x) => {
+ let l = x.len().min(32);
+ let mut r = vec![l as u8 + 1; l + 1];
+ r[1..].copy_from_slice(&x[..l as usize]);
+ r
+ },
+ Data::BlakeTwo256(ref h) => once(34u8).chain(h.iter().cloned()).collect(),
+ Data::Sha256(ref h) => once(35u8).chain(h.iter().cloned()).collect(),
+ Data::Keccak256(ref h) => once(36u8).chain(h.iter().cloned()).collect(),
+ Data::ShaThree256(ref h) => once(37u8).chain(h.iter().cloned()).collect(),
+ }
+ }
+}
+impl codec::EncodeLike for Data {}
+
+/// Add a Raw variant with the given index and a fixed sized byte array
+macro_rules! data_raw_variants {
+ ($variants:ident, $(($index:literal, $size:literal)),* ) => {
+ $variants
+ $(
+ .variant(concat!("Raw", stringify!($size)), |v| v
+ .index($index)
+ .fields(Fields::unnamed().field(|f| f.ty::<[u8; $size]>()))
+ )
+ )*
+ }
+}
+
+impl TypeInfo for Data {
+ type Identity = Self;
+
+ fn type_info() -> Type {
+ let variants = Variants::new().variant("None", |v| v.index(0));
+
+ // create a variant for all sizes of Raw data from 0-32
+ let variants = data_raw_variants!(
+ variants,
+ (1, 0),
+ (2, 1),
+ (3, 2),
+ (4, 3),
+ (5, 4),
+ (6, 5),
+ (7, 6),
+ (8, 7),
+ (9, 8),
+ (10, 9),
+ (11, 10),
+ (12, 11),
+ (13, 12),
+ (14, 13),
+ (15, 14),
+ (16, 15),
+ (17, 16),
+ (18, 17),
+ (19, 18),
+ (20, 19),
+ (21, 20),
+ (22, 21),
+ (23, 22),
+ (24, 23),
+ (25, 24),
+ (26, 25),
+ (27, 26),
+ (28, 27),
+ (29, 28),
+ (30, 29),
+ (31, 30),
+ (32, 31),
+ (33, 32)
+ );
+
+ let variants = variants
+ .variant("BlakeTwo256", |v| {
+ v.index(34).fields(Fields::unnamed().field(|f| f.ty::<[u8; 32]>()))
+ })
+ .variant("Sha256", |v| {
+ v.index(35).fields(Fields::unnamed().field(|f| f.ty::<[u8; 32]>()))
+ })
+ .variant("Keccak256", |v| {
+ v.index(36).fields(Fields::unnamed().field(|f| f.ty::<[u8; 32]>()))
+ })
+ .variant("ShaThree256", |v| {
+ v.index(37).fields(Fields::unnamed().field(|f| f.ty::<[u8; 32]>()))
+ });
+
+ Type::builder().path(Path::new("Data", module_path!())).variant(variants)
+ }
+}
+
+impl Default for Data {
+ fn default() -> Self {
+ Self::None
+ }
+}
+
+/// An identifier for a single name registrar/identity verification service.
+pub type RegistrarIndex = u32;
+
+/// An attestation of a registrar over how accurate some `IdentityInfo` is in describing an account.
+///
+/// NOTE: Registrars may pay little attention to some fields. Registrars may want to make clear
+/// which fields their attestation is relevant for by off-chain means.
+#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
+pub enum Judgement<Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq>
+{
+ /// The default value; no opinion is held.
+ Unknown,
+ /// No judgement is yet in place, but a deposit is reserved as payment for providing one.
+ FeePaid(Balance),
+ /// The data appears to be reasonably acceptable in terms of its accuracy, however no in depth
+ /// checks (such as in-person meetings or formal KYC) have been conducted.
+ Reasonable,
+ /// The target is known directly by the registrar and the registrar can fully attest to the
+ /// the data's accuracy.
+ KnownGood,
+ /// The data was once good but is currently out of date. There is no malicious intent in the
+ /// inaccuracy. This judgement can be removed through updating the data.
+ OutOfDate,
+ /// The data is imprecise or of sufficiently low-quality to be problematic. It is not
+ /// indicative of malicious intent. This judgement can be removed through updating the data.
+ LowQuality,
+ /// The data is erroneous. This may be indicative of malicious intent. This cannot be removed
+ /// except by the registrar.
+ Erroneous,
+}
+
+impl<Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq>
+ Judgement<Balance>
+{
+ /// Returns `true` if this judgement is indicative of a deposit being currently held. This means
+ /// it should not be cleared or replaced except by an operation which utilizes the deposit.
+ pub(crate) fn has_deposit(&self) -> bool {
+ matches!(self, Judgement::FeePaid(_))
+ }
+
+ /// Returns `true` if this judgement is one that should not be generally be replaced outside
+ /// of specialized handlers. Examples include "malicious" judgements and deposit-holding
+ /// judgements.
+ pub(crate) fn is_sticky(&self) -> bool {
+ matches!(self, Judgement::FeePaid(_) | Judgement::Erroneous)
+ }
+}
+
+/// The fields that we use to identify the owner of an account with. Each corresponds to a field
+/// in the `IdentityInfo` struct.
+#[bitflags]
+#[repr(u64)]
+#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
+pub enum IdentityField {
+ Display = 0b0000000000000000000000000000000000000000000000000000000000000001,
+ Legal = 0b0000000000000000000000000000000000000000000000000000000000000010,
+ Web = 0b0000000000000000000000000000000000000000000000000000000000000100,
+ Riot = 0b0000000000000000000000000000000000000000000000000000000000001000,
+ Email = 0b0000000000000000000000000000000000000000000000000000000000010000,
+ PgpFingerprint = 0b0000000000000000000000000000000000000000000000000000000000100000,
+ Image = 0b0000000000000000000000000000000000000000000000000000000001000000,
+ Twitter = 0b0000000000000000000000000000000000000000000000000000000010000000,
+}
+
+/// Wrapper type for `BitFlags<IdentityField>` that implements `Codec`.
+#[derive(Clone, Copy, PartialEq, Default, RuntimeDebug)]
+pub struct IdentityFields(pub BitFlags<IdentityField>);
+
+impl MaxEncodedLen for IdentityFields {
+ fn max_encoded_len() -> usize {
+ u64::max_encoded_len()
+ }
+}
+
+impl Eq for IdentityFields {}
+impl Encode for IdentityFields {
+ fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
+ self.0.bits().using_encoded(f)
+ }
+}
+impl Decode for IdentityFields {
+ fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
+ let field = u64::decode(input)?;
+ Ok(Self(<BitFlags<IdentityField>>::from_bits(field as u64).map_err(|_| "invalid value")?))
+ }
+}
+impl TypeInfo for IdentityFields {
+ type Identity = Self;
+
+ fn type_info() -> Type {
+ Type::builder()
+ .path(Path::new("BitFlags", module_path!()))
+ .type_params(vec![TypeParameter::new("T", Some(meta_type::<IdentityField>()))])
+ .composite(Fields::unnamed().field(|f| f.ty::<u64>().type_name("IdentityField")))
+ }
+}
+
+/// Information concerning the identity of the controller of an account.
+///
+/// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra
+/// fields in a backwards compatible way through a specialized `Decode` impl.
+#[derive(
+ CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
+)]
+#[codec(mel_bound())]
+#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
+#[scale_info(skip_type_params(FieldLimit))]
+pub struct IdentityInfo<FieldLimit: Get<u32>> {
+ /// Additional fields of the identity that are not catered for with the struct's explicit
+ /// fields.
+ pub additional: BoundedVec<(Data, Data), FieldLimit>,
+
+ /// A reasonable display name for the controller of the account. This should be whatever it is
+ /// that it is typically known as and should not be confusable with other entities, given
+ /// reasonable context.
+ ///
+ /// Stored as UTF-8.
+ pub display: Data,
+
+ /// The full legal name in the local jurisdiction of the entity. This might be a bit
+ /// long-winded.
+ ///
+ /// Stored as UTF-8.
+ pub legal: Data,
+
+ /// A representative website held by the controller of the account.
+ ///
+ /// NOTE: `https://` is automatically prepended.
+ ///
+ /// Stored as UTF-8.
+ pub web: Data,
+
+ /// The Riot/Matrix handle held by the controller of the account.
+ ///
+ /// Stored as UTF-8.
+ pub riot: Data,
+
+ /// The email address of the controller of the account.
+ ///
+ /// Stored as UTF-8.
+ pub email: Data,
+
+ /// The PGP/GPG public key of the controller of the account.
+ pub pgp_fingerprint: Option<[u8; 20]>,
+
+ /// A graphic image representing the controller of the account. Should be a company,
+ /// organization or project logo or a headshot in the case of a human.
+ pub image: Data,
+
+ /// The Twitter identity. The leading `@` character may be elided.
+ pub twitter: Data,
+}
+
+impl<FieldLimit: Get<u32>> IdentityInfo<FieldLimit> {
+ pub(crate) fn fields(&self) -> IdentityFields {
+ let mut res = <BitFlags<IdentityField>>::empty();
+ if !self.display.is_none() {
+ res.insert(IdentityField::Display);
+ }
+ if !self.legal.is_none() {
+ res.insert(IdentityField::Legal);
+ }
+ if !self.web.is_none() {
+ res.insert(IdentityField::Web);
+ }
+ if !self.riot.is_none() {
+ res.insert(IdentityField::Riot);
+ }
+ if !self.email.is_none() {
+ res.insert(IdentityField::Email);
+ }
+ if self.pgp_fingerprint.is_some() {
+ res.insert(IdentityField::PgpFingerprint);
+ }
+ if !self.image.is_none() {
+ res.insert(IdentityField::Image);
+ }
+ if !self.twitter.is_none() {
+ res.insert(IdentityField::Twitter);
+ }
+ IdentityFields(res)
+ }
+}
+
+/// Information concerning the identity of the controller of an account.
+///
+/// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a
+/// backwards compatible way through a specialized `Decode` impl.
+#[derive(
+ CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
+)]
+#[codec(mel_bound())]
+#[scale_info(skip_type_params(MaxJudgements, MaxAdditionalFields))]
+pub struct Registration<
+ Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq,
+ MaxJudgements: Get<u32>,
+ MaxAdditionalFields: Get<u32>,
+> {
+ /// Judgements from the registrars on this identity. Stored ordered by `RegistrarIndex`. There
+ /// may be only a single judgement from each registrar.
+ pub judgements: BoundedVec<(RegistrarIndex, Judgement<Balance>), MaxJudgements>,
+
+ /// Amount held on deposit for this information.
+ pub deposit: Balance,
+
+ /// Information on the identity.
+ pub info: IdentityInfo<MaxAdditionalFields>,
+}
+
+impl<
+ Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq + Zero + Add,
+ MaxJudgements: Get<u32>,
+ MaxAdditionalFields: Get<u32>,
+ > Registration<Balance, MaxJudgements, MaxAdditionalFields>
+{
+ pub(crate) fn total_deposit(&self) -> Balance {
+ self.deposit +
+ self.judgements
+ .iter()
+ .map(|(_, ref j)| if let Judgement::FeePaid(fee) = j { *fee } else { Zero::zero() })
+ .fold(Zero::zero(), |a, i| a + i)
+ }
+}
+
+impl<
+ Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq,
+ MaxJudgements: Get<u32>,
+ MaxAdditionalFields: Get<u32>,
+ > Decode for Registration<Balance, MaxJudgements, MaxAdditionalFields>
+{
+ fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
+ let (judgements, deposit, info) = Decode::decode(&mut AppendZerosInput::new(input))?;
+ Ok(Self { judgements, deposit, info })
+ }
+}
+
+/// Information concerning a registrar.
+#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
+pub struct RegistrarInfo<
+ Balance: Encode + Decode + Clone + Debug + Eq + PartialEq,
+ AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq,
+> {
+ /// The account of the registrar.
+ pub account: AccountId,
+
+ /// Amount required to be given to the registrar for them to provide judgement.
+ pub fee: Balance,
+
+ /// Relevant fields for this registrar. Registrar judgements are limited to attestations on
+ /// these fields.
+ pub fields: IdentityFields,
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn manual_data_type_info() {
+ let mut registry = scale_info::Registry::new();
+ let type_id = registry.register_type(&scale_info::meta_type::<Data>());
+ let registry: scale_info::PortableRegistry = registry.into();
+ let type_info = registry.resolve(type_id.id()).unwrap();
+
+ let check_type_info = |data: &Data| {
+ let variant_name = match data {
+ Data::None => "None".to_string(),
+ Data::BlakeTwo256(_) => "BlakeTwo256".to_string(),
+ Data::Sha256(_) => "Sha256".to_string(),
+ Data::Keccak256(_) => "Keccak256".to_string(),
+ Data::ShaThree256(_) => "ShaThree256".to_string(),
+ Data::Raw(bytes) => format!("Raw{}", bytes.len()),
+ };
+ if let scale_info::TypeDef::Variant(variant) = type_info.type_def() {
+ let variant = variant
+ .variants()
+ .iter()
+ .find(|v| v.name() == &variant_name)
+ .expect(&format!("Expected to find variant {}", variant_name));
+
+ let field_arr_len = variant
+ .fields()
+ .first()
+ .and_then(|f| registry.resolve(f.ty().id()))
+ .map(|ty| {
+ if let scale_info::TypeDef::Array(arr) = ty.type_def() {
+ arr.len()
+ } else {
+ panic!("Should be an array type")
+ }
+ })
+ .unwrap_or(0);
+
+ let encoded = data.encode();
+ assert_eq!(encoded[0], variant.index());
+ assert_eq!(encoded.len() as u32 - 1, field_arr_len);
+ } else {
+ panic!("Should be a variant type")
+ };
+ };
+
+ let mut data = vec![
+ Data::None,
+ Data::BlakeTwo256(Default::default()),
+ Data::Sha256(Default::default()),
+ Data::Keccak256(Default::default()),
+ Data::ShaThree256(Default::default()),
+ ];
+
+ // A Raw instance for all possible sizes of the Raw data
+ for n in 0..32 {
+ data.push(Data::Raw(vec![0u8; n as usize].try_into().unwrap()))
+ }
+
+ for d in data.iter() {
+ check_type_info(d);
+ }
+ }
+}
pallets/identity/src/weights.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/identity/src/weights.rs
@@ -0,0 +1,504 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network 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.
+
+// Unique Network 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 Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+// Original license:
+// This file is part of Substrate.
+
+// Copyright (C) 2022 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Autogenerated weights for pallet_identity
+//!
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
+//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
+//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
+
+// Executed Command:
+// ./target/production/substrate
+// benchmark
+// pallet
+// --chain=dev
+// --steps=50
+// --repeat=20
+// --pallet=pallet_identity
+// --extrinsic=*
+// --execution=wasm
+// --wasm-execution=compiled
+// --heap-pages=4096
+// --output=./frame/identity/src/weights.rs
+// --header=./HEADER-APACHE2
+// --template=./.maintain/frame-weight-template.hbs
+
+#![cfg_attr(rustfmt, rustfmt_skip)]
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+
+use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
+use sp_std::marker::PhantomData;
+
+/// Weight functions needed for pallet_identity.
+pub trait WeightInfo {
+ fn add_registrar(r: u32, ) -> Weight;
+ fn set_identity(r: u32, x: u32, ) -> Weight;
+ fn set_subs_new(s: u32, ) -> Weight;
+ fn set_subs_old(p: u32, ) -> Weight;
+ fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight;
+ fn request_judgement(r: u32, x: u32, ) -> Weight;
+ fn cancel_request(r: u32, x: u32, ) -> Weight;
+ fn set_fee(r: u32, ) -> Weight;
+ fn set_account_id(r: u32, ) -> Weight;
+ fn set_fields(r: u32, ) -> Weight;
+ fn provide_judgement(r: u32, x: u32, ) -> Weight;
+ fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;
+ fn add_sub(s: u32, ) -> Weight;
+ fn rename_sub(s: u32, ) -> Weight;
+ fn remove_sub(s: u32, ) -> Weight;
+ fn quit_sub(s: u32, ) -> Weight;
+}
+
+/// Weights for pallet_identity using the Substrate node and recommended hardware.
+pub struct SubstrateWeight<T>(PhantomData<T>);
+impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn add_registrar(r: u32, ) -> Weight {
+ // Minimum execution time: 20_269 nanoseconds.
+ Weight::from_ref_time(21_910_543 as u64)
+ // Standard Error: 4_604
+ .saturating_add(Weight::from_ref_time(223_104 as u64).saturating_mul(r as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn set_identity(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 41_872 nanoseconds.
+ Weight::from_ref_time(40_230_216 as u64)
+ // Standard Error: 2_342
+ .saturating_add(Weight::from_ref_time(145_168 as u64).saturating_mul(r as u64))
+ // Standard Error: 457
+ .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:2 w:2)
+ /// The range of component `s` is `[0, 100]`.
+ fn set_subs_new(s: u32, ) -> Weight {
+ // Minimum execution time: 12_024 nanoseconds.
+ Weight::from_ref_time(32_550_819 as u64)
+ // Standard Error: 5_057
+ .saturating_add(Weight::from_ref_time(2_521_245 as u64).saturating_mul(s as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(s as u64)))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:2)
+ /// The range of component `p` is `[0, 100]`.
+ fn set_subs_old(p: u32, ) -> Weight {
+ // Minimum execution time: 12_232 nanoseconds.
+ Weight::from_ref_time(34_009_761 as u64)
+ // Standard Error: 5_047
+ .saturating_add(Weight::from_ref_time(1_113_100 as u64).saturating_mul(p as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(p as u64)))
+ }
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:100)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `s` is `[0, 100]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 57_144 nanoseconds.
+ Weight::from_ref_time(41_559_247 as u64)
+ // Standard Error: 9_996
+ .saturating_add(Weight::from_ref_time(146_770 as u64).saturating_mul(r as u64))
+ // Standard Error: 1_952
+ .saturating_add(Weight::from_ref_time(1_086_673 as u64).saturating_mul(s as u64))
+ // Standard Error: 1_952
+ .saturating_add(Weight::from_ref_time(162_481 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(2 as u64))
+ .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity Registrars (r:1 w:0)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn request_judgement(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 44_726 nanoseconds.
+ Weight::from_ref_time(41_637_308 as u64)
+ // Standard Error: 1_907
+ .saturating_add(Weight::from_ref_time(219_078 as u64).saturating_mul(r as u64))
+ // Standard Error: 372
+ .saturating_add(Weight::from_ref_time(309_888 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn cancel_request(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 39_719 nanoseconds.
+ Weight::from_ref_time(38_008_751 as u64)
+ // Standard Error: 2_394
+ .saturating_add(Weight::from_ref_time(181_870 as u64).saturating_mul(r as u64))
+ // Standard Error: 467
+ .saturating_add(Weight::from_ref_time(314_990 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_fee(r: u32, ) -> Weight {
+ // Minimum execution time: 10_634 nanoseconds.
+ Weight::from_ref_time(11_383_704 as u64)
+ // Standard Error: 2_250
+ .saturating_add(Weight::from_ref_time(193_094 as u64).saturating_mul(r as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_account_id(r: u32, ) -> Weight {
+ // Minimum execution time: 10_840 nanoseconds.
+ Weight::from_ref_time(11_638_740 as u64)
+ // Standard Error: 1_985
+ .saturating_add(Weight::from_ref_time(193_016 as u64).saturating_mul(r as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_fields(r: u32, ) -> Weight {
+ // Minimum execution time: 10_748 nanoseconds.
+ Weight::from_ref_time(11_346_901 as u64)
+ // Standard Error: 2_132
+ .saturating_add(Weight::from_ref_time(196_630 as u64).saturating_mul(r as u64))
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:0)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn provide_judgement(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 33_682 nanoseconds.
+ Weight::from_ref_time(31_336_603 as u64)
+ // Standard Error: 3_056
+ .saturating_add(Weight::from_ref_time(200_403 as u64).saturating_mul(r as u64))
+ // Standard Error: 565
+ .saturating_add(Weight::from_ref_time(525_142 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ // Storage: System Account (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:100)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `s` is `[0, 100]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 68_794 nanoseconds.
+ Weight::from_ref_time(52_114_486 as u64)
+ // Standard Error: 4_808
+ .saturating_add(Weight::from_ref_time(153_462 as u64).saturating_mul(r as u64))
+ // Standard Error: 939
+ .saturating_add(Weight::from_ref_time(1_084_612 as u64).saturating_mul(s as u64))
+ // Standard Error: 939
+ .saturating_add(Weight::from_ref_time(170_112 as u64).saturating_mul(x as u64))
+ .saturating_add(T::DbWeight::get().reads(3 as u64))
+ .saturating_add(T::DbWeight::get().writes(3 as u64))
+ .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[0, 99]`.
+ fn add_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 37_914 nanoseconds.
+ Weight::from_ref_time(43_488_083 as u64)
+ // Standard Error: 1_631
+ .saturating_add(Weight::from_ref_time(118_845 as u64).saturating_mul(s as u64))
+ .saturating_add(T::DbWeight::get().reads(3 as u64))
+ .saturating_add(T::DbWeight::get().writes(2 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ /// The range of component `s` is `[1, 100]`.
+ fn rename_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 16_124 nanoseconds.
+ Weight::from_ref_time(18_580_462 as u64)
+ // Standard Error: 688
+ .saturating_add(Weight::from_ref_time(67_220 as u64).saturating_mul(s as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[1, 100]`.
+ fn remove_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 41_517 nanoseconds.
+ Weight::from_ref_time(45_123_530 as u64)
+ // Standard Error: 1_530
+ .saturating_add(Weight::from_ref_time(105_429 as u64).saturating_mul(s as u64))
+ .saturating_add(T::DbWeight::get().reads(3 as u64))
+ .saturating_add(T::DbWeight::get().writes(2 as u64))
+ }
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[0, 99]`.
+ fn quit_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 30_171 nanoseconds.
+ Weight::from_ref_time(33_355_514 as u64)
+ // Standard Error: 1_286
+ .saturating_add(Weight::from_ref_time(114_716 as u64).saturating_mul(s as u64))
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(2 as u64))
+ }
+}
+
+// For backwards compatibility and tests
+impl WeightInfo for () {
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn add_registrar(r: u32, ) -> Weight {
+ // Minimum execution time: 20_269 nanoseconds.
+ Weight::from_ref_time(21_910_543 as u64)
+ // Standard Error: 4_604
+ .saturating_add(Weight::from_ref_time(223_104 as u64).saturating_mul(r as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn set_identity(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 41_872 nanoseconds.
+ Weight::from_ref_time(40_230_216 as u64)
+ // Standard Error: 2_342
+ .saturating_add(Weight::from_ref_time(145_168 as u64).saturating_mul(r as u64))
+ // Standard Error: 457
+ .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:2 w:2)
+ /// The range of component `s` is `[0, 100]`.
+ fn set_subs_new(s: u32, ) -> Weight {
+ // Minimum execution time: 12_024 nanoseconds.
+ Weight::from_ref_time(32_550_819 as u64)
+ // Standard Error: 5_057
+ .saturating_add(Weight::from_ref_time(2_521_245 as u64).saturating_mul(s as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(s as u64)))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:2)
+ /// The range of component `p` is `[0, 100]`.
+ fn set_subs_old(p: u32, ) -> Weight {
+ // Minimum execution time: 12_232 nanoseconds.
+ Weight::from_ref_time(34_009_761 as u64)
+ // Standard Error: 5_047
+ .saturating_add(Weight::from_ref_time(1_113_100 as u64).saturating_mul(p as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(p as u64)))
+ }
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:100)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `s` is `[0, 100]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 57_144 nanoseconds.
+ Weight::from_ref_time(41_559_247 as u64)
+ // Standard Error: 9_996
+ .saturating_add(Weight::from_ref_time(146_770 as u64).saturating_mul(r as u64))
+ // Standard Error: 1_952
+ .saturating_add(Weight::from_ref_time(1_086_673 as u64).saturating_mul(s as u64))
+ // Standard Error: 1_952
+ .saturating_add(Weight::from_ref_time(162_481 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity Registrars (r:1 w:0)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn request_judgement(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 44_726 nanoseconds.
+ Weight::from_ref_time(41_637_308 as u64)
+ // Standard Error: 1_907
+ .saturating_add(Weight::from_ref_time(219_078 as u64).saturating_mul(r as u64))
+ // Standard Error: 372
+ .saturating_add(Weight::from_ref_time(309_888 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn cancel_request(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 39_719 nanoseconds.
+ Weight::from_ref_time(38_008_751 as u64)
+ // Standard Error: 2_394
+ .saturating_add(Weight::from_ref_time(181_870 as u64).saturating_mul(r as u64))
+ // Standard Error: 467
+ .saturating_add(Weight::from_ref_time(314_990 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_fee(r: u32, ) -> Weight {
+ // Minimum execution time: 10_634 nanoseconds.
+ Weight::from_ref_time(11_383_704 as u64)
+ // Standard Error: 2_250
+ .saturating_add(Weight::from_ref_time(193_094 as u64).saturating_mul(r as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_account_id(r: u32, ) -> Weight {
+ // Minimum execution time: 10_840 nanoseconds.
+ Weight::from_ref_time(11_638_740 as u64)
+ // Standard Error: 1_985
+ .saturating_add(Weight::from_ref_time(193_016 as u64).saturating_mul(r as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ fn set_fields(r: u32, ) -> Weight {
+ // Minimum execution time: 10_748 nanoseconds.
+ Weight::from_ref_time(11_346_901 as u64)
+ // Standard Error: 2_132
+ .saturating_add(Weight::from_ref_time(196_630 as u64).saturating_mul(r as u64))
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity Registrars (r:1 w:0)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ /// The range of component `r` is `[1, 19]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn provide_judgement(r: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 33_682 nanoseconds.
+ Weight::from_ref_time(31_336_603 as u64)
+ // Standard Error: 3_056
+ .saturating_add(Weight::from_ref_time(200_403 as u64).saturating_mul(r as u64))
+ // Standard Error: 565
+ .saturating_add(Weight::from_ref_time(525_142 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity SubsOf (r:1 w:1)
+ // Storage: Identity IdentityOf (r:1 w:1)
+ // Storage: System Account (r:1 w:1)
+ // Storage: Identity SuperOf (r:0 w:100)
+ /// The range of component `r` is `[1, 20]`.
+ /// The range of component `s` is `[0, 100]`.
+ /// The range of component `x` is `[0, 100]`.
+ fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight {
+ // Minimum execution time: 68_794 nanoseconds.
+ Weight::from_ref_time(52_114_486 as u64)
+ // Standard Error: 4_808
+ .saturating_add(Weight::from_ref_time(153_462 as u64).saturating_mul(r as u64))
+ // Standard Error: 939
+ .saturating_add(Weight::from_ref_time(1_084_612 as u64).saturating_mul(s as u64))
+ // Standard Error: 939
+ .saturating_add(Weight::from_ref_time(170_112 as u64).saturating_mul(x as u64))
+ .saturating_add(RocksDbWeight::get().reads(3 as u64))
+ .saturating_add(RocksDbWeight::get().writes(3 as u64))
+ .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[0, 99]`.
+ fn add_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 37_914 nanoseconds.
+ Weight::from_ref_time(43_488_083 as u64)
+ // Standard Error: 1_631
+ .saturating_add(Weight::from_ref_time(118_845 as u64).saturating_mul(s as u64))
+ .saturating_add(RocksDbWeight::get().reads(3 as u64))
+ .saturating_add(RocksDbWeight::get().writes(2 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ /// The range of component `s` is `[1, 100]`.
+ fn rename_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 16_124 nanoseconds.
+ Weight::from_ref_time(18_580_462 as u64)
+ // Standard Error: 688
+ .saturating_add(Weight::from_ref_time(67_220 as u64).saturating_mul(s as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Identity IdentityOf (r:1 w:0)
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[1, 100]`.
+ fn remove_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 41_517 nanoseconds.
+ Weight::from_ref_time(45_123_530 as u64)
+ // Standard Error: 1_530
+ .saturating_add(Weight::from_ref_time(105_429 as u64).saturating_mul(s as u64))
+ .saturating_add(RocksDbWeight::get().reads(3 as u64))
+ .saturating_add(RocksDbWeight::get().writes(2 as u64))
+ }
+ // Storage: Identity SuperOf (r:1 w:1)
+ // Storage: Identity SubsOf (r:1 w:1)
+ /// The range of component `s` is `[0, 99]`.
+ fn quit_sub(s: u32, ) -> Weight {
+ // Minimum execution time: 30_171 nanoseconds.
+ Weight::from_ref_time(33_355_514 as u64)
+ // Standard Error: 1_286
+ .saturating_add(Weight::from_ref_time(114_716 as u64).saturating_mul(s as u64))
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(2 as u64))
+ }
+}
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -276,11 +276,6 @@
git = 'https://github.com/paritytech/substrate'
branch = 'polkadot-v0.9.36'
-[dependencies.pallet-identity]
-default-features = false
-git = 'https://github.com/paritytech/substrate'
-branch = 'polkadot-v0.9.36'
-
[dependencies.pallet-balances]
default-features = false
git = "https://github.com/paritytech/substrate"
@@ -505,6 +500,7 @@
pallet-app-promotion = { path = '../../pallets/app-promotion', default-features = false }
up-data-structs = { path = '../../primitives/data-structs', default-features = false }
pallet-collator-selection = { default-features = false, path = "../../pallets/collator-selection" }
+pallet-identity = { default-features = false, path = "../../pallets/identity" }
pallet-configuration = { default-features = false, path = "../../pallets/configuration" }
pallet-common = { default-features = false, path = "../../pallets/common" }
pallet-structure = { default-features = false, path = "../../pallets/structure" }
runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -260,11 +260,6 @@
git = 'https://github.com/paritytech/substrate'
branch = 'polkadot-v0.9.36'
-[dependencies.pallet-identity]
-default-features = false
-git = 'https://github.com/paritytech/substrate'
-branch = 'polkadot-v0.9.36'
-
[dependencies.pallet-balances]
default-features = false
git = "https://github.com/paritytech/substrate"
@@ -496,6 +491,7 @@
pallet-app-promotion = { path = '../../pallets/app-promotion', default-features = false }
up-data-structs = { path = '../../primitives/data-structs', default-features = false }
pallet-collator-selection = { default-features = false, path = "../../pallets/collator-selection" }
+pallet-identity = { default-features = false, path = "../../pallets/identity" }
pallet-configuration = { default-features = false, path = "../../pallets/configuration" }
pallet-common = { default-features = false, path = "../../pallets/common" }
pallet-structure = { default-features = false, path = "../../pallets/structure" }
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -260,11 +260,6 @@
git = 'https://github.com/paritytech/substrate'
branch = 'polkadot-v0.9.36'
-[dependencies.pallet-identity]
-default-features = false
-git = 'https://github.com/paritytech/substrate'
-branch = 'polkadot-v0.9.36'
-
[dependencies.pallet-balances]
default-features = false
git = "https://github.com/paritytech/substrate"
@@ -487,6 +482,7 @@
pallet-app-promotion = { path = '../../pallets/app-promotion', default-features = false }
up-data-structs = { path = '../../primitives/data-structs', default-features = false }
pallet-collator-selection = { default-features = false, path = "../../pallets/collator-selection" }
+pallet-identity = { default-features = false, path = "../../pallets/identity" }
pallet-configuration = { default-features = false, path = "../../pallets/configuration" }
pallet-common = { default-features = false, path = "../../pallets/common" }
pallet-structure = { default-features = false, path = "../../pallets/structure" }