Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirvolek committed Feb 23, 2024
2 parents 703aa11 + 1873734 commit 71799b6
Show file tree
Hide file tree
Showing 150 changed files with 2,467 additions and 954 deletions.
9 changes: 4 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
stages:
- prebuild
- build
- integration tests - mainnet
- integration tests - testnets
- integration tests

Lint, Typescript:
stage: prebuild
Expand All @@ -22,21 +21,21 @@ Nix build:
- nix-build -A blockfrost-backend-ryo

Integration tests - mainnet:
stage: integration tests - mainnet
stage: integration tests
needs:
- Nix build
script:
- nix-build -A blockfrost-backend-ryo-test-mainnet --option sandbox false

Integration tests - preview:
stage: integration tests - testnets
stage: integration tests
needs:
- Nix build
script:
- nix-build -A blockfrost-backend-ryo-test-preview --option sandbox false

Integration tests - preprod:
stage: integration tests - testnets
stage: integration tests
needs:
- Nix build
script:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/c8-npm-7.14.0-dbb87a3021-ca44bbd200.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-21ad2b1333-8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/y18n-npm-5.0.8-5f3a0a7e62-54f0fb9562.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- support for Cardano Sanchonet
- translation of cost models from numerical IDs to strings,
required for `cardano-db-sync 13.1.1.3` and newer [#130](https://github.com/blockfrost/blockfrost-backend-ryo/pull/130)
- indices improving `/assets/{asset}` when querying CIP68 assets and `/txs/{tx_hash}` with redeemers
- IS_LOCAL env for testing

### Changed

- improved `/assets/:asset` performance for assets with many mint txs
- node_modules
- yarn
- updated vitest
- removed token registry mock server, using function mocking instead

### Fixed

- port configuration via config option `dbSync.port`
- error in `/epochs/n/parameters` for epochs without PlutusV1/PlutusV2 cost models

## [1.7.0] - 2023-08-30

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ CREATE UNIQUE INDEX IF NOT EXISTS bf_u_idx_epoch_stake_epoch_and_id ON epoch_sta
CREATE INDEX IF NOT EXISTS bf_idx_reference_tx_in_tx_in_id ON reference_tx_in (tx_in_id);
CREATE INDEX IF NOT EXISTS bf_idx_collateral_tx_in_tx_in_id ON collateral_tx_in (tx_in_id);
CREATE INDEX IF NOT EXISTS bf_idx_redeemer_script_hash ON redeemer USING HASH (encode(script_hash, 'hex'));
CREATE INDEX IF NOT EXISTS bf_idx_redeemer_tx_id ON redeemer USING btree (tx_id);
CREATE INDEX IF NOT EXISTS bf_idx_col_tx_out ON collateral_tx_out USING btree (tx_id);
CREATE INDEX IF NOT EXISTS bf_idx_ma_tx_mint_ident ON ma_tx_mint USING btree (ident);
CREATE INDEX IF NOT EXISTS bf_idx_ma_tx_out_ident ON ma_tx_out USING btree (ident);
```

### Docker
Expand Down
32 changes: 18 additions & 14 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{ pkgs ? let
{ nixpkgs ? let
lockfile = builtins.fromJSON (builtins.readFile ./flake.lock);
nixpkgs = lockfile.nodes.nixpkgs.locked;
in
import
(builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgs.rev}.tar.gz";
(builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgs.rev}.tar.gz";
sha256 = nixpkgs.narHash;
}),
pkgs ? import nixpkgs {}
, blockfrost-tests ?
(builtins.fetchGit {
url = "ssh://[email protected]/blockfrost/blockfrost-tests.git";
rev = "19350708ee2e401f0f50dc6bd25c71a6d030ce6f";
})
{ }
, system ? builtins.currentSystem
}:
let
Expand Down Expand Up @@ -65,7 +69,7 @@ in
imports = [ ./nixos-module.nix ];
# We have to increase memsize, otherwise we will get error:
# "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom"
virtualisation.memorySize = 4096;
virtualisation.memorySize = 8192;

services.blockfrost = {
enable = true;
Expand All @@ -85,9 +89,9 @@ in
start_all()
machine.wait_for_unit("blockfrost-backend-ryo.service")
machine.wait_for_open_port(3000)
machine.succeed("cp -r ${blockfrost-backend-ryo}/libexec/source /tmp")
machine.succeed("cp -r ${blockfrost-tests} /tmp/tests")
machine.succeed(
"cd /tmp/source && ${pkgs.yarn}/bin/yarn set version 3.6.3 && ${pkgs.yarn}/bin/yarn test-integration:mainnet"
"cd /tmp/tests && NIX_PATH=nixpkgs=${nixpkgs} nix-shell --run 'SERVER_URL=http://localhost:3000/ IS_LOCAL=true TEST_AUTH=false IS_CACHED=true yarn test:mainnet --run' >&2"
)
'';
};
Expand All @@ -100,7 +104,7 @@ in
imports = [ ./nixos-module.nix ];
# We have to increase memsize, otherwise we will get error:
# "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom"
virtualisation.memorySize = 4096;
virtualisation.memorySize = 8192;

services.blockfrost = {
enable = true;
Expand All @@ -121,9 +125,9 @@ in
start_all()
machine.wait_for_unit("blockfrost-backend-ryo.service")
machine.wait_for_open_port(3000)
machine.succeed("cp -r ${blockfrost-backend-ryo}/libexec/source /tmp")
machine.succeed("cp -r ${blockfrost-tests} /tmp/tests")
machine.succeed(
"cd /tmp/source && ${pkgs.yarn}/bin/yarn set version 3.6.3 && ${pkgs.yarn}/bin/yarn test-integration:preview"
"cd /tmp/tests && NIX_PATH=nixpkgs=${nixpkgs} nix-shell --run 'SERVER_URL=http://localhost:3000/ IS_LOCAL=true TEST_AUTH=false IS_CACHED=true yarn test:preview --run' >&2"
)
'';
};
Expand All @@ -136,7 +140,7 @@ in
imports = [ ./nixos-module.nix ];
# We have to increase memsize, otherwise we will get error:
# "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom"
virtualisation.memorySize = 4096;
virtualisation.memorySize = 8192;

services.blockfrost = {
enable = true;
Expand All @@ -157,9 +161,9 @@ in
start_all()
machine.wait_for_unit("blockfrost-backend-ryo.service")
machine.wait_for_open_port(3000)
machine.succeed("cp -r ${blockfrost-backend-ryo}/libexec/source /tmp")
machine.succeed("cp -r ${blockfrost-tests} /tmp/tests")
machine.succeed(
"cd /tmp/source && ${pkgs.yarn}/bin/yarn set version 3.6.3 && ${pkgs.yarn}/bin/yarn test-integration:preprod"
"cd /tmp/tests && NIX_PATH=nixpkgs=${nixpkgs} nix-shell --run 'SERVER_URL=http://localhost:3000/ IS_LOCAL=true TEST_AUTH=false IS_CACHED=true yarn test:preprod --run' >&2"
)
'';
};
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
"start-testnet": "cross-env-shell NODE_ENV=testnet \"yarn start\"",
"test": "cross-env NODE_OPTIONS='--max-http-header-size 32768' NODE_ENV=test vitest",
"test-badges": "make-coverage-badge --output-path ./docs/images/badge.svg",
"test-integration:mainnet": "cross-env NETWORK=mainnet vitest -c vitest.config.integration.ts --run --segfault-retry=3",
"test-integration:preprod": "cross-env NETWORK=preprod vitest -c vitest.config.integration.ts --run --segfault-retry=3",
"test-integration:preview": "cross-env NETWORK=preview vitest -c vitest.config.integration.ts --run --segfault-retry=3",
"type-check": "tsc --project tsconfig.json"
},
"dependencies": {
"@blockfrost/blockfrost-js": "5.4.0",
"@blockfrost/blockfrost-utils": "2.8.0",
"@blockfrost/openapi": "0.1.60",
"@emurgo/cardano-serialization-lib-nodejs": "11.5.0",
"@emurgo/cip14-js": "^3.0.1",
"@fastify/cors": "^8.3.0",
"@fastify/postgres": "^5.2.0",
"@sentry/node": "^7.69.0",
Expand All @@ -46,7 +42,7 @@
"rimraf": "^5.0.1"
},
"devDependencies": {
"@blockfrost/blockfrost-tests": "1.12.0",
"@types/blake2b": "^2.1.3",
"@types/config": "3.3.1",
"@types/express": "^4.17.17",
"@types/node": "^20.6.2",
Expand All @@ -56,8 +52,8 @@
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "6.7.2",
"@vitest/coverage-c8": "^0.27",
"change-case": "^4.1.2",
"@vitest/coverage-v8": "^1.2.2",
"blake2b": "^2.1.4",
"eslint": "8.49.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "^2.28.1",
Expand All @@ -71,7 +67,7 @@
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"vitest": "^0.27"
"vitest": "^1.2.2"
},
"packageManager": "[email protected]",
"type": "module",
Expand Down
15 changes: 6 additions & 9 deletions src/routes/assets/asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getSchemaForEndpoint,
validateCIP68Metadata,
} from '@blockfrost/openapi';
import AssetFingerprint from '@emurgo/cip14-js';
import { AssetFingerprint } from '../../../utils/cip14.js';
import { FastifyInstance, FastifyRequest } from 'fastify';
import { SQLQuery } from '../../../sql/index.js';
import * as QueryTypes from '../../../types/queries/assets.js';
Expand Down Expand Up @@ -92,14 +92,11 @@ async function route(fastify: FastifyInstance) {

// retrieve off-chain metadata
const metadata = await fetchAssetMetadata(request.params.asset);
// @ts-expect-error due to using ESM with vitest and some weirdness with cip14 lib we need to call .default
// otherwise unit test fails on ""...is not a function".
const fingerprint = AssetFingerprint.default
.fromParts(
Uint8Array.from(Buffer.from(rows[0].policy_id, 'hex')),
Uint8Array.from(Buffer.from(rows[0].asset_name ?? '', 'hex')),
)
.fingerprint();

const fingerprint = AssetFingerprint.fromParts(
Uint8Array.from(Buffer.from(rows[0].policy_id, 'hex')),
Uint8Array.from(Buffer.from(rows[0].asset_name ?? '', 'hex')),
).fingerprint();

return reply.send({
...rows[0],
Expand Down
59 changes: 59 additions & 0 deletions src/utils/cip14.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copy pasted from https://github.com/Emurgo/cip14-js due to ESM issues with the lib
import blake2b from 'blake2b';
import { bech32 } from 'bech32';

/// note: this function can't be inverted due to the hash

const DATA = 'asset';

export class AssetFingerprint {
readonly hashBuf: Uint8Array;

private constructor(hashBuf: Uint8Array) {
this.hashBuf = hashBuf;
}

static fromHash(hash: Uint8Array): AssetFingerprint {
return new AssetFingerprint(hash);
}

static fromParts(policyId: Uint8Array, assetName: Uint8Array): AssetFingerprint {
// see https://github.com/cardano-foundation/CIPs/pull/64
const hashBuf = blake2b(20)
.update(new Uint8Array([...policyId, ...assetName]))
.digest('binary');

return AssetFingerprint.fromHash(hashBuf);
}

static fromBech32(fingerprint: string): AssetFingerprint {
const { prefix, words } = bech32.decode(fingerprint);

if (prefix !== DATA) {
throw new Error('Invalid asset fingerprint');
}

const hashBuf = Buffer.from(bech32.fromWords(words));

return AssetFingerprint.fromHash(hashBuf);
}

fingerprint(): string {
const words = bech32.toWords(this.hashBuf);

return bech32.encode(DATA, words);
}

hash(): string {
return Buffer.from(this.hashBuf).toString('hex');
}

prefix(): string {
return DATA;
}

// The last six characters of the data part form a checksum and contain no information
checksum(): string {
return this.fingerprint().slice(-6);
}
}
10 changes: 6 additions & 4 deletions src/utils/cost-models-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,17 @@ const plutusV2Names: Array<string> = [

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const costModelsMap = (costModels: any) => {
if (costModels === null || typeof costModels !== 'object') return null;

costModels = sortKeysInObject(costModels);

if (Object.keys(costModels.PlutusV1).length !== plutusV1Names.length)
if ('PlutusV1' in costModels && Object.keys(costModels.PlutusV1).length !== plutusV1Names.length)
throw new Error('The size of the Plutus V1 cost model mismatched');

if (Object.keys(costModels.PlutusV2).length !== plutusV2Names.length)
if ('PlutusV2' in costModels && Object.keys(costModels.PlutusV2).length !== plutusV2Names.length)
throw new Error('The size of the Plutus V1 cost model mismatched');

if (validation.isNumber(Object.keys(costModels.PlutusV1)[0])) {
if ('PlutusV1' in costModels && validation.isNumber(Object.keys(costModels.PlutusV1)[0])) {
const PlutusV1: Record<string, number> = {};

for (let index = 0; index < plutusV1Names.length; index++)
Expand All @@ -372,7 +374,7 @@ export const costModelsMap = (costModels: any) => {
costModels = { ...costModels, PlutusV1 };
}

if (validation.isNumber(Object.keys(costModels.PlutusV2)[0])) {
if ('PlutusV2' in costModels && validation.isNumber(Object.keys(costModels.PlutusV2)[0])) {
const PlutusV2: Record<string, number> = {};

for (let index = 0; index < plutusV2Names.length; index++)
Expand Down
7 changes: 0 additions & 7 deletions test/integration/tests/common/routes.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/integration/tests/mainnet/routes.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/integration/tests/preprod/routes.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/integration/tests/preview/routes.ts

This file was deleted.

Loading

0 comments on commit 71799b6

Please sign in to comment.