mirror of
https://github.com/stronk-dev/LivepeerEvents.git
synced 2025-07-05 18:55:09 +02:00
Added endpoint to O subgraph
This commit is contained in:
parent
6b4dce94e8
commit
2c537b0f4c
@ -22,6 +22,7 @@
|
|||||||
"esm": "^3.2.20",
|
"esm": "^3.2.20",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-session": "^1.17.0",
|
"express-session": "^1.17.0",
|
||||||
|
"graphql-request": "^4.0.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"joi": "^14.3.1",
|
"joi": "^14.3.1",
|
||||||
"mongoose": "^5.12.3",
|
"mongoose": "^5.12.3",
|
||||||
|
@ -5,6 +5,8 @@ const apiRouter = express.Router();
|
|||||||
import {
|
import {
|
||||||
API_CMC, API_L1_HTTP, API_L2_HTTP, API_L2_WS
|
API_CMC, API_L1_HTTP, API_L2_HTTP, API_L2_WS
|
||||||
} from "../config";
|
} from "../config";
|
||||||
|
const https = require('https');
|
||||||
|
import { request, gql } from 'graphql-request';
|
||||||
|
|
||||||
// Get ETH price & LPT coin prices
|
// Get ETH price & LPT coin prices
|
||||||
const CoinMarketCap = require('coinmarketcap-api');
|
const CoinMarketCap = require('coinmarketcap-api');
|
||||||
@ -42,6 +44,54 @@ let claimTicketCostL2 = 0;
|
|||||||
let withdrawFeeCostL1 = 0;
|
let withdrawFeeCostL1 = 0;
|
||||||
let withdrawFeeCostL2 = 0;
|
let withdrawFeeCostL2 = 0;
|
||||||
|
|
||||||
|
// Update info from thegraph every 5 minutes
|
||||||
|
const timeoutTheGraph = 300000;
|
||||||
|
let theGraphGet = 0;
|
||||||
|
// Address of O info we are want to display
|
||||||
|
const orchQuery = gql`
|
||||||
|
{
|
||||||
|
transcoders(where: {id: "0x847791cbf03be716a7fe9dc8c9affe17bd49ae5e"}) {
|
||||||
|
activationRound
|
||||||
|
deactivationRound
|
||||||
|
active
|
||||||
|
lastRewardRound {
|
||||||
|
id
|
||||||
|
length
|
||||||
|
startBlock
|
||||||
|
endBlock
|
||||||
|
mintableTokens
|
||||||
|
volumeETH
|
||||||
|
volumeUSD
|
||||||
|
totalActiveStake
|
||||||
|
totalSupply
|
||||||
|
participationRate
|
||||||
|
movedStake
|
||||||
|
newStake
|
||||||
|
}
|
||||||
|
rewardCut
|
||||||
|
feeShare
|
||||||
|
pricePerSegment
|
||||||
|
pendingPricePerSegment
|
||||||
|
pendingFeeShare
|
||||||
|
pendingRewardCut
|
||||||
|
totalStake
|
||||||
|
totalVolumeETH
|
||||||
|
totalVolumeUSD
|
||||||
|
serviceURI
|
||||||
|
delegators {
|
||||||
|
id
|
||||||
|
bondedAmount
|
||||||
|
startRound
|
||||||
|
}
|
||||||
|
delegator {
|
||||||
|
id
|
||||||
|
bondedAmount
|
||||||
|
startRound
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
let orchestratorCache = {};
|
||||||
|
|
||||||
// Listen to smart contract emitters. Resync with DB every 5 minutes
|
// Listen to smart contract emitters. Resync with DB every 5 minutes
|
||||||
const timeoutEvents = 300000;
|
const timeoutEvents = 300000;
|
||||||
@ -221,7 +271,8 @@ apiRouter.get("/getEvents", async (req, res) => {
|
|||||||
transactionUrl: 1,
|
transactionUrl: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
data: 1,
|
data: 1,
|
||||||
_id: 0});
|
_id: 0
|
||||||
|
});
|
||||||
eventsGet = now;
|
eventsGet = now;
|
||||||
}
|
}
|
||||||
res.send(eventsCache);
|
res.send(eventsCache);
|
||||||
@ -230,4 +281,17 @@ apiRouter.get("/getEvents", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apiRouter.get("/getOrchestrator", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
// Update cmc once their data has expired
|
||||||
|
if (now - theGraphGet > timeoutTheGraph) {
|
||||||
|
orchestratorCache = JSON.stringify(await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", orchQuery));
|
||||||
|
}
|
||||||
|
res.send(orchestratorCache);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(400).send(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default apiRouter;
|
export default apiRouter;
|
Loading…
x
Reference in New Issue
Block a user