Skip to content

Commit

Permalink
Merge branch 'main' into feat/purge-volatile-data-after-roll-forward
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenj authored Dec 2, 2024
2 parents 86b837d + f9b60fa commit e238a68
Show file tree
Hide file tree
Showing 101 changed files with 2,651 additions and 935 deletions.
3 changes: 2 additions & 1 deletion .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Arbritrary
ARCHS
ARGB
Arissara
asat
asmjs
asyncio
asyncpg
Expand Down Expand Up @@ -241,6 +242,7 @@ rustflags
rustfmt
rustls
rxdart
ryszard-schossler
saibatizoku
Schemathesis
Scripthash
Expand Down Expand Up @@ -286,7 +288,6 @@ trailings
TXNZD
txos
Typer
ryszard-schossler
unawaited
unchunk
Unlogged
Expand Down
3 changes: 2 additions & 1 deletion catalyst-gateway/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ target/
# Build artifacts
cat-gateway.coverage.info
cat-gateway.junit-report.xml
cat-gateway-api.*
cat-gateway-api.*
expanded.rs
21 changes: 18 additions & 3 deletions catalyst-gateway/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,22 @@ run-cat-gateway-mainnet: build-cat-gateway
RUST_LOG="error,cat_gateway=debug,cardano_chain_follower=debug,mithril-client=debug" \
./target/release/cat-gateway run --log-level debug

# Do the minimal work needed to test the schema generated by cat-gateway
quick-schema-lint: build-cat-gateway
# expand all macros and produce a single unified source file.
expand-macros:
just bin/expand-macros

# Generate the current openapi schema file locally.
generate-openapi-schema: build-cat-gateway
./target/release/cat-gateway docs cat-gateway-api.json
docker run --rm -it -v $(pwd):/tmp stoplight/spectral:latest lint --ruleset "/tmp/tests/.oapi-v3.spectral.yml" "/tmp/cat-gateway-api.json"

# Lint an openapi schema that has already been generated
lint-generated-schema:
docker run --rm -it -v $(pwd):/tmp stoplight/spectral:latest lint --ruleset "/tmp/tests/openapi-v3.0-lints/.spectral.yml" "/tmp/cat-gateway-api.json"

# Lint an openapi schema that has already been generated locally.
# Make sure before running this command, you have installed "spectral" locally.
lint-generated-schema-local:
spectral lint --ruleset "./tests/openapi-v3.0-lints/.spectral.yml" "cat-gateway-api.json"

# Do the minimal work needed to test the schema generated by cat-gateway
quick-schema-lint: generate-openapi-schema lint-generated-schema
3 changes: 2 additions & 1 deletion catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository.workspace = true
workspace = true

[dependencies]
cardano-chain-follower = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "2024-10-15-01" }
cardano-chain-follower = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower-v0.0.5" }
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" }

pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
Expand Down Expand Up @@ -92,6 +92,7 @@ der-parser = "9.0.0"
jsonschema = "0.26.1"
bech32 = "0.11.0"
const_format = "0.2.33"
regex = "1.11.1"

[dev-dependencies]
proptest = "1.5.0"
Expand Down
12 changes: 12 additions & 0 deletions catalyst-gateway/bin/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# use with https://github.com/casey/just
#
# Developer convenience functions

# cspell: words prereqs, commitlog, rustls, nocapture

default:
@just --list --unsorted

