Skip to content

Commit

Permalink
Merge e4f2cbb into 0241e23
Browse files Browse the repository at this point in the history
  • Loading branch information
fersirni committed Dec 8, 2022
2 parents 0241e23 + e4f2cbb commit 44406cb
Show file tree
Hide file tree
Showing 22 changed files with 1,415 additions and 316 deletions.
41 changes: 22 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,32 @@ 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"
- "mongo"
mongo-express:
image: mongo-express
restart: always
ports:
- 80:80
depends_on:
- postgres
- 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"
15 changes: 15 additions & 0 deletions initdb.d/mongo-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

mongosh <<EOF
use $MONGO_INITDB_DATABASE
db.createUser({
user: '$MONGO_INITDB_USER',
pwd: '$MONGO_INITDB_PWD',
roles: [{
role: 'readWrite',
db: '$MONGO_INITDB_DATABASE'
}]
})
EOF
10 changes: 5 additions & 5 deletions mocks/transactions-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const mockTransaction = {
'0xdcd2f242d04cf19bf4695606a4244da9c7ab1d7a71153bcc3010909294dcb633e14841e833f35de113f8400b9687f10b93a27d3940926ba434318a7fc639f986',
signer: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
nonce: 37,
tip: 0,
tip: '0',
timestamp: 1600000000000,
createdDate: '2022-08-25 23:42:49.006343',
}
Expand All @@ -25,7 +25,7 @@ export const mockTransactions = [
'0xdcd2f242d04cf19bf4695606a4244da9c7ab1d7a71153bcc3010909294dcb633e14841e833f35de113f8400b9687f10b93a27d3940926ba434318a7fc639f986',
signer: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
nonce: 33,
tip: 0,
tip: '0',
createdDate: '2022-08-25 22:49:21.987641',
},
{
Expand All @@ -37,7 +37,7 @@ export const mockTransactions = [
'0x4eb9be0d2604225259ca3a0f183d424122f0fc6e2694e5d2f161f1c82b14fd5079ca525f9d89b1dbbfce666cbcf4ee843787f07c15993a26cb87ca24573bc087',
signer: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
nonce: 32,
tip: 0,
tip: '0',
createdDate: '2022-08-25 22:49:21.96569',
},
]
Expand Down Expand Up @@ -105,7 +105,7 @@ mockTransaction1.nonce = 0
mockTransaction1.signature =
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
mockTransaction1.signer = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'
mockTransaction1.tip = 0
mockTransaction1.tip = '0'
mockTransaction1.method = 'set'
mockTransaction1.section = 'timestamp'

Expand All @@ -116,7 +116,7 @@ mockTransaction2.nonce = 4
mockTransaction2.signature =
'0x984c98e3d74fcc35ddc5397282d282dcfda496ae95cb98f4e7d6d22125ec1e7cf03dc3f6fab3add1763bec4b8ee01346b198804b4faaaa1b88d37c5dbc9ca98b'
mockTransaction2.signer = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
mockTransaction2.tip = 0
mockTransaction2.tip = '0'
mockTransaction2.method = 'call'
mockTransaction2.section = 'timestamp'

Expand Down
45 changes: 45 additions & 0 deletions mongo-indexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'dotenv/config'
import mongoose from 'mongoose'

const host = process.env.DATABASE_HOST
const port = process.env.DATABASE_PORT
const username = process.env.DATABASE_USERNAME
const password = process.env.DATABASE_PASSWORD
const database = process.env.DATABASE_NAME

export async function main() {
const con = await mongoose.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`)

// block indexes
const blocks = con.connection.collection('blocks')
await blocks.createIndex({ timestamp: -1 })
await blocks.createIndex({ timestamp: 1 })

await blocks.createIndex({ number: -1 })
await blocks.createIndex({ number: 1 })

// transactions indexes
const transactions = con.connection.collection('transactions')
await transactions.createIndex({ timestamp: -1 })
await transactions.createIndex({ timestamp: 1 })
await transactions.createIndex({ blockHash: -1 })
await transactions.createIndex({ blockHash: 1 })

// events indexes
const events = con.connection.collection('events')
await events.createIndex({ timestamp: -1 })
await events.createIndex({ timestamp: 1 })
await events.createIndex({ contract: -1 })
await events.createIndex({ contract: 1 })
await events.createIndex({ transactionHash: -1 })
await events.createIndex({ transactionHash: 1 })

console.log('all indexes added')
}

// main()
// .catch((err) => console.log(err))
// .then(() => {
// console.log('all index added')
// process.exit()
// })
4 changes: 2 additions & 2 deletions ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dotenv/config'
import { DataSource } from 'typeorm'

export const connectionSource = new DataSource({
type: 'postgres',
host: '127.0.0.1',
type: 'mongodb',
host: 'localhost',
port: Number(process.env.DATABASE_PORT),
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
Expand Down
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ink-substrate-explorer-api",
"version": "1.0.5",
"version": "1.0.6",
"description": "Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains.",
"author": "Blockcoders <engineering@blockcoders.io>",
"license": "MIT",
Expand Down Expand Up @@ -43,10 +43,11 @@
"typeorm:drop": "npm run typeorm schema:drop",
"typeorm:reset": "npm run typeorm:drop && npm run typeorm:sync",
"typeorm:migrate": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:generate -d ormconfig.ts -- -n",
"typeorm:create": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:create -d ormconfig.ts -- -n",
"typeorm:create": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:create -d ormconfig.ts",
"typeorm:run": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:run -d ormconfig.ts",
"typeorm:revert": "npm run typeorm migration:revert",
"check": "npm run lint && npm run test && npm run build"
"check": "npm run lint && npm run test && npm run build",
"mongo:indexes": "ts-node mongo-indexes"
},
"precommit": [
"lint:ci",
Expand Down Expand Up @@ -93,13 +94,13 @@
"@nestjs/mapped-types": "^1.2.0",
"@nestjs/platform-fastify": "^8.4.7",
"@nestjs/typeorm": "^9.0.1",
"@polkadot/api": "9.9.1",
"@polkadot/api-augment": "9.9.1",
"@polkadot/api-contract": "9.9.1",
"@polkadot/types": "9.9.1",
"@polkadot/types-codec": "9.9.1",
"@polkadot/types-create": "9.9.1",
"@polkadot/util": "10.1.13",
"@polkadot/api": "9.10.1",
"@polkadot/api-augment": "9.10.1",
"@polkadot/api-contract": "9.10.1",
"@polkadot/types": "9.10.1",
"@polkadot/types-codec": "9.10.1",
"@polkadot/types-create": "9.10.1",
"@polkadot/util": "10.2.1",
"apollo-server-fastify": "^3.11.1",
"async-await-retry": "^2.0.0",
"class-transformer": "^0.5.1",
Expand All @@ -108,6 +109,8 @@
"fastify": "^3.29.3",
"graphql": "^16.6.0",
"graphql-type-json": "^0.3.2",
"mongodb": "^4.12.1",
"mongoose": "^6.8.0",
"nestjs-pino": "^3.1.1",
"p-queue": "^6.6.2",
"pg": "^8.8.0",
Expand Down
Loading

0 comments on commit 44406cb

Please sign in to comment.