0.28.1 • Published 4 days ago

@cardano-sdk/cardano-services v0.28.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 days ago

Cardano JS SDK | Cardano GraphQL Services

Libraries and program entrypoints for services to facilitate remote data and submit access using Provider interfaces over HTTP; The TxSubmitHttpService can be configured to submit via Ogmios or via submit-api. Data is sourced from Cardano DB Sync, the local Cardano Node via Ogmios Local State Queries, genesis files, and remote sources.

Features

  • CLI with configuration via command line arguments or environment variables and optional loading of secrets from disk.
  • Service port discovery via DNS resolution, or static configuration.
  • Fault-tolerant transaction submission.
  • Optional Prometheus metrics available at /metrics
  • Data sourced from Cardano DB Sync PostgreSQL, Local State Queries, genesis files, and remote sources.

Services

The services require instances of Cardano Node and Ogmios as a minimum, with Cardano DB Sync dependent on the run command. Please refer to docker-compose.json for the current supported version of each service dependency.

Provider Server

The Provider server can be started with one or more services by name, segmented by URL path. Run the CLI with start-provider-server --help to see the full list of options.

Examples

The following examples require the install and build steps to be completed.

All Providers | Static Service Config | Direct Tx Submission

  • The server will expose all Provider HTTP services
  • Transactions will be submitted directly via Ogmios, running at ws://localhost:1338.
  • Connects to PostgreSQL service running at localhost:5432
  • HTTP API exposed using a custom API URL

start-provider-server using CLI options:

./dist/cjs/cli.js \
  start-provider-server \
    --api-url http://localhost:6000 \
    --cardano-node-config-path ./config/network/preprod/cardano-node/config.json \
    --postgres-connection-string-db-sync postgresql://somePgUser:somePassword@localhost:5432/someDbName \
    --ogmios-url  ws://localhost:1338 \
    asset chain-history stake-pool tx-submit network-info utxo rewards

start-provider-server using env variables:

SERVICE_NAMES=asset,chain-history,stake-pool,tx-submit,network-info,utxo,rewards \
API_URL=http://localhost:6000 \
CARDANO_NODE_CONFIG_PATH=./config/network/preprod/cardano-node/config.json \
POSTGRES_CONNECTION_STRING_DB_SYNC=postgresql://somePgUser:somePassword@localhost:5432/someDbName \
OGMIOS_URL=ws://localhost:1338 \
./dist/cjs/cli.js start-provider-server

All Providers | Service Discovery | Metrics

start-provider-server using CLI options:

./dist/cjs/cli.js \
  start-provider-server \
    --api-url http://localhost:6000 \
    --enable-metrics \
    --cardano-node-config-path ./config/network/preprod/cardano-node/config.json \
    --postgres-srv-service-name-db-sync someHostName \
    --postgres-db-db-sync someDbName \
    --postgres-user-db-sync somePgUser \
    --postgres-password-db-sync somePassword \
    --ogmios-srv-service-name  some-domain-for-ogmios \
    asset chain-history stake-pool tx-submit network-info utxo rewards

start-provider-server using env variables:

SERVICE_NAMES=asset,chain-history,stake-pool,tx-submit,network-info,utxo,rewards \
API_URL=http://localhost:6000 \
ENABLE_METRICS=true \
CARDANO_NODE_CONFIG_PATH=./config/network/preprod/cardano-node/config.json \
POSTGRES_SRV_SERVICE_NAME_DB_SYNC=some-domain-for-postgres-db
POSTGRES_DB_DB_SYNC=someDbName \
POSTGRES_USER_DB_SYNC=someUser \
POSTGRES_PASSWORD_DB_SYNC=somePassword \
OGMIOS_SRV_SERVICE_NAME=some-domain-for-ogmios \
./dist/cjs/cli.js start-provider-server

start-worker using CLI options:

./dist/cjs/cli.js \
  start-worker \
    --ogmios-srv-service-name  some-domain-for-ogmios

start-worker using env variables:

OGMIOS_SRV_SERVICE_NAME=some-domain-for-ogmios \
./dist/cjs/cli.js start-worker

start-projector using CLI options with Ogmios and PostgreSQL running on localhost:

./dist/cjs/cli.js \
  start-projector \
    --ogmios-url 'ws://localhost:1339' \
    --postgres-connection-string 'postgresql://postgres:doNoUseThisSecret!@localhost/projection' \
    stake-pool,stake-pool-metadata-job

Production

The Docker images produced by the SDK and the docker compose infrastructures (mainnet, preprod and local-network) it includes are ready to be used in production environment.

Note: the docker compose infrastructures included in the SDK are mainly used for development purposes: to use them in production environments, the projector service(s) must be instructed to run the migration scripts rather than to use the synchronize development option from TypeORM. This can be achieved through environment variables:

SYNCHRONIZE=false yarn preprod:up

Development

To speed up the development process, developers can ignore the migrations while developing or debugging changes. This freedom is granted by the synchronize development option from TypeORM, which is enabled by default in the docker compose infrastructures included in the SDK.

Generating Projector Schema Migrations

In order to grant to the projection service the ability to choose which projections it needs to activate, the migrations must be scoped to a single model: if a single change has impact on more models, one migration for each impacted model must be generated.

Hint: isolating all the changes to each model in distinct commits can be so helpful for this target!

For each migration, once the change is finalized (all the new entities are added to the entities object at src/Projection/prepareTypeormProjection.ts, apart from last minor refinements the PR is approved, etc...), the relative migration can be generated following these steps.