# expand all macros and produce a single unified source file.
expand-macros:
cargo expand --release --bin cat-gateway > ../expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ INSERT INTO txo_assets_by_stake (
txn,
txo,
policy_id,
policy_name,
asset_name,
value
) VALUES (
:stake_address,
:slot_no,
:txn,
:txo,
:policy_id,
:policy_name,
:asset_name,
:value
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ INSERT INTO unstaked_txo_assets_by_txn_hash (
txn_hash,
txo,
policy_id,
policy_name,
asset_name,
slot_no,
txn,
value
) VALUES (
:txn_hash,
:txo,
:policy_id,
:policy_name,
:asset_name,
:slot_no,
:txn,
:value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub(super) struct Params {
txo: i16,
/// Policy hash of the asset
policy_id: Vec<u8>,
/// Policy name of the asset
policy_name: String,
/// Name of the asset, within the Policy.
asset_name: Vec<u8>,
/// Value of the asset
value: num_bigint::BigInt,
}
Expand All @@ -41,15 +41,15 @@ impl Params {
#[allow(clippy::too_many_arguments)]
pub(super) fn new(
stake_address: &[u8], slot_no: u64, txn: i16, txo: i16, policy_id: &[u8],
policy_name: &str, value: i128,
asset_name: &[u8], value: i128,
) -> Self {
Self {
stake_address: stake_address.to_vec(),
slot_no: slot_no.into(),
txn,
txo,
policy_id: policy_id.to_vec(),
policy_name: policy_name.to_owned(),
asset_name: asset_name.to_vec(),
value: value.into(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(super) struct Params {
/// Policy hash of the asset
policy_id: Vec<u8>,
/// Policy name of the asset
policy_name: String,
asset_name: Vec<u8>,
/// Block Slot Number
slot_no: num_bigint::BigInt,
/// Transaction Offset inside the block.
Expand All @@ -40,14 +40,14 @@ impl Params {
/// values.
#[allow(clippy::too_many_arguments)]
pub(super) fn new(
txn_hash: &[u8], txo: i16, policy_id: &[u8], policy_name: &str, slot_no: u64, txn: i16,
txn_hash: &[u8], txo: i16, policy_id: &[u8], asset_name: &[u8], slot_no: u64, txn: i16,
value: i128,
) -> Self {
Self {
txn_hash: txn_hash.to_vec(),
txo,
policy_id: policy_id.to_vec(),
policy_name: policy_name.to_owned(),
asset_name: asset_name.to_vec(),
slot_no: slot_no.into(),
txn,
value: value.into(),
Expand Down
12 changes: 3 additions & 9 deletions catalyst-gateway/bin/src/db/index/block/txo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl TxoInsertQuery {
let policy_id = asset.policy().to_vec();
for policy_asset in asset.assets() {
if policy_asset.is_output() {
let policy_name = policy_asset.to_ascii_name().unwrap_or_default();
let asset_name = policy_asset.name();
let value = policy_asset.any_coin();

if staked {
Expand All @@ -191,19 +191,13 @@ impl TxoInsertQuery {
txn,
txo_index,
&policy_id,
&policy_name,
asset_name,
value,
);
self.staked_txo_asset.push(params);
} else {
let params = insert_unstaked_txo_asset::Params::new(
txn_hash,
txo_index,
&policy_id,
&policy_name,
slot_no,
txn,
value,
txn_hash, txo_index, &policy_id, asset_name, slot_no, txn, value,
);
self.unstaked_txo_asset.push(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SELECT
txo,
slot_no,
policy_id,
policy_name,
asset_name,
value
FROM txo_assets_by_stake
WHERE stake_address = :stake_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod result {
/// Asset hash.
pub policy_id: Vec<u8>,
/// Asset name.
pub policy_name: String,
pub asset_name: Vec<u8>,
/// Asset value.
pub value: num_bigint::BigInt,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ CREATE TABLE IF NOT EXISTS txo_assets_by_stake (
txn smallint, -- Which Transaction in the Slot is the TXO.
txo smallint, -- offset in the txo list of the transaction the txo is in.
policy_id blob, -- asset policy hash (id) (28 byte binary hash)
policy_name text, -- name of the policy (UTF8) TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
asset_name blob, -- name of the asset policy (UTF8) (32 bytes)


-- None Key Data of the asset.
value varint, -- Value of the asset (i128)

PRIMARY KEY (stake_address, slot_no, txn, txo, policy_id, policy_name)
PRIMARY KEY (stake_address, slot_no, txn, txo, policy_id, asset_name)
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS unstaked_txo_assets_by_txn_hash (
txn_hash blob, -- 32 byte hash of this transaction.
txo smallint, -- offset in the txo list of the transaction the txo is in.
policy_id blob, -- asset policy hash (id) (28 byte binary hash)
policy_name text, -- name of the policy (UTF8)
asset_name blob, -- name of the policy (UTF8) (32 bytes)

-- Secondary Location information for the transaction.
slot_no varint, -- slot number the txo was created in.
Expand All @@ -13,5 +13,5 @@ CREATE TABLE IF NOT EXISTS unstaked_txo_assets_by_txn_hash (
-- Value of the asset.
value varint, -- Value of the asset (u64)

PRIMARY KEY (txn_hash, txo, policy_id, policy_name)
PRIMARY KEY (txn_hash, txo, policy_id, asset_name)
);
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/src/db/index/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{settings::cassandra_db, utils::blake2b_hash::generate_uuid_string_fr
/// change accidentally, and is NOT to be used directly to set the schema version of the
/// table namespaces.
#[allow(dead_code)]
const SCHEMA_VERSION: &str = "08193dfe-698a-8177-bdf8-20c5691a06e7";
const SCHEMA_VERSION: &str = "75ae6ac9-ddd8-8472-8a7a-8676d04f8679";

/// Keyspace Create (Templated)
const CREATE_NAMESPACE_CQL: &str = include_str!("./cql/namespace.cql");
Expand Down
32 changes: 32 additions & 0 deletions catalyst-gateway/bin/src/service/api/cardano/cip36/endpoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Implementation of the GET `/cardano/cip36` endpoint
use std::time::Duration;

use poem::http::HeaderMap;
use tokio::time::sleep;

use super::{
cardano::{self},
response, NoneOrRBAC, SlotNo,
};
use crate::service::common::{self};

/// Process the endpoint operation
pub(crate) async fn cip36_registrations(
_lookup: Option<cardano::query::stake_or_voter::StakeOrVoter>, _asat: Option<SlotNo>,
_page: common::types::generic::query::pagination::Page,
_limit: common::types::generic::query::pagination::Limit, _auth: NoneOrRBAC,
_headers: &HeaderMap,
) -> response::AllRegistration {
// Dummy sleep, remove it
sleep(Duration::from_millis(1)).await;

// Todo: refactor the below into a single operation here.

// If _asat is None, then get the latest slot number from the chain follower and use that.
// If _for is not defined, use the stake addresses defined for Role0 in the _auth
// parameter. _auth not yet implemented, so put placeholder for that, and return not
// found until _auth is implemented.

response::Cip36Registration::NotFound.into()
}
Loading

0 comments on commit e238a68

Please sign in to comment.