@@ -5,182 +5,24 @@ pub(crate) mod rules;
55
66use std:: { collections:: HashMap , sync:: LazyLock } ;
77
8- use catalyst_types:: catalyst_id:: role_index:: RoleId ;
9- use rules:: {
10- ContentEncodingRule , ContentRule , ContentSchema , ContentTypeRule , IdRule , OriginalAuthorRule ,
11- ParametersRule , RefRule , ReplyRule , Rules , SectionRule , SignatureKidRule , VerRule ,
12- } ;
8+ use rules:: Rules ;
139
1410use crate :: {
15- doc_types:: {
16- BRAND_PARAMETERS , CAMPAIGN_PARAMETERS , CATEGORY_PARAMETERS , PROPOSAL , PROPOSAL_COMMENT ,
17- PROPOSAL_COMMENT_FORM_TEMPLATE , PROPOSAL_FORM_TEMPLATE , PROPOSAL_SUBMISSION_ACTION ,
18- } ,
1911 metadata:: DocType ,
2012 providers:: { CatalystIdProvider , CatalystSignedDocumentProvider } ,
21- validator:: rules:: { CollaboratorsRule , SignatureRule , TemplateRule } ,
22- CatalystSignedDocument , ContentEncoding , ContentType ,
13+ CatalystSignedDocument ,
2314} ;
2415
2516/// A table representing a full set or validation rules per document id.
2617static DOCUMENT_RULES : LazyLock < HashMap < DocType , Rules > > = LazyLock :: new ( document_rules_init) ;
2718
28- /// Proposal
29- /// Require field: type, id, ver, template, parameters
30- /// <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/proposal/>
31- fn proposal_rule ( ) -> Rules {
32- // Parameter can be either brand, campaign or category
33- let parameters = vec ! [
34- BRAND_PARAMETERS . clone( ) ,
35- CAMPAIGN_PARAMETERS . clone( ) ,
36- CATEGORY_PARAMETERS . clone( ) ,
37- ] ;
38- Rules {
39- id : IdRule ,
40- ver : VerRule ,
41- content_type : ContentTypeRule :: Specified {
42- exp : ContentType :: Json ,
43- } ,
44- content_encoding : ContentEncodingRule :: Specified {
45- exp : vec ! [ ContentEncoding :: Brotli ] ,
46- optional : false ,
47- } ,
48- template : TemplateRule :: Specified {
49- allowed_type : PROPOSAL_FORM_TEMPLATE . clone ( ) ,
50- } ,
51- parameters : ParametersRule :: Specified {
52- allowed_type : parameters. clone ( ) ,
53- optional : false ,
54- } ,
55- doc_ref : RefRule :: NotSpecified ,
56- reply : ReplyRule :: NotSpecified ,
57- section : SectionRule :: NotSpecified ,
58- collaborators : CollaboratorsRule :: NotSpecified ,
59- content : ContentRule :: NotNil ,
60- kid : SignatureKidRule {
61- allowed_roles : [ RoleId :: Proposer ] . into_iter ( ) . collect ( ) ,
62- } ,
63- signature : SignatureRule { mutlisig : false } ,
64- original_author : OriginalAuthorRule ,
65- }
66- }
67-
68- /// Proposal Comment
69- /// Require field: type, id, ver, ref, template, parameters
70- /// <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/proposal_comment_template/>
71- fn proposal_comment_rule ( ) -> Rules {
72- // Parameter can be either brand, campaign or category
73- let parameters = vec ! [
74- BRAND_PARAMETERS . clone( ) ,
75- CAMPAIGN_PARAMETERS . clone( ) ,
76- CATEGORY_PARAMETERS . clone( ) ,
77- ] ;
78- Rules {
79- id : IdRule ,
80- ver : VerRule ,
81- content_type : ContentTypeRule :: Specified {
82- exp : ContentType :: Json ,
83- } ,
84- content_encoding : ContentEncodingRule :: Specified {
85- exp : vec ! [ ContentEncoding :: Brotli ] ,
86- optional : false ,
87- } ,
88- template : TemplateRule :: Specified {
89- allowed_type : PROPOSAL_COMMENT_FORM_TEMPLATE . clone ( ) ,
90- } ,
91- doc_ref : RefRule :: Specified {
92- allowed_type : vec ! [ PROPOSAL . clone( ) ] ,
93- multiple : false ,
94- optional : false ,
95- } ,
96- reply : ReplyRule :: Specified {
97- allowed_type : PROPOSAL_COMMENT . clone ( ) ,
98- optional : true ,
99- } ,
100- section : SectionRule :: NotSpecified ,
101- parameters : ParametersRule :: Specified {
102- allowed_type : parameters. clone ( ) ,
103- optional : false ,
104- } ,
105- collaborators : CollaboratorsRule :: NotSpecified ,
106- content : ContentRule :: NotNil ,
107- kid : SignatureKidRule {
108- allowed_roles : [ RoleId :: Role0 ] . into_iter ( ) . collect ( ) ,
109- } ,
110- signature : SignatureRule { mutlisig : false } ,
111- original_author : OriginalAuthorRule ,
112- }
113- }
114-
115- /// Proposal Submission Action
116- /// Require fields: type, id, ver, ref, parameters
117- /// <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/proposal_submission_action/>
118- #[ allow( clippy:: expect_used) ]
119- fn proposal_submission_action_rule ( ) -> Rules {
120- // Parameter can be either brand, campaign or category
121- let parameters = vec ! [
122- BRAND_PARAMETERS . clone( ) ,
123- CAMPAIGN_PARAMETERS . clone( ) ,
124- CATEGORY_PARAMETERS . clone( ) ,
125- ] ;
126-
127- let proposal_action_json_schema_content = & serde_json:: from_str ( include_str ! (
128- "./../../../../specs/definitions/signed_docs/docs/payload_schemas/proposal_submission_action.schema.json"
129- ) )
130- . expect ( "Must be a valid json file" ) ;
131-
132- let proposal_action_json_schema =
133- json_schema:: JsonSchema :: try_from ( proposal_action_json_schema_content)
134- . expect ( "Must be a valid json scheme file" ) ;
135-
136- Rules {
137- id : IdRule ,
138- ver : VerRule ,
139- content_type : ContentTypeRule :: Specified {
140- exp : ContentType :: Json ,
141- } ,
142- content_encoding : ContentEncodingRule :: Specified {
143- exp : vec ! [ ContentEncoding :: Brotli ] ,
144- optional : false ,
145- } ,
146- template : TemplateRule :: NotSpecified ,
147- parameters : ParametersRule :: Specified {
148- allowed_type : parameters,
149- optional : false ,
150- } ,
151- doc_ref : RefRule :: Specified {
152- allowed_type : vec ! [ PROPOSAL . clone( ) ] ,
153- multiple : false ,
154- optional : false ,
155- } ,
156- reply : ReplyRule :: NotSpecified ,
157- section : SectionRule :: NotSpecified ,
158- collaborators : CollaboratorsRule :: NotSpecified ,
159- content : ContentRule :: StaticSchema ( ContentSchema :: Json ( proposal_action_json_schema) ) ,
160- kid : SignatureKidRule {
161- allowed_roles : [ RoleId :: Proposer ] . into_iter ( ) . collect ( ) ,
162- } ,
163- signature : SignatureRule { mutlisig : false } ,
164- original_author : OriginalAuthorRule ,
165- }
166- }
167-
16819/// `DOCUMENT_RULES` initialization function
16920#[ allow( clippy:: expect_used) ]
17021fn document_rules_init ( ) -> HashMap < DocType , Rules > {
171- let mut document_rules_map: HashMap < DocType , Rules > = Rules :: documents_rules ( )
22+ let document_rules_map: HashMap < DocType , Rules > = Rules :: documents_rules ( )
17223 . expect ( "cannot fail to initialize validation rules" )
17324 . collect ( ) ;
17425
175- // TODO: remove this redefinitions of the validation rules after
176- // `catalyst_signed_documents_rules!` macro would be fully finished
177- document_rules_map. insert ( PROPOSAL . clone ( ) , proposal_rule ( ) ) ;
178- document_rules_map. insert ( PROPOSAL_COMMENT . clone ( ) , proposal_comment_rule ( ) ) ;
179- document_rules_map. insert (
180- PROPOSAL_SUBMISSION_ACTION . clone ( ) ,
181- proposal_submission_action_rule ( ) ,
182- ) ;
183-
18426 document_rules_map
18527}
18628
0 commit comments