Implement #[pallet::composite_enum] (#13722)

* Implement #[pallet::hold_reason]

* Appease clippy

* cargo fmt

* Update test expectations

* Update test expectations

* Support composite_enum attribute instead

* Update test expectations

* Change hold_reason to composite_enum

* Add UI test for unsupported identifier when using composite_enum

* Fix comment

* Add documentation for pallet::composable_enum

* More docs

* cargo fmt
This commit is contained in:
Keith Yeung
2023-04-04 20:28:46 +08:00
committed by GitHub
parent c268f3d3c8
commit 1a55f961c6
26 changed files with 682 additions and 11 deletions
@@ -38,6 +38,10 @@ mod keyword {
syn::custom_keyword!(Origin);
syn::custom_keyword!(Inherent);
syn::custom_keyword!(ValidateUnsigned);
syn::custom_keyword!(FreezeReason);
syn::custom_keyword!(HoldReason);
syn::custom_keyword!(LockId);
syn::custom_keyword!(SlashReason);
syn::custom_keyword!(exclude_parts);
syn::custom_keyword!(use_parts);
}
@@ -370,6 +374,10 @@ pub enum PalletPartKeyword {
Origin(keyword::Origin),
Inherent(keyword::Inherent),
ValidateUnsigned(keyword::ValidateUnsigned),
FreezeReason(keyword::FreezeReason),
HoldReason(keyword::HoldReason),
LockId(keyword::LockId),
SlashReason(keyword::SlashReason),
}
impl Parse for PalletPartKeyword {
@@ -392,6 +400,14 @@ impl Parse for PalletPartKeyword {
Ok(Self::Inherent(input.parse()?))
} else if lookahead.peek(keyword::ValidateUnsigned) {
Ok(Self::ValidateUnsigned(input.parse()?))
} else if lookahead.peek(keyword::FreezeReason) {
Ok(Self::FreezeReason(input.parse()?))
} else if lookahead.peek(keyword::HoldReason) {
Ok(Self::HoldReason(input.parse()?))
} else if lookahead.peek(keyword::LockId) {
Ok(Self::LockId(input.parse()?))
} else if lookahead.peek(keyword::SlashReason) {
Ok(Self::SlashReason(input.parse()?))
} else {
Err(lookahead.error())
}
@@ -410,6 +426,10 @@ impl PalletPartKeyword {
Self::Origin(_) => "Origin",
Self::Inherent(_) => "Inherent",
Self::ValidateUnsigned(_) => "ValidateUnsigned",
Self::FreezeReason(_) => "FreezeReason",
Self::HoldReason(_) => "HoldReason",
Self::LockId(_) => "LockId",
Self::SlashReason(_) => "SlashReason",
}
}
@@ -435,6 +455,10 @@ impl Spanned for PalletPartKeyword {
Self::Origin(inner) => inner.span(),
Self::Inherent(inner) => inner.span(),
Self::ValidateUnsigned(inner) => inner.span(),
Self::FreezeReason(inner) => inner.span(),
Self::HoldReason(inner) => inner.span(),
Self::LockId(inner) => inner.span(),
Self::SlashReason(inner) => inner.span(),
}
}
}