Skip to content

Commit bd072eb

Browse files
Merge main into feat/sync-with-gateway-v2-endpoints-3362
2 parents 8c6712a + c9f669f commit bd072eb

File tree

92 files changed

+6882
-632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+6882
-632
lines changed

.github/workflows/gateway-tests.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ jobs:
106106
run: |
107107
docker compose -f catalyst-gateway/tests/docker-compose.yml up api-tests-runner --exit-code-from api-tests-runner
108108
109-
# Skip for now as it adds ~10mins to CI execution time, will try to incorporate this in nightly instead
110-
- name: Integration health thru proxy tests
111-
if: false
112-
env:
113-
API_TEST_MARKS: "health_with_proxy_endpoint"
114-
EVENT_DB_URL: "haproxy:18080"
115-
INDEX_DB_URL: "haproxy:18090"
116-
run: |
117-
docker stop cat-gateway || true
118-
docker compose -f catalyst-gateway/tests/docker-compose.yml up haproxy --detach
119-
docker compose -f catalyst-gateway/tests/docker-compose.yml up api-tests-runner --exit-code-from api-tests-runner
120-
121109
- name: Collect and upload test reports
122110
uses: actions/upload-artifact@v4
123111
if: success() || failure()

.github/workflows/nightly-ci.yml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,65 @@ jobs:
6969
id: gateway-healthy
7070
if: ${{ steps.gateway-started.conclusion == 'success' }}
7171
run: |
72-
echo "Waiting for container to be healthy..."
73-
for i in {1..500}; do
74-
STATUS=$(docker inspect --format='{{.State.Health.Status}}' cat-gateway)
75-
echo "Health status: $STATUS"
76-
if [ "$STATUS" == "healthy" ]; then
77-
echo "Container is healthy!"
78-
break
79-
fi
80-
if [ "$STATUS" == "unhealthy" ]; then
81-
echo "Container became unhealthy."
82-
exit 1
83-
fi
84-
sleep 5
85-
done
72+
echo "Waiting for container to be healthy..."
73+
for i in {1..500}; do
74+
STATUS=$(docker inspect --format='{{.State.Health.Status}}' cat-gateway)
75+
echo "Health status: $STATUS"
76+
if [ "$STATUS" == "healthy" ]; then
77+
echo "Container is healthy!"
78+
break
79+
fi
80+
if [ "$STATUS" == "unhealthy" ]; then
81+
echo "Container became unhealthy."
82+
exit 1
83+
fi
84+
sleep 5
85+
done
8686
8787
- name: Schemathesis tests
88+
id: schemathesis-tests
8889
if: ${{ steps.gateway-healthy.conclusion == 'success' }}
8990
run: |
9091
export HYPOTHESIS_MAX_EXAMPLES=5000
9192
export MAX_RESPONSE_TIME=25000
9293
docker compose -f catalyst-gateway/tests/docker-compose.yml up schemathesis-runner --exit-code-from schemathesis-runner
9394
95+
- name: Spin up catalyst-gateway with haproxy
96+
id: gateway-with-proxy-started
97+
env:
98+
EVENT_DB_URL: "haproxy:18080"
99+
INDEX_DB_URL: "haproxy:18090"
100+
run: |
101+
docker stop cat-gateway || true
102+
docker compose -f catalyst-gateway/tests/docker-compose.yml up haproxy --detach
103+
docker compose -f catalyst-gateway/tests/docker-compose.yml up cat-gateway --detach
104+
105+
- name: Wait for cat-gateway to become healthy
106+
id: gateway-with-proxy-healthy
107+
if: ${{ steps.gateway-with-proxy-started.conclusion == 'success' }}
108+
run: |
109+
echo "Waiting for container to be healthy..."
110+
for i in {1..500}; do
111+
STATUS=$(docker inspect --format='{{.State.Health.Status}}' cat-gateway)
112+
echo "Health status: $STATUS"
113+
if [ "$STATUS" == "healthy" ]; then
114+
echo "Container is healthy!"
115+
break
116+
fi
117+
if [ "$STATUS" == "unhealthy" ]; then
118+
echo "Container became unhealthy."
119+
exit 1
120+
fi
121+
sleep 5
122+
done
123+
124+
- name: Integration health thru proxy tests
125+
if: ${{ steps.gateway-with-proxy-healthy.conclusion == 'success' }}
126+
env:
127+
API_TEST_MARKS: "health_with_proxy_endpoint"
128+
run: |
129+
docker compose -f catalyst-gateway/tests/docker-compose.yml up api-tests-runner --exit-code-from api-tests-runner
130+
94131
slack:
95132
name: slack notification
96133
needs: tests

Earthfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
VERSION 0.8
22

3-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/mdlint:v3.6.1 AS mdlint-ci
4-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/cspell:v3.6.1 AS cspell-ci
5-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/postgresql:v3.6.1 AS postgresql-ci
3+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/mdlint:v3.6.3 AS mdlint-ci
4+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/cspell:v3.6.3 AS cspell-ci
5+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/postgresql:v3.6.3 AS postgresql-ci
66

77
ARG --global REGISTRY="harbor.shared-services.projectcatalyst.io/dockerhub/library"
88
FROM ${REGISTRY}/debian:stable-slim

catalyst-gateway/Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
VERSION 0.8
22

3-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.6.1 AS rust-ci
3+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.6.3 AS rust-ci
44
IMPORT ../ AS repo-ci
55
IMPORT github.com/input-output-hk/catalyst-voices/catalyst-gateway:main AS cat-gateway-main
66

catalyst-gateway/README.md

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
* [Catalyst Data Gateway](#catalyst-data-gateway)
44
* [Code Organization](#code-organization)
55
* [`./bin`](#bin)
6-
* [`./crates`](#crates)
76
* [`./event-db`](#event-db)
87
* [Build and Run](#build-and-run)
98
* [Docker images](#docker-images)
9+
* [Build](#build)
10+
* [Run](#run)
1011
* [Rust binary](#rust-binary)
12+
* [Build](#build-1)
13+
* [Run](#run-1)
1114

1215
The Catalyst Data Gateway is the backend of the Catalyst Voices hosted stack.
1316

@@ -20,11 +23,6 @@ In future it will also act as a gateway from Centralized catalyst infrastructure
2023

2124
This is the main Catalyst Gateway Application.
2225

23-
### `./crates`
24-
25-
These are fully re-usable generalized `rust` crates that the Catalyst Gateway uses and are developed with it.
26-
They are also able to be used stand-alone in other projects and can be published separately.
27-
2826
### `./event-db`
2927

3028
Defines the Postgres Catalyst Event Database that the Catalyst gateway uses for running Catalyst Events.
@@ -40,30 +38,60 @@ or you can build a docker image and run everything with the `docker-compose`.
4038

4139
To build and run docker images follow these steps:
4240

43-
1. Run `earthly +package` to build a cat-gateway docker image.
44-
2. Run `earthly ./event-db+build` to build an event-db docker image.
45-
3. Run `docker-compose up cat-gateway` to spin up cat-gateway with event-db from already built images.
41+
#### Build
42+
43+
* Build `cat-gateway`:
44+
45+
```sh
46+
earthly ./catalyst-gateway+docker
47+
```
48+
49+
* Build `event-db`:
4650

47-
Note that every time when you are building an image it obsoletes an old image but does not remove it,
48-
so don't forget to clean up dangling images of the event-db and cat-gateway in your docker environment.
51+
```sh
52+
earthly ./catalyst-gateway/event-db+docker
53+
```
54+
55+
#### Run
56+
57+
```sh
58+
docker compose -f ./catalyst-gateway/docker-compose.yml up cat-gateway
59+
```
4960

5061
### Rust binary
5162

52-
To build and run a Rust binary follow these steps:
53-
54-
1. Run `cargo build -p cat-gateway --release`
55-
to compile a release version of the cat-gateway
56-
2. Run `earthly ./event-db+build` to build an event-db docker image
57-
3. If you need to have a `preprod-snapshot` unarchive snapshot data to the `/tmp/preprod/` dir.
58-
You can download `preprod-snapshot` from this
59-
[resource](https://mithril.network/explorer/?aggregator=https%3A%2F%2Faggregator.release-preprod.api.mithril.network%2Faggregator).
60-
4. Run
61-
62-
```sh
63-
./target/release/cat-gateway run \
64-
--address "127.0.0.1:3030" \
65-
--database-url=postgres://catalyst-event-dev:CHANGE_ME@localhost/CatalystEventDev \
66-
--log-level=debug \
67-
--log-format=compact \
68-
--metrics-address "127.0.0.1:3032"
69-
```
63+
To build and run `cat-gateway` natively,
64+
as a first step it will be needed to anyway build and run `event-db` and `index-db` as docker containers
65+
66+
#### Build
67+
68+
* Build `cat-gateway`:
69+
70+
```sh
71+
cd catalyst-gateway
72+
cargo b --release
73+
```
74+
75+
* Build `event-db`:
76+
77+
```sh
78+
earthly ./catalyst-gateway/event-db+docker
79+
```
80+
81+
#### Run
82+
83+
* Run `event-db` and `index-db`:
84+
85+
```sh
86+
docker compose -f ./catalyst-gateway/docker-compose.yml up event-db index-db
87+
```
88+
89+
* Run `cat-gateway`:
90+
91+
```sh
92+
export SIGNED_DOC_SK="0x6455585b5dcc565c8975bc136e215d6d4dd96540620f37783c564da3cb3686dd"
93+
export CHAIN_NETWORK="Preprod"
94+
export INTERNAL_API_KEY="123"
95+
export EVENT_DB_URL="postgres://catalyst-event-dev:CHANGE_ME@localhost:5432/CatalystEventDev"
96+
./catalyst-gateway/target/release/cat-gateway run
97+
```

catalyst-gateway/bin/src/service/api/documents/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl DocumentApi {
9090
}
9191
}
9292

93-
/// Post A Signed Document Index Query for Newer Versions of v0.04.
93+
/// Post A Signed Document Index Query (v2).
9494
///
9595
/// Produces a summary of signed documents that meet the criteria
9696
/// defined in the request body for new signed document versions of v0.04.

catalyst-gateway/bin/src/service/api/documents/post_document_index_query/v2/response.rs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use crate::{
1212
self,
1313
types::{
1414
array_types::impl_array_types,
15+
cardano::collaborators_list::CollaboratorsList,
1516
document::{
16-
doc_ref_v2::{DocumentReferenceListV2, DocumentReferenceV2},
17-
doc_type::DocumentType,
18-
id::DocumentId,
19-
ver::DocumentVer,
17+
doc_chain::DocumentChainDocumented, doc_ref_v2::DocumentReferenceListV2,
18+
doc_type::DocumentType, id::DocumentId, ver::DocumentVer,
2019
},
2120
},
2221
},
@@ -155,6 +154,8 @@ pub(crate) struct IndexedDocumentVersionV2 {
155154
/// Document Type that matches the filter
156155
#[oai(rename = "type")]
157156
pub doc_type: DocumentType,
157+
/// A unique document identifier that matches the filter.
158+
pub id: DocumentId,
158159
/// Document Reference that matches the filter
159160
#[oai(rename = "ref", skip_serializing_if_is_none)]
160161
pub doc_ref: Option<DocumentReferenceListV2>,
@@ -167,43 +168,31 @@ pub(crate) struct IndexedDocumentVersionV2 {
167168
/// Document Parameter Reference that matches the filter
168169
#[oai(rename = "doc_parameters", skip_serializing_if_is_none)]
169170
pub parameters: Option<DocumentReferenceListV2>,
171+
/// A list of collaborators who can participate in drafting and submitting a document
172+
/// that matches the filter.
173+
#[oai(skip_serializing_if_is_none)]
174+
pub collaborators: Option<CollaboratorsList>,
175+
/// A link to a previous document in a chained sequence that matches the filter.
176+
#[oai(skip_serializing_if_is_none)]
177+
pub chain: Option<DocumentChainDocumented>,
170178
}
171179

172180
impl Example for IndexedDocumentVersionV2 {
173181
fn example() -> Self {
174182
Self {
175183
ver: Example::example(),
176184
doc_type: Example::example(),
185+
id: Example::example(),
177186
doc_ref: Some(Example::example()),
178187
reply: None,
179188
template: None,
180189
parameters: None,
190+
collaborators: Some(Example::example()),
191+
chain: Some(Example::example()),
181192
}
182193
}
183194
}
184195

185-
/// Document Reference for filtered Documents.
186-
#[derive(NewType, Debug, Clone, From, Into)]
187-
#[oai(
188-
from_multipart = false,
189-
from_parameter = false,
190-
to_header = false,
191-
example = true
192-
)]
193-
pub(crate) struct FilteredDocumentReferenceV2(DocumentReferenceV2);
194-
195-
impl From<catalyst_signed_doc::DocumentRef> for FilteredDocumentReferenceV2 {
196-
fn from(value: catalyst_signed_doc::DocumentRef) -> Self {
197-
Self(value.into())
198-
}
199-
}
200-
201-
impl Example for FilteredDocumentReferenceV2 {
202-
fn example() -> Self {
203-
Self(Example::example())
204-
}
205-
}
206-
207196
// List of Indexed Document Version Documented
208197
impl_array_types!(
209198
IndexedDocumentVersionDocumentedListV2,
@@ -256,6 +245,8 @@ impl TryFrom<SignedDocBody> for IndexedDocumentVersionDocumentedV2 {
256245
let mut reply = None;
257246
let mut template = None;
258247
let mut parameters = None;
248+
let mut collaborators = None;
249+
let mut chain = None;
259250
if let Some(json_meta) = doc.metadata() {
260251
let meta = catalyst_signed_doc::Metadata::from_json(json_meta.clone())?;
261252

@@ -264,17 +255,31 @@ impl TryFrom<SignedDocBody> for IndexedDocumentVersionDocumentedV2 {
264255
reply = meta.reply().cloned().map(Into::into);
265256
template = meta.template().cloned().map(Into::into);
266257
parameters = meta.parameters().cloned().map(Into::into);
258+
if !meta.collaborators().is_empty() {
259+
collaborators = Some(
260+
meta.collaborators()
261+
.iter()
262+
.cloned()
263+
.map(Into::into)
264+
.collect::<Vec<_>>()
265+
.into(),
266+
);
267+
}
268+
chain = meta.chain().map(Into::into);
267269
}
268270

269271
if let Some(doc_type) = doc_type {
270272
Ok(IndexedDocumentVersionDocumentedV2(
271273
IndexedDocumentVersionV2 {
272274
ver: DocumentVer::new_unchecked(doc.ver().to_string()),
273275
doc_type: DocumentType::new_unchecked(doc_type.to_string()),
276+
id: DocumentId::new_unchecked(doc.id().to_string()),
274277
doc_ref,
275278
reply,
276279
template,
277280
parameters,
281+
collaborators,
282+
chain,
278283
},
279284
))
280285
} else {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Implement newtype of `RegistrationList`
2+
3+
use poem_openapi::{
4+
registry::MetaSchema,
5+
types::{Example, ToJSON},
6+
};
7+
8+
use crate::service::common::types::{
9+
array_types::impl_array_types, cardano::catalyst_id::CatalystId,
10+
};
11+
12+
impl_array_types!(
13+
CollaboratorsList,
14+
CatalystId,
15+
Some(MetaSchema {
16+
example: Self::example().to_json(),
17+
max_items: Some(100),
18+
items: Some(Box::new(CatalystId::schema_ref())),
19+
..MetaSchema::ANY
20+
})
21+
);
22+
23+
impl Example for CollaboratorsList {
24+
fn example() -> Self {
25+
Self(vec![Example::example()])
26+
}
27+
}

catalyst-gateway/bin/src/service/common/types/cardano/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod asset_value;
66
pub(crate) mod catalyst_id;
77
pub(crate) mod cip19_shelley_address;
88
pub(crate) mod cip19_stake_address;
9+
pub(crate) mod collaborators_list;
910
pub(crate) mod hash28;
1011
pub(crate) mod nonce;
1112
pub(crate) mod query;

0 commit comments

Comments
 (0)