Twitter field for IdentityInfo (in a back-compat way) (#4476)

This commit is contained in:
Gavin Wood
2019-12-22 23:11:34 +01:00
committed by GitHub
parent 3c70800eab
commit 205ddec344
2 changed files with 74 additions and 3 deletions
+28 -3
View File
@@ -69,7 +69,8 @@ use sp_std::prelude::*;
use sp_std::{fmt::Debug, ops::Add, iter::once};
use enumflags2::BitFlags;
use codec::{Encode, Decode};
use sp_runtime::{DispatchResult, traits::{StaticLookup, EnsureOrigin, Zero}, RuntimeDebug};
use sp_runtime::{DispatchResult, RuntimeDebug};
use sp_runtime::traits::{StaticLookup, EnsureOrigin, Zero, AppendZerosInput};
use frame_support::{
decl_module, decl_event, decl_storage, ensure, decl_error,
traits::{Currency, ReservableCurrency, OnUnbalanced, Get},
@@ -246,6 +247,7 @@ pub enum IdentityField {
Email = 0b0000000000000000000000000000000000000000000000000000000000010000,
PgpFingerprint = 0b0000000000000000000000000000000000000000000000000000000000100000,
Image = 0b0000000000000000000000000000000000000000000000000000000001000000,
Twitter = 0b0000000000000000000000000000000000000000000000000000000010000000,
}
/// Wrapper type for `BitFlags<IdentityField>` that implements `Codec`.
@@ -296,7 +298,7 @@ pub struct IdentityInfo {
/// Stored as UTF-8.
pub web: Data,
/// The Riot handle held by the controller of the account.
/// The Riot/Matrix handle held by the controller of the account.
///
/// Stored as UTF-8.
pub riot: Data,
@@ -312,6 +314,9 @@ pub struct IdentityInfo {
/// 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,
}
/// Information concerning the identity of the controller of an account.
@@ -344,7 +349,7 @@ impl <
}
/// Information concerning a registrar.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug)]
#[derive(Clone, Encode, Eq, PartialEq, RuntimeDebug)]
pub struct RegistrarInfo<
Balance: Encode + Decode + Clone + Debug + Eq + PartialEq,
AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq
@@ -360,6 +365,16 @@ pub struct RegistrarInfo<
pub fields: IdentityFields,
}
impl<
Balance: Encode + Decode + Clone + Debug + Eq + PartialEq,
AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq
> Decode for RegistrarInfo<Balance, AccountId> {
fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
let (account, fee, fields) = Decode::decode(&mut AppendZerosInput::new(input))?;
Ok(Self { account, fee, fields })
}
}
decl_storage! {
trait Store for Module<T: Trait> as Sudo {
/// Information that is pertinent to identify the entity behind an account.
@@ -958,6 +973,16 @@ mod tests {
}
}
#[test]
fn trailing_zeros_decodes_into_default_data() {
let encoded = Data::Raw(b"Hello".to_vec()).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()));
assert_eq!(b, Data::None);
}
#[test]
fn adding_registrar_should_work() {
new_test_ext().execute_with(|| {