mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
add has_identity (#11197)
* add has_identity * Update frame/identity/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * update * update Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Generated
+1
-1
@@ -9106,7 +9106,7 @@ dependencies = [
|
||||
name = "sc-sysinfo"
|
||||
version = "6.0.0-dev"
|
||||
dependencies = [
|
||||
"futures 0.3.19",
|
||||
"futures 0.3.21",
|
||||
"libc",
|
||||
"log 0.4.14",
|
||||
"rand 0.7.3",
|
||||
|
||||
@@ -978,4 +978,10 @@ impl<T: Config> Pallet<T> {
|
||||
.filter_map(|a| SuperOf::<T>::get(&a).map(|x| (a, x.1)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Check if the account has corresponding identity information by the identity field.
|
||||
pub fn has_identity(who: &T::AccountId, fields: u64) -> bool {
|
||||
IdentityOf::<T>::get(who)
|
||||
.map_or(false, |registration| (registration.info.fields().0.bits() & fields) == fields)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,3 +500,20 @@ fn setting_account_id_should_work() {
|
||||
assert_ok!(Identity::set_account_id(Origin::signed(4), 0, 3));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_identity() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::set_identity(Origin::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
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,6 +53,12 @@ pub enum Data {
|
||||
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()?;
|
||||
@@ -333,6 +339,37 @@ pub struct IdentityInfo<FieldLimit: Get<u32>> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user