Skip to content

roke-to/roketo-api

Repository files navigation

Roke.to api

Installation

$ yarn

Running locally (testnet)

Export all the required testnet env variables

export NEAR_NETWORK_ID=testnet
export NEAR_NODE_URL=https://rpc.testnet.near.org
export NEAR_WALLET_URL=https://wallet.testnet.near.org
export ROKETO_CONTRACT_NAME=streaming-r-v2.dcversus.testnet
export VAULT_CONTRACT_NAME=vault.vengone.testnet
export INDEXER_DB_URL=postgres://public_readonly:[email protected]/testnet_explorer
export DISABLE_DATABASE_SSL=true

Prepare local Postgres DB using docker:

Install docker and docker-compose.

Start Docker container with Postgres DB:

docker-compose up -d

Set DB connection string to environment variable:

export DATABASE_URL=postgres://postgres:[email protected]/eco-postgres

Change TypeORM config for development:

In ormconfig.ts:

-  ssl: {
-    rejectUnauthorized: false,
-  },
+  synchronize: true,
+  ssl: false,

Build the project before executing migrations:

yarn build

Execute all the built migrations:

yarn migrate

Run backend in development mode:

yarn start:dev

Mirroring testnet production DB to local DB

To drop all the data from your local DB and mirror testnet DB run the following command (it should NOT log any errors):

pg_dump --no-privileges --format c --dbname=$DB_URL | pg_restore --no-owner --clean --if-exists --dbname=$DATABASE_URL

You may need to install postgresql-14 Linux package or brew upgrade postgresql for macOS first.

If you don't have such Linux package for installation, try adding a custom Postgres PPA: https://www.postgresql.org/download/linux/ubuntu/

Generating migrations for production DBs

Migrations can be generated by comparing live schema of DB with built entities. To generate a migration, do the following:

  1. Stop backend from running.
  2. Mirror testnet production DB to local DB using the command from the previous paragraph.
  3. Build the project with yarn build (so all the updated entities files are built).
  4. Generate a migration with yarn typeorm migration:generate -n "MIGRATION_NAME_HERE" while replacing MIGRATION_NAME_HERE placeholder with actual migration name.

At this point you should have a new file generated in src/migrations folder. For validation, do the following:

  1. Build the project with yarn build (so the fresh migration is built).
  2. Apply it to DB with yarn migrate.
  3. Remove synchronize: true from ORMConfig file.
  4. Run backend as usual.

If it runs without synchronize: true option as good as it run with it, then a migration was generated and applied correctly.

Using with local frontend

Feel free to run client API generation script at any point:

./generate-and-deploy-api-client.sh

After that, use the produced API version in package.json of frontend app and change VITE_WEB_API_URL in .env file to point at you local backend instance.

Run on docker

# Build image with current
docker build .
docker images
# REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
# <none>       <none>    9d1b89be622a   2 minutes ago   405MB

docker run -p 4001:3000 --env DATABASE_URL=$DB_URL --env DISABLE_DATABASE_SSL=true $ACCESS_STRING

Testnet env vars

- ROKETO_CONTRACT_NAME=streaming-r-v2.dcversus.testnet
- VAULT_CONTRACT_NAME=vault.vengone.testnet
- NEAR_NETWORK_ID=testnet
- NEAR_NODE_URL=https://rpc.testnet.near.org
- NEAR_WALLET_URL=https://wallet.testnet.near.org
- API_HOST=https://api.test.roke.to
- DAPP_HOST=https://app2.test.roke.to
- INDEXER_DB_URL="postgres://public_readonly:[email protected]/testnet_explorer"

Prod env vars

- ROKETO_CONTRACT_NAME=streaming.r-v2.near
- VAULT_CONTRACT_NAME=vault-roketo.near
- NEAR_NETWORK_ID=mainnet
- NEAR_NODE_URL=https://rpc.mainnet.near.org
- NEAR_WALLET_URL=https://wallet.near.org
- API_HOST=https://api.roke.to
- DAPP_HOST=https://app2.roke.to
- INDEXER_DB_URL="postgres://public_readonly:[email protected]/mainnet_explorer"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published