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

(Feature) Sdk graphql refactoring #42

Merged
merged 21 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
6 changes: 5 additions & 1 deletion config/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const PROTOCOL_DIVISION_BASE = 1000000
const TOKEN_DECIMALS_MULTIPLIER = 1000000000000000000
const CACHE_UPDATE_INTERVAL = 1000 * 60 * 60 * 2 // Updates every 2 hours

module.exports = {
PROTOCOL_DIVISION_BASE
PROTOCOL_DIVISION_BASE,
TOKEN_DECIMALS_MULTIPLIER,
CACHE_UPDATE_INTERVAL
}
139 changes: 127 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"main": "index.js",
"private": false,
"engines": {
"node": ">=8.10.0",
"node": ">=10.16.0",
"npm": ">=5.6.0",
"yarn": ">=1.5.1"
},
"scripts": {
"start": "nodemon index.js",
"start": "nodemon --harmony index.js",
"lint": "esw *.js server config --color",
"lint:watch": "npm run lint -- --watch",
"test": "NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js --timeout=1200000 --ui bdd --reporter spec --colors server",
"test": "NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js --timeout=1200000 --ui bdd --reporter spec --colors server --harmony --exit",
"test:watch": "npm run test -- --watch",
"test:coverage": "NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- test/*.test.js --timeout=1200000 --ui bdd --reporter spec --colors server",
"test:coverage": "NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- test/*.test.js --timeout=1200000 --ui bdd --reporter spec --colors server --exit",
"test:check-coverage": "npm run test:coverage && istanbul check-coverage",
"report-coverage": "coveralls < ./coverage/lcov.info"
},
Expand Down Expand Up @@ -65,6 +65,7 @@
"node-telegram-bot-api": "^0.30.0",
"nodemon": "^1.19.1",
"promise-retry": "^1.1.1",
"sinon": "^7.3.2",
"striptags": "^3.1.1",
"web3": "github:ethereum/web3.js",
"winston": "2.4.1"
Expand Down
16 changes: 8 additions & 8 deletions server/delegate/delegate.controller.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/**
* Activate subscriber.
* @returns {Subscriber}
* Handler for delegates
* @returns {Delegate}
*/

const { getDelegate } = require('../helpers/delegate')

const { MathBN, tokenAmountInUnits } = require('../helpers/utils')
const BN = require('bn.js')
const { getDelegateRewards, getDelegateTotalStake } = require('../helpers/graphql/queries/delegate')
const { getDelegateService } = require('../helpers/services/delegateService')

const getByAddress = async (req, res, next) => {
const { address } = req.params
const delegateService = getDelegateService()
try {
const result = await getDelegate(address)
const result = await delegateService.getDelegate(address)
res.json(result)
} catch (error) {
next(error)
}
}
const getROI = async (req, res, next) => {
const { address } = req.params
const delegateService = getDelegateService()
try {
const rewards = await getDelegateRewards(address)
const totalStake = await getDelegateTotalStake(address)
const rewards = await delegateService.getDelegateRewards(address)
const totalStake = await delegateService.getDelegateTotalStake(address)
let roi = null
if (rewards && totalStake) {
const totalReward = rewards.reduce((total, reward) => {
Expand Down
13 changes: 7 additions & 6 deletions server/earning/earning.model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { getProtocolService } = require('../helpers/services/protocolService')
const { getDelegatorService } = require('../helpers/services/delegatorService')

const Promise = require('bluebird')
const mongoose = require('mongoose')
const {
getLivepeerDelegatorAccount,
getLivepeerCurrentRoundInfo
} = require('../helpers/livepeerAPI')
const { MathBN } = require('../helpers/utils')
/**
* Earning Schema
Expand Down Expand Up @@ -64,9 +63,11 @@ EarningSchema.statics = {
*/
async save(subscriber) {
const { address, email } = subscriber
const delegatorService = getDelegatorService()
const protocolService = getProtocolService()
let [delegator, currentRoundInfo] = await Promise.all([
getLivepeerDelegatorAccount(address),
getLivepeerCurrentRoundInfo()
delegatorService.getDelegatorAccount(address),
protocolService.getCurrentRoundInfo()
])

const { lastClaimRound, pendingStake, bondedAmount } = delegator
Expand Down
Loading