Skip to content

Commit

Permalink
add scale codec index to enums (#2247)
Browse files Browse the repository at this point in the history
* add scale codec index to enums

* ts formatting
  • Loading branch information
kziemianek authored Nov 13, 2023
1 parent e626277 commit 0db6242
Show file tree
Hide file tree
Showing 39 changed files with 258 additions and 9 deletions.
6 changes: 6 additions & 0 deletions pallets/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ pub mod pallet {

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum ProposalStatus {
#[codec(index = 0)]
Initiated,
#[codec(index = 1)]
Approved,
#[codec(index = 2)]
Rejected,
}

Expand All @@ -92,8 +95,11 @@ pub mod pallet {

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum BridgeEvent {
#[codec(index = 0)]
FungibleTransfer(BridgeChainId, DepositNonce, ResourceId, u128, Vec<u8>),
#[codec(index = 1)]
NonFungibleTransfer(BridgeChainId, DepositNonce, ResourceId, Vec<u8>, Vec<u8>, Vec<u8>),
#[codec(index = 2)]
GenericTransfer(BridgeChainId, DepositNonce, ResourceId, Vec<u8>),
}

Expand Down
3 changes: 3 additions & 0 deletions pallets/extrinsic-filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ pub use weights::WeightInfo;
pub enum OperationalMode {
/// when parachain runs normally
#[default]
#[codec(index = 0)]
Normal,
/// when parachain traps in contigency situation
#[codec(index = 1)]
Safe,
/// when parachain is used for testing purpose
#[codec(index = 2)]
Test,
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/parachain-staking/src/delegation_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ use sp_std::{vec, vec::Vec};
/// An action that can be performed upon a delegation
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, PartialOrd, Ord)]
pub enum DelegationAction<Balance> {
#[codec(index = 0)]
Revoke(Balance),
#[codec(index = 1)]
Decrease(Balance),
}

Expand Down
9 changes: 9 additions & 0 deletions pallets/parachain-staking/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ impl<AccountId: Ord, Balance> PartialEq for Bond<AccountId, Balance> {
pub enum CollatorStatus {
/// Committed to be online and producing valid blocks (not equivocating)
#[default]
#[codec(index = 0)]
Active,
/// Temporarily inactive and excused for inactivity
#[codec(index = 1)]
Idle,
/// Bonded until the inner round
#[codec(index = 2)]
Leaving(RoundIndex),
}

Expand Down Expand Up @@ -252,10 +255,13 @@ impl<AccountId, Balance: Copy + Ord + sp_std::ops::AddAssign + Zero + Saturating
/// Capacity status for top or bottom delegations
pub enum CapacityStatus {
/// Reached capacity
#[codec(index = 0)]
Full,
/// Empty aka contains no delegations
#[codec(index = 1)]
Empty,
/// Partially full (nonempty and not full)
#[codec(index = 2)]
Partial,
}

Expand Down Expand Up @@ -1020,13 +1026,16 @@ impl<
/// Delegations added to the top yield a new total
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum DelegatorAdded<B> {
#[codec(index = 0)]
AddedToTop { new_total: B },
#[codec(index = 1)]
AddedToBottom,
}

#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum DelegatorStatus {
/// Active with no scheduled exit
#[codec(index = 0)]
Active,
}

Expand Down
5 changes: 5 additions & 0 deletions pallets/teerex/sgx-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,15 @@ pub struct SgxQuote {
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, sp_core::RuntimeDebug, TypeInfo, Default)]
pub enum SgxStatus {
#[default]
#[codec(index = 0)]
Invalid,
#[codec(index = 1)]
Ok,
#[codec(index = 2)]
GroupOutOfDate,
#[codec(index = 3)]
GroupRevoked,
#[codec(index = 4)]
ConfigurationNeeded,
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/vc-management/src/vc_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use crate::{Assertion, Config};

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum Status {
#[codec(index = 0)]
Active,
#[codec(index = 1)]
Disabled,
// Revoked, // commented out for now, we can delete the VC entry when revoked
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/xcm-asset-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ impl pallet_balances::Config for Test {
pub type AssetId = u32;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum MockAssetType {
#[codec(index = 0)]
MockAsset(AssetId),
#[codec(index = 1)]
Xcm(Box<MultiLocation>),
}

Expand Down
31 changes: 30 additions & 1 deletion primitives/core/src/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,27 @@ pub struct AchainableToken {
#[rustfmt::skip]
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum AchainableParams {
#[codec(index = 0)]
AmountHolding(AchainableAmountHolding),
#[codec(index = 1)]
AmountToken(AchainableAmountToken),
#[codec(index = 2)]
Amount(AchainableAmount),
#[codec(index = 3)]
Amounts(AchainableAmounts),
#[codec(index = 4)]
Basic(AchainableBasic),
#[codec(index = 5)]
BetweenPercents(AchainableBetweenPercents),
#[codec(index = 6)]
ClassOfYear(AchainableClassOfYear),
#[codec(index = 7)]
DateInterval(AchainableDateInterval),
#[codec(index = 8)]
DatePercent(AchainableDatePercent),
#[codec(index = 9)]
Date(AchainableDate),
#[codec(index = 10)]
Token(AchainableToken),
}

Expand Down Expand Up @@ -159,31 +170,45 @@ impl AchainableParams {
#[rustfmt::skip]
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum Assertion {
#[codec(index = 0)]
A1,
#[codec(index = 1)]
A2(ParameterString), // (guild_id)
#[codec(index = 2)]
A3(ParameterString, ParameterString, ParameterString), // (guild_id, channel_id, role_id)
#[codec(index = 3)]
A4(ParameterString), // (minimum_amount)
#[codec(index = 4)]
A6,
#[codec(index = 5)]
A7(ParameterString), // (minimum_amount)
#[codec(index = 6)]
A8(BoundedWeb3Network), // litentry, litmus, polkadot, kusama, khala, ethereum
#[codec(index = 7)]
A10(ParameterString), // (minimum_amount)
#[codec(index = 8)]
A11(ParameterString), // (minimum_amount)

// ----- begin polkadot decoded 2023 -----
#[codec(index = 9)]
A13(AccountId), // (participant_account), can only be requested by delegatee
#[codec(index = 10)]
A14,
// for Holder assertions we'll reuse A4/A7
// ----- end polkadot decoded 2023 -----

#[codec(index = 11)]
Achainable(AchainableParams),

// For EVM Version Early Bird
#[codec(index = 12)]
A20,

// For Oneblock
#[codec(index = 13)]
Oneblock(OneBlockCourseType),

// Sora Quiz
#[codec(index = 14)]
SoraQuiz(SoraQuizType, ParameterString), // (sora_quiz_type, guild_id)
}

Expand Down Expand Up @@ -238,8 +263,12 @@ pub const ASSERTION_FROM_DATE: [&str; 14] = [

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum AmountHoldingTimeType {
#[codec(index = 0)]
LIT,
#[codec(index = 1)]
DOT,
#[codec(index = 2)]
WBTC,
#[codec(index = 3)]
ETH,
}
20 changes: 20 additions & 0 deletions primitives/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,36 @@ pub type ErrorString = BoundedVec<u8, MaxStringLength>;
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum ErrorDetail {
// error when importing the parentchain blocks and executing indirect calls
#[codec(index = 0)]
ImportError,
// the direct or indirect request comes from an unauthorized signer
#[codec(index = 1)]
UnauthorizedSigner,
// generic error when executing STF, the `ErrorString` should indicate the actual reason
#[codec(index = 2)]
StfError(ErrorString),
// error when sending stf request to the receiver fails
#[codec(index = 3)]
SendStfRequestFailed,
// generic parse error, can be caused by UTF8/JSON serde..
#[codec(index = 4)]
ParseError,
// errors when communicating with data provider, e.g. HTTP error
#[codec(index = 5)]
DataProviderError(ErrorString),
#[codec(index = 6)]
InvalidIdentity,
#[codec(index = 7)]
WrongWeb2Handle,
#[codec(index = 8)]
UnexpectedMessage,
#[codec(index = 9)]
WrongSignatureType,
#[codec(index = 10)]
VerifyWeb3SignatureFailed,
#[codec(index = 11)]
RecoverEvmAddressFailed,
#[codec(index = 12)]
Web3NetworkOutOfBounds,
}

Expand Down Expand Up @@ -79,14 +92,19 @@ where
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum IMPError {
// errors when executing individual error
#[codec(index = 0)]
LinkIdentityFailed(ErrorDetail),
#[codec(index = 1)]
DeactivateIdentityFailed(ErrorDetail),
#[codec(index = 2)]
ActivateIdentityFailed(ErrorDetail),
// scheduled encalve import error
#[codec(index = 3)]
ImportScheduledEnclaveFailed,

// should be unreached, but just to be on the safe side
// we should classify the error if we ever get this
#[codec(index = 4)]
UnclassifiedError(ErrorDetail),
}

Expand All @@ -98,8 +116,10 @@ impl frame_support::traits::PalletError for IMPError {
// Verified Credential(VC) Management Pallet Error
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum VCMPError {
#[codec(index = 0)]
RequestVCFailed(Assertion, ErrorDetail),
// should be unreached, but just to be on the safe side
// we should classify the error if we ever get this
#[codec(index = 1)]
UnclassifiedError(ErrorDetail),
}
9 changes: 9 additions & 0 deletions primitives/core/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,25 @@ pub type BoundedWeb3Network = BoundedVec<Web3Network, ConstU32<MAX_WEB3NETWORK_L
)]
pub enum Web3Network {
// substrate
#[codec(index = 0)]
Polkadot,
#[codec(index = 1)]
Kusama,
#[codec(index = 2)]
Litentry,
#[codec(index = 3)]
Litmus,
#[codec(index = 4)]
LitentryRococo,
#[codec(index = 5)]
Khala,
#[codec(index = 6)]
SubstrateTestnet, // when launched it with standalone (integritee-)node

// evm
#[codec(index = 7)]
Ethereum,
#[codec(index = 8)]
Bsc,
}

Expand Down
3 changes: 3 additions & 0 deletions primitives/core/src/oneblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ use scale_info::TypeInfo;
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum OneBlockCourseType {
// Substrate Blockchain Development Course Completion
#[codec(index = 0)]
CourseCompletion,

// Substrate Blockchain Development Course Outstanding Student
#[codec(index = 1)]
CourseOutstanding,

// Substrate Blockchain Development Course Participation
#[codec(index = 2)]
CourseParticipation,
}
2 changes: 2 additions & 0 deletions primitives/core/src/soraquiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use scale_info::TypeInfo;

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum SoraQuizType {
#[codec(index = 0)]
Attendee,
#[codec(index = 1)]
Master,
}
2 changes: 2 additions & 0 deletions primitives/teerex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ use sp_std::prelude::*;

#[derive(Encode, Decode, Copy, Clone, Default, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub enum SgxBuildMode {
#[codec(index = 0)]
Debug,
#[default]
#[codec(index = 1)]
Production,
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/xcm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ impl ContainsPair<MultiAsset, MultiLocation> for MultiNativeAsset {

#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub enum CurrencyId4Compare {
#[codec(index = 0)]
SelfReserve,
#[codec(index = 1)]
ParachainReserve(Box<MultiLocation>),
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,19 @@ impl pallet_multisig::Config for Runtime {
)]
pub enum ProxyType {
/// Fully permissioned proxy. Can execute any call on behalf of _proxied_.
#[codec(index = 0)]
Any,
/// Can execute any call that does not transfer funds, including asset transfers.
#[codec(index = 1)]
NonTransfer,
/// Proxy with the ability to reject time-delay proxy announcements.
#[codec(index = 2)]
CancelProxy,
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
#[codec(index = 3)]
Collator,
/// Governance
#[codec(index = 4)]
Governance,
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/litmus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,19 @@ impl pallet_multisig::Config for Runtime {
)]
pub enum ProxyType {
/// Fully permissioned proxy. Can execute any call on behalf of _proxied_.
#[codec(index = 0)]
Any,
/// Can execute any call that does not transfer funds, including asset transfers.
#[codec(index = 1)]
NonTransfer,
/// Proxy with the ability to reject time-delay proxy announcements.
#[codec(index = 2)]
CancelProxy,
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
#[codec(index = 3)]
Collator,
/// Governance
#[codec(index = 4)]
Governance,
}

Expand Down
Loading

0 comments on commit 0db6242

Please sign in to comment.