diff --git a/catalyst-gateway/Cargo.lock b/catalyst-gateway/Cargo.lock index 5c0751f8d557..1ead867a9db3 100644 --- a/catalyst-gateway/Cargo.lock +++ b/catalyst-gateway/Cargo.lock @@ -828,7 +828,7 @@ dependencies = [ [[package]] name = "catalyst-signed-doc" version = "0.0.4" -source = "git+https://github.com/input-output-hk/catalyst-libs.git?tag=cardano-chain-follower-v0.0.10#cbd70c471d73f72674e07112a4e09c84159e4e13" +source = "git+https://github.com/input-output-hk/catalyst-libs.git?tag=catalyst-signed-doc%2Fv0.0.4-f15-rc#26b42964c3d2178b8c30e3cc1b367ef185b0ee5f" dependencies = [ "anyhow", "brotli 7.0.0", diff --git a/catalyst-gateway/bin/Cargo.toml b/catalyst-gateway/bin/Cargo.toml index 37512339aa1b..0419b50f78d0 100644 --- a/catalyst-gateway/bin/Cargo.toml +++ b/catalyst-gateway/bin/Cargo.toml @@ -19,7 +19,7 @@ cardano-chain-follower = { version = "0.0.10", git = "https://github.com/input-o rbac-registration = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower-v0.0.10" } catalyst-types = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" } cardano-blockchain-types = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" } -catalyst-signed-doc = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower-v0.0.10" } +catalyst-signed-doc = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v0.0.4-f15-rc" } c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" } pallas = { version = "0.33.0" } diff --git a/catalyst-gateway/bin/src/service/api/documents/common/mod.rs b/catalyst-gateway/bin/src/service/api/documents/common/mod.rs index 1480f3166aff..a809f2697cbb 100644 --- a/catalyst-gateway/bin/src/service/api/documents/common/mod.rs +++ b/catalyst-gateway/bin/src/service/api/documents/common/mod.rs @@ -5,28 +5,13 @@ use std::collections::HashMap; use catalyst_signed_doc::CatalystSignedDocument; -use super::templates::get_doc_static_template; +use super::templates::get_active_doc_static_template; use crate::{ db::event::{error::NotFoundError, signed_docs::FullSignedDoc}, service::common::auth::rbac::token::CatalystRBACTokenV1, settings::Settings, }; -/// Get document from the database -pub(crate) async fn get_document( - document_id: &uuid::Uuid, - version: Option<&uuid::Uuid>, -) -> anyhow::Result { - // Find the doc in the static templates first - if let Some(doc) = get_doc_static_template(document_id) { - return Ok(doc); - } - - // If doesn't exist in the static templates, try to find it in the database - let db_doc = FullSignedDoc::retrieve(document_id, version).await?; - db_doc.raw().try_into() -} - /// A struct which implements a /// `catalyst_signed_doc::providers::CatalystSignedDocumentProvider` trait pub(crate) struct DocProvider; @@ -38,8 +23,14 @@ impl catalyst_signed_doc::providers::CatalystSignedDocumentProvider for DocProvi ) -> anyhow::Result> { let id = doc_ref.id.uuid(); let ver = doc_ref.ver.uuid(); - match get_document(&id, Some(&ver)).await { - Ok(doc) => Ok(Some(doc)), + + // Find the doc in the static templates first + if let Some(doc) = get_active_doc_static_template(&id) { + return Ok(Some(doc)); + } + + match FullSignedDoc::retrieve(&id, Some(&ver)).await { + Ok(doc) => doc.raw().try_into().map(Some), Err(err) if err.is::() => Ok(None), Err(err) => Err(err), } diff --git a/catalyst-gateway/bin/src/service/api/documents/get_document.rs b/catalyst-gateway/bin/src/service/api/documents/get_document.rs index 469634ba59d8..cb7b02c67684 100644 --- a/catalyst-gateway/bin/src/service/api/documents/get_document.rs +++ b/catalyst-gateway/bin/src/service/api/documents/get_document.rs @@ -2,9 +2,9 @@ use poem_openapi::ApiResponse; -use super::common; +use super::templates::get_doc_static_template; use crate::{ - db::event::error::NotFoundError, + db::event::{error::NotFoundError, signed_docs::FullSignedDoc}, service::common::{responses::WithErrorResponses, types::payload::cbor::Cbor}, }; @@ -31,13 +31,16 @@ pub(crate) async fn endpoint( document_id: uuid::Uuid, version: Option, ) -> AllResponses { - match common::get_document(&document_id, version.as_ref()).await { - Ok(doc) => { - match doc.try_into() { - Ok(doc_cbor_bytes) => Responses::Ok(Cbor(doc_cbor_bytes)).into(), - Err(err) => AllResponses::handle_error(&err), - } - }, + // Find the doc in the static templates first + if let Some(doc) = get_doc_static_template(&document_id) { + return match doc.try_into() { + Ok(doc_cbor_bytes) => Responses::Ok(Cbor(doc_cbor_bytes)).into(), + Err(err) => AllResponses::handle_error(&err), + }; + } + + match FullSignedDoc::retrieve(&document_id, version.as_ref()).await { + Ok(doc) => Responses::Ok(Cbor(doc.raw().to_vec())).into(), Err(err) if err.is::() => Responses::NotFound.into(), Err(err) => AllResponses::handle_error(&err), } diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/f14_comment_template.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/f14_comment_template.schema.json deleted file mode 120000 index 734955b8aa85..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/f14_comment_template.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../docs/src/architecture/08_concepts/document_templates/F14-Comments/0b8424d4-ebfd-46e3-9577-1775a69d290c.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_concept.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_concept.schema.json deleted file mode 120000 index 7ffb2f3578d8..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_concept.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-7371-8bd3-c15811b2b063.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_developer.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_developer.schema.json deleted file mode 120000 index 81422eec5969..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_developer.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-79c7-a222-2c3b581443a8.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_ecosystem.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_ecosystem.schema.json deleted file mode 120000 index 74e38030559f..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_ecosystem.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-716f-a04e-f422f08a99dc.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_partner_product.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_partner_product.schema.json deleted file mode 120000 index d246651087bf..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_partner_product.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-75b5-b4a4-5cf331cd8d1a.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_proposal_template.schema.json b/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_proposal_template.schema.json deleted file mode 120000 index 9026619ecab0..000000000000 --- a/catalyst-gateway/bin/src/service/api/documents/templates/docs/proposal/f14_proposal_template.schema.json +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0ce8ab38-9258-4fbc-a62e-7faa6e58318f.schema.json \ No newline at end of file diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/data.rs b/catalyst-gateway/bin/src/service/api/documents/templates/f14.rs similarity index 64% rename from catalyst-gateway/bin/src/service/api/documents/templates/data.rs rename to catalyst-gateway/bin/src/service/api/documents/templates/f14.rs index 5eb8e868c74e..df0e8737f859 100644 --- a/catalyst-gateway/bin/src/service/api/documents/templates/data.rs +++ b/catalyst-gateway/bin/src/service/api/documents/templates/f14.rs @@ -1,30 +1,34 @@ -//! Document templates hardcoded data. +//! F14 Document templates hardcoded data. use super::SignedDocData; +/// Fund 14 Campaign ID. +const CAMPAIGN_ID: &str = "0194cfcf-15a2-7e32-b559-386b93d0724e"; + /// An empty JSON object bytes slice const EMPTY_JSON_OBJECT_BYTES: &[u8] = b"{}"; /// A definition of Category document hardcoded data pub(crate) struct CategoryDocData( /// ID and Version &'static str, + /// Campaign ID + &'static str, ); -/// List of category documents, 12 categories for Fund 14. -// TODO: Fix Content once it is added +/// List of category documents, categories. #[rustfmt::skip] pub(crate) const CATEGORY_DOCUMENTS: [CategoryDocData; 12] = [ - CategoryDocData("0194d490-30bf-7473-81c8-a0eaef369619"), - CategoryDocData("0194d490-30bf-7043-8c5c-f0e09f8a6d8c"), - CategoryDocData("0194d490-30bf-7e75-95c1-a6cf0e8086d9"), - CategoryDocData("0194d490-30bf-7703-a1c0-83a916b001e7"), - CategoryDocData("0194d490-30bf-79d1-9a0f-84943123ef38"), - CategoryDocData("0194d490-30bf-706d-91c6-0d4707f74cdf"), - CategoryDocData("0194d490-30bf-759e-b729-304306fbaa5e"), - CategoryDocData("0194d490-30bf-7e27-b5fd-de3133b54bf6"), - CategoryDocData("0194d490-30bf-7f9e-8a5d-91fb67c078f2"), - CategoryDocData("0194d490-30bf-7676-9658-36c0b67e656e"), - CategoryDocData("0194d490-30bf-7978-b031-7aa2ccc5e3fd"), - CategoryDocData("0194d490-30bf-7d34-bba9-8498094bd627"), + CategoryDocData("0194d490-30bf-7473-81c8-a0eaef369619", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7043-8c5c-f0e09f8a6d8c", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7e75-95c1-a6cf0e8086d9", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7703-a1c0-83a916b001e7", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-79d1-9a0f-84943123ef38", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-706d-91c6-0d4707f74cdf", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-759e-b729-304306fbaa5e", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7e27-b5fd-de3133b54bf6", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7f9e-8a5d-91fb67c078f2", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7676-9658-36c0b67e656e", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7978-b031-7aa2ccc5e3fd", CAMPAIGN_ID), + CategoryDocData("0194d490-30bf-7d34-bba9-8498094bd627", CAMPAIGN_ID), ]; impl From for SignedDocData { @@ -34,7 +38,7 @@ impl From for SignedDocData { ver: value.0, doc_type: catalyst_signed_doc::doc_types::CATEGORY_DOCUMENT_UUID_TYPE, content: EMPTY_JSON_OBJECT_BYTES, - category_id: None, + category_id: Some(value.1), } } } @@ -49,13 +53,13 @@ pub(crate) struct ProposalTemplateDocData( &'static [u8], ); -/// List of proposal templates, 12 proposals each of which is uniquely associated with one of the predefined categories. +/// List of proposal templates, proposals each of which is uniquely associated with one of the predefined categories. #[rustfmt::skip] pub(crate) const PROPOSAL_TEMPLATES: [ProposalTemplateDocData; 12] = [ - ProposalTemplateDocData("0194d492-1daa-75b5-b4a4-5cf331cd8d1a", CATEGORY_DOCUMENTS[0].0, include_bytes!("./docs/proposal/f14_partner_product.schema.json")), - ProposalTemplateDocData("0194d492-1daa-7371-8bd3-c15811b2b063", CATEGORY_DOCUMENTS[1].0, include_bytes!("./docs/proposal/f14_concept.schema.json")), - ProposalTemplateDocData("0194d492-1daa-79c7-a222-2c3b581443a8", CATEGORY_DOCUMENTS[2].0, include_bytes!("./docs/proposal/f14_developer.schema.json")), - ProposalTemplateDocData("0194d492-1daa-716f-a04e-f422f08a99dc", CATEGORY_DOCUMENTS[3].0, include_bytes!("./docs/proposal/f14_ecosystem.schema.json")), + ProposalTemplateDocData("0194d492-1daa-75b5-b4a4-5cf331cd8d1a", CATEGORY_DOCUMENTS[0].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-75b5-b4a4-5cf331cd8d1a.schema.json")), + ProposalTemplateDocData("0194d492-1daa-7371-8bd3-c15811b2b063", CATEGORY_DOCUMENTS[1].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-7371-8bd3-c15811b2b063.schema.json")), + ProposalTemplateDocData("0194d492-1daa-79c7-a222-2c3b581443a8", CATEGORY_DOCUMENTS[2].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-79c7-a222-2c3b581443a8.schema.json")), + ProposalTemplateDocData("0194d492-1daa-716f-a04e-f422f08a99dc", CATEGORY_DOCUMENTS[3].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-716f-a04e-f422f08a99dc.schema.json")), ProposalTemplateDocData("0194d492-1daa-78fc-818a-bf20fc3e9b87", CATEGORY_DOCUMENTS[4].0, EMPTY_JSON_OBJECT_BYTES), ProposalTemplateDocData("0194d492-1daa-7d98-a3aa-c57d99121f78", CATEGORY_DOCUMENTS[5].0, EMPTY_JSON_OBJECT_BYTES), ProposalTemplateDocData("0194d492-1daa-77be-a1a5-c238fe25fe4f", CATEGORY_DOCUMENTS[6].0, EMPTY_JSON_OBJECT_BYTES), @@ -85,7 +89,7 @@ pub(crate) struct CommentTemplateDocData( /// Category ID &'static str, ); -/// List of comment templates, 12 comments each of which is uniquely associated with one of the predefined categories. +/// List of comment templates, comments each of which is uniquely associated with one of the predefined categories. #[rustfmt::skip] pub(crate) const COMMENT_TEMPLATES: [CommentTemplateDocData; 12] = [ CommentTemplateDocData("0194d494-4402-7e0e-b8d6-171f8fea18b0", CATEGORY_DOCUMENTS[0].0), @@ -108,7 +112,7 @@ impl From for SignedDocData { id: value.0, ver: value.0, doc_type: catalyst_signed_doc::doc_types::COMMENT_TEMPLATE_UUID_TYPE, - content: include_bytes!("./docs/f14_comment_template.schema.json"), + content: include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/F14-Comments/0b8424d4-ebfd-46e3-9577-1775a69d290c.schema.json"), category_id: Some(value.1), } } diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/f15.rs b/catalyst-gateway/bin/src/service/api/documents/templates/f15.rs new file mode 100644 index 000000000000..c3e99e82e4cf --- /dev/null +++ b/catalyst-gateway/bin/src/service/api/documents/templates/f15.rs @@ -0,0 +1,95 @@ +//! F15 Document templates hardcoded data. + +use super::SignedDocData; + +/// Fund 15 Campaign ID. +const CAMPAIGN_ID: &str = "0199802c-21b4-7d91-986d-0e913cd81391"; + +/// An empty JSON object bytes slice +const EMPTY_JSON_OBJECT_BYTES: &[u8] = b"{}"; +/// A definition of Category document hardcoded data +pub(crate) struct CategoryDocData( + /// ID and Version + &'static str, + /// Campaign ID + &'static str, +); +/// List of category documents. +#[rustfmt::skip] +pub(crate) const CATEGORY_DOCUMENTS: [CategoryDocData; 4] = [ + CategoryDocData("0199802c-21b4-721f-aa1d-5123b006879e", CAMPAIGN_ID), + CategoryDocData("0199802c-21b4-7dc8-8537-7eae5ea4c4d3", CAMPAIGN_ID), + CategoryDocData("0199802c-21b4-7c84-873c-f55119cdc811", CAMPAIGN_ID), + CategoryDocData("0199802c-21b4-7161-a16e-a77af492780f", CAMPAIGN_ID), +]; + +impl From for SignedDocData { + fn from(value: CategoryDocData) -> Self { + Self { + id: value.0, + ver: value.0, + doc_type: catalyst_signed_doc::doc_types::CATEGORY_DOCUMENT_UUID_TYPE, + content: EMPTY_JSON_OBJECT_BYTES, + category_id: Some(value.1), + } + } +} + +/// A definition of Proposal Template document hardcoded data +pub(crate) struct ProposalTemplateDocData( + /// ID and Version + &'static str, + /// Category ID + &'static str, + /// Content bytes + &'static [u8], +); + +/// List of proposal templates, proposals each of which is uniquely associated with one of the predefined categories. +#[rustfmt::skip] +pub(crate) const PROPOSAL_TEMPLATES: [ProposalTemplateDocData; 4] = [ + ProposalTemplateDocData("0199802c-21b4-717d-9619-11357877f471", CATEGORY_DOCUMENTS[0].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-75b5-b4a4-5cf331cd8d1a.schema.json")), + ProposalTemplateDocData("0199802c-21b4-7982-ba3f-ec0cd0207b11", CATEGORY_DOCUMENTS[1].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-7371-8bd3-c15811b2b063.schema.json")), + ProposalTemplateDocData("0199802c-21b4-7f75-b14a-331cd1605f74", CATEGORY_DOCUMENTS[2].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-79c7-a222-2c3b581443a8.schema.json")), + ProposalTemplateDocData("0199802c-21b4-7d6c-aacd-54aa31fe1e4c", CATEGORY_DOCUMENTS[3].0, include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0194d492-1daa-716f-a04e-f422f08a99dc.schema.json")), +]; + +impl From for SignedDocData { + fn from(value: ProposalTemplateDocData) -> Self { + Self { + id: value.0, + ver: value.0, + doc_type: catalyst_signed_doc::doc_types::PROPOSAL_TEMPLATE_UUID_TYPE, + content: value.2, + category_id: Some(value.1), + } + } +} + +/// A definition of Comment Template document hardcoded data +pub(crate) struct CommentTemplateDocData( + /// ID and Version + &'static str, + /// Category ID + &'static str, +); +/// List of comment templates, comments each of which is uniquely associated with one of the predefined categories. +#[rustfmt::skip] +pub(crate) const COMMENT_TEMPLATES: [CommentTemplateDocData; 4] = [ + CommentTemplateDocData("0199802c-21b4-7b2c-aafd-0af557e8408c", CATEGORY_DOCUMENTS[0].0), + CommentTemplateDocData("0199802c-21b4-78d8-a1df-2e4bd2e73507", CATEGORY_DOCUMENTS[1].0), + CommentTemplateDocData("0199802c-21b4-76da-9384-4dc1e2dc3d51", CATEGORY_DOCUMENTS[2].0), + CommentTemplateDocData("0199802c-21b4-7884-84cb-0bdf6c08e690", CATEGORY_DOCUMENTS[3].0), +]; + +impl From for SignedDocData { + fn from(value: CommentTemplateDocData) -> Self { + Self { + id: value.0, + ver: value.0, + doc_type: catalyst_signed_doc::doc_types::COMMENT_TEMPLATE_UUID_TYPE, + content: include_bytes!("../../../../../../../docs/src/architecture/08_concepts/document_templates/F14-Comments/0b8424d4-ebfd-46e3-9577-1775a69d290c.schema.json"), + category_id: Some(value.1), + } + } +} diff --git a/catalyst-gateway/bin/src/service/api/documents/templates/mod.rs b/catalyst-gateway/bin/src/service/api/documents/templates/mod.rs index 236460a8ebc2..37daafc329f0 100644 --- a/catalyst-gateway/bin/src/service/api/documents/templates/mod.rs +++ b/catalyst-gateway/bin/src/service/api/documents/templates/mod.rs @@ -1,45 +1,59 @@ //! Catalyst signed document templates. -mod data; +mod f14; +mod f15; use std::{collections::HashMap, env, sync::LazyLock}; use catalyst_signed_doc::{ Builder, CatalystId, CatalystSignedDocument, ContentEncoding, ContentType, }; -use data::{CATEGORY_DOCUMENTS, COMMENT_TEMPLATES, PROPOSAL_TEMPLATES}; use ed25519_dalek::{ed25519::signature::Signer, SigningKey}; use hex::FromHex; use uuid::Uuid; -/// Catalyst brand ID. -const BRAND_ID: &str = "0194cfcd-bddc-7bb3-b5e9-455168bd3ff7"; -/// Catalyst brand Version (same as ID). -const BRAND_VERSION: &str = BRAND_ID; +/// A map of F14 signed document templates to its ID. +static F14_TEMPLATES: LazyLock>> = + LazyLock::new(|| { + let sk = load_doc_signing_key()?; -/// Fund 14 Campaign ID. -const CAMPAIGN_ID: &str = "0194cfcf-15a2-7e32-b559-386b93d0724e"; -/// Fund 14 Campaign Version (Same as ID). -const CAMPAIGN_VERSION: &str = CAMPAIGN_ID; + let mut map = HashMap::new(); + map.extend( + f14::CATEGORY_DOCUMENTS + .into_iter() + .map(|t| build_signed_doc(&t.into(), &sk)), + ); + map.extend( + f14::PROPOSAL_TEMPLATES + .into_iter() + .map(|t| build_signed_doc(&t.into(), &sk)), + ); + map.extend( + f14::COMMENT_TEMPLATES + .into_iter() + .map(|t| build_signed_doc(&t.into(), &sk)), + ); + Some(map) + }); -/// A map of signed document templates to its ID. -pub(crate) static TEMPLATES: LazyLock>> = +/// A map of F15 signed document templates to its ID. +static F15_TEMPLATES: LazyLock>> = LazyLock::new(|| { let sk = load_doc_signing_key()?; let mut map = HashMap::new(); map.extend( - CATEGORY_DOCUMENTS + f15::CATEGORY_DOCUMENTS .into_iter() .map(|t| build_signed_doc(&t.into(), &sk)), ); map.extend( - PROPOSAL_TEMPLATES + f15::PROPOSAL_TEMPLATES .into_iter() .map(|t| build_signed_doc(&t.into(), &sk)), ); map.extend( - COMMENT_TEMPLATES + f15::COMMENT_TEMPLATES .into_iter() .map(|t| build_signed_doc(&t.into(), &sk)), ); @@ -105,11 +119,9 @@ fn build_signed_doc( "type": data.doc_type, "id": data.id, "ver": data.ver, - "category_id": data.category_id.map(|v| serde_json::json!({"id": v, "ver": v })), + "parameters": data.category_id.map(|v| serde_json::json!({"id": v, "ver": v })), "content-type": ContentType::Json.to_string(), "content-encoding": ContentEncoding::Brotli.to_string(), - "campaign_id": {"id": CAMPAIGN_ID, "ver": CAMPAIGN_VERSION}, - "brand_id": {"id": BRAND_ID, "ver": BRAND_VERSION}, }); let kid = CatalystId::new(KID_NETWORK, None, sk.verifying_key()); @@ -127,9 +139,25 @@ fn build_signed_doc( (doc_id, doc) } -/// Get a static document template from ID and version. +/// Get a static document template from ID and version looking from all available static +/// templates. pub(crate) fn get_doc_static_template(document_id: &uuid::Uuid) -> Option { - TEMPLATES + F15_TEMPLATES + .as_ref() + .and_then(|templates| templates.get(document_id)) + .or_else(|| { + F14_TEMPLATES + .as_ref() + .and_then(|templates| templates.get(document_id)) + }) + .cloned() +} + +/// Get an active static document template from ID and version. +pub(crate) fn get_active_doc_static_template( + document_id: &uuid::Uuid +) -> Option { + F15_TEMPLATES .as_ref() .and_then(|templates| templates.get(document_id)) .cloned() @@ -151,7 +179,13 @@ mod tests { unsafe { env::set_var("SIGNED_DOC_SK", sk_hex); } - for doc in TEMPLATES.as_ref().unwrap().values() { + for doc in F14_TEMPLATES + .as_ref() + .unwrap() + .values() + .chain(F15_TEMPLATES.as_ref().unwrap().values()) + { + println!("{:?}", doc.doc_meta()); assert!(!doc.problem_report().is_problematic()); } } diff --git a/catalyst-gateway/tests/api_tests/integration/test_signed_doc.py b/catalyst-gateway/tests/api_tests/integration/test_signed_doc.py index 92c95907ec8a..407aa5a9c070 100644 --- a/catalyst-gateway/tests/api_tests/integration/test_signed_doc.py +++ b/catalyst-gateway/tests/api_tests/integration/test_signed_doc.py @@ -35,8 +35,9 @@ def build_and_sign( @pytest.fixture def proposal_templates() -> List[str]: - # comes from the 'templates/data.rs' file + # comes from the 'templates/f14.rs' and 'templates/f15.rs' file return [ + # f14 "0194d492-1daa-75b5-b4a4-5cf331cd8d1a", "0194d492-1daa-7371-8bd3-c15811b2b063", "0194d492-1daa-79c7-a222-2c3b581443a8", @@ -49,13 +50,19 @@ def proposal_templates() -> List[str]: "0194d492-1daa-7fce-84ee-b872a4661075", "0194d492-1daa-7878-9bcc-2c79fef0fc13", "0194d492-1daa-722f-94f4-687f2c068a5d", + # f15 + "0199802c-21b4-717d-9619-11357877f471", + "0199802c-21b4-7982-ba3f-ec0cd0207b11", + "0199802c-21b4-7f75-b14a-331cd1605f74", + "0199802c-21b4-7d6c-aacd-54aa31fe1e4c", ] @pytest.fixture def comment_templates() -> List[str]: - # comes from the 'templates/data.rs' file + # comes from the 'templates/f14.rs' and 'templates/f15.rs' file return [ + # f14 "0194d494-4402-7e0e-b8d6-171f8fea18b0", "0194d494-4402-7444-9058-9030815eb029", "0194d494-4402-7351-b4f7-24938dc2c12e", @@ -68,6 +75,11 @@ def comment_templates() -> List[str]: "0194d494-4402-7202-8ebb-8c4c47c286d8", "0194d494-4402-7fb5-b680-c23fe4beb088", "0194d494-4402-7aa5-9dbc-5fe886e60ebc", + # f15 + "0199802c-21b4-7b2c-aafd-0af557e8408c", + "0199802c-21b4-78d8-a1df-2e4bd2e73507", + "0199802c-21b4-76da-9384-4dc1e2dc3d51", + "0199802c-21b4-7884-84cb-0bdf6c08e690", ] @@ -78,7 +90,6 @@ def __proposal_doc_factory() -> tuple[SignedDocument, RoleID]: role_id = RoleID.PROPOSER rbac_chain = rbac_chain_factory() proposal_doc_id = uuid_v7.uuid_v7() - category_id = "0194d490-30bf-7473-81c8-a0eaef369619" proposal_metadata_json = { "id": proposal_doc_id, "ver": proposal_doc_id, @@ -86,15 +97,14 @@ def __proposal_doc_factory() -> tuple[SignedDocument, RoleID]: "type": "7808d2ba-d511-40af-84e8-c0d1625fdfdc", "content-type": "application/json", "content-encoding": "br", - # referenced to the defined proposal template id, comes from the 'templates/data.rs' file "template": { - "id": proposal_templates[0], - "ver": proposal_templates[0], + "id": proposal_templates[12], + "ver": proposal_templates[12], }, - # referenced to the defined category id, comes from the 'templates/data.rs' file "parameters": { - "id": category_id, - "ver": category_id, + # corresponding category ref, in accordance with the proposal template + "id": "0199802c-21b4-721f-aa1d-5123b006879e", + "ver": "0199802c-21b4-721f-aa1d-5123b006879e", }, } with open("./test_data/signed_docs/proposal.json", "r") as proposal_json_file: @@ -135,8 +145,13 @@ def __comment_doc_factory() -> tuple[SignedDocument, RoleID]: "ver": proposal_doc.metadata["ver"], }, "template": { - "id": comment_templates[0], - "ver": comment_templates[0], + "id": comment_templates[12], + "ver": comment_templates[12], + }, + "parameters": { + # corresponding category ref, in accordance with the comment template + "id": "0199802c-21b4-721f-aa1d-5123b006879e", + "ver": "0199802c-21b4-721f-aa1d-5123b006879e", }, } with open("./test_data/signed_docs/comment.json", "r") as comment_json_file: @@ -176,6 +191,11 @@ def __submission_action_factory() -> tuple[SignedDocument, RoleID]: "id": proposal_doc.metadata["id"], "ver": proposal_doc.metadata["ver"], }, + "parameters": { + # corresponding category ref, in accordance with proposal doc + "id": "0199802c-21b4-721f-aa1d-5123b006879e", + "ver": "0199802c-21b4-721f-aa1d-5123b006879e", + }, } with open( "./test_data/signed_docs/submission_action.json", "r"