Skip to content

Commit

Permalink
Production Release (#996)
Browse files Browse the repository at this point in the history
* fix(jungle): migrate dev environment to jungle 4 (#988)

* fix(jungle): migrate dev environment to jungle 4

* fix(jungle): migrate dev environment to jungle 4

* Improve(hapi): changed hapi server routes structure (#992)

* fix(enviroment): change env value

* fix(hasura): add permissions tables

* fix(comments): fix comments section

* fix(hyperion): fix codefactor issues

* fix(hyperion): fix codefactor issues

* fix(hasura): delete migration restriction

* fix(hyperion): fix updater flows

* improve(hapi): changed hapi server routes structure

* feat(hapi): created eosrate stats api endpoint (#993)

* fix(enviroment): change env value

* fix(hasura): add permissions tables

* fix(comments): fix comments section

* fix(hyperion): fix codefactor issues

* fix(hyperion): fix codefactor issues

* fix(hasura): delete migration restriction

* fix(hyperion): fix updater flows

* feat(hapi): created eosrate stats api endpoint

* fix(hapi): fix codefactor error

* fix(webapp): added validation on bp profile page (#995)

* fix(enviroment): change env value

* fix(hasura): add permissions tables

* fix(comments): fix comments section

* fix(hyperion): fix codefactor issues

* fix(hyperion): fix codefactor issues

* fix(hasura): delete migration restriction

* fix(hyperion): fix updater flows

* feat(hapi): created eosrate stats api endpoint

* fix(hapi): fix codefactor error

* fix(webapp): added validation on bp profile page

Co-authored-by: Angelo Castro Gamboa <[email protected]>
  • Loading branch information
xavier506 and AngeloCG97 authored Nov 28, 2022
1 parent 9f59bc4 commit 766cbba
Show file tree
Hide file tree
Showing 38 changed files with 916 additions and 486 deletions.
15 changes: 8 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ HAPI_POSTGRES_DB=eosrate
HAPI_POSTGRES_SCHEMA=public
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=0.0.0.0
HAPI_EOS_API_ENDPOINT=https://jungle3.cryptolions.io
HAPI_EOS_API_ENDPOINT=https://jungle.edenia.cloud
HAPI_VALID_USERS=[{"username": "username", "password": "password"}]
HAPI_EOS_CHAIN_ID=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906
HAPI_PROXY_CONTRACT=proxyaccount
HAPI_RATING_CONTRACT=rateproducer
HAPI_HYPERION_API=https://jungle3history.cryptolions.io
HAPI_HYPERION_API=http://jungle.eosusa.io
HAPI_HYPERION_START_AT=2022-03-01T00:00:00.000+00:00
HAPI_HASURA_URL=http://hasura:8080/v1/graphql
HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
Expand All @@ -34,16 +35,16 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090
# WEBAPP
REACT_APP_RATING_CONTRACT=rateproducer
REACT_APP_GRAPHQL_HTTP_URL=http://localhost:8080/v1/graphql
REACT_APP_API_URL=https://jungle3.cryptolions.io
REACT_APP_API_URL=https://jungle.edenia.cloud
REACT_APP_GRAPHQL_WS_URL=ws://localhost:8080/v1/graphql
REACT_APP_EOS_API_URL=https://jungle3.cryptolions.io
REACT_APP_EOS_API_HOST=jungle3.cryptolions.io
REACT_APP_EOS_API_URL=https://jungle.edenia.cloud
REACT_APP_EOS_API_HOST=jungle.edenia.cloud
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840
REACT_APP_EOS_CHAIN_ID=73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d
REACT_APP_BLOCK_EXPLORER=https://jungle3.bloks.io
REACT_APP_NETWORK_MONITOR_URL=https://jungle.eosio.online/
REACT_APP_VERSION=v1.4.21
REACT_APP_MAINNET_VERSION= v1.4.21
REACT_APP_EDEN_CONTRACT=genesisdeden
REACT_APP_EDEN_CONTRACT=genesis.eden
REACT_APP_UAL_APP_NAME=EOSRate
1 change: 1 addition & 0 deletions .github/workflows/push-master-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
# hapi
HAPI_SERVER_ADDRESS: 0.0.0.0
HAPI_SERVER_PORT: 9090
HAPI_VALID_USERS: ${{secrets.HAPI_VALID_USERS}}
HAPI_POSTGRES_USER: ${{ secrets.HAPI_POSTGRES_USER }}
HAPI_POSTGRES_PASSWORD: ${{ secrets.HAPI_POSTGRES_PASSWORD }}
HAPI_HASURA_URL: ${{ secrets.HAPI_HASURA_URL }}
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/push-staging-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ jobs:
REACT_APP_VERSION: ${{ github.ref }}
REACT_APP_RATING_CONTRACT: rateproducer
REACT_APP_MAINNET_VERSION: false
REACT_APP_EDEN_CONTRACT: genesisdeden
REACT_APP_EDEN_CONTRACT: genesis.eden
REACT_APP_GRAPHQL_HTTP_URL: https://graphql-jungle.eosrate.io/v1/graphql
REACT_APP_GRAPHQL_WS_URL: wss://graphql-jungle.eosrate.io/v1/graphql
REACT_APP_EOS_API_URL: https://jungle3.cryptolions.io
REACT_APP_EOS_API_HOST: jungle3.cryptolions.io
REACT_APP_EOS_API_URL: https://jungle.edenia.cloud
REACT_APP_EOS_API_HOST: jungle.edenia.cloud
REACT_APP_EOS_API_PORT: 443
REACT_APP_EOS_API_PROTOCOL: https
REACT_APP_EOS_CHAIN_ID: 2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840
REACT_APP_BLOCK_EXPLORER: https://jungle3.bloks.io
REACT_APP_EOS_CHAIN_ID: 73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d
REACT_APP_BLOCK_EXPLORER: https://local.bloks.io/?nodeUrl=https%3A%2F%2Fjungle4.api.eosnation.io&systemDomain=eosio&hyperionUrl=https%3A%2F%2Fjungle4.cryptolions.io
REACT_APP_NETWORK_MONITOR_URL: https://jungle.eosio.online/

- name: Build kubernetes files
Expand All @@ -77,6 +77,7 @@ jobs:
# hapi
HAPI_SERVER_ADDRESS: 0.0.0.0
HAPI_SERVER_PORT: 9090
HAPI_VALID_USERS: ${{secrets.HAPI_VALID_USERS}}
HAPI_POSTGRES_USER: ${{ secrets.HAPI_POSTGRES_USER }}
HAPI_POSTGRES_PASSWORD: ${{ secrets.HAPI_POSTGRES_PASSWORD }}
HAPI_HASURA_URL: ${{ secrets.HAPI_HASURA_URL }}
Expand All @@ -87,9 +88,9 @@ jobs:
HAPI_POSTGRES_HOST: postgres
HAPI_POSTGRES_PORT: 5432
HAPI_POSTGRES_SCHEMA: public
HAPI_EOS_API_ENDPOINT: https://jungle3.cryptolions.io
HAPI_EOS_CHAIN_ID: 2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840
HAPI_HYPERION_API: https://jungle3history.cryptolions.io
HAPI_EOS_API_ENDPOINT: https://jungle.edenia.cloud
HAPI_EOS_CHAIN_ID: 73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d
HAPI_HYPERION_API: http://jungle.eosusa.io
HAPI_HYPERION_START_AT: '2022-03-01T00:00:00.000+00:00'
# hasura
HASURA_GRAPHQL_DATABASE_URL: ${{ secrets.HASURA_GRAPHQL_DATABASE_URL }}
Expand Down
10 changes: 5 additions & 5 deletions contracts/rateproducer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ make -j

Add resources:
```bash
cleos -u https://jungle3.cryptolions.io system buyram rateproducer rateproducer "100 EOS"
cleos -u https://jungle.edenia.cloud system buyram rateproducer rateproducer "100 EOS"
```

Publish Contract:
```bash
cleos -u https://jungle3.cryptolions.io set contract rateproducer ./ -p rateproducer@active
cleos -u https://jungle.edenia.cloud set contract rateproducer ./ -p rateproducer@active
```

Push rating with all categories:
Expand All @@ -66,7 +66,7 @@ cleos -u hhttp://jungle2.cryptolions.io:80 push action rateproducer rate '{ "use

example 2:
```bash
cleos -u https://jungle3.cryptolions.io push action rateproducer rate '{ "user": "eoscrvoter11", "bp":"eoscrprodo51","transparency":8,"infrastructure":8,"trustiness":7,"development":6,"community":9 }' -p eoscrvoter11@active
cleos -u https://jungle.edenia.cloud push action rateproducer rate '{ "user": "eoscrvoter11", "bp":"eoscrprodo51","transparency":8,"infrastructure":8,"trustiness":7,"development":6,"community":9 }' -p eoscrvoter11@active
```

Push rating with partial categories:
Expand All @@ -76,12 +76,12 @@ cleos -u http://monitor.jungletestnet.io:8888 push action rateproducer rate '{ "

Get stats table:
```bash
cleos -u https://jungle3.cryptolions.io get table -l 50 rateproducer rateproducer stats
cleos -u https://jungle.edenia.cloud get table -l 50 rateproducer rateproducer stats
```

Get bp table:
```bash
cleos -u https://jungle3.cryptolions.io get table -l 50 rateproducer rateproducer ratings
cleos -u https://jungle.edenia.cloud get table -l 50 rateproducer rateproducer ratings
```

Clean data for a block producer:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
environment:
HAPI_SERVER_ADDRESS: "${HAPI_SERVER_ADDRESS}"
HAPI_SERVER_PORT: "${HAPI_SERVER_PORT}"
HAPI_VALID_USERS: "${HAPI_VALID_USERS}"
HAPI_POSTGRES_USER: "${HAPI_POSTGRES_USER}"
HAPI_POSTGRES_PASSWORD: "${HAPI_POSTGRES_PASSWORD}"
HAPI_POSTGRES_PORT: "${HAPI_POSTGRES_PORT}"
Expand Down
4 changes: 4 additions & 0 deletions hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
"author": "EOS Costa Rica",
"license": "MIT",
"dependencies": {
"@hapi/basic": "^7.0.0",
"@hapi/boom": "^10.0.0",
"@hapi/hapi": "^20.1.5",
"axios": "^0.26.1",
"bcrypt": "^5.1.0",
"eosjs": "^22.1.0",
"eosjs-api": "^7.0.4",
"graphql": "^16.3.0",
"graphql-request": "^4.1.0",
"joi": "^17.7.0",
"massive": "^6.9.1",
"moment": "^2.29.1",
"node-fetch": "^2.6.7",
Expand Down
79 changes: 28 additions & 51 deletions hapi/src/index.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,45 @@
'use strict'
const { HAPI_SERVER_PORT, HAPI_SERVER_ADDRESS } = process.env

const {
updateBpStatsUtil,
updateUserRatingUtil,
validateAccountNameUtil
} = require('./utils/')
const { HAPI_SERVER_PORT, HAPI_SERVER_ADDRESS, HAPI_VALID_USERS } = process.env

const Hapi = require('@hapi/hapi')
const Bcrypt = require('bcrypt')

const routes = require('./routes')
const { workerService } = require('./services')

const init = async () => {
const server = Hapi.server({
port: HAPI_SERVER_PORT,
host: HAPI_SERVER_ADDRESS
})
const validate = async (request, username, password) => {
if (!HAPI_VALID_USERS) return { credentials: null, isValid: false }

server.route({
method: 'GET',
path: '/',
handler: function () {
return '<h2>EOS Rate HTTP API service</h2>'
}
})
const users = JSON.parse(HAPI_VALID_USERS || '[]')
const user = users.find(user => user.username === username)

server.route({
method: 'POST',
path: '/ratebp',
handler: async req => {
try {
const {
payload: { input }
} = req
if (!user) {
return { credentials: null, isValid: false }
}

if (!input) throw new Error('Invalid ratebp Input')
const saltRounds = 10
const hashPassword = await Bcrypt.hash(user.password, saltRounds)
const isValid = await Bcrypt.compare(password, hashPassword)
const credentials = { id: users.indexOf(user), name: user.username }

const {
ratingInput: { user, producer, transaction, isEden }
} = input
const isValidAccountName = validateAccountNameUtil([
{ name: user, type: 'user account' },
{ name: producer, type: 'block producer' }
])
return { isValid, credentials }
}

if (!isValidAccountName.isValidAccountName)
throw new Error(isValidAccountName.message)
const init = async () => {
const server = Hapi.server({
port: HAPI_SERVER_PORT,
host: HAPI_SERVER_ADDRESS,
routes: {
cors: { origin: ['*'] }
},
debug: { request: ['handler'] }
})

const { edenResult, totalStats } = await updateBpStatsUtil(producer)
const result = await updateUserRatingUtil(
user,
producer,
transaction,
isEden
)
await server.register(require('@hapi/basic'))

return { resultEden: edenResult, totalStats, ...result }
} catch (error) {
console.error('ratebp', error)
server.auth.strategy('simple', 'basic', { validate })

return error
}
}
})
server.route(routes)

await server.start()
console.log(`🚀 Server ready at ${server.info.uri}`)
Expand Down
2 changes: 1 addition & 1 deletion hapi/src/libs/sync-bps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const request = require('request-promise')
const { massiveDB, chainConfig } = require('../config')

const HAPI_EOS_API_ENDPOINT =
process.env.HAPI_EOS_API_ENDPOINT || 'https://jungle3.cryptolions.io'
process.env.HAPI_EOS_API_ENDPOINT || 'https://jungle.edenia.cloud'

const getBlockProducersData = async () => {
const eos = EosApi({
Expand Down
39 changes: 39 additions & 0 deletions hapi/src/routes/get-rates-stats.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Boom = require('@hapi/boom')
const Joi = require('joi')

const { ratesStatsService } = require('../services')

module.exports = {
method: 'POST',
path: '/get-rates-stats',
handler: async ({ payload: { input } }) => {
try {
if (!input) throw new Error('Invalid get-rates-stats Input')

const whereCondition = input?.ratesStatsInput?.bps
? { _in: input?.ratesStatsInput?.bps }
: { _nin: [] }
const bpsStats = await ratesStatsService.getRatesStats({
where: { bp: whereCondition }
})

return { bpsStats }
} catch (error) {
console.error('get-rates-stats', error)

return Boom.badRequest(error.message)
}
},
options: {
validate: {
payload: Joi.object({
input: Joi.object({
ratesStatsInput: Joi.object({
bps: Joi.array().items(Joi.string().required()).optional()
}).required()
}).required()
}).options({ stripUnknown: true })
},
auth: 'simple'
}
}
10 changes: 10 additions & 0 deletions hapi/src/routes/healthz.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
method: 'GET',
path: '/healthz',
handler: () => {
return '<h2>EOS Rate HTTP API service</h2>'
},
options: {
auth: false
}
}
5 changes: 5 additions & 0 deletions hapi/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const healthzRoute = require('./healthz.route')
const ratebpRoute = require('./ratebp.route')
const getRatesStats = require('./get-rates-stats.route')

module.exports = [healthzRoute, ratebpRoute, getRatesStats]
58 changes: 58 additions & 0 deletions hapi/src/routes/ratebp.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const Boom = require('@hapi/boom')
const Joi = require('joi')

const {
updateBpStatsUtil,
updateUserRatingUtil,
validateAccountNameUtil
} = require('../utils')

module.exports = {
method: 'POST',
path: '/ratebp',
handler: async ({ payload: { input } }) => {
try {
if (!input) throw new Error('Invalid ratebp Input')

const {
ratingInput: { user, producer, transaction, isEden }
} = input
const isValidAccountName = validateAccountNameUtil([
{ name: user, type: 'user account' },
{ name: producer, type: 'block producer' }
])

if (!isValidAccountName.isValidAccountName)
throw new Error(isValidAccountName.message)

const { edenResult, totalStats } = await updateBpStatsUtil(producer)
const result = await updateUserRatingUtil(
user,
producer,
transaction,
isEden
)

return { resultEden: edenResult, totalStats, ...result }
} catch (error) {
console.error('ratebp', error)

return Boom.badRequest(error.message)
}
},
options: {
validate: {
payload: Joi.object({
input: Joi.object({
ratingInput: Joi.object({
user: Joi.string().required(),
isEden: Joi.boolean().required(),
producer: Joi.string().required(),
transaction: Joi.object().required()
}).required()
}).required()
}).options({ stripUnknown: true })
},
auth: false
}
}
25 changes: 25 additions & 0 deletions hapi/src/services/get-rates-stats.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { hasuraUtil } = require('../utils')

const getRatesStats = async ({ where }) => {
const query = `
query ($where: total_ratings_stats_bool_exp!) {
total_ratings_stats(where: $where) {
average
bp
community
development
infrastructure
ratings_cntr
transparency
trustiness
}
}
`
const data = await hasuraUtil.instance.request(query, { where })

return data?.total_ratings_stats || [{}]
}

module.exports = {
getRatesStats
}
Loading

0 comments on commit 766cbba

Please sign in to comment.