Skip to content

Commit

Permalink
Merge pull request #149 from protofire/hotfix/fixSDKBug
Browse files Browse the repository at this point in the history
(Hotfix) Updates livepeerSDK version
  • Loading branch information
Mariano Aguero committed Nov 26, 2019
2 parents ca89543 + 22a68cf commit 699b2f6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 48 deletions.
77 changes: 47 additions & 30 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"livepeer"
],
"dependencies": {
"@livepeer/sdk": "^1.0.0-alpha.6",
"@livepeer/sdk": "^1.0.0-alpha.7",
"@sendgrid/mail": "^6.3.1",
"apollo-boost": "^0.4.2",
"apollo-cache-inmemory": "^1.6.2",
Expand Down
8 changes: 6 additions & 2 deletions server/helpers/sdk/delegate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const LivepeerSDK = require('@livepeer/sdk')

const getLivepeerSDKInstance = () =>{
return LivepeerSDK.default({gas: 2.1 * 1000000})
}

const getLivepeerDelegates = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getTranscoders()
}

const getLivepeerDelegateAccount = async address => {
if (!address) {
return null
}
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getTranscoder(address)
}

Expand Down
8 changes: 5 additions & 3 deletions server/helpers/sdk/delegator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let rpcInstance = null

const getLivepeerRpc = async () => {
if (!rpcInstance) {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await LivepeerSDK.default({gas: 2.1 * 1000000})
rpcInstance = rpc
// Sets an interval that will reset the cached values periodically
setInterval(() => {
Expand All @@ -29,15 +29,17 @@ const getLivepeerDelegatorTokenBalance = async address => {
if (!address) {
return null
}
const { rpc } = await LivepeerSDK.default()

const rpc = await getLivepeerRpc()
return await rpc.getTokenBalance(address)
}

const getLivepeerDelegatorStake = async address => {
if (!address) {
return null
}
const { rpc } = await LivepeerSDK.default()

const rpc = await getLivepeerRpc()
const summary = await rpc.getDelegator(address)
console.log(`Calculate summary for address ${address}`)
return getTotalStakeFromSummary(summary)
Expand Down
28 changes: 16 additions & 12 deletions server/helpers/sdk/protocol.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
const LivepeerSDK = require('@livepeer/sdk')

const getLivepeerSDKInstance = () =>{
return LivepeerSDK.default({gas: 2.1 * 1000000})
}

const getLivepeerCurrentRound = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getCurrentRound()
}

const getLivepeerLastInitializedRound = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getLastInitializedRound()
}

const getLivepeerCurrentRoundInfo = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getCurrentRoundInfo()
}

const getLivepeerRoundLength = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getRoundLength()
}

const getLivepeerRoundsPerYear = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getRoundsPerYear()
}
const getTokenTotalSupply = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return rpc.getTokenTotalSupply()
}

// Returns the inflation of the current round, the value should be divided by 1.000.000 in order to make it a ratio
const getInflationRate = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getInflation()
}

// Returns the change of inflation for the next round, the value should be divided by 1.000.000 in order to make it a ratio
const getInflationChange = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getInflationChange()
}

// Returns the targetBondingRate, the value should be divided by 1.000.000 in order to make it a ratio
const getTargetBondingRate = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getTargetBondingRate()
}

// Returns the total amount of tokens bonded in the protocol
const getTotalBonded = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getTotalBonded()
}

const getLivepeerDefaultConstants = async () => {
const { constants } = await LivepeerSDK.default()
const { constants } = await getLivepeerSDKInstance()
const { Bonded, Pending, Unbonded, Unbonding } = constants.DELEGATOR_STATUS
return {
DELEGATOR_STATUS: {
Expand All @@ -71,7 +75,7 @@ const getLivepeerDefaultConstants = async () => {
}

const getLivepeerLatestBlock = async () => {
const { rpc } = await LivepeerSDK.default()
const { rpc } = await getLivepeerSDKInstance()
return await rpc.getBlock('latest')
}

Expand Down

0 comments on commit 699b2f6

Please sign in to comment.