diff --git a/backend/src/models/Round.js b/backend/src/models/Round.js new file mode 100644 index 0000000..2bd3aa6 --- /dev/null +++ b/backend/src/models/Round.js @@ -0,0 +1,55 @@ +import mongoose from 'mongoose'; + +const RoundSchema = new mongoose.Schema({ + number: { + type: Number, + required: true + }, + lengthBlocks: { + type: Number, + required: true + }, + startBlock: { + type: Number, + required: true + }, + endBlock: { + type: Number, + required: true + }, + mintableTokens: { + type: Number, + required: true + }, + volumeEth: { + type: Number, + required: true + }, + volumeUsd: { + type: Number, + required: true + }, + totalActiveStake: { + type: Number, + required: true + }, + totalSupply: { + type: Number, + required: true + }, + participationRate: { + type: Number, + required: true + }, + movedStake: { + type: Number, + required: true + }, + newStake: { + type: Number, + required: true + } +}, { timestamps: false }); + +const Round = mongoose.model('RoundSchema', RoundSchema); +export default Round; \ No newline at end of file diff --git a/backend/src/models/block.js b/backend/src/models/block.js index ef843fc..8e728d3 100644 --- a/backend/src/models/block.js +++ b/backend/src/models/block.js @@ -8,10 +8,6 @@ const BlockSchema = new mongoose.Schema({ blockTime: { type: Number, required: true - }, - blockRound: { - type: Number, - required: false } }, { timestamps: false }); diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js index 3043611..a10979c 100644 --- a/backend/src/routes/livepeer.js +++ b/backend/src/routes/livepeer.js @@ -1259,6 +1259,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed reward events and cache them @@ -1268,6 +1269,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed claim events and cache them @@ -1280,6 +1282,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed withdraw fees events and cache them @@ -1289,6 +1292,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed withdraw stake events and cache them @@ -1299,6 +1303,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed transfer winning ticket events and cache them @@ -1309,6 +1314,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed redeem winning ticket events and cache them @@ -1318,6 +1324,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed orchestrator activation events and cache them @@ -1328,6 +1335,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed unbond events and cache them @@ -1339,6 +1347,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed stake events and cache them @@ -1350,6 +1359,7 @@ const initSync = async function () { transactionHash: 1, blockNumber: 1, blockTime: 1, + blockRound: 1, _id: 0 }); // Get all parsed monthly stats and cache them @@ -2632,6 +2642,72 @@ apiRouter.get("/getAllOrchScores", async (req, res) => { } }); +/* + +BLOCKS - LIVEPEER ROUNDS +Gets livepeer round number for a given block number +Gets entire round details if the round does not exist yet +Saves entire round details as separate data point as well +Mutates roundCache to contain the new round +Mutates the Event in the database to contain the round number + +*/ + +let roundCache = []; + +const mutateRoundToDB = async function (scoreObj) { + // Immediately mutate new object + const doc = await MonthlyStat.findOneAndUpdate({ + year: year, + month: month + }, { + testScores: scoreObj + }, { + upsert: true, + new: true, + setDefaultsOnInsert: true + }); + // Then find and mutate all Event objects which fall in this round +} + +apiRouter.post("/getRoundAtBlock", async (req, res) => { + try { + const { blockNumber } = req.body; + if (blockNumber) { + // Since months get counted starting at 0 + const now = new Date().getTime(); + let wasInCache = false; + // See if it is cached + for (const thisAddr of orchScoreCache) { + if (thisAddr.year === year && thisAddr.month === month) { + // Check timeout + if (now - thisAddr.timestamp < 360000) { + res.send(thisAddr); + return; + } + wasInCache = true; + } + } + // Check DB + // Get from thegraph + console.log("Getting new Orchestrator scores for " + year + "-" + month + " @ " + url); + // Save to DB + mutateRoundToDB(); + } + } catch (err) { + console.log(err); + res.status(400).send(err); + } +}); +// Returns entire orch score mapping cache +apiRouter.get("/getAllRounds", async (req, res) => { + try { + res.send(roundCache); + } catch (err) { + res.status(400).send(err); + } +}); + export default apiRouter; \ No newline at end of file diff --git a/src/components/MonthlyGraphs.js b/src/components/MonthlyGraphs.js index 4f322fe..430d665 100644 --- a/src/components/MonthlyGraphs.js +++ b/src/components/MonthlyGraphs.js @@ -253,11 +253,6 @@ const MonthlyGraphs = (obj) => { }); } - console.log("+1 for tickets"); - console.log(obj.data.winningTicketsSent); - console.log(obj.data.winningTicketsReceivedSum); - console.log(pieList); - totalGraphs++; broadcasterObj =
diff --git a/src/components/OrchDelegatorViewer.js b/src/components/OrchDelegatorViewer.js index abfd566..a8fbbf1 100644 --- a/src/components/OrchDelegatorViewer.js +++ b/src/components/OrchDelegatorViewer.js @@ -19,7 +19,7 @@ const OrchDelegatorViewer = (obj) => { // Find current O with most ticket wins in Eth while (ticketIdx2 >= 0) { const currentOrch = tmpCopy[ticketIdx2]; - let thisVal = currentOrch.bondedAmount; + let thisVal = parseFloat(currentOrch.bondedAmount); if (thisVal > largestValue) { largestIdx = ticketIdx2; diff --git a/src/components/eventViewer.js b/src/components/eventViewer.js index 1ecfa76..3481e20 100644 --- a/src/components/eventViewer.js +++ b/src/components/eventViewer.js @@ -1,8 +1,9 @@ import React, { useState, useRef } from "react"; import EventButton from "./eventButton"; import ScrollContainer from 'react-indiana-drag-scroll'; -import { Pagination } from "@mantine/core"; +import { Pagination, Title } from "@mantine/core"; import Filter from './filterComponent'; +import { Dialog, Stack, Button, Group } from '@mantine/core'; const thresholdStaking = 0.001; const thresholdFees = 0.00009; @@ -444,19 +445,31 @@ const EventViewer = (obj) => { let filterBit; if (obj.showFilter) { filterBit = -
-
- Showing {hidden + unfiltered} out of {limitShown} results -
- -
+ obj.setShowFilter(false)} + size="xl" + shadow="xl" + position={{ bottom: 20, left: 20 }} + radius="md" + styles={{ + root: { backgroundColor: 'rgba(214, 214, 214, 0.90)' }, + closeButton: {}, + }} + > + + Showing {hidden + unfiltered} out of {limitShown} results + + + } return (
{filterBit}
-
+
diff --git a/src/pages/livepeer.js b/src/pages/livepeer.js index 3d01bfb..8e8f918 100644 --- a/src/pages/livepeer.js +++ b/src/pages/livepeer.js @@ -6,6 +6,7 @@ import { getOrchestratorInfo, clearOrchestrator } from "../actions/livepeer"; import EventViewer from "../components/eventViewer"; import Orchestrator from "../components/orchestratorViewer"; import ContractPrices from '../components/ContractPrices'; +import { Dialog } from '@mantine/core'; // Shows the EventViewer and other Livepeer related info const defaultMaxShown = 50; @@ -19,6 +20,7 @@ const Livepeer = (obj) => { const livepeer = useSelector((state) => state.livepeerstate); const [redirectToHome, setRedirectToHome] = useState(false); const [showFilter, setShowFilter] = useState(false); + const [opened, setOpened] = useState(false); const [showSidebar, setShowSidebar] = useState(true); console.log("Rendering Livepeer"); @@ -44,7 +46,7 @@ const Livepeer = (obj) => { } let sidebar; - if (showSidebar) { + if (showSidebar && false) { sidebar =
@@ -82,7 +84,7 @@ const Livepeer = (obj) => { }}>

✖️ Clear

-

Sidebar

+

Detail

setShowSidebar(!showSidebar)}>
{showSidebar ? "Show" : "Hide"} @@ -97,10 +99,37 @@ const Livepeer = (obj) => {
+ setShowSidebar(false)} + size="xl" + shadow="xl" + radius="md" + styles={{ + root: { backgroundColor: 'rgba(214, 214, 214, 0.90)' }, + closeButton: { }, + }} + > +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
{sidebar}
{ unbondEvents={livepeer.unbondEvents} stakeEvents={livepeer.stakeEvents} monthlyStats={livepeer.monthlyStats} - /> + />