Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catalyst-gateway/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
27 changes: 9 additions & 18 deletions catalyst-gateway/bin/src/service/api/documents/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CatalystSignedDocument> {
// 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;
Expand All @@ -38,8 +23,14 @@ impl catalyst_signed_doc::providers::CatalystSignedDocumentProvider for DocProvi
) -> anyhow::Result<Option<CatalystSignedDocument>> {
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::<NotFoundError>() => Ok(None),
Err(err) => Err(err),
}
Expand Down
21 changes: 12 additions & 9 deletions catalyst-gateway/bin/src/service/api/documents/get_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -31,13 +31,16 @@ pub(crate) async fn endpoint(
document_id: uuid::Uuid,
version: Option<uuid::Uuid>,
) -> 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::<NotFoundError>() => Responses::NotFound.into(),
Err(err) => AllResponses::handle_error(&err),
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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),
Comment on lines +17 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious and checked that: as far as I can see, the rustfmt::skip does nothing here. Perhaps it was useful before we made some of the formatting changes, but unless I'm missing something it can be removed now.

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<CategoryDocData> for SignedDocData {
Expand All @@ -34,7 +38,7 @@ impl From<CategoryDocData> 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),
}
}
}
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -108,7 +112,7 @@ impl From<CommentTemplateDocData> 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),
}
}
Expand Down
95 changes: 95 additions & 0 deletions catalyst-gateway/bin/src/service/api/documents/templates/f15.rs
Original file line number Diff line number Diff line change
@@ -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<CategoryDocData> 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<ProposalTemplateDocData> 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<CommentTemplateDocData> 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),
}
}
}
Loading
Loading