Skip to content

Commit

Permalink
Merge branch 'master' into chore/LW-7691-master-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceahasegan committed Jun 13, 2024
2 parents 1f57156 + c6700aa commit 6349484
Show file tree
Hide file tree
Showing 123 changed files with 604 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
'error',
{
paths: ['lodash'],
patterns: ['@cardano-sdk/*/src/*']
patterns: ['@cardano-sdk/*/src/*', 'lodash/*', '!lodash/*.js']
}
],
'no-shadow': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: 🔨 Build
run: |
yarn install --immutable --inline-builds --mode=skip-build
yarn build
yarn build:cjs
docker build --no-cache .
env:
NODE_OPTIONS: '--max_old_space_size=8192'
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN yarn --immutable --inline-builds --mode=skip-build
COPY packages packages
RUN \
echo "export const unused = 'unused';" > packages/e2e/src/index.ts &&\
NODE_OPTIONS=--max_old_space_size=10240 yarn build
NODE_OPTIONS=--max_old_space_size=10240 yarn build:cjs

FROM nodejs-builder as cardano-services-production-deps
RUN yarn workspaces focus --all --production
Expand Down
6 changes: 5 additions & 1 deletion nix/cardano-services/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ in {
buildInputs = oldAttrs.buildInputs ++ [nixpkgs.pkg-config nixpkgs.libusb1];
# run actual build
buildPhase = ''
yarn workspace @cardano-sdk/cardano-services run build
yarn workspace @cardano-sdk/cardano-services run build:cjs
'';
# override installPhase to only install what's necessary
installPhase = ''
Expand All @@ -71,12 +71,16 @@ in {
mkdir -p $out/libexec/$sourceRoot/packages/$p
cp -r packages/$p/dist $out/libexec/$sourceRoot/packages/$p/dist
cp -r packages/$p/package.json $out/libexec/$sourceRoot/packages/$p/package.json
ln -s $out/libexec/$sourceRoot/packages/$p/package.json $out/libexec/$sourceRoot/packages/$p/dist/package.json
done
cp -r ${production-deps}/libexec/$sourceRoot/packages/cardano-services/config $out/libexec/$sourceRoot/packages/cardano-services/config
cd "$out/libexec/$sourceRoot"
runHook postInstall
# Test that Node.js loads our code correctly:
$out/bin/cli --version
'';
# add a bin script that should be used to run cardano-services CLI
postInstall = ''
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"scripts": {
"build": "yarn workspaces foreach -v run build",
"build:cjs": "yarn workspaces foreach -v run build:cjs",
"circular-deps:check": "yarn workspaces foreach -v run circular-deps:check",
"cleanup-build": "yarn workspaces foreach -v run cleanup && yarn install && yarn workspaces foreach -v run build",
"reinstall": "yarn workspaces foreach -v run cleanup:nm && yarn install",
Expand Down Expand Up @@ -84,6 +85,7 @@
"ts-jest": "^28.0.7",
"ts-node": "^10.0.0",
"ts-node-dev": "^1.1.8",
"tsc-alias": "^1.8.10",
"typedoc": "^0.23.24",
"typedoc-plugin-missing-exports": "^1.0.0",
"typescript": "^4.7.4"
Expand Down
9 changes: 4 additions & 5 deletions packages/cardano-services-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
},
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build:version": "bash -c 'if node ./scripts/createVersionSource.js --check ; then node ./scripts/createVersionSource.js --create && yarn lint:fix ; fi && cp ./package.json ./dist/package.json'",
"build": "yarn build:version && run-s build:cjs build:esm module-fixup",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "yarn build:version && tsc --build src && cp ./package.json dist/ && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"build:version": "bash -c 'if node ./scripts/createVersionSource.js --check ; then node ./scripts/createVersionSource.js --create && yarn lint:fix ; fi'",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"circular-deps:check": "madge --circular dist/cjs",
Expand All @@ -50,6 +48,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/cardano-services-client/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
declare module '*.json';

// exclude from build, as it has to be imported at runtime
declare module '../package.json';
5 changes: 2 additions & 3 deletions packages/cardano-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:cjs": "tsc --build src && chmod +x ./dist/cjs/cli.js",
"build:copy-assets": "bash ./copy-assets.sh",
"build": "run-s build:cjs build:copy-assets",
"build": "yarn build:cjs",
"build:cjs": "tsc --build src && chmod +x ./dist/cjs/cli.js && bash ./copy-assets.sh",
"build:test-db": "./test/jest-setup/rebuild-test-db.sh",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from 'ts-log';
import { TokenMetadataService } from './types';
import { contextLogger } from '@cardano-sdk/util';
import axios, { AxiosInstance } from 'axios';
import pick from 'lodash/pick';
import pick from 'lodash/pick.js';

export const DEFAULT_TOKEN_METADATA_CACHE_TTL = Seconds(10 * 60);
export const DEFAULT_TOKEN_METADATA_REQUEST_TIMEOUT = Milliseconds(3 * 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ import {
mapTxTokenMap,
mapWithdrawal
} from './mappers';
import omit from 'lodash/omit';
import orderBy from 'lodash/orderBy';
import omit from 'lodash/omit.js';
import orderBy from 'lodash/orderBy.js';

const {
CredentialType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { QueryResult } from 'pg';
import { TxMetadataService } from '../../Metadata';
import { hexStringToBuffer } from '@cardano-sdk/util';
import { mapBlock, mapTxAlonzo, mapTxIn, mapTxOut } from './mappers';
import orderBy from 'lodash/orderBy';
import orderBy from 'lodash/orderBy.js';

/** Properties that are need to create DbSyncChainHistoryProvider */
export interface ChainHistoryProviderProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Logger } from 'ts-log';
import { NetworkInfoBuilder } from './NetworkInfoBuilder';
import { RunnableModule } from '@cardano-sdk/util';
import { toGenesisParams, toLedgerTip, toProtocolParams, toSupply } from './mappers';
import memoize from 'lodash/memoize';
import memoize from 'lodash/memoize.js';

/** Dependencies that are need to create DbSyncNetworkInfoProvider */
export interface NetworkInfoProviderDependencies extends DbSyncProviderDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { createLogger } from 'bunyan';
import { getConnectionConfig, getOgmiosObservableCardanoNode } from '../services';
import { getEntities } from '../../Projection/prepareTypeormProjection';
import { isNotNil } from '@cardano-sdk/util';
import memoize from 'lodash/memoize';
import memoize from 'lodash/memoize.js';

export const ALLOWED_ORIGINS_DEFAULT = false;
export const DISABLE_DB_CACHE_DEFAULT = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { PromiseOrValue, RunnableModule, resolveObjectValues } from '@cardano-sd
import { StakePoolBuilder } from './StakePoolBuilder';
import { StakePoolMetadataService } from '../types';
import { toStakePoolResults } from './mappers';
import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

/** Properties that are need to create DbSyncStakePoolProvider */
export interface StakePoolProviderProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/cardano-services/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
},
{
"path": "../../util-rxjs/src"
},
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getPort } from 'get-port-please';
import { isNotNil } from '@cardano-sdk/util';
import { logger } from '@cardano-sdk/util-dev';
import axios from 'axios';
import lowerCase from 'lodash/lowerCase';
import lowerCase from 'lodash/lowerCase.js';

const UNSUPPORTED_MEDIA_STRING = 'Request failed with status code 415';
const APPLICATION_CBOR = 'application/cbor';
Expand Down
2 changes: 1 addition & 1 deletion packages/cardano-services/test/data-mocks/tx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Cardano } from '@cardano-sdk/core';
import { Hash28ByteBase16, Hash32ByteBase16 } from '@cardano-sdk/crypto';

