Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Sep 29, 2022
2 parents 33c3ccd + f1de21a commit 715cbf2
Show file tree
Hide file tree
Showing 35 changed files with 350 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .env.jungle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.lacchain
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_STATS_INTERVAL=60
Expand Down
2 changes: 1 addition & 1 deletion .env.libre
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.libretestnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_URL=http://hasura:8080/v1/graphql
HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_EOS_EXCHANGE_RATE_API=
Expand Down
2 changes: 1 addition & 1 deletion .env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=0
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.proton
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.protontestnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.telos
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_EOS_EXCHANGE_RATE_API=https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=usd
Expand Down
4 changes: 2 additions & 2 deletions .env.telostestnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=telos
HAPI_EOS_API_ENDPOINT=testnet.telos.caleos.io:9879
HAPI_EOS_API_ENDPOINT=testnet.telos.caleos.io
HAPI_EOS_API_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
HAPI_EOS_BASE_ACCOUNT=eosmechatero
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
Expand Down Expand Up @@ -71,7 +71,7 @@ REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
REACT_APP_EOS_API_NETWORK_NAME=telos-testnet
REACT_APP_EOS_API_NETWORK_LABEL=Telos Testnet
REACT_APP_EOS_API_NETWORK_LOGO=https://eosio.online/images/telos.jpg
REACT_APP_EOS_API_HOST=testnet.telos.caleos.io:9879
REACT_APP_EOS_API_HOST=testnet.telos.caleos.io
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
Expand Down
2 changes: 1 addition & 1 deletion .env.ultratestnet
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .env.waxtestnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCERS_INTERVAL=14400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-jungle-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
HAPI_SERVER_PORT: 9090
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: 86400
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: 1
HAPI_SYNC_PRODUCER_CPU_INTERVAL: 6
HAPI_SYNC_EXCHANGE_RATE: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-lacchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_SERVER_PORT: '9090'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-libre-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-libre.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-proton-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-proton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-telos-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'telos-testnet'
REACT_APP_EOS_API_NETWORK_LABEL: 'Telos Testnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://eosio.online/images/telos.jpg'
REACT_APP_EOS_API_HOST: 'testnet.telos.caleos.io:9879'
REACT_APP_EOS_API_HOST: 'testnet.telos.caleos.io'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f'
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_ENDPOINT: testnet.telos.caleos.io:9879
HAPI_EOS_API_ENDPOINT: testnet.telos.caleos.io
HAPI_EOS_API_CHAIN_ID: 1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-telos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-ultra-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-wax-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-wax.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HAPI_SERVER_PORT: '9090'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_DATABASE_URL: ${{ secrets.HAPI_DATABASE_URL }}
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCERS_INTERVAL: '14400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '1'
HAPI_SYNC_SCHEDULE_HISTORY_INTERVAL: 86400
Expand Down
2 changes: 1 addition & 1 deletion hapi/src/config/workers.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
syncProducersInterval: parseInt(
process.env.HAPI_SYNC_PRODUCERS_INTERVAL || 86400
process.env.HAPI_SYNC_PRODUCERS_INTERVAL || 14400
),
syncProducerInfoInterval: parseInt(
process.env.HAPI_SYNC_PRODUCER_INFO_INTERVAL || 1
Expand Down
51 changes: 26 additions & 25 deletions hapi/src/services/eosio.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ const getProducers = async () => {

producers = await Promise.all(
producers.map(async (producer, index) => {
const bpJson = await getBPJson(producer)
const producerUrl = getProducerUrl(producer)
const chains = await getChains(producerUrl)
const chainUrl = chains[eosConfig.chainId] || '/bp.json'
const bpJson = await getBPJson(producerUrl, chainUrl)
const healthStatus = getProducerHealthStatus(bpJson)
const nodes = await getNodes(bpJson)
const endpoints = producerUtil.getEndpoints(bpJson.nodes)

let nodes = []
let endpoints = { api: [], ssl: [], p2p: [] }

if (chains[eosConfig.chainId]) {
nodes = await getNodes(bpJson)
endpoints = producerUtil.getEndpoints(bpJson.nodes)
}

return {
endpoints,
Expand Down Expand Up @@ -149,54 +158,46 @@ const getExpectedRewards = async (producers, totalVotes) => {
)
}

const getBPJson = async (producer) => {
const bpJsonUrl = await getBPJsonUrl(producer)
const getBPJson = async (producerUrl, chainUrl) => {
const bpJsonUrl = `${producerUrl}/${chainUrl}`.replace(
/(?<=:\/\/.*)((\/\/))/,
'/'
)
let bpJson = {}

try {
const { data: _bpJson } = await axiosUtil.instance.get(bpJsonUrl)
bpJson = _bpJson || bpJson

if (typeof bpJson !== 'object') {
bpJson = {}
}
bpJson = !!_bpJson && typeof _bpJson === 'object' ? _bpJson : bpJson
} catch (error) {}

return bpJson
}

const getBPJsonUrl = async (producer = {}) => {
const getProducerUrl = (producer) => {
let producerUrl = producer.url || ''

if (!producerUrl.startsWith('http')) {
producerUrl = `http://${producerUrl}`
}

if (producerUrl === 'http://infinitystones.io') {
producerUrl = 'https://infinitystones.io'
}

if (producer.owner === 'eosauthority') {
producerUrl =
'https://ipfs.edenia.cloud/ipfs/QmVDRzUbnJLLM27nBw4FPWveaZ4ukHXAMZRzkbRiTZGdnH'

return producerUrl
}
return producerUrl
}

const getChains = async (producerUrl) => {
const chainsUrl = `${producerUrl}/chains.json`.replace(
/(?<=:\/\/.*)((\/\/))/,
'/'
)
let chainUrl = '/bp.json'

try {
const {
data: { chains }
} = await axiosUtil.instance.get(chainsUrl)
chainUrl = chains[eosConfig.chainId] || chainUrl
} catch (error) {}

return `${producerUrl}/${chainUrl}`.replace(/(?<=:\/\/.*)((\/\/))/, '/')
return chains ?? {}
} catch (error) {
return {}
}
}

const getProducerHealthStatus = (bpJson) => {
Expand Down
Loading

0 comments on commit 715cbf2

Please sign in to comment.