Created
August 11, 2021 09:24
-
-
Save zacksleo/f4a0af0a8c887c53dd06d59eaefb54a6 to your computer and use it in GitHub Desktop.
pallet-registrar cargo expand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// The module that hosts all the | |
/// [FRAME](https://substrate.dev/docs/en/knowledgebase/runtime/frame) | |
/// types needed to add this pallet to a | |
/// [runtime](https://substrate.dev/docs/en/knowledgebase/runtime/). | |
/// | |
pub mod pallet { | |
use frame_support::{log, pallet_prelude::*}; | |
use frame_system::{pallet_prelude::*, RawOrigin}; | |
use pallet_did as did; | |
use pallet_did::did::Did; | |
use sp_std::{if_std, prelude::*}; | |
type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | |
type DbWeightOf<T> = <T as frame_system::Config>::DbWeight; | |
/// | |
/// The [pallet](https://substrate.dev/docs/en/knowledgebase/runtime/pallets) implementing | |
/// the on-chain logic. | |
/// | |
pub struct Pallet<T>(frame_support::sp_std::marker::PhantomData<(T)>); | |
const _: () = { | |
impl<T> core::clone::Clone for Pallet<T> { | |
fn clone(&self) -> Self { | |
Self(core::clone::Clone::clone(&self.0)) | |
} | |
} | |
}; | |
const _: () = { | |
impl<T> core::cmp::Eq for Pallet<T> {} | |
}; | |
const _: () = { | |
impl<T> core::cmp::PartialEq for Pallet<T> { | |
fn eq(&self, other: &Self) -> bool { | |
true && self.0 == other.0 | |
} | |
} | |
}; | |
const _: () = { | |
impl<T> core::fmt::Debug for Pallet<T> { | |
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { | |
fmt.debug_tuple("Pallet").field(&self.0).finish() | |
} | |
} | |
}; | |
/// | |
/// Configuration trait of this pallet. | |
/// | |
/// Implement this type for a runtime in order to customize this pallet. | |
/// | |
pub trait Config: frame_system::Config + did::Config { | |
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>; | |
} | |
#[allow(type_alias_bounds)] | |
pub type Organizations<T: Config> = | |
StorageValue<_GeneratedPrefixForStorageOrganizations<T>, Vec<AccountIdOf<T>>, ValueQuery>; | |
#[allow(type_alias_bounds)] | |
pub type MembersOf<T: Config> = StorageMap< | |
_GeneratedPrefixForStorageMembersOf<T>, | |
Blake2_128Concat, | |
AccountIdOf<T>, | |
Vec<AccountIdOf<T>>, | |
ValueQuery, | |
>; | |
/// | |
/// The [event](https://substrate.dev/docs/en/knowledgebase/runtime/events) emitted | |
/// by this pallet. | |
/// | |
pub enum Event<T: Config> { | |
/// An organization has been created. [creator, organization_id] | |
CreatedOrganization(<T as frame_system::Config>::AccountId, Vec<u8>), | |
/// An account was added to an organization. [account, organization_id] | |
AddedToOrganization(<T as frame_system::Config>::AccountId, Vec<u8>), | |
#[doc(hidden)] | |
#[codec(skip)] | |
__Ignore( | |
frame_support::sp_std::marker::PhantomData<(T)>, | |
frame_support::Never, | |
), | |
} | |
const _: () = { | |
impl<T: Config> core::clone::Clone for Event<T> { | |
fn clone(&self) -> Self { | |
match self { | |
Self::CreatedOrganization(ref _0, ref _1) => Self::CreatedOrganization( | |
core::clone::Clone::clone(_0), | |
core::clone::Clone::clone(_1), | |
), | |
Self::AddedToOrganization(ref _0, ref _1) => Self::AddedToOrganization( | |
core::clone::Clone::clone(_0), | |
core::clone::Clone::clone(_1), | |
), | |
Self::__Ignore(ref _0, ref _1) => { | |
Self::__Ignore(core::clone::Clone::clone(_0), core::clone::Clone::clone(_1)) | |
} | |
} | |
} | |
} | |
}; | |
const _: () = { | |
impl<T: Config> core::cmp::Eq for Event<T> {} | |
}; | |
const _: () = { | |
impl<T: Config> core::cmp::PartialEq for Event<T> { | |
fn eq(&self, other: &Self) -> bool { | |
match (self, other) { | |
( | |
Self::CreatedOrganization(_0, _1), | |
Self::CreatedOrganization(_0_other, _1_other), | |
) => true && _0 == _0_other && _1 == _1_other, | |
( | |
Self::AddedToOrganization(_0, _1), | |
Self::AddedToOrganization(_0_other, _1_other), | |
) => true && _0 == _0_other && _1 == _1_other, | |
(Self::__Ignore(_0, _1), Self::__Ignore(_0_other, _1_other)) => { | |
true && _0 == _0_other && _1 == _1_other | |
} | |
(Self::CreatedOrganization { .. }, Self::AddedToOrganization { .. }) => false, | |
(Self::CreatedOrganization { .. }, Self::__Ignore { .. }) => false, | |
(Self::AddedToOrganization { .. }, Self::CreatedOrganization { .. }) => false, | |
(Self::AddedToOrganization { .. }, Self::__Ignore { .. }) => false, | |
(Self::__Ignore { .. }, Self::CreatedOrganization { .. }) => false, | |
(Self::__Ignore { .. }, Self::AddedToOrganization { .. }) => false, | |
} | |
} | |
} | |
}; | |
const _: () = { | |
impl<T: Config> core::fmt::Debug for Event<T> { | |
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { | |
match *self { | |
Self::CreatedOrganization(ref _0, ref _1) => fmt | |
.debug_tuple("Event::CreatedOrganization") | |
.field(&_0) | |
.field(&_1) | |
.finish(), | |
Self::AddedToOrganization(ref _0, ref _1) => fmt | |
.debug_tuple("Event::AddedToOrganization") | |
.field(&_0) | |
.field(&_1) | |
.finish(), | |
Self::__Ignore(ref _0, ref _1) => fmt | |
.debug_tuple("Event::__Ignore") | |
.field(&_0) | |
.field(&_1) | |
.finish(), | |
} | |
} | |
} | |
}; | |
const _: () = { | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate codec as _parity_scale_codec; | |
impl<T: Config> _parity_scale_codec::Encode for Event<T> | |
where | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
{ | |
fn encode_to<__CodecOutputEdqy: _parity_scale_codec::Output + ?Sized>( | |
&self, | |
__codec_dest_edqy: &mut __CodecOutputEdqy, | |
) { | |
match *self { | |
Event::CreatedOrganization(ref aa, ref ba) => { | |
__codec_dest_edqy.push_byte(0usize as ::core::primitive::u8); | |
_parity_scale_codec::Encode::encode_to(aa, __codec_dest_edqy); | |
_parity_scale_codec::Encode::encode_to(ba, __codec_dest_edqy); | |
} | |
Event::AddedToOrganization(ref aa, ref ba) => { | |
__codec_dest_edqy.push_byte(1usize as ::core::primitive::u8); | |
_parity_scale_codec::Encode::encode_to(aa, __codec_dest_edqy); | |
_parity_scale_codec::Encode::encode_to(ba, __codec_dest_edqy); | |
} | |
_ => (), | |
} | |
} | |
} | |
impl<T: Config> _parity_scale_codec::EncodeLike for Event<T> | |
where | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Encode, | |
{ | |
} | |
}; | |
const _: () = { | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate codec as _parity_scale_codec; | |
impl<T: Config> _parity_scale_codec::Decode for Event<T> | |
where | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Decode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Decode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Decode, | |
<T as frame_system::Config>::AccountId: _parity_scale_codec::Decode, | |
{ | |
fn decode<__CodecInputEdqy: _parity_scale_codec::Input>( | |
__codec_input_edqy: &mut __CodecInputEdqy, | |
) -> ::core::result::Result<Self, _parity_scale_codec::Error> { | |
match __codec_input_edqy | |
.read_byte() | |
.map_err(|e| e.chain("Could not decode `Event`, failed to read variant byte"))? | |
{ | |
__codec_x_edqy if __codec_x_edqy == 0usize as ::core::primitive::u8 => { | |
::core::result::Result::Ok(Event::<T>::CreatedOrganization( | |
{ | |
let __codec_res_edqy = < < T as frame_system :: Config > :: AccountId as _parity_scale_codec :: Decode > :: decode (__codec_input_edqy) ; | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err(e.chain( | |
"Could not decode `Event::CreatedOrganization.0`", | |
)) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => { | |
__codec_res_edqy | |
} | |
} | |
}, | |
{ | |
let __codec_res_edqy = | |
<Vec<u8> as _parity_scale_codec::Decode>::decode( | |
__codec_input_edqy, | |
); | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err(e.chain( | |
"Could not decode `Event::CreatedOrganization.1`", | |
)) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => { | |
__codec_res_edqy | |
} | |
} | |
}, | |
)) | |
} | |
__codec_x_edqy if __codec_x_edqy == 1usize as ::core::primitive::u8 => { | |
::core::result::Result::Ok(Event::<T>::AddedToOrganization( | |
{ | |
let __codec_res_edqy = < < T as frame_system :: Config > :: AccountId as _parity_scale_codec :: Decode > :: decode (__codec_input_edqy) ; | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err(e.chain( | |
"Could not decode `Event::AddedToOrganization.0`", | |
)) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => { | |
__codec_res_edqy | |
} | |
} | |
}, | |
{ | |
let __codec_res_edqy = | |
<Vec<u8> as _parity_scale_codec::Decode>::decode( | |
__codec_input_edqy, | |
); | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err(e.chain( | |
"Could not decode `Event::AddedToOrganization.1`", | |
)) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => { | |
__codec_res_edqy | |
} | |
} | |
}, | |
)) | |
} | |
_ => ::core::result::Result::Err( | |
"Could not decode `Event`, variant doesn\'t exist".into(), | |
), | |
} | |
} | |
} | |
}; | |
/// | |
/// Custom [dispatch errors](https://substrate.dev/docs/en/knowledgebase/runtime/errors) | |
/// of this pallet. | |
/// | |
pub enum Error<T> { | |
#[doc(hidden)] | |
__Ignore( | |
frame_support::sp_std::marker::PhantomData<(T)>, | |
frame_support::Never, | |
), | |
/// Cannot create the organization because it already exists. | |
OrganizationExists, | |
/// Cannot add users to a non-existent organization. | |
InvalidOrganization, | |
/// Cannot add a user to an organization to which they already belong. | |
MemberOfOrganization, | |
} | |
/// | |
/// Can be used to configure the | |
/// [genesis state](https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec#the-genesis-state) | |
/// of this pallet. | |
/// | |
#[cfg(feature = "std")] | |
#[serde(rename_all = "camelCase")] | |
#[serde(deny_unknown_fields)] | |
#[serde(bound(serialize = ""))] | |
#[serde(bound(deserialize = ""))] | |
#[serde(crate = "frame_support::serde")] | |
pub struct GenesisConfig<T: Config> { | |
pub orgs: Vec<(AccountIdOf<T>, Vec<u8>)>, | |
pub members: Vec<(AccountIdOf<T>, Vec<AccountIdOf<T>>)>, | |
} | |
#[doc(hidden)] | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _: () = { | |
use frame_support::serde as _serde; | |
#[automatically_derived] | |
impl<T: Config> frame_support::serde::Serialize for GenesisConfig<T> { | |
fn serialize<__S>( | |
&self, | |
__serializer: __S, | |
) -> frame_support::serde::__private::Result<__S::Ok, __S::Error> | |
where | |
__S: frame_support::serde::Serializer, | |
{ | |
let mut __serde_state = match _serde::Serializer::serialize_struct( | |
__serializer, | |
"GenesisConfig", | |
false as usize + 1 + 1, | |
) { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
}; | |
match _serde::ser::SerializeStruct::serialize_field( | |
&mut __serde_state, | |
"orgs", | |
&self.orgs, | |
) { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
}; | |
match _serde::ser::SerializeStruct::serialize_field( | |
&mut __serde_state, | |
"members", | |
&self.members, | |
) { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
}; | |
_serde::ser::SerializeStruct::end(__serde_state) | |
} | |
} | |
}; | |
#[doc(hidden)] | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _: () = { | |
use frame_support::serde as _serde; | |
#[automatically_derived] | |
impl<'de, T: Config> frame_support::serde::Deserialize<'de> for GenesisConfig<T> { | |
fn deserialize<__D>( | |
__deserializer: __D, | |
) -> frame_support::serde::__private::Result<Self, __D::Error> | |
where | |
__D: frame_support::serde::Deserializer<'de>, | |
{ | |
#[allow(non_camel_case_types)] | |
enum __Field { | |
__field0, | |
__field1, | |
} | |
struct __FieldVisitor; | |
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor { | |
type Value = __Field; | |
fn expecting( | |
&self, | |
__formatter: &mut _serde::__private::Formatter, | |
) -> _serde::__private::fmt::Result { | |
_serde::__private::Formatter::write_str(__formatter, "field identifier") | |
} | |
fn visit_u64<__E>( | |
self, | |
__value: u64, | |
) -> _serde::__private::Result<Self::Value, __E> | |
where | |
__E: _serde::de::Error, | |
{ | |
match __value { | |
0u64 => _serde::__private::Ok(__Field::__field0), | |
1u64 => _serde::__private::Ok(__Field::__field1), | |
_ => _serde::__private::Err(_serde::de::Error::invalid_value( | |
_serde::de::Unexpected::Unsigned(__value), | |
&"field index 0 <= i < 2", | |
)), | |
} | |
} | |
fn visit_str<__E>( | |
self, | |
__value: &str, | |
) -> _serde::__private::Result<Self::Value, __E> | |
where | |
__E: _serde::de::Error, | |
{ | |
match __value { | |
"orgs" => _serde::__private::Ok(__Field::__field0), | |
"members" => _serde::__private::Ok(__Field::__field1), | |
_ => _serde::__private::Err(_serde::de::Error::unknown_field( | |
__value, FIELDS, | |
)), | |
} | |
} | |
fn visit_bytes<__E>( | |
self, | |
__value: &[u8], | |
) -> _serde::__private::Result<Self::Value, __E> | |
where | |
__E: _serde::de::Error, | |
{ | |
match __value { | |
b"orgs" => _serde::__private::Ok(__Field::__field0), | |
b"members" => _serde::__private::Ok(__Field::__field1), | |
_ => { | |
let __value = &_serde::__private::from_utf8_lossy(__value); | |
_serde::__private::Err(_serde::de::Error::unknown_field( | |
__value, FIELDS, | |
)) | |
} | |
} | |
} | |
} | |
impl<'de> _serde::Deserialize<'de> for __Field { | |
#[inline] | |
fn deserialize<__D>( | |
__deserializer: __D, | |
) -> _serde::__private::Result<Self, __D::Error> | |
where | |
__D: _serde::Deserializer<'de>, | |
{ | |
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) | |
} | |
} | |
struct __Visitor<'de, T: Config> { | |
marker: _serde::__private::PhantomData<GenesisConfig<T>>, | |
lifetime: _serde::__private::PhantomData<&'de ()>, | |
} | |
impl<'de, T: Config> _serde::de::Visitor<'de> for __Visitor<'de, T> { | |
type Value = GenesisConfig<T>; | |
fn expecting( | |
&self, | |
__formatter: &mut _serde::__private::Formatter, | |
) -> _serde::__private::fmt::Result { | |
_serde::__private::Formatter::write_str(__formatter, "struct GenesisConfig") | |
} | |
#[inline] | |
fn visit_seq<__A>( | |
self, | |
mut __seq: __A, | |
) -> _serde::__private::Result<Self::Value, __A::Error> | |
where | |
__A: _serde::de::SeqAccess<'de>, | |
{ | |
let __field0 = match match _serde::de::SeqAccess::next_element::< | |
Vec<(AccountIdOf<T>, Vec<u8>)>, | |
>(&mut __seq) | |
{ | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
} { | |
_serde::__private::Some(__value) => __value, | |
_serde::__private::None => { | |
return _serde::__private::Err(_serde::de::Error::invalid_length( | |
0usize, | |
&"struct GenesisConfig with 2 elements", | |
)); | |
} | |
}; | |
let __field1 = match match _serde::de::SeqAccess::next_element::< | |
Vec<(AccountIdOf<T>, Vec<AccountIdOf<T>>)>, | |
>(&mut __seq) | |
{ | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
} { | |
_serde::__private::Some(__value) => __value, | |
_serde::__private::None => { | |
return _serde::__private::Err(_serde::de::Error::invalid_length( | |
1usize, | |
&"struct GenesisConfig with 2 elements", | |
)); | |
} | |
}; | |
_serde::__private::Ok(GenesisConfig { | |
orgs: __field0, | |
members: __field1, | |
}) | |
} | |
#[inline] | |
fn visit_map<__A>( | |
self, | |
mut __map: __A, | |
) -> _serde::__private::Result<Self::Value, __A::Error> | |
where | |
__A: _serde::de::MapAccess<'de>, | |
{ | |
let mut __field0: _serde::__private::Option< | |
Vec<(AccountIdOf<T>, Vec<u8>)>, | |
> = _serde::__private::None; | |
let mut __field1: _serde::__private::Option< | |
Vec<(AccountIdOf<T>, Vec<AccountIdOf<T>>)>, | |
> = _serde::__private::None; | |
while let _serde::__private::Some(__key) = | |
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
} | |
{ | |
match __key { | |
__Field::__field0 => { | |
if _serde::__private::Option::is_some(&__field0) { | |
return _serde::__private::Err( | |
<__A::Error as _serde::de::Error>::duplicate_field( | |
"orgs", | |
), | |
); | |
} | |
__field0 = _serde::__private::Some( | |
match _serde::de::MapAccess::next_value::< | |
Vec<(AccountIdOf<T>, Vec<u8>)>, | |
>(&mut __map) | |
{ | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
}, | |
); | |
} | |
__Field::__field1 => { | |
if _serde::__private::Option::is_some(&__field1) { | |
return _serde::__private::Err( | |
<__A::Error as _serde::de::Error>::duplicate_field( | |
"members", | |
), | |
); | |
} | |
__field1 = _serde::__private::Some( | |
match _serde::de::MapAccess::next_value::< | |
Vec<(AccountIdOf<T>, Vec<AccountIdOf<T>>)>, | |
>(&mut __map) | |
{ | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
}, | |
); | |
} | |
} | |
} | |
let __field0 = match __field0 { | |
_serde::__private::Some(__field0) => __field0, | |
_serde::__private::None => { | |
match _serde::__private::de::missing_field("orgs") { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
} | |
} | |
}; | |
let __field1 = match __field1 { | |
_serde::__private::Some(__field1) => __field1, | |
_serde::__private::None => { | |
match _serde::__private::de::missing_field("members") { | |
_serde::__private::Ok(__val) => __val, | |
_serde::__private::Err(__err) => { | |
return _serde::__private::Err(__err); | |
} | |
} | |
} | |
}; | |
_serde::__private::Ok(GenesisConfig { | |
orgs: __field0, | |
members: __field1, | |
}) | |
} | |
} | |
const FIELDS: &'static [&'static str] = &["orgs", "members"]; | |
_serde::Deserializer::deserialize_struct( | |
__deserializer, | |
"GenesisConfig", | |
FIELDS, | |
__Visitor { | |
marker: _serde::__private::PhantomData::<GenesisConfig<T>>, | |
lifetime: _serde::__private::PhantomData, | |
}, | |
) | |
} | |
} | |
}; | |
#[cfg(feature = "std")] | |
impl<T: Config> Default for GenesisConfig<T> { | |
fn default() -> Self { | |
GenesisConfig { | |
orgs: Default::default(), | |
members: Default::default(), | |
} | |
} | |
} | |
#[cfg(feature = "std")] | |
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> { | |
fn build(&self) { | |
for org in self.orgs.iter() { | |
match Pallet::<T>::create_org(&org.0, org.1.clone()) { | |
Err(e) => ::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1( | |
&[""], | |
&match (&e,) { | |
(arg0,) => { | |
[::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)] | |
} | |
}, | |
)), | |
Ok(_) => (), | |
} | |
} | |
for (org, members) in self.members.iter() { | |
for member in members.iter() { | |
match Pallet::<T>::add_to_org(org, member) { | |
Err(e) => ::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1( | |
&[""], | |
&match (&e,) { | |
(arg0,) => { | |
[::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)] | |
} | |
}, | |
)), | |
Ok(_) => (), | |
} | |
} | |
} | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
/// Create an organization. Will return an OrganizationExists error if the organization has already | |
/// been created. Will emit a CreatedOrganization event on success. | |
/// | |
/// The dispatch origin for this call must be Signed. | |
pub fn create_organization(origin: OriginFor<T>, org_name: Vec<u8>) -> DispatchResult { | |
let who = ensure_signed(origin)?; | |
Self::create_org(&who, org_name.clone())?; | |
Self::deposit_event(Event::CreatedOrganization(who, org_name)); | |
Ok(()) | |
} | |
/// Add an account to an organization. Will return an InvalidOrganization error if the organization | |
/// does not exist or the account is already a member. Will emit a AddedToOrganization event on success. | |
/// | |
/// The dispatch origin for this call must be Signed. | |
pub fn add_to_organization( | |
origin: OriginFor<T>, | |
account: AccountIdOf<T>, | |
) -> DispatchResult { | |
let who = ensure_signed(origin)?; | |
Self::add_to_org(&who, &account)?; | |
Self::deposit_event(Event::AddedToOrganization(account, b"OrgMember".to_vec())); | |
Ok(()) | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
pub fn create_org(owner: &AccountIdOf<T>, org_name: Vec<u8>) -> DispatchResult { | |
let mut orgs = <Pallet<T>>::organizations(); | |
{ | |
if !!orgs.contains(&owner) { | |
{ | |
return Err(Error::<T>::OrganizationExists.into()); | |
}; | |
} | |
}; | |
orgs.push(owner.clone()); | |
<Organizations<T>>::put(orgs); | |
<did::Pallet<T>>::create_attribute(&owner, &owner, b"Org", &org_name, None)?; | |
Ok(()) | |
} | |
pub fn add_to_org(org: &AccountIdOf<T>, account: &AccountIdOf<T>) -> DispatchResult { | |
let orgs = Self::organizations(); | |
{ | |
if !orgs.contains(&org) { | |
{ | |
return Err(Error::<T>::InvalidOrganization.into()); | |
}; | |
} | |
}; | |
let mut members = Self::members_of(&org); | |
if !members.contains(&account) { | |
members.push(account.clone()); | |
MembersOf::<T>::insert(&org, members); | |
} else { | |
return Err(Error::<T>::MemberOfOrganization.into()); | |
} | |
<did::Pallet<T>>::create_delegate(&org, &org, &account, &b"OrgMember".to_vec(), None)?; | |
Ok(()) | |
} | |
/// Returns true if and only if the account is a member of an organization. | |
pub fn part_of_organization(account: &AccountIdOf<T>) -> bool { | |
let orgs = <Pallet<T>>::organizations(); | |
for org in orgs.iter() { | |
if <did::Pallet<T>>::valid_delegate(org, &b"OrgMember".to_vec(), &account).is_ok() { | |
return true; | |
} | |
} | |
false | |
} | |
} | |
/// Ensure that a consortium member is invoking a dispatch. | |
pub struct EnsureOrg<T>(sp_std::marker::PhantomData<T>); | |
impl<T: Config> EnsureOrigin<T::Origin> for EnsureOrg<T> { | |
type Success = T::AccountId; | |
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> { | |
{ | |
::std::io::_print(::core::fmt::Arguments::new_v1( | |
&["inside custom origin\n"], | |
&match () { | |
() => [], | |
}, | |
)); | |
}; | |
o.into().and_then(|o| match o { | |
RawOrigin::Signed(ref who) if <Pallet<T>>::part_of_organization(&who) => { | |
Ok(who.clone()) | |
} | |
r => Err(T::Origin::from(r)), | |
}) | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
#[doc(hidden)] | |
pub fn module_constants_metadata( | |
) -> &'static [frame_support::dispatch::ModuleConstantMetadata] { | |
&[] | |
} | |
} | |
impl<T: Config> frame_support::error::ModuleErrorMetadata for Pallet<T> { | |
fn metadata() -> &'static [frame_support::error::ErrorMetadata] { | |
<Error<T> as frame_support::error::ModuleErrorMetadata>::metadata() | |
} | |
} | |
/// Type alias to `Pallet`, to be used by `construct_runtime`. | |
/// | |
/// Generated by `pallet` attribute macro. | |
#[deprecated(note = "use `Pallet` instead")] | |
#[allow(dead_code)] | |
pub type Module<T> = Pallet<T>; | |
impl<T: Config> frame_support::traits::GetPalletVersion for Pallet<T> { | |
fn current_version() -> frame_support::traits::PalletVersion { | |
frame_support::traits::PalletVersion { | |
major: 3u16, | |
minor: 0u8, | |
patch: 0u8, | |
} | |
} | |
fn storage_version() -> Option<frame_support::traits::PalletVersion> { | |
let key = frame_support::traits::PalletVersion::storage_key::< | |
<T as frame_system::Config>::PalletInfo, | |
Self, | |
>() | |
.expect("Every active pallet has a name in the runtime; qed"); | |
frame_support::storage::unhashed::get(&key) | |
} | |
} | |
impl<T: Config> frame_support::traits::OnGenesis for Pallet<T> { | |
fn on_genesis() { | |
frame_support::traits::PalletVersion { | |
major: 3u16, | |
minor: 0u8, | |
patch: 0u8, | |
} | |
.put_into_storage::<<T as frame_system::Config>::PalletInfo, Self>(); | |
} | |
} | |
impl<T: Config> frame_support::traits::PalletInfoAccess for Pallet<T> { | |
fn index() -> usize { | |
<<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::index::< | |
Self, | |
>() | |
.expect( | |
"Pallet is part of the runtime because pallet `Config` trait is \ | |
implemented by the runtime", | |
) | |
} | |
fn name() -> &'static str { | |
<<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::< | |
Self, | |
>() | |
.expect( | |
"Pallet is part of the runtime because pallet `Config` trait is \ | |
implemented by the runtime", | |
) | |
} | |
} | |
#[doc(hidden)] | |
pub mod __substrate_call_check { | |
#[doc(hidden)] | |
pub use __is_call_part_defined_0 as is_call_part_defined; | |
} | |
///Contains one variant per dispatchable that can be called by an extrinsic. | |
#[codec(encode_bound())] | |
#[codec(decode_bound())] | |
#[allow(non_camel_case_types)] | |
pub enum Call<T: Config> { | |
#[doc(hidden)] | |
#[codec(skip)] | |
__Ignore( | |
frame_support::sp_std::marker::PhantomData<(T,)>, | |
frame_support::Never, | |
), | |
/// Create an organization. Will return an OrganizationExists error if the organization has already | |
/// been created. Will emit a CreatedOrganization event on success. | |
/// | |
/// The dispatch origin for this call must be Signed. | |
create_organization(Vec<u8>), | |
/// Add an account to an organization. Will return an InvalidOrganization error if the organization | |
/// does not exist or the account is already a member. Will emit a AddedToOrganization event on success. | |
/// | |
/// The dispatch origin for this call must be Signed. | |
add_to_organization(AccountIdOf<T>), | |
} | |
const _: () = { | |
impl<T: Config> core::fmt::Debug for Call<T> { | |
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { | |
match *self { | |
Self::__Ignore(ref _0, ref _1) => fmt | |
.debug_tuple("Call::__Ignore") | |
.field(&_0) | |
.field(&_1) | |
.finish(), | |
Self::create_organization(ref _0) => fmt | |
.debug_tuple("Call::create_organization") | |
.field(&_0) | |
.finish(), | |
Self::add_to_organization(ref _0) => fmt | |
.debug_tuple("Call::add_to_organization") | |
.field(&_0) | |
.finish(), | |
} | |
} | |
} | |
}; | |
const _: () = { | |
impl<T: Config> core::clone::Clone for Call<T> { | |
fn clone(&self) -> Self { | |
match self { | |
Self::__Ignore(ref _0, ref _1) => { | |
Self::__Ignore(core::clone::Clone::clone(_0), core::clone::Clone::clone(_1)) | |
} | |
Self::create_organization(ref _0) => { | |
Self::create_organization(core::clone::Clone::clone(_0)) | |
} | |
Self::add_to_organization(ref _0) => { | |
Self::add_to_organization(core::clone::Clone::clone(_0)) | |
} | |
} | |
} | |
} | |
}; | |
const _: () = { | |
impl<T: Config> core::cmp::Eq for Call<T> {} | |
}; | |
const _: () = { | |
impl<T: Config> core::cmp::PartialEq for Call<T> { | |
fn eq(&self, other: &Self) -> bool { | |
match (self, other) { | |
(Self::__Ignore(_0, _1), Self::__Ignore(_0_other, _1_other)) => { | |
true && _0 == _0_other && _1 == _1_other | |
} | |
(Self::create_organization(_0), Self::create_organization(_0_other)) => { | |
true && _0 == _0_other | |
} | |
(Self::add_to_organization(_0), Self::add_to_organization(_0_other)) => { | |
true && _0 == _0_other | |
} | |
(Self::__Ignore { .. }, Self::create_organization { .. }) => false, | |
(Self::__Ignore { .. }, Self::add_to_organization { .. }) => false, | |
(Self::create_organization { .. }, Self::__Ignore { .. }) => false, | |
(Self::create_organization { .. }, Self::add_to_organization { .. }) => false, | |
(Self::add_to_organization { .. }, Self::__Ignore { .. }) => false, | |
(Self::add_to_organization { .. }, Self::create_organization { .. }) => false, | |
} | |
} | |
} | |
}; | |
const _: () = { | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate codec as _parity_scale_codec; | |
#[allow(non_camel_case_types)] | |
impl<T: Config> _parity_scale_codec::Encode for Call<T> { | |
fn encode_to<__CodecOutputEdqy: _parity_scale_codec::Output + ?Sized>( | |
&self, | |
__codec_dest_edqy: &mut __CodecOutputEdqy, | |
) { | |
match *self { | |
Call::create_organization(ref aa) => { | |
__codec_dest_edqy.push_byte(0usize as ::core::primitive::u8); | |
_parity_scale_codec::Encode::encode_to(aa, __codec_dest_edqy); | |
} | |
Call::add_to_organization(ref aa) => { | |
__codec_dest_edqy.push_byte(1usize as ::core::primitive::u8); | |
_parity_scale_codec::Encode::encode_to(aa, __codec_dest_edqy); | |
} | |
_ => (), | |
} | |
} | |
} | |
impl<T: Config> _parity_scale_codec::EncodeLike for Call<T> {} | |
}; | |
const _: () = { | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate codec as _parity_scale_codec; | |
#[allow(non_camel_case_types)] | |
impl<T: Config> _parity_scale_codec::Decode for Call<T> { | |
fn decode<__CodecInputEdqy: _parity_scale_codec::Input>( | |
__codec_input_edqy: &mut __CodecInputEdqy, | |
) -> ::core::result::Result<Self, _parity_scale_codec::Error> { | |
match __codec_input_edqy | |
.read_byte() | |
.map_err(|e| e.chain("Could not decode `Call`, failed to read variant byte"))? | |
{ | |
__codec_x_edqy if __codec_x_edqy == 0usize as ::core::primitive::u8 => { | |
::core::result::Result::Ok(Call::<T>::create_organization({ | |
let __codec_res_edqy = <Vec<u8> as _parity_scale_codec::Decode>::decode( | |
__codec_input_edqy, | |
); | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err( | |
e.chain("Could not decode `Call::create_organization.0`"), | |
) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => __codec_res_edqy, | |
} | |
})) | |
} | |
__codec_x_edqy if __codec_x_edqy == 1usize as ::core::primitive::u8 => { | |
::core::result::Result::Ok(Call::<T>::add_to_organization({ | |
let __codec_res_edqy = | |
<AccountIdOf<T> as _parity_scale_codec::Decode>::decode( | |
__codec_input_edqy, | |
); | |
match __codec_res_edqy { | |
::core::result::Result::Err(e) => { | |
return ::core::result::Result::Err( | |
e.chain("Could not decode `Call::add_to_organization.0`"), | |
) | |
} | |
::core::result::Result::Ok(__codec_res_edqy) => __codec_res_edqy, | |
} | |
})) | |
} | |
_ => ::core::result::Result::Err( | |
"Could not decode `Call`, variant doesn\'t exist".into(), | |
), | |
} | |
} | |
} | |
}; | |
impl<T: Config> frame_support::dispatch::GetDispatchInfo for Call<T> { | |
fn get_dispatch_info(&self) -> frame_support::dispatch::DispatchInfo { | |
match *self { | |
Self::create_organization(ref org_name) => { | |
let __pallet_base_weight = 10_000 + <DbWeightOf<T>>::get().writes(1); | |
let __pallet_weight = | |
<dyn frame_support::dispatch::WeighData<(&Vec<u8>,)>>::weigh_data( | |
&__pallet_base_weight, | |
(org_name,), | |
); | |
let __pallet_class = < dyn frame_support :: dispatch :: ClassifyDispatch < (& Vec < u8 > ,) > > :: classify_dispatch (& __pallet_base_weight , (org_name ,)) ; | |
let __pallet_pays_fee = | |
<dyn frame_support::dispatch::PaysFee<(&Vec<u8>,)>>::pays_fee( | |
&__pallet_base_weight, | |
(org_name,), | |
); | |
frame_support::dispatch::DispatchInfo { | |
weight: __pallet_weight, | |
class: __pallet_class, | |
pays_fee: __pallet_pays_fee, | |
} | |
} | |
Self::add_to_organization(ref account) => { | |
let __pallet_base_weight = 10_000 + <DbWeightOf<T>>::get().writes(1); | |
let __pallet_weight = <dyn frame_support::dispatch::WeighData< | |
(&AccountIdOf<T>,), | |
>>::weigh_data( | |
&__pallet_base_weight, (account,) | |
); | |
let __pallet_class = <dyn frame_support::dispatch::ClassifyDispatch<( | |
&AccountIdOf<T>, | |
)>>::classify_dispatch( | |
&__pallet_base_weight, (account,) | |
); | |
let __pallet_pays_fee = <dyn frame_support::dispatch::PaysFee< | |
(&AccountIdOf<T>,), | |
>>::pays_fee( | |
&__pallet_base_weight, (account,) | |
); | |
frame_support::dispatch::DispatchInfo { | |
weight: __pallet_weight, | |
class: __pallet_class, | |
pays_fee: __pallet_pays_fee, | |
} | |
} | |
Self::__Ignore(_, _) => { | |
::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1( | |
&["internal error: entered unreachable code: "], | |
&match (&"__Ignore cannot be used",) { | |
(arg0,) => [::core::fmt::ArgumentV1::new( | |
arg0, | |
::core::fmt::Display::fmt, | |
)], | |
}, | |
)) | |
} | |
} | |
} | |
} | |
impl<T: Config> frame_support::dispatch::GetCallName for Call<T> { | |
fn get_call_name(&self) -> &'static str { | |
match *self { | |
Self::create_organization(..) => "create_organization", | |
Self::add_to_organization(..) => "add_to_organization", | |
Self::__Ignore(_, _) => { | |
::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1( | |
&["internal error: entered unreachable code: "], | |
&match (&"__PhantomItem cannot be used.",) { | |
(arg0,) => [::core::fmt::ArgumentV1::new( | |
arg0, | |
::core::fmt::Display::fmt, | |
)], | |
}, | |
)) | |
} | |
} | |
} | |
fn get_call_names() -> &'static [&'static str] { | |
&["create_organization", "add_to_organization"] | |
} | |
} | |
impl<T: Config> frame_support::traits::UnfilteredDispatchable for Call<T> { | |
type Origin = frame_system::pallet_prelude::OriginFor<T>; | |
fn dispatch_bypass_filter( | |
self, | |
origin: Self::Origin, | |
) -> frame_support::dispatch::DispatchResultWithPostInfo { | |
match self { | |
Self::create_organization(org_name) => { | |
let __within_span__ = { | |
use ::tracing::__macro_support::Callsite as _; | |
static CALLSITE: ::tracing::__macro_support::MacroCallsite = { | |
use ::tracing::__macro_support::MacroCallsite; | |
static META: ::tracing::Metadata<'static> = { | |
::tracing_core::metadata::Metadata::new( | |
"create_organization", | |
"pallet_registrar::pallet", | |
::tracing::Level::TRACE, | |
Some("pallets/registrar/src/lib.rs"), | |
Some(14u32), | |
Some("pallet_registrar::pallet"), | |
::tracing_core::field::FieldSet::new( | |
&[], | |
::tracing_core::callsite::Identifier(&CALLSITE), | |
), | |
::tracing::metadata::Kind::SPAN, | |
) | |
}; | |
MacroCallsite::new(&META) | |
}; | |
let mut interest = ::tracing::subscriber::Interest::never(); | |
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL | |
&& ::tracing::Level::TRACE | |
<= ::tracing::level_filters::LevelFilter::current() | |
&& { | |
interest = CALLSITE.interest(); | |
!interest.is_never() | |
} | |
&& CALLSITE.is_enabled(interest) | |
{ | |
let meta = CALLSITE.metadata(); | |
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) }) | |
} else { | |
let span = CALLSITE.disabled_span(); | |
{}; | |
span | |
} | |
}; | |
let __tracing_guard__ = __within_span__.enter(); | |
<Pallet<T>>::create_organization(origin, org_name) | |
.map(Into::into) | |
.map_err(Into::into) | |
} | |
Self::add_to_organization(account) => { | |
let __within_span__ = { | |
use ::tracing::__macro_support::Callsite as _; | |
static CALLSITE: ::tracing::__macro_support::MacroCallsite = { | |
use ::tracing::__macro_support::MacroCallsite; | |
static META: ::tracing::Metadata<'static> = { | |
::tracing_core::metadata::Metadata::new( | |
"add_to_organization", | |
"pallet_registrar::pallet", | |
::tracing::Level::TRACE, | |
Some("pallets/registrar/src/lib.rs"), | |
Some(14u32), | |
Some("pallet_registrar::pallet"), | |
::tracing_core::field::FieldSet::new( | |
&[], | |
::tracing_core::callsite::Identifier(&CALLSITE), | |
), | |
::tracing::metadata::Kind::SPAN, | |
) | |
}; | |
MacroCallsite::new(&META) | |
}; | |
let mut interest = ::tracing::subscriber::Interest::never(); | |
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL | |
&& ::tracing::Level::TRACE | |
<= ::tracing::level_filters::LevelFilter::current() | |
&& { | |
interest = CALLSITE.interest(); | |
!interest.is_never() | |
} | |
&& CALLSITE.is_enabled(interest) | |
{ | |
let meta = CALLSITE.metadata(); | |
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) }) | |
} else { | |
let span = CALLSITE.disabled_span(); | |
{}; | |
span | |
} | |
}; | |
let __tracing_guard__ = __within_span__.enter(); | |
<Pallet<T>>::add_to_organization(origin, account) | |
.map(Into::into) | |
.map_err(Into::into) | |
} | |
Self::__Ignore(_, _) => { | |
let _ = origin; | |
{ | |
{ | |
::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1( | |
&["internal error: entered unreachable code: "], | |
&match (&"__PhantomItem cannot be used.",) { | |
(arg0,) => [::core::fmt::ArgumentV1::new( | |
arg0, | |
::core::fmt::Display::fmt, | |
)], | |
}, | |
)) | |
} | |
}; | |
} | |
} | |
} | |
} | |
impl<T: Config> frame_support::dispatch::Callable<T> for Pallet<T> { | |
type Call = Call<T>; | |
} | |
impl<T: Config> Pallet<T> { | |
#[doc(hidden)] | |
#[allow(dead_code)] | |
pub fn call_functions() -> &'static [frame_support::dispatch::FunctionMetadata] { | |
& [frame_support :: dispatch :: FunctionMetadata { name : frame_support :: dispatch :: DecodeDifferent :: Encode ("create_organization") , arguments : frame_support :: dispatch :: DecodeDifferent :: Encode (& [frame_support :: dispatch :: FunctionArgumentMetadata { name : frame_support :: dispatch :: DecodeDifferent :: Encode ("org_name") , ty : frame_support :: dispatch :: DecodeDifferent :: Encode ("Vec<u8>") , }]) , documentation : frame_support :: dispatch :: DecodeDifferent :: Encode (& [" Create an organization. Will return an OrganizationExists error if the organization has already" , " been created. Will emit a CreatedOrganization event on success." , "" , " The dispatch origin for this call must be Signed."]) , } , frame_support :: dispatch :: FunctionMetadata { name : frame_support :: dispatch :: DecodeDifferent :: Encode ("add_to_organization") , arguments : frame_support :: dispatch :: DecodeDifferent :: Encode (& [frame_support :: dispatch :: FunctionArgumentMetadata { name : frame_support :: dispatch :: DecodeDifferent :: Encode ("account") , ty : frame_support :: dispatch :: DecodeDifferent :: Encode ("AccountIdOf<T>") , }]) , documentation : frame_support :: dispatch :: DecodeDifferent :: Encode (& [" Add an account to an organization. Will return an InvalidOrganization error if the organization" , " does not exist or the account is already a member. Will emit a AddedToOrganization event on success." , "" , " The dispatch origin for this call must be Signed."]) , }] | |
} | |
} | |
impl<T: Config> frame_support::sp_std::fmt::Debug for Error<T> { | |
fn fmt( | |
&self, | |
f: &mut frame_support::sp_std::fmt::Formatter<'_>, | |
) -> frame_support::sp_std::fmt::Result { | |
f.write_str(self.as_str()) | |
} | |
} | |
impl<T: Config> Error<T> { | |
pub fn as_u8(&self) -> u8 { | |
match &self { | |
Self::__Ignore(_, _) => { | |
::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1( | |
&["internal error: entered unreachable code: "], | |
&match (&"`__Ignore` can never be constructed",) { | |
(arg0,) => [::core::fmt::ArgumentV1::new( | |
arg0, | |
::core::fmt::Display::fmt, | |
)], | |
}, | |
)) | |
} | |
Self::OrganizationExists => 0usize as u8, | |
Self::InvalidOrganization => 1usize as u8, | |
Self::MemberOfOrganization => 2usize as u8, | |
} | |
} | |
pub fn as_str(&self) -> &'static str { | |
match &self { | |
Self::__Ignore(_, _) => { | |
::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1( | |
&["internal error: entered unreachable code: "], | |
&match (&"`__Ignore` can never be constructed",) { | |
(arg0,) => [::core::fmt::ArgumentV1::new( | |
arg0, | |
::core::fmt::Display::fmt, | |
)], | |
}, | |
)) | |
} | |
Self::OrganizationExists => "OrganizationExists", | |
Self::InvalidOrganization => "InvalidOrganization", | |
Self::MemberOfOrganization => "MemberOfOrganization", | |
} | |
} | |
} | |
impl<T: Config> From<Error<T>> for &'static str { | |
fn from(err: Error<T>) -> &'static str { | |
err.as_str() | |
} | |
} | |
impl<T: Config> From<Error<T>> for frame_support::sp_runtime::DispatchError { | |
fn from(err: Error<T>) -> Self { | |
let index = < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: index :: < Pallet < T > > () . expect ("Every active module has an index in the runtime; qed") as u8 ; | |
frame_support::sp_runtime::DispatchError::Module { | |
index, | |
error: err.as_u8(), | |
message: Some(err.as_str()), | |
} | |
} | |
} | |
impl<T: Config> frame_support::error::ModuleErrorMetadata for Error<T> { | |
fn metadata() -> &'static [frame_support::error::ErrorMetadata] { | |
&[ | |
frame_support::error::ErrorMetadata { | |
name: frame_support::error::DecodeDifferent::Encode("OrganizationExists"), | |
documentation: frame_support::error::DecodeDifferent::Encode(&[ | |
" Cannot create the organization because it already exists.", | |
]), | |
}, | |
frame_support::error::ErrorMetadata { | |
name: frame_support::error::DecodeDifferent::Encode("InvalidOrganization"), | |
documentation: frame_support::error::DecodeDifferent::Encode(&[ | |
" Cannot add users to a non-existent organization.", | |
]), | |
}, | |
frame_support::error::ErrorMetadata { | |
name: frame_support::error::DecodeDifferent::Encode("MemberOfOrganization"), | |
documentation: frame_support::error::DecodeDifferent::Encode(&[ | |
" Cannot add a user to an organization to which they already belong.", | |
]), | |
}, | |
] | |
} | |
} | |
#[doc(hidden)] | |
pub mod __substrate_event_check { | |
#[doc(hidden)] | |
pub use __is_event_part_defined_1 as is_event_part_defined; | |
} | |
impl<T: Config> Pallet<T> { | |
pub(super) fn deposit_event(event: Event<T>) { | |
let event = <<T as Config>::Event as From<Event<T>>>::from(event); | |
let event = | |
<<T as Config>::Event as Into<<T as frame_system::Config>::Event>>::into(event); | |
<frame_system::Pallet<T>>::deposit_event(event) | |
} | |
} | |
impl<T: Config> From<Event<T>> for () { | |
fn from(_: Event<T>) {} | |
} | |
impl<T: Config> Event<T> { | |
#[allow(dead_code)] | |
#[doc(hidden)] | |
pub fn metadata() -> &'static [frame_support::event::EventMetadata] { | |
&[ | |
frame_support::event::EventMetadata { | |
name: frame_support::event::DecodeDifferent::Encode("CreatedOrganization"), | |
arguments: frame_support::event::DecodeDifferent::Encode(&[ | |
"<T as frame_system::Config>::AccountId", | |
"Vec<u8>", | |
]), | |
documentation: frame_support::event::DecodeDifferent::Encode(&[ | |
" An organization has been created. [creator, organization_id]", | |
]), | |
}, | |
frame_support::event::EventMetadata { | |
name: frame_support::event::DecodeDifferent::Encode("AddedToOrganization"), | |
arguments: frame_support::event::DecodeDifferent::Encode(&[ | |
"<T as frame_system::Config>::AccountId", | |
"Vec<u8>", | |
]), | |
documentation: frame_support::event::DecodeDifferent::Encode(&[ | |
" An account was added to an organization. [account, organization_id]", | |
]), | |
}, | |
] | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
#[doc(hidden)] | |
pub fn storage_metadata() -> frame_support::metadata::StorageMetadata { | |
frame_support :: metadata :: StorageMetadata { prefix : frame_support :: metadata :: DecodeDifferent :: Encode (< < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: name :: < Pallet < T > > () . expect ("Every active pallet has a name in the runtime; qed")) , entries : frame_support :: metadata :: DecodeDifferent :: Encode (& [frame_support :: metadata :: StorageEntryMetadata { name : frame_support :: metadata :: DecodeDifferent :: Encode (< Organizations < T > as frame_support :: storage :: types :: StorageValueMetadata > :: NAME) , modifier : < Organizations < T > as frame_support :: storage :: types :: StorageValueMetadata > :: MODIFIER , ty : frame_support :: metadata :: StorageEntryType :: Plain (frame_support :: metadata :: DecodeDifferent :: Encode ("Vec<AccountIdOf<T>>")) , default : frame_support :: metadata :: DecodeDifferent :: Encode (< Organizations < T > as frame_support :: storage :: types :: StorageValueMetadata > :: DEFAULT) , documentation : frame_support :: metadata :: DecodeDifferent :: Encode (& []) , } , frame_support :: metadata :: StorageEntryMetadata { name : frame_support :: metadata :: DecodeDifferent :: Encode (< MembersOf < T > as frame_support :: storage :: types :: StorageMapMetadata > :: NAME) , modifier : < MembersOf < T > as frame_support :: storage :: types :: StorageMapMetadata > :: MODIFIER , ty : frame_support :: metadata :: StorageEntryType :: Map { hasher : < MembersOf < T > as frame_support :: storage :: types :: StorageMapMetadata > :: HASHER , key : frame_support :: metadata :: DecodeDifferent :: Encode ("AccountIdOf<T>") , value : frame_support :: metadata :: DecodeDifferent :: Encode ("Vec<AccountIdOf<T>>") , unused : false , } , default : frame_support :: metadata :: DecodeDifferent :: Encode (< MembersOf < T > as frame_support :: storage :: types :: StorageMapMetadata > :: DEFAULT) , documentation : frame_support :: metadata :: DecodeDifferent :: Encode (& []) , }]) , } | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
pub fn organizations() -> Vec<AccountIdOf<T>> { | |
<Organizations<T> as frame_support::storage::StorageValue<Vec<AccountIdOf<T>>>>::get() | |
} | |
} | |
impl<T: Config> Pallet<T> { | |
pub fn members_of<KArg>(k: KArg) -> Vec<AccountIdOf<T>> | |
where | |
KArg: frame_support::codec::EncodeLike<AccountIdOf<T>>, | |
{ | |
<MembersOf<T> as frame_support::storage::StorageMap< | |
AccountIdOf<T>, | |
Vec<AccountIdOf<T>>, | |
>>::get(k) | |
} | |
} | |
pub struct _GeneratedPrefixForStorageOrganizations<T>(core::marker::PhantomData<(T,)>); | |
impl<T: Config> frame_support::traits::StorageInstance | |
for _GeneratedPrefixForStorageOrganizations<T> | |
{ | |
fn pallet_prefix() -> &'static str { | |
<<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::< | |
Pallet<T>, | |
>() | |
.expect("Every active pallet has a name in the runtime; qed") | |
} | |
const STORAGE_PREFIX: &'static str = "Organizations"; | |
} | |
pub struct _GeneratedPrefixForStorageMembersOf<T>(core::marker::PhantomData<(T,)>); | |
impl<T: Config> frame_support::traits::StorageInstance for _GeneratedPrefixForStorageMembersOf<T> { | |
fn pallet_prefix() -> &'static str { | |
<<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::< | |
Pallet<T>, | |
>() | |
.expect("Every active pallet has a name in the runtime; qed") | |
} | |
const STORAGE_PREFIX: &'static str = "MembersOf"; | |
} | |
#[doc(hidden)] | |
pub mod __substrate_inherent_check { | |
#[doc(hidden)] | |
pub use __is_inherent_part_defined_2 as is_inherent_part_defined; | |
} | |
/// Hidden instance generated to be internally used when module is used without | |
/// instance. | |
#[doc(hidden)] | |
pub type __InherentHiddenInstance = (); | |
pub(super) trait Store { | |
type Organizations; | |
type MembersOf; | |
} | |
impl<T: Config> Store for Pallet<T> { | |
type Organizations = Organizations<T>; | |
type MembersOf = MembersOf<T>; | |
} | |
impl<T: Config> frame_support::traits::Hooks<<T as frame_system::Config>::BlockNumber> | |
for Pallet<T> | |
{ | |
} | |
impl<T: Config> frame_support::traits::OnFinalize<<T as frame_system::Config>::BlockNumber> | |
for Pallet<T> | |
{ | |
fn on_finalize(n: <T as frame_system::Config>::BlockNumber) { | |
let __within_span__ = { | |
use ::tracing::__macro_support::Callsite as _; | |
static CALLSITE: ::tracing::__macro_support::MacroCallsite = { | |
use ::tracing::__macro_support::MacroCallsite; | |
static META: ::tracing::Metadata<'static> = { | |
::tracing_core::metadata::Metadata::new( | |
"on_finalize", | |
"pallet_registrar::pallet", | |
::tracing::Level::TRACE, | |
Some("pallets/registrar/src/lib.rs"), | |
Some(14u32), | |
Some("pallet_registrar::pallet"), | |
::tracing_core::field::FieldSet::new( | |
&[], | |
::tracing_core::callsite::Identifier(&CALLSITE), | |
), | |
::tracing::metadata::Kind::SPAN, | |
) | |
}; | |
MacroCallsite::new(&META) | |
}; | |
let mut interest = ::tracing::subscriber::Interest::never(); | |
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL | |
&& ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current() | |
&& { | |
interest = CALLSITE.interest(); | |
!interest.is_never() | |
} | |
&& CALLSITE.is_enabled(interest) | |
{ | |
let meta = CALLSITE.metadata(); | |
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) }) | |
} else { | |
let span = CALLSITE.disabled_span(); | |
{}; | |
span | |
} | |
}; | |
let __tracing_guard__ = __within_span__.enter(); | |
< Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_finalize (n) | |
} | |
} | |
impl<T: Config> frame_support::traits::OnIdle<<T as frame_system::Config>::BlockNumber> | |
for Pallet<T> | |
{ | |
fn on_idle( | |
n: <T as frame_system::Config>::BlockNumber, | |
remaining_weight: frame_support::weights::Weight, | |
) -> frame_support::weights::Weight { | |
< Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_idle (n , remaining_weight) | |
} | |
} | |
impl<T: Config> frame_support::traits::OnInitialize<<T as frame_system::Config>::BlockNumber> | |
for Pallet<T> | |
{ | |
fn on_initialize( | |
n: <T as frame_system::Config>::BlockNumber, | |
) -> frame_support::weights::Weight { | |
let __within_span__ = { | |
use ::tracing::__macro_support::Callsite as _; | |
static CALLSITE: ::tracing::__macro_support::MacroCallsite = { | |
use ::tracing::__macro_support::MacroCallsite; | |
static META: ::tracing::Metadata<'static> = { | |
::tracing_core::metadata::Metadata::new( | |
"on_initialize", | |
"pallet_registrar::pallet", | |
::tracing::Level::TRACE, | |
Some("pallets/registrar/src/lib.rs"), | |
Some(14u32), | |
Some("pallet_registrar::pallet"), | |
::tracing_core::field::FieldSet::new( | |
&[], | |
::tracing_core::callsite::Identifier(&CALLSITE), | |
), | |
::tracing::metadata::Kind::SPAN, | |
) | |
}; | |
MacroCallsite::new(&META) | |
}; | |
let mut interest = ::tracing::subscriber::Interest::never(); | |
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL | |
&& ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current() | |
&& { | |
interest = CALLSITE.interest(); | |
!interest.is_never() | |
} | |
&& CALLSITE.is_enabled(interest) | |
{ | |
let meta = CALLSITE.metadata(); | |
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) }) | |
} else { | |
let span = CALLSITE.disabled_span(); | |
{}; | |
span | |
} | |
}; | |
let __tracing_guard__ = __within_span__.enter(); | |
< Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_initialize (n) | |
} | |
} | |
impl<T: Config> frame_support::traits::OnRuntimeUpgrade for Pallet<T> { | |
fn on_runtime_upgrade() -> frame_support::weights::Weight { | |
let __within_span__ = { | |
use ::tracing::__macro_support::Callsite as _; | |
static CALLSITE: ::tracing::__macro_support::MacroCallsite = { | |
use ::tracing::__macro_support::MacroCallsite; | |
static META: ::tracing::Metadata<'static> = { | |
::tracing_core::metadata::Metadata::new( | |
"on_runtime_update", | |
"pallet_registrar::pallet", | |
::tracing::Level::TRACE, | |
Some("pallets/registrar/src/lib.rs"), | |
Some(14u32), | |
Some("pallet_registrar::pallet"), | |
::tracing_core::field::FieldSet::new( | |
&[], | |
::tracing_core::callsite::Identifier(&CALLSITE), | |
), | |
::tracing::metadata::Kind::SPAN, | |
) | |
}; | |
MacroCallsite::new(&META) | |
}; | |
let mut interest = ::tracing::subscriber::Interest::never(); | |
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL | |
&& ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current() | |
&& { | |
interest = CALLSITE.interest(); | |
!interest.is_never() | |
} | |
&& CALLSITE.is_enabled(interest) | |
{ | |
let meta = CALLSITE.metadata(); | |
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) }) | |
} else { | |
let span = CALLSITE.disabled_span(); | |
{}; | |
span | |
} | |
}; | |
let __tracing_guard__ = __within_span__.enter(); | |
let new_storage_version = frame_support::traits::PalletVersion { | |
major: 3u16, | |
minor: 0u8, | |
patch: 0u8, | |
}; | |
let pallet_name = < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: name :: < Self > () . unwrap_or ("<unknown pallet name>") ; | |
{ | |
let lvl = ::log::Level::Info; | |
if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { | |
::log::__private_api_log( | |
::core::fmt::Arguments::new_v1( | |
&[ | |
"\u{2705} no migration for ", | |
", setting storage version to ", | |
], | |
&match (&pallet_name, &new_storage_version) { | |
(arg0, arg1) => [ | |
::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt), | |
::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Debug::fmt), | |
], | |
}, | |
), | |
lvl, | |
&( | |
frame_support::LOG_TARGET, | |
"pallet_registrar::pallet", | |
"pallets/registrar/src/lib.rs", | |
14u32, | |
), | |
); | |
} | |
}; | |
let result = <Self as frame_support::traits::Hooks< | |
<T as frame_system::Config>::BlockNumber, | |
>>::on_runtime_upgrade(); | |
new_storage_version.put_into_storage::<<T as frame_system::Config>::PalletInfo, Self>(); | |
let additional_write = | |
<<T as frame_system::Config>::DbWeight as frame_support::traits::Get<_>>::get() | |
.writes(1); | |
result.saturating_add(additional_write) | |
} | |
} | |
impl<T: Config> frame_support::traits::OffchainWorker<<T as frame_system::Config>::BlockNumber> | |
for Pallet<T> | |
{ | |
fn offchain_worker(n: <T as frame_system::Config>::BlockNumber) { | |
< Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: offchain_worker (n) | |
} | |
} | |
impl<T: Config> frame_support::traits::IntegrityTest for Pallet<T> { | |
fn integrity_test() { | |
< Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: integrity_test () | |
} | |
} | |
#[cfg(feature = "std")] | |
impl<T: Config> frame_support::sp_runtime::BuildModuleGenesisStorage<T, ()> for GenesisConfig<T> { | |
fn build_module_genesis_storage( | |
&self, | |
storage: &mut frame_support::sp_runtime::Storage, | |
) -> std::result::Result<(), std::string::String> { | |
frame_support::BasicExternalities::execute_with_storage(storage, || { | |
<Self as frame_support::traits::GenesisBuild<T>>::build(self); | |
Ok(()) | |
}) | |
} | |
} | |
#[doc(hidden)] | |
pub mod __substrate_genesis_config_check { | |
#[doc(hidden)] | |
pub use __is_genesis_config_defined_3 as is_genesis_config_defined; | |
} | |
#[doc(hidden)] | |
pub mod __substrate_origin_check { | |
#[doc(hidden)] | |
pub use __is_origin_part_defined_4 as is_origin_part_defined; | |
} | |
#[doc(hidden)] | |
pub mod __substrate_validate_unsigned_check { | |
#[doc(hidden)] | |
pub use __is_validate_unsigned_part_defined_5 as is_validate_unsigned_part_defined; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment