Skip to content

Commit 94f7445

Browse files
fix(rust/signed-doc): Change types for brand_id, campaign_id and category_id meta fields. (#181)
* update documentation spec * update ExtraField * revert for "election_id" * wip * wip --------- Co-authored-by: Joaquín Rosales <[email protected]>
1 parent 3017ece commit 94f7445

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

docs/src/architecture/08_concepts/signed_doc/cddl/additional_meta.cddl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ additional_fields = {
55
? "reply" => ref_type,
66
? "section" => text,
77
? "collabs" => [+any],
8-
? "brand_id" => UUID, ; UUID v4
9-
? "campaign_id" => UUID, ; UUID v4
8+
? "brand_id" => ref_type,
9+
? "campaign_id" => ref_type,
1010
? "election_id" => UUID, ; UUID v4
11-
? "category_id" => UUID, ; UUID v4
11+
? "category_id" => ref_type,
1212
}
1313

1414
ref_type = UUID / [UUID, UUID] ; UUIDs v7

docs/src/architecture/08_concepts/signed_doc/meta.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ This list can impact actions that can be performed by the `Proposal Action Docum
8888

8989
## `brand_id`
9090

91-
Unique identifier [UUID] v4, which represents a "brand" who is running the voting,
92-
e.g. Catalyst, Midnight.
91+
This is a reply to another document.
92+
The format is the same as the [CBOR] Array form of [`ref`](#ref-document-reference).
93+
94+
`brand_id` represents a "brand" who is running the voting, e.g. Catalyst, Midnight.
9395

9496
## `campaign_id`
9597

96-
Unique identifier [UUID] v4, which defines a "campaign" of voting,
97-
e.g. "treasury campaign".
98+
This is a reply to another document.
99+
The format is the same as the [CBOR] Array form of [`ref`](#ref-document-reference).
100+
101+
`campaign_id` defines a "campaign" of voting, e.g. "treasury campaign".
98102

99103
## `election_id`
100104

@@ -103,7 +107,10 @@ e.g. "Catalyst Fund 1", "Catalyst Fund 2".
103107

104108
## `category_id`
105109

106-
Unique identifier [UUID] v4 which defines a voting category as a collection of proposals,
110+
This is a reply to another document.
111+
The format is the same as the [CBOR] Array form of [`ref`](#ref-document-reference).
112+
113+
`campaign_id` defines a voting category as a collection of proposals,
107114
e.g. "Development & Infrastructure", "Products & Integrations".
108115

109116
[UUID]: https://www.rfc-editor.org/rfc/rfc9562.html

rust/signed_doc/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ mod tests {
268268
"template": {"id": uuid_v7.to_string()},
269269
"section": section,
270270
"collabs": collabs,
271-
"campaign_id": uuid_v4.to_string(),
271+
"campaign_id": {"id": uuid_v7.to_string()},
272272
"election_id": uuid_v4.to_string(),
273-
"brand_id": uuid_v4.to_string(),
274-
"category_id": uuid_v4.to_string(),
273+
"brand_id": {"id": uuid_v7.to_string()},
274+
"category_id": {"id": uuid_v7.to_string()},
275275
}))
276276
.unwrap();
277277
let content = vec![1, 2, 4, 5, 6, 7, 8, 9];

rust/signed_doc/src/metadata/extra_fields.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Catalyst Signed Document Extra Fields.
22
33
use anyhow::bail;
4-
use catalyst_types::problem_report::ProblemReport;
4+
use catalyst_types::{problem_report::ProblemReport, uuid::UuidV4};
55
use coset::{cbor::Value, Label, ProtectedHeader};
66

7-
use super::{cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef, UuidV4};
7+
use super::{cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef};
88

99
/// `ref` field COSE key value
1010
const REF_KEY: &str = "ref";
@@ -47,16 +47,16 @@ pub struct ExtraFields {
4747
collabs: Vec<String>,
4848
/// Unique identifier for the brand that is running the voting.
4949
#[serde(skip_serializing_if = "Option::is_none")]
50-
brand_id: Option<UuidV4>,
50+
brand_id: Option<DocumentRef>,
5151
/// Unique identifier for the campaign of voting.
5252
#[serde(skip_serializing_if = "Option::is_none")]
53-
campaign_id: Option<UuidV4>,
53+
campaign_id: Option<DocumentRef>,
5454
/// Unique identifier for the election.
5555
#[serde(skip_serializing_if = "Option::is_none")]
5656
election_id: Option<UuidV4>,
5757
/// Unique identifier for the voting category as a collection of proposals.
5858
#[serde(skip_serializing_if = "Option::is_none")]
59-
category_id: Option<UuidV4>,
59+
category_id: Option<DocumentRef>,
6060
}
6161

6262
impl ExtraFields {
@@ -92,13 +92,13 @@ impl ExtraFields {
9292

9393
/// Return `brand_id` field.
9494
#[must_use]
95-
pub fn brand_id(&self) -> Option<UuidV4> {
95+
pub fn brand_id(&self) -> Option<DocumentRef> {
9696
self.brand_id
9797
}
9898

9999
/// Return `campaign_id` field.
100100
#[must_use]
101-
pub fn campaign_id(&self) -> Option<UuidV4> {
101+
pub fn campaign_id(&self) -> Option<DocumentRef> {
102102
self.campaign_id
103103
}
104104

@@ -110,7 +110,7 @@ impl ExtraFields {
110110

111111
/// Return `category_id` field.
112112
#[must_use]
113-
pub fn category_id(&self) -> Option<UuidV4> {
113+
pub fn category_id(&self) -> Option<DocumentRef> {
114114
self.category_id
115115
}
116116

@@ -139,12 +139,12 @@ impl ExtraFields {
139139
);
140140
}
141141
if let Some(brand_id) = &self.brand_id {
142-
builder = builder.text_value(BRAND_ID_KEY.to_string(), encode_cbor_uuid(brand_id)?);
142+
builder = builder.text_value(BRAND_ID_KEY.to_string(), Value::try_from(*brand_id)?);
143143
}
144144

145145
if let Some(campaign_id) = &self.campaign_id {
146146
builder =
147-
builder.text_value(CAMPAIGN_ID_KEY.to_string(), encode_cbor_uuid(campaign_id)?);
147+
builder.text_value(CAMPAIGN_ID_KEY.to_string(), Value::try_from(*campaign_id)?);
148148
}
149149

150150
if let Some(election_id) = &self.election_id {
@@ -154,7 +154,7 @@ impl ExtraFields {
154154

155155
if let Some(category_id) = &self.category_id {
156156
builder =
157-
builder.text_value(CATEGORY_ID_KEY.to_string(), encode_cbor_uuid(*category_id)?);
157+
builder.text_value(CATEGORY_ID_KEY.to_string(), Value::try_from(*category_id)?);
158158
}
159159
Ok(builder)
160160
}
@@ -278,7 +278,7 @@ impl ExtraFields {
278278
if let Some(cbor_doc_brand_id) = cose_protected_header_find(protected, |key| {
279279
key == &Label::Text(BRAND_ID_KEY.to_string())
280280
}) {
281-
match decode_cbor_uuid(cbor_doc_brand_id.clone()) {
281+
match DocumentRef::try_from(cbor_doc_brand_id) {
282282
Ok(brand_id) => {
283283
extra.brand_id = Some(brand_id);
284284
},
@@ -296,7 +296,7 @@ impl ExtraFields {
296296
if let Some(cbor_doc_campaign_id) = cose_protected_header_find(protected, |key| {
297297
key == &Label::Text(CAMPAIGN_ID_KEY.to_string())
298298
}) {
299-
match decode_cbor_uuid(cbor_doc_campaign_id.clone()) {
299+
match DocumentRef::try_from(cbor_doc_campaign_id) {
300300
Ok(campaign_id) => {
301301
extra.campaign_id = Some(campaign_id);
302302
},
@@ -332,7 +332,7 @@ impl ExtraFields {
332332
if let Some(cbor_doc_category_id) = cose_protected_header_find(protected, |key| {
333333
key == &Label::Text(CATEGORY_ID_KEY.to_string())
334334
}) {
335-
match decode_cbor_uuid(cbor_doc_category_id.clone()) {
335+
match DocumentRef::try_from(cbor_doc_category_id) {
336336
Ok(category_id) => {
337337
extra.category_id = Some(category_id);
338338
},

0 commit comments

Comments
 (0)