import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

export const valueWithCoinOnly: Cardano.Value = {
coins: 7_420_514n
Expand Down
7 changes: 3 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -44,6 +42,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Asset/NftMetadata/fromMetadatum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from 'ts-log';
import { asMetadatumArray, asMetadatumMap } from '../../util/metadatum';
import { asString } from './util';
import { isNotNil } from '@cardano-sdk/util';
import difference from 'lodash/difference';
import difference from 'lodash/difference.js';

const isString = (obj: unknown): obj is string => typeof obj === 'string';
const VersionRegExp = /^\d+\.?\d?$/;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Asset/util/subtractTokenMaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable complexity,sonarjs/cognitive-complexity */
import * as Cardano from '../../Cardano';
import uniq from 'lodash/uniq';
import uniq from 'lodash/uniq.js';

/**
* Given two Cardano.TokenMaps, compute a Cardano.TokenMap with the difference between the left-hand side and the right-hand side.
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/Serialization/PlutusData/PlutusList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { bytesToHex, hexToBytes } from '../../util/misc';
/** A list of plutus data. */
export class PlutusList {
readonly #array = new Array<PlutusData>();
#useIndefiniteEncoding = false;

/**
* Serializes this PlutusList instance into its CBOR representation as a Uint8Array.
Expand All @@ -15,8 +14,9 @@ export class PlutusList {
*/
toCbor(): HexBlob {
const writer = new CborWriter();
const shouldUseIndefinite = this.#array.length > 0;

if (this.#useIndefiniteEncoding) {
if (shouldUseIndefinite) {
writer.writeStartArray();
} else {
writer.writeStartArray(this.#array.length);
Expand All @@ -26,7 +26,7 @@ export class PlutusList {
writer.writeEncodedValue(hexToBytes(elem.toCbor()));
}

if (this.#useIndefiniteEncoding) writer.writeEndArray();
if (shouldUseIndefinite) writer.writeEndArray();

return HexBlob.fromBytes(writer.encode());
}
Expand All @@ -41,9 +41,7 @@ export class PlutusList {
const list = new PlutusList();
const reader = new CborReader(cbor);

const length = reader.readStartArray();

if (length === null) list.#useIndefiniteEncoding = true;
reader.readStartArray();

while (reader.peekState() !== CborReaderState.EndArray) {
list.add(PlutusData.fromCbor(bytesToHex(reader.readEncodedValue())));
Expand Down Expand Up @@ -88,7 +86,6 @@ export class PlutusList {
* @returns true if objects are equals; otherwise false.
*/
equals(other: PlutusList): boolean {
if (this.#useIndefiniteEncoding !== other.#useIndefiniteEncoding) return false;
if (this.#array.length !== other.#array.length) return false;

for (let i = 0; i < this.#array.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Redeemers } from './Redeemer';
import { SerializationError, SerializationFailure } from '../../errors';
import { VkeyWitness } from './VkeyWitness';
import { hexToBytes } from '../../util/misc';
import _groupBy from 'lodash/groupBy';
import uniqWith from 'lodash/uniqWith';
import _groupBy from 'lodash/groupBy.js';
import uniqWith from 'lodash/uniqWith.js';

/** This type represents the segregated CDDL scripts. */
type CddlScripts = {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/util/slotCalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CustomError } from 'ts-custom-error';
import { EpochNo, NetworkMagics, Slot } from '../Cardano';
import { EraSummary } from '../CardanoNode';
import { NetworkInfoProvider } from '../Provider/NetworkInfoProvider';
import groupBy from 'lodash/groupBy';
import last from 'lodash/last';
import memoize from 'lodash/memoize';
import orderBy from 'lodash/orderBy';
import groupBy from 'lodash/groupBy.js';
import last from 'lodash/last.js';
import memoize from 'lodash/memoize.js';
import orderBy from 'lodash/orderBy.js';

export interface SlotDate {
slot: Slot;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/tokenTransferInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssetProvider } from '../Provider';
import { Inspector, resolveInputs } from './txInspector';
import { coalesceValueQuantities } from './coalesceValueQuantities';
import { subtractValueQuantities } from './subtractValueQuantities';
import uniq from 'lodash/uniq';
import uniq from 'lodash/uniq.js';

export type AssetInfoWithAmount = { amount: Cardano.Lovelace; assetInfo: AssetInfo };

Expand Down
12 changes: 9 additions & 3 deletions packages/core/test/Serialization/PlutusData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ describe('PlutusData', () => {
});

describe('List', () => {
it('can encode an empty plutus list', () => {
const data = new Serialization.PlutusList();

expect(data.toCbor()).toEqual('80');
});

it('can encode simple plutus list', () => {
const data = new Serialization.PlutusList();

Expand All @@ -142,7 +148,7 @@ describe('PlutusData', () => {
data.add(Serialization.PlutusData.newInteger(4n));
data.add(Serialization.PlutusData.newInteger(5n));

expect(data.toCbor()).toEqual('850102030405');
expect(data.toCbor()).toEqual('9f0102030405ff');
});

it('can encode a list of plutus list', () => {
Expand All @@ -162,7 +168,7 @@ describe('PlutusData', () => {
outer.add(Serialization.PlutusData.newList(innerList));
outer.add(Serialization.PlutusData.newInteger(5n));

expect(outer.toCbor()).toEqual('85010285010203040585010203040505');
expect(outer.toCbor()).toEqual('9f01029f0102030405ff9f0102030405ff05ff');
});
});

Expand Down Expand Up @@ -292,7 +298,7 @@ describe('PlutusData', () => {

const data = new Serialization.ConstrPlutusData(0n, args);

expect(data.toCbor()).toEqual('d879850102030405');
expect(data.toCbor()).toEqual('d8799f0102030405ff');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/util/slotCalc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../src';
import { fromSerializableObject } from '@cardano-sdk/util';

import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

// Era summaries copied from util-dev package.
// Importing directly from util-dev reports Milliseconds types incompatible.
Expand Down
7 changes: 3 additions & 4 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"circular-deps:check": "madge --circular dist/cjs",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -48,6 +46,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 6349484

Please sign in to comment.