|
1 | 1 | //! Catalyst Signed Document Extra Fields. |
2 | 2 |
|
3 | 3 | use anyhow::anyhow; |
| 4 | +use catalyst_types::uuid::UuidV4; |
4 | 5 | use coset::{cbor::Value, Label, ProtectedHeader}; |
5 | 6 |
|
6 | | -use super::{cose_protected_header_find, DocumentRef}; |
| 7 | +use super::{cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef}; |
7 | 8 |
|
8 | 9 | /// `ref` field COSE key value |
9 | 10 | const REF_KEY: &str = "ref"; |
@@ -52,7 +53,7 @@ pub struct ExtraFields { |
52 | 53 | campaign_id: Option<DocumentRef>, |
53 | 54 | /// Unique identifier for the election. |
54 | 55 | #[serde(skip_serializing_if = "Option::is_none")] |
55 | | - election_id: Option<DocumentRef>, |
| 56 | + election_id: Option<UuidV4>, |
56 | 57 | /// Unique identifier for the voting category as a collection of proposals. |
57 | 58 | #[serde(skip_serializing_if = "Option::is_none")] |
58 | 59 | category_id: Option<DocumentRef>, |
@@ -103,7 +104,7 @@ impl ExtraFields { |
103 | 104 |
|
104 | 105 | /// Return `election_id` field. |
105 | 106 | #[must_use] |
106 | | - pub fn election_id(&self) -> Option<DocumentRef> { |
| 107 | + pub fn election_id(&self) -> Option<UuidV4> { |
107 | 108 | self.election_id |
108 | 109 | } |
109 | 110 |
|
@@ -148,7 +149,7 @@ impl ExtraFields { |
148 | 149 |
|
149 | 150 | if let Some(election_id) = &self.election_id { |
150 | 151 | builder = |
151 | | - builder.text_value(ELECTION_ID_KEY.to_string(), Value::try_from(*election_id)?); |
| 152 | + builder.text_value(ELECTION_ID_KEY.to_string(), encode_cbor_uuid(election_id)?); |
152 | 153 | } |
153 | 154 |
|
154 | 155 | if let Some(category_id) = &self.category_id { |
@@ -288,7 +289,7 @@ impl TryFrom<&ProtectedHeader> for ExtraFields { |
288 | 289 | if let Some(cbor_doc_election_id) = cose_protected_header_find(protected, |key| { |
289 | 290 | key == &Label::Text(ELECTION_ID_KEY.to_string()) |
290 | 291 | }) { |
291 | | - match DocumentRef::try_from(cbor_doc_election_id) { |
| 292 | + match decode_cbor_uuid(cbor_doc_election_id.clone()) { |
292 | 293 | Ok(election_id) => { |
293 | 294 | extra.election_id = Some(election_id); |
294 | 295 | }, |
|
0 commit comments