Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to mongodb #15

Merged
merged 28 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NODE_ENV=production
PORT=5000
PORT=8080
LOG_NAME=ink-substrate-explorer-api
LOG_LEVEL=debug

Expand All @@ -8,11 +8,11 @@ GRAPHQL_PLAYGROUND=true
GRAPHQL_SORT_SCHEMA=true
GRAPHQL_INTROSPECTION=true

DATABASE_HOST=postgres
DATABASE_HOST=mongo
DATABASE_NAME=ink
DATABASE_USERNAME=root
DATABASE_PASSWORD=password
DATABASE_PORT=5432
DATABASE_USERNAME=mongodb
DATABASE_PASSWORD=mongodb
DATABASE_PORT=27017
DATABASE_SSL_CA=""
DATABASE_RETRY_ATTEMPTS=5
DATABASE_RETRY_DELAY=3000
Expand Down
53 changes: 16 additions & 37 deletions README-es.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Ink! Explorer API

## **Acerca del explorador**

Ink Explorer es una aplicacion que provee informacion relativa a los contratos que utilizan Ink! en blockchains basadas en Substrate. Se suscribe a la blockchain y a los eventos emitidos por los modulos de Ink! y guarda la informacion en su propia base de datos PostgreSQL. El back-end expone una API que puede interactuar con la base de datos y ejecutar consultas rapidas para obtener informacion especifica en poco tiempo.
Ink Explorer es una aplicacion que provee informacion relativa a los contratos que utilizan Ink! en blockchains basadas en Substrate. Se suscribe a la blockchain y a los eventos emitidos por los modulos de Ink! y guarda la informacion en su propia base de datos. El back-end expone una API que puede interactuar con la base de datos y ejecutar consultas rapidas para obtener informacion especifica en poco tiempo.

La idea de este proyecto es brindar una herramienta que permita a los desarrolladores de Ink! explorar y analizar los contratos que se encuentran en blockchain. Esta herramienta se puede utilizar para analizar los contratos que se encuentran en blockchains basadas en Substrate que utilizan módulos Ink!. También se puede usar para analizar contratos que están en una blockchain local.

Expand All @@ -40,7 +40,7 @@ pnpm i --frozen-lockfile

### Configurar las variables de entorno

**Nota**: El archivo .env tiene la configuracion para GraphQL, la base de datos PostgreSQL, Node y la url del RPC de la blockchain basada en Substrate.
**Nota**: El archivo .env tiene la configuracion para GraphQL, la base de datos Mongo, Node y la url del RPC de la blockchain basada en Substrate.

