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

DAO-471: New Instance for DAO #146

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .env → .env.dao
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ NODE_URL=https://public-node.testnet.rsk.co
NODE_MAINNET_URL=https://public-node.rsk.co
CYPHER_ESTIMATE_FEE_URL=https://api.blockcypher.com/v1/btc/test3
CYPHER_ESTIMATE_FEE_MAINNET_URL=https://api.blockcypher.com/v1/btc/main
# API_URL=https://rootstock-testnet.blockscout.com/api
API_URL=https://rootstock-testnet.blockscout.com/api
API_MAINNET_URL=https://rootstock.blockscout.com/api
10 changes: 10 additions & 0 deletions .env.wallet
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
COIN_MARKET_CAP_KEY=
DEFAULT_CONVERT_FIAT=USD
BLOCKBOOK_URL=http://ip-10-10-130-64.ec2.internal:19130
BLOCKBOOK_MAINNET_URL=http://ip-10-10-130-76.ec2.internal:9130
NODE_URL=https://public-node.testnet.rsk.co
NODE_MAINNET_URL=https://public-node.rsk.co
CYPHER_ESTIMATE_FEE_URL=https://api.blockcypher.com/v1/btc/test3
CYPHER_ESTIMATE_FEE_MAINNET_URL=https://api.blockcypher.com/v1/btc/main
API_URL=https://be.explorer.testnet.rootstock.io/api
API_MAINNET_URL=https://be.explorer.rootstock.io/api
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ node_modules/

# others
.vscode
.env*
.DS_Store
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16
FROM node:18-slim

WORKDIR /app

Expand All @@ -9,7 +9,7 @@ RUN npm i

COPY ./src ./src
COPY ./tsconfig.json ./
COPY ./.env ./
COPY ./.env.* ./

RUN npm run build

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ npm run start:prod
We provide two different indexer integrations to get balances, transactions, events:
- RSKExplorerAPI(Default)
- BlockscoutAPI
You should only replace the RSKExplorerAPI class in src/index.ts and set blockscout url in .env
To use RSKExplorerAPI, you should set profile environment variable into PROFILE=wallet
To use BlockscoutAPI, you should set profile environment variable into PROFILE=dao
3 changes: 2 additions & 1 deletion src/controller/httpsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class HttpsAPI {

const whilelist = ['https://dapp.testnet.dao.rif.technology',
'https://dapp.mainnet.dao.rif.technology',
'https://rif-wallet-services.testnet.rifcomputing.net']
'https://rif-wallet-services.testnet.rifcomputing.net',
'https://dao-backend.testnet.rifcomputing.net']
this.app.use(cors({
origin: (origin, callback) => {
if (!origin || whilelist.indexOf(origin) !== -1) {
Expand Down
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dotenv/config'
import dotenv from 'dotenv'
import express from 'express'
import axios from 'axios'
import http from 'http'
Expand All @@ -14,24 +14,40 @@ import BitcoinCore from './service/bitcoin/BitcoinCore'
import { ethers } from 'ethers'
import { AddressService } from './service/address/AddressService'
import { RSKExplorerAPI } from './rskExplorerApi'
import { BlockscoutAPI } from './blockscoutApi'

async function main () {
const profile = process.env.PROFILE || 'wallet'

dotenv.config({
path: `.env.${profile}`
})

const createInstance = (apiUrl: string, chainId: number, _axios: typeof axios, id: string) => {
switch (profile) {
case 'wallet':
return new RSKExplorerAPI(apiUrl, chainId, _axios, id)
case 'dao':
return new BlockscoutAPI(apiUrl, chainId, _axios, id)
default:
throw new Error(`Unknown environment: ${profile}`)
}
}

const environment = {
// TODO: remove these defaults
NETWORKS: [
{
ID: '31',
API_URL: (process.env.API_URL as string) ||
'https://be.explorer.testnet.rootstock.io/api',
API_URL: process.env.API_URL as string,
CHAIN_ID: parseInt(process.env.CHAIN_ID as string) || 31,
BLOCKBOOK_URL: process.env.BLOCKBOOK_URL,
NODE_URL: process.env.NODE_URL,
CYPHER_ESTIMATE_FEE_URL: process.env.CYPHER_ESTIMATE_FEE_URL
},
{
ID: '30',
API_URL: (process.env.API_MAINNET_URL as string) ||
'https://be.explorer.rootstock.io/api',
API_URL: (process.env.API_MAINNET_URL as string),
CHAIN_ID: parseInt(process.env.CHAIN_MAINNET_ID as string) || 30,
BLOCKBOOK_URL: process.env.BLOCKBOOK_MAINNET_URL,
NODE_URL: process.env.NODE_MAINNET_URL,
Expand All @@ -51,8 +67,7 @@ async function main () {
const bitcoinMapping: BitcoinDatasource = {}
const nodeProvider: RSKNodeProvider = {}
environment.NETWORKS.forEach(network => {
dataSourceMapping[network.ID] = new RSKExplorerAPI(network.API_URL, network.CHAIN_ID, axios, network.ID)
// dataSourceMapping[network.ID] = new BlockscoutAPI(network.API_URL, network.CHAIN_ID, axios, network.ID)
dataSourceMapping[network.ID] = createInstance(network.API_URL, network.CHAIN_ID, axios, network.ID)
bitcoinMapping[network.ID] = new BitcoinCore({
BLOCKBOOK_URL: network.BLOCKBOOK_URL,
CYPHER_ESTIMATE_FEE_URL: network.CYPHER_ESTIMATE_FEE_URL
Expand Down
Loading