Hint: if previous hint was followed, to checkout each commit which requires a migration to produce a fixup commit for each of them can be an easy way to iterate over all the impacted models.

  1. Start a new fresh database with DROP_PROJECTOR_SCHEMA=true SYNCHRONIZE=false yarn preprod up
    • Note: do not override PROJECTION_NAMES since in this scope all the projections must be loaded
    • Note: this will not apply the current changes to the models into the database schema, so the currently developed feature may not work properly, this is not relevant for the target of creating the migration
    • DROP_PROJECTOR_SCHEMA=true is used to let the projection service to create the database schema from scratch
    • with SYNCHRONIZE=false the projection service runs all migrations rather than reflecting the changes to the models on the schema (through the synchronize development option from TypeORM)
  2. Run yarn generate-migration to produce a new migration in src/Projections/migrations directory
    • this compares the database schema against all the models (repeat: only one of them should be changed) and generates the required migration
  3. Inspect the generated migration
    • Check: if the migration has impact on more than one table, the changes was not isolated per model! (the change must be reworked)
  4. Add the static entity property to the migration class (to see other migrations for reference)
  5. Rename the newly generated migration file and class giving them mnemonic names
  6. Export the new migration from migrations array at src/Projections/migrations/index.ts

Tests

See code coverage report

0.28.1

4 days ago

0.28.0

12 days ago

0.27.1

24 days ago

0.27.0

1 month ago

0.26.6

2 months ago

0.26.5

2 months ago

0.26.4

2 months ago

0.26.3

2 months ago

0.26.2

2 months ago

0.26.1

3 months ago

0.26.0

3 months ago

0.25.4

3 months ago

0.25.3

3 months ago

0.25.2

3 months ago

0.25.1

3 months ago

0.25.0

3 months ago

0.24.5

4 months ago

0.24.4

4 months ago

0.24.3

4 months ago

0.24.2

4 months ago

0.24.1

5 months ago

0.24.0

5 months ago

0.23.1

5 months ago

0.23.0

5 months ago

0.20.0

7 months ago

0.17.0

8 months ago

0.21.1

7 months ago

0.21.0

7 months ago

0.14.3-patch.0

10 months ago

0.14.5

10 months ago

0.14.6

9 months ago

0.14.7

9 months ago

0.14.8

9 months ago

0.14.1

10 months ago

0.14.2

10 months ago

0.14.3

10 months ago

0.18.0

8 months ago

0.14.4

10 months ago

0.22.0

6 months ago

0.19.0

7 months ago

0.15.0

9 months ago

0.21.1-patch.0

5 months ago

0.16.0

9 months ago

0.16.1

8 months ago

0.14.9-patch.0

8 months ago

0.14.0

10 months ago

0.13.0

11 months ago

0.13.1

11 months ago

0.13.2

10 months ago

0.13.3

10 months ago

0.12.0

11 months ago

0.12.1

11 months ago

0.11.0-nightly.10

12 months ago

0.11.0

12 months ago

0.11.1

12 months ago

0.11.2

11 months ago

0.11.3

11 months ago

0.11.4

11 months ago

0.11.1-test.0

12 months ago

0.11.1-test.1

12 months ago

0.12.0-nightly.1

12 months ago

0.12.0-nightly.0

12 months ago

0.11.2-patch.0

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.9.0-nightly.2

1 year ago

0.9.0-nightly.1

1 year ago

0.8.0

1 year ago

0.9.0-nightly.0

1 year ago

0.8.0-nightly.4

1 year ago

0.8.0-nightly.3

1 year ago

0.8.0-nightly.2

1 year ago

0.8.0-nightly.1

1 year ago

0.6.0-nightly.17

2 years ago

0.6.0-nightly.18

2 years ago

0.7.0

1 year ago

0.6.1-nightly.0

1 year ago

0.6.1-nightly.2

1 year ago

0.6.1-nightly.1

1 year ago

0.7.0-nightly.1

1 year ago

0.7.0-nightly.2

1 year ago

0.7.0-nightly.0

1 year ago

0.7.0-nightly.5

1 year ago

0.7.0-nightly.6

1 year ago

0.7.0-nightly.3

1 year ago

0.7.0-nightly.4

1 year ago

0.7.0-nightly.7

1 year ago

0.7.0-nightly.8

1 year ago

0.8.0-nightly.0

1 year ago

0.6.0

1 year ago

0.6.0-nightly.15

2 years ago

0.6.0-nightly.16

2 years ago

0.6.0-nightly.13

2 years ago

0.6.0-nightly.14

2 years ago

0.6.0-nightly.12

2 years ago

0.5.1-nightly.0

2 years ago

0.5.1-nightly.1

2 years ago

0.6.0-nightly.1

2 years ago

0.6.0-nightly.0

2 years ago

0.6.0-nightly.9

2 years ago

0.6.0-nightly.8

2 years ago

0.6.0-nightly.5

2 years ago

0.6.0-nightly.7

2 years ago

0.6.0-nightly.6

2 years ago

0.6.0-nightly.11

2 years ago

0.5.0

2 years ago

0.5.0-nightly.13

2 years ago

0.6.0-nightly.10

2 years ago

0.5.0-nightly.12

2 years ago

0.5.0-nightly.11

2 years ago

0.5.0-nightly.10

2 years ago

0.5.0-nightly.9

2 years ago

0.5.0-nightly.8

2 years ago

0.5.0-nightly.7

2 years ago

0.5.0-nightly.6

2 years ago

0.5.0-nightly.5

2 years ago

0.5.0-nightly.4

2 years ago

0.5.0-nightly.3

2 years ago

0.5.0-nightly.2

2 years ago

0.5.0-nightly.1

2 years ago

0.5.0-nightly.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago