referrerpolicy=no-referrer-when-downgrade

people_rococo_runtime/
people.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17use crate::xcm_config::LocationToAccountId;
18use codec::{Decode, Encode, MaxEncodedLen};
19use enumflags2::{bitflags, BitFlags};
20use frame_support::{
21	parameter_types, traits::ConstU32, CloneNoBound, DebugNoBound, EqNoBound, PartialEqNoBound,
22};
23use pallet_identity::{Data, IdentityInformationProvider};
24use parachains_common::{impls::ToParentTreasury, DAYS};
25use scale_info::TypeInfo;
26use sp_runtime::{
27	traits::{AccountIdConversion, Verify},
28	Debug,
29};
30
31parameter_types! {
32	//   27 | Min encoded size of `Registration`
33	// - 10 | Min encoded size of `IdentityInfo`
34	// -----|
35	//   17 | Min size without `IdentityInfo` (accounted for in byte deposit)
36	pub const BasicDeposit: Balance = deposit(1, 17);
37	pub const ByteDeposit: Balance = deposit(0, 1);
38	pub const UsernameDeposit: Balance = deposit(0, 32);
39	pub const SubAccountDeposit: Balance = deposit(1, 53);
40	pub RelayTreasuryAccount: AccountId =
41		parachains_common::TREASURY_PALLET_ID.into_account_truncating();
42}
43
44impl pallet_identity::Config for Runtime {
45	type RuntimeEvent = RuntimeEvent;
46	type Currency = Balances;
47	type BasicDeposit = BasicDeposit;
48	type ByteDeposit = ByteDeposit;
49	type UsernameDeposit = UsernameDeposit;
50	type SubAccountDeposit = SubAccountDeposit;
51	type MaxSubAccounts = ConstU32<100>;
52	type IdentityInformation = IdentityInfo;
53	type MaxRegistrars = ConstU32<20>;
54	type Slashed = ToParentTreasury<RelayTreasuryAccount, LocationToAccountId, Runtime>;
55	type ForceOrigin = EnsureRoot<Self::AccountId>;
56	type RegistrarOrigin = EnsureRoot<Self::AccountId>;
57	type OffchainSignature = Signature;
58	type SigningPublicKey = <Signature as Verify>::Signer;
59	type UsernameAuthorityOrigin = EnsureRoot<Self::AccountId>;
60	type PendingUsernameExpiration = ConstU32<{ 7 * DAYS }>;
61	type UsernameGracePeriod = ConstU32<{ 3 * DAYS }>;
62	type MaxSuffixLength = ConstU32<7>;
63	type MaxUsernameLength = ConstU32<32>;
64	#[cfg(feature = "runtime-benchmarks")]
65	type BenchmarkHelper = ();
66	type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
67}
68
69/// The fields that we use to identify the owner of an account with. Each corresponds to a field
70/// in the `IdentityInfo` struct.
71#[bitflags]
72#[repr(u64)]
73#[derive(Clone, Copy, PartialEq, Eq, Debug)]
74pub enum IdentityField {
75	Display,
76	Legal,
77	Web,
78	Matrix,
79	Email,
80	PgpFingerprint,
81	Image,
82	Twitter,
83	GitHub,
84	Discord,
85}
86
87/// Information concerning the identity of the controller of an account.
88#[derive(
89	CloneNoBound,
90	Encode,
91	Decode,
92	DecodeWithMemTracking,
93	EqNoBound,
94	MaxEncodedLen,
95	PartialEqNoBound,
96	DebugNoBound,
97	TypeInfo,
98)]
99#[codec(mel_bound())]
100pub struct IdentityInfo {
101	/// A reasonable display name for the controller of the account. This should be whatever the
102	/// account is typically known as and should not be confusable with other entities, given
103	/// reasonable context.
104	///
105	/// Stored as UTF-8.
106	pub display: Data,
107
108	/// The full legal name in the local jurisdiction of the entity. This might be a bit
109	/// long-winded.
110	///
111	/// Stored as UTF-8.
112	pub legal: Data,
113
114	/// A representative website held by the controller of the account.
115	///
116	/// NOTE: `https://` is automatically prepended.
117	///
118	/// Stored as UTF-8.
119	pub web: Data,
120
121	/// The Matrix (e.g. for Element) handle held by the controller of the account. Previously,
122	/// this was called `riot`.
123	///
124	/// Stored as UTF-8.
125	pub matrix: Data,
126
127	/// The email address of the controller of the account.
128	///
129	/// Stored as UTF-8.
130	pub email: Data,
131
132	/// The PGP/GPG public key of the controller of the account.
133	pub pgp_fingerprint: Option<[u8; 20]>,
134
135	/// A graphic image representing the controller of the account. Should be a company,
136	/// organization or project logo or a headshot in the case of a human.
137	pub image: Data,
138
139	/// The Twitter identity. The leading `@` character may be elided.
140	pub twitter: Data,
141
142	/// The GitHub username of the controller of the account.
143	pub github: Data,
144
145	/// The Discord username of the controller of the account.
146	pub discord: Data,
147}
148
149impl IdentityInformationProvider for IdentityInfo {
150	type FieldsIdentifier = u64;
151
152	fn has_identity(&self, fields: Self::FieldsIdentifier) -> bool {
153		self.fields().bits() & fields == fields
154	}
155
156	#[cfg(feature = "runtime-benchmarks")]
157	fn create_identity_info() -> Self {
158		let data = Data::Raw(alloc::vec![0; 32].try_into().unwrap());
159
160		IdentityInfo {
161			display: data.clone(),
162			legal: data.clone(),
163			web: data.clone(),
164			matrix: data.clone(),
165			email: data.clone(),
166			pgp_fingerprint: Some([0; 20]),
167			image: data.clone(),
168			twitter: data.clone(),
169			github: data.clone(),
170			discord: data,
171		}
172	}
173
174	#[cfg(feature = "runtime-benchmarks")]
175	fn all_fields() -> Self::FieldsIdentifier {
176		use enumflags2::BitFlag;
177		IdentityField::all().bits()
178	}
179}
180
181impl IdentityInfo {
182	pub(crate) fn fields(&self) -> BitFlags<IdentityField> {
183		let mut res = <BitFlags<IdentityField>>::empty();
184		if !self.display.is_none() {
185			res.insert(IdentityField::Display);
186		}
187		if !self.legal.is_none() {
188			res.insert(IdentityField::Legal);
189		}
190		if !self.web.is_none() {
191			res.insert(IdentityField::Web);
192		}
193		if !self.matrix.is_none() {
194			res.insert(IdentityField::Matrix);
195		}
196		if !self.email.is_none() {
197			res.insert(IdentityField::Email);
198		}
199		if self.pgp_fingerprint.is_some() {
200			res.insert(IdentityField::PgpFingerprint);
201		}
202		if !self.image.is_none() {
203			res.insert(IdentityField::Image);
204		}
205		if !self.twitter.is_none() {
206			res.insert(IdentityField::Twitter);
207		}
208		if !self.github.is_none() {
209			res.insert(IdentityField::GitHub);
210		}
211		if !self.discord.is_none() {
212			res.insert(IdentityField::Discord);
213		}
214		res
215	}
216}
217
218/// A `Default` identity. This is given to users who get a username but have not set an identity.
219impl Default for IdentityInfo {
220	fn default() -> Self {
221		IdentityInfo {
222			display: Data::None,
223			legal: Data::None,
224			web: Data::None,
225			matrix: Data::None,
226			email: Data::None,
227			pgp_fingerprint: None,
228			image: Data::None,
229			twitter: Data::None,
230			github: Data::None,
231			discord: Data::None,
232		}
233	}
234}