```sh
cp .env.sample .env
Expand All @@ -67,10 +67,10 @@ GRAPHQL_INTROSPECTION=true
#### Configuraciones de la base de datos

```sh
DATABASE_HOST=postgres
DATABASE_HOST=mongo
DATABASE_NAME=ink
DATABASE_USERNAME=root
DATABASE_PASSWORD=password
DATABASE_USERNAME=mongodb
DATABASE_PASSWORD=mongodb
DATABASE_RETRY_ATTEMPTS=5
DATABASE_RETRY_DELAY=3000
```
Expand All @@ -89,37 +89,16 @@ BLOCK_CONCURRENCY=1000

## **Levantando el servicio (DEV)**

### Instanciar una BD Postgres utilizando docker (opcional)
### Instanciar una BD Mongo utilizando docker (opcional)

Para levantar el servicio es necesario contar con una **BD PostgreSQL**. Para esto, el archivo **dev-docker-compose.yaml** ya tiene una imagen configurada lista para usar.
Ejecutando el siguiente comando tambien instanciara un contenedor para pgAdmin:
Para levantar el servicio es necesario contar con una **BD Mongo**. Para esto, el archivo **dev-docker-compose.yaml** ya tiene una imagen configurada lista para usar.
Ejecutando el siguiente comando tambien instanciara un contenedor para Mongo Express:

```sh
docker-compose -f dev-docker-compose.yaml up -d
```

Una vez que el servicio se está ejecutando, se puede acceder a pgAdmin siguiendo el enlace que se muestra en la terminal (en este caso localhost:80).

![pgAdmin](/.images/pg_admin_up.png)

Las credenciales para acceder a pgAdmin son (establecidas en el archivo dev-docker-compose):

- PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
- PGADMIN_DEFAULT_PASSWORD: "admin"

Registre un nuevo servidor en pgAdmin y establezca las credenciales para la base de datos PostgreSQL:

Haga clic derecho en 'Servidores' y seleccione "Registrarse" -> "Servidor"

![pgAdmin](/.images/pg_admin_select_server.png)

Establezca un nombre para el servidor (en este ejemplo, "Docker")

![pgAdmin](/.images/pg_admin_server_name.png)

Establezca las credenciales para la base de datos PostgreSQL (esto se puede encontrar en el archivo dev-docker-compose):

![pgAdmin](/.images/pg_admin_connection.png)
Una vez que el servicio se está ejecutando, se puede acceder a Mongo Express siguiendo el enlace que se muestra en la terminal (en este caso localhost:8081).

### Instanciar un nodo local de Substrate (opcional)

Expand All @@ -143,17 +122,17 @@ pnpm start:dev
Ejecuta el servicio en el modo de desarrollo.
El servicio se recargará si realiza ediciones.

**Nota**: Se requiere una base de datos postgres en funcionamiento y una conexión válida a un nodo de Substrate.
**Nota**: Se requiere una base de datos Mongo en funcionamiento y una conexión válida a un nodo de Substrate.

## **Levantando el servicio (PROD)**

Para iniciar los contenedores del servicio de backend, la BD y pgAdmin ejecutar el siguiente comando:
Para iniciar los contenedores del servicio de backend, la BD y Mongo Express ejecutar el siguiente comando:

```sh
docker-compose up -d
```

**Nota**: Se requiere una base de datos postgres en funcionamiento y una conexión válida a un nodo de Substrate.
**Nota**: Se requiere una base de datos Mongo en funcionamiento y una conexión válida a un nodo de Substrate.
Opcionalmente, comente el servicio de back-end en el archivo docker-compose si desea ejecutar la imagen localmente.

## Ejecutar la imagen de Docker del servicio back-end
Expand Down Expand Up @@ -250,7 +229,7 @@ query {
```graphql
{
"data": {
"version": "v1.0.5"
"version": "v1.1.0"
}
}
```
Expand Down Expand Up @@ -394,7 +373,7 @@ query {
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 132
Expand Down Expand Up @@ -464,7 +443,7 @@ query {
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 132
Expand Down Expand Up @@ -526,7 +505,7 @@ query {
"signer": "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 4
Expand Down
53 changes: 16 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Ink! Explorer API

## **About the explorer**

Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains. It subscribes to blockchain and Ink modules events and store the information on its own PostgreSQL database. The backend exposes an API that can interact with the DB and run fast queries to get specific information in a short time.
Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains. It subscribes to blockchain and Ink modules events and store the information on its own database. The backend exposes an API that can interact with the DB and run fast queries to get specific information in a short time.

The idea of this project is to provide a tool that allows developers of Ink! explore and analyze the contracts found on the blockchain. This tool can be used to analyze the contracts found on Substrate based blockchains that are using Ink! modules. It can also be used to analyze contracts that are on a local blockchain.

Expand All @@ -40,7 +40,7 @@ pnpm i --frozen-lockfile

### Configure the environment variables

**Note**: The .env file has the configuration for GraphQL, the PostgreSQL database, Node and the RPC url of the Substrate Blockchain.
**Note**: The .env file has the configuration for GraphQL, the Mongo database, Node and the RPC url of the Substrate Blockchain.

```sh
cp .env.sample .env
Expand All @@ -67,10 +67,10 @@ GRAPHQL_INTROSPECTION=true
#### Database configurations

```sh
DATABASE_HOST=postgres
DATABASE_HOST=mongo
DATABASE_NAME=ink
DATABASE_USERNAME=root
DATABASE_PASSWORD=password
DATABASE_USERNAME=mongodb
DATABASE_PASSWORD=mongodb
DATABASE_RETRY_ATTEMPTS=5
DATABASE_RETRY_DELAY=3000
```
Expand All @@ -89,37 +89,16 @@ BLOCK_CONCURRENCY=1000

## **Starting the project (DEV)**

### Start a Postgres DB using docker (optional)
### Start a Mongo DB using docker (optional)

To start the project a **PostgreSQL DB** is needed. For that, the **dev-docker-compose.yaml** file already has an image set up ready to use.
Running this command it will also start a container for pgAdmin:
To start the project a **Mongo DB** is needed. For that, the **dev-docker-compose.yaml** file already has an image set up ready to use.
Running this command it will also start a container for Mongo Express:

```sh
docker-compose -f dev-docker-compose.yaml up -d
```

Once the service is running, pgAdmin can be accessed following the link that is shown in the terminal (In this case localhost:80).

![pgAdmin](/.images/pg_admin_up.png)

The credentials to access pgAdmin are (set in the dev-docker-compose file):

- PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
- PGADMIN_DEFAULT_PASSWORD: "admin"

Register a new server in pgAdmin and set the credentials for the PostgreSQL DB:

Right click on 'Servers' and select "Register" -> "Server"

![pgAdmin](/.images/pg_admin_select_server.png)

Set a name for the server (In this example "Docker")

![pgAdmin](/.images/pg_admin_server_name.png)

Set the credentials for the PostgreSQL DB (this can be found in the dev-docker-compose file):

![pgAdmin](/.images/pg_admin_connection.png)
Once the service is running, Mongo Express can be accessed following the link that is shown in the terminal (In this case localhost:8081).

### Start a local Substrate Node (optional)

Expand All @@ -143,17 +122,17 @@ pnpm start:dev
Runs the service in the development mode.
The service will reload if you make edits.

**Note**: A postgresDB up and running and a valid connection to a substrate node are required.
**Note**: A Mongo DB up and running and a valid connection to a substrate node are required.

## **Starting the project (PROD)**

To start the backend service, DB and pgAdmin containers run the following command:
To start the backend service, Mongo DB and Mongo Express containers run the following command:

```sh
docker-compose up -d
```

**Note**: A postgresDB up and running and a valid connection to a substrate node are required.
**Note**: A Mongo DB up and running and a valid connection to a substrate node are required.
Optionally comment the backend service in the docker-compose file if you want to run the image locally.

## Running the Back-end service Docker image
Expand Down Expand Up @@ -250,7 +229,7 @@ query {
```graphql
{
"data": {
"version": "v1.0.5"
"version": "v1.1.0"
}
}
```
Expand Down Expand Up @@ -394,7 +373,7 @@ query {
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 132
Expand Down Expand Up @@ -464,7 +443,7 @@ query {
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 132
Expand Down Expand Up @@ -526,7 +505,7 @@ query {
"signer": "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
"ss58": "42",
"timestamp": 1666888006111,
"tip": 0,
"tip": "0",
"tokens": "Unit",
"type": 4,
"version": 4
Expand Down
35 changes: 19 additions & 16 deletions dev-docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
version: '3.7'
services:
postgres:
image: postgres:14.4
mongo:
image: mongo:latest
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB_DATABASE=ink
- MONGO_INITDB_USER=mongodb
- MONGO_INITDB_PWD=mongodb
ports:
- '27017:27017'
volumes:
- ./initdb.d/:/docker-entrypoint-initdb.d/
mongo-express:
image: mongo-express
restart: always
ports:
- 5432:5432
- 8081:8081
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=password
- POSTGRES_DB=ink
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017
substrate:
image: blockcoders/substrate-contracts-node
restart: on-failure
ports:
- 9944:9944
command: '--dev --ws-external'
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
PGADMIN_DEFAULT_PASSWORD: "admin"
ports:
- 80:80
depends_on:
- postgres
command: '--dev --ws-external'
43 changes: 24 additions & 19 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
#image: blockcoders/ink-substrate-explorer-api:latest
restart: on-failure
depends_on:
- postgres
- mongo
build:
context: .
# dockerfile: dev.Dockerfile
Expand All @@ -27,29 +27,34 @@ services:
ink-explorer-network:
aliases:
- "backend"
postgres:
image: postgres:14.4
restart: always
ports:
- 5432:5432
mongo:
image: mongo:latest
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=password
- POSTGRES_DB=ink
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB_DATABASE=ink
- MONGO_INITDB_USER=mongodb
- MONGO_INITDB_PWD=mongodb
ports:
- '27017:27017'
volumes:
- ./initdb.d/:/docker-entrypoint-initdb.d/
networks:
ink-explorer-network:
aliases:
- "postgres"
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
PGADMIN_DEFAULT_PASSWORD: "admin"
ports:
- 80:80
- "mongo"
mongo-express:
image: mongo-express
restart: always
depends_on:
- postgres
- mongo
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017
networks:
ink-explorer-network:
aliases:
- "pgadmin"
- "mongo-express"
Loading