ar-io / arns-service

Koa microservice that leverages Warp to support the ArNS Portal and ar.io observers.
https://api.arns.app
GNU Affero General Public License v3.0
19 stars 4 forks source link
ario arns arweave koa smartweave swagger warp

arns-service

Koa microservice that facilities the ArNS Portal.

Getting Started

Requirements:

Running Locally

Starting the service:

You can check the service is running by running the command:

curl localhost:3000/healthcheck
{"timestamp":"2023-04-13T13:33:38.299Z","status":200,"message":"Hello world."}

Docker

Build and run the latest image:

docker run -e GATEWAY_HOST=arweave.net -p 3000:3000 ghcr.io/ar-io/arns-service:latest

You can run on a different port by changing the -e PORT=3000 -p 3000:3000 to -e PORT=4000 -p 4000:4000, for example, or specify a .env file with --env-file flag.

Profiles

The service can be run with different profiles to facilitate different environments. The following profiles are supported:

To run the service with a profile, you can use the --profile flag:

docker compose --env-file .env --profile litestream up --build

Warp

The service leverages Warp SDK to retrieve, evaluate and cache contract state. To request a contract state, run:

curl localhost:3000/v1/contract/${CONTRACT_ID}

e.g.

curl localhost:3000/v1/contract/bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U

For more advanced features of Warp caching and state evaluation (e.g. D.R.E nodes), refer to the Warp documentation.

SQLite

This service uses the warp-contracts-sqlite for storing contract state. The sqlite database is stored in the ./cache directory. To clear the Warp cache, run:

rm -rf ./cache

Evaluation Options

By default, the service will load Contract-Manifest tags for state evaluation.

Syncing State

Similar to D.R.E nodes, the service can be configured to sync state for a given contract. This is useful for contracts with large number of interactions that may take a long time to evaluate locally. To sync state from this service via Warp, you can use syncState() with the /v1/contract/${CONTRACT_ID} endpoint:

const contract = await warp
  .contract(CONTRACT_TX_ID)
  .setEvaluationOptions(evaluationOptions)
  .syncState(`https://api.arns.app/v1/contract/${CONTRACT_TX_ID}`, {
    validity: true,
  });

Configuration

The service can be configured using environment variables. The following environment variables are supported:

You can cp .env.sample .env and modify them locally.

Integration Tests

Integration tests are used to validate endpoints and response payloads. Then can be run locally via:

  1. Run the service locally against the test environment:
yarn dotenv -e .env.test yarn start:watch
  1. In a separate terminal, run the integration tests:
yarn test:integration:local

or entirely via docker compose:

yarn test:docker

Swagger

Swagger is used for endpoint documentation and testing. When running the service, you can load the Swagger UI in your browser at:

http://localhost:3000/api-docs

For production, the Swagger UI is available at https://api.arns.app/api-docs

Contributions