|
| 1 | +//! An implementation of different defined document types |
| 2 | +//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/> |
| 3 | +
|
| 4 | +mod proposal_document; |
| 5 | + |
| 6 | +use catalyst_types::uuid::UuidV4; |
| 7 | +pub use proposal_document::{ProposalDocument, PROPOSAL_DOCUMENT_UUID_TYPE}; |
| 8 | + |
| 9 | +/// Represents different types of documents. |
| 10 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 11 | +pub enum DocumentType { |
| 12 | + /// A proposal document containing proposal details. |
| 13 | + ProposalDocument, |
| 14 | + /// A template for proposal documents, defining the expected structure. |
| 15 | + ProposalTemplate, |
| 16 | + /// A document representing a comment on a proposal. |
| 17 | + CommentDocument, |
| 18 | + /// A template for comment documents, defining the expected structure. |
| 19 | + CommentTemplate, |
| 20 | + /// A review document containing feedback on a proposal. |
| 21 | + ReviewDocument, |
| 22 | + /// A template for review documents, defining the expected structure. |
| 23 | + ReviewTemplate, |
| 24 | + /// A document defining parameters for a specific category. |
| 25 | + CategoryParametersDocument, |
| 26 | + /// A template for category parameter documents, defining the expected structure. |
| 27 | + CategoryParametersTemplate, |
| 28 | + /// A document containing parameters for a specific campaign. |
| 29 | + CampaignParametersDocument, |
| 30 | + /// A template for campaign parameter documents, defining the expected structure. |
| 31 | + CampaignParametersTemplate, |
| 32 | + /// A document containing brand-related parameters. |
| 33 | + BrandParametersDocument, |
| 34 | + /// A template for brand parameter documents, defining the expected structure. |
| 35 | + BrandParametersTemplate, |
| 36 | + /// A document representing an action related to a proposal. |
| 37 | + ProposalActionDocument, |
| 38 | + /// A public voting transaction version 2. |
| 39 | + PublicVoteTxV2, |
| 40 | + /// A private voting transaction version 2. |
| 41 | + PrivateVoteTxV2, |
| 42 | + /// A block in the immutable ledger. |
| 43 | + ImmutableLedgerBlock, |
| 44 | +} |
| 45 | + |
| 46 | +/// Proposal template `UuidV4` type. |
| 47 | +const PROPOSAL_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 48 | + uuid::Uuid::from_u128(0x0CE8_AB38_9258_4FBC_A62E_7FAA_6E58_318F); |
| 49 | +/// Comment document `UuidV4` type. |
| 50 | +const COMMENT_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 51 | + uuid::Uuid::from_u128(0xB679_DED3_0E7C_41BA_89F8_DA62_A178_98EA); |
| 52 | +/// Comment template `UuidV4` type. |
| 53 | +const COMMENT_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 54 | + uuid::Uuid::from_u128(0x0B84_24D4_EBFD_46E3_9577_1775_A69D_290C); |
| 55 | +/// Review document `UuidV4` type. |
| 56 | +const REVIEW_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 57 | + uuid::Uuid::from_u128(0xE4CA_F5F0_098B_45FD_94F3_0702_A457_3DB5); |
| 58 | +/// Review template `UuidV4` type. |
| 59 | +const REVIEW_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 60 | + uuid::Uuid::from_u128(0xEBE5_D0BF_5D86_4577_AF4D_008F_DDBE_2EDC); |
| 61 | +/// Category parameters document `UuidV4` type. |
| 62 | +const CATEGORY_PARAMETERS_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 63 | + uuid::Uuid::from_u128(0x48C2_0109_362A_4D32_9BBA_E0A9_CF8B_45BE); |
| 64 | +/// Category parameters template `UuidV4` type. |
| 65 | +const CATEGORY_PARAMETERS_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 66 | + uuid::Uuid::from_u128(0x65B1_E8B0_51F1_46A5_9970_72CD_F268_84BE); |
| 67 | +/// Campaign parameters document `UuidV4` type. |
| 68 | +const CAMPAIGN_PARAMETERS_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 69 | + uuid::Uuid::from_u128(0x0110_EA96_A555_47CE_8408_36EF_E6ED_6F7C); |
| 70 | +/// Campaign parameters template `UuidV4` type. |
| 71 | +const CAMPAIGN_PARAMETERS_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 72 | + uuid::Uuid::from_u128(0x7E8F_5FA2_44CE_49C8_BFD5_02AF_42C1_79A3); |
| 73 | +/// Brand parameters document `UuidV4` type. |
| 74 | +const BRAND_PARAMETERS_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 75 | + uuid::Uuid::from_u128(0x3E48_08CC_C86E_467B_9702_D60B_AA9D_1FCA); |
| 76 | +/// Brand parameters template `UuidV4` type. |
| 77 | +const BRAND_PARAMETERS_TEMPLATE_UUID_TYPE: uuid::Uuid = |
| 78 | + uuid::Uuid::from_u128(0xFD3C_1735_80B1_4EEA_8D63_5F43_6D97_EA31); |
| 79 | +/// Proposal action document `UuidV4` type. |
| 80 | +const PROPOSAL_ACTION_DOCUMENT_UUID_TYPE: uuid::Uuid = |
| 81 | + uuid::Uuid::from_u128(0x5E60_E623_AD02_4A1B_A1AC_406D_B978_EE48); |
| 82 | +/// Public vote transaction v2 `UuidV4` type. |
| 83 | +const PUBLIC_VOTE_TX_V2_UUID_TYPE: uuid::Uuid = |
| 84 | + uuid::Uuid::from_u128(0x8DE5_586C_E998_4B95_8742_7BE3_C859_2803); |
| 85 | +/// Private vote transaction v2 `UuidV4` type. |
| 86 | +const PRIVATE_VOTE_TX_V2_UUID_TYPE: uuid::Uuid = |
| 87 | + uuid::Uuid::from_u128(0xE78E_E18D_F380_44C1_A852_80AA_6ECB_07FE); |
| 88 | +/// Immutable ledger block `UuidV4` type. |
| 89 | +const IMMUTABLE_LEDGER_BLOCK_UUID_TYPE: uuid::Uuid = |
| 90 | + uuid::Uuid::from_u128(0xD9E7_E6CE_2401_4D7D_9492_F4F7_C642_41C3); |
| 91 | + |
| 92 | +impl TryFrom<UuidV4> for DocumentType { |
| 93 | + type Error = anyhow::Error; |
| 94 | + |
| 95 | + fn try_from(uuid: UuidV4) -> Result<Self, Self::Error> { |
| 96 | + match uuid.uuid() { |
| 97 | + PROPOSAL_DOCUMENT_UUID_TYPE => Ok(DocumentType::ProposalDocument), |
| 98 | + PROPOSAL_TEMPLATE_UUID_TYPE => Ok(DocumentType::ProposalTemplate), |
| 99 | + COMMENT_DOCUMENT_UUID_TYPE => Ok(DocumentType::CommentDocument), |
| 100 | + COMMENT_TEMPLATE_UUID_TYPE => Ok(DocumentType::CommentTemplate), |
| 101 | + REVIEW_DOCUMENT_UUID_TYPE => Ok(DocumentType::ReviewDocument), |
| 102 | + REVIEW_TEMPLATE_UUID_TYPE => Ok(DocumentType::ReviewTemplate), |
| 103 | + CATEGORY_PARAMETERS_DOCUMENT_UUID_TYPE => Ok(DocumentType::CategoryParametersDocument), |
| 104 | + CATEGORY_PARAMETERS_TEMPLATE_UUID_TYPE => Ok(DocumentType::CategoryParametersTemplate), |
| 105 | + CAMPAIGN_PARAMETERS_DOCUMENT_UUID_TYPE => Ok(DocumentType::CampaignParametersDocument), |
| 106 | + CAMPAIGN_PARAMETERS_TEMPLATE_UUID_TYPE => Ok(DocumentType::CampaignParametersTemplate), |
| 107 | + BRAND_PARAMETERS_DOCUMENT_UUID_TYPE => Ok(DocumentType::BrandParametersDocument), |
| 108 | + BRAND_PARAMETERS_TEMPLATE_UUID_TYPE => Ok(DocumentType::BrandParametersTemplate), |
| 109 | + PROPOSAL_ACTION_DOCUMENT_UUID_TYPE => Ok(DocumentType::ProposalActionDocument), |
| 110 | + PUBLIC_VOTE_TX_V2_UUID_TYPE => Ok(DocumentType::PublicVoteTxV2), |
| 111 | + PRIVATE_VOTE_TX_V2_UUID_TYPE => Ok(DocumentType::PrivateVoteTxV2), |
| 112 | + IMMUTABLE_LEDGER_BLOCK_UUID_TYPE => Ok(DocumentType::ImmutableLedgerBlock), |
| 113 | + _ => anyhow::bail!("Unsupported document type"), |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments