diff --git a/README.md b/README.md index 2ff6d52..d07433f 100644 --- a/README.md +++ b/README.md @@ -150,11 +150,13 @@ Set configuration variables - `API_L2_HTTP` should be edited to the HTTP url of a L2 ethereum node - `API_L2_WS` should be edited to the WS url of an Arbitrum mainnet Alchemy node - `CONF_DEFAULT_ORCH` should be edited to the public address of your own Orchestrator. This is the default Orchestrator the backend will return -- 'CONF_SIMPLE_MODE' if set to true, will disable live smart contract monitoring. Also disabled all MONGO related functionalities. Config flags 'API_L2_WS', 'MONGO_URI', 'MONGO_URI_DEV' and 'MONGO_URI_LOCAL' can be ignored if this flag is set to true. -- 'CONF_TIMEOUT_CMC' time in milliseconds of how long coinmarketcap data is kept in the cache before a new request is made. Recommended is around 5-6 minutes in order to stay below the default daily soft cap -- 'CONF_TIMEOUT_ALCHEMY' time in milliseconds of how long blockchain information, like gas prices, is being kept in the cache -- 'CONF_TIMEOUT_LIVEPEER' time in milliseconds of how long livepeer data, like orchestrator and delegator information, is being kept in the cache - +- `CONF_SIMPLE_MODE` if set to true, will disable live smart contract monitoring. Also disabled all MONGO related functionalities. Config flags `API_L2_WS`, `MONGO_URI`, `MONGO_URI_DEV` and `MONGO_URI_LOCAL` can be ignored if this flag is set to true. +- `CONF_TIMEOUT_CMC` time in milliseconds of how long coinmarketcap data is kept in the cache before a new request is made. Recommended is around 5-6 minutes in order to stay below the default daily soft cap +- `CONF_TIMEOUT_ALCHEMY` time in milliseconds of how long blockchain information, like gas prices, is being kept in the cache +- `CONF_TIMEOUT_LIVEPEER` time in milliseconds of how long livepeer data, like orchestrator and delegator information, is being kept in the cache +- `CONF_DISABLE_SYNC` set to true to disable syncing events and tickets at boot +- `CONF_DISABLE_DB` set to false to disable persistent storage of events and tickets into a mongodb database +- `CONF_DISABLE_CMC` set to false to disable coin quotes using CMC ## Developing Open the directory of your backend and run - `npm run dev` diff --git a/backend/src/config.js b/backend/src/config.js index e56b62b..a2bec61 100644 --- a/backend/src/config.js +++ b/backend/src/config.js @@ -18,5 +18,6 @@ export const { CONF_TIMEOUT_ALCHEMY = 2000, CONF_TIMEOUT_LIVEPEER = 60000, CONF_DISABLE_SYNC = false, - CONF_DISABLE_DB = false + CONF_DISABLE_DB = false, + CONF_DISABLE_CMC = false } = process.env; diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js index 7bf6894..0a329e5 100644 --- a/backend/src/routes/livepeer.js +++ b/backend/src/routes/livepeer.js @@ -8,7 +8,8 @@ import { API_CMC, API_L1_HTTP, API_L2_HTTP, API_L2_WS, CONF_DEFAULT_ORCH, CONF_SIMPLE_MODE, CONF_TIMEOUT_CMC, CONF_TIMEOUT_ALCHEMY, CONF_TIMEOUT_LIVEPEER, CONF_DISABLE_SYNC, - CONF_DISABLE_DB + CONF_DISABLE_DB, + CONF_DISABLE_CMC } from "../config"; // Do API requests to other API's const https = require('https'); @@ -17,8 +18,20 @@ const fs = require('fs'); // Used for the livepeer thegraph API import { request, gql } from 'graphql-request'; // Gets ETH, LPT and other coin info -const CoinMarketCap = require('coinmarketcap-api'); -const cmcClient = new CoinMarketCap(API_CMC); +let CoinMarketCap = require('coinmarketcap-api'); +let cmcClient = new CoinMarketCap(API_CMC); +let cmcEnabled = false; +if(!CONF_DISABLE_CMC){ + if(API_CMC == ""){ + console.log("Please provide a CMC api key"); + }else { + CoinMarketCap = require('coinmarketcap-api'); + cmcClient = new CoinMarketCap(API_CMC); + cmcEnabled = true; + } +}else{ + console.log("Running without CMC api"); +} // Gets blockchain data const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); // Gets gas prices @@ -395,6 +408,9 @@ if (!isEventSyncing && !CONF_SIMPLE_MODE && !CONF_DISABLE_SYNC) { // Splits of raw CMC object into coin quote data const parseCmc = async function () { try { + if (!cmcEnabled){ + return; + } cmcCache = await cmcClient.getTickers({ limit: 200 }); for (var idx = 0; idx < cmcCache.data.length; idx++) { const coinData = cmcCache.data[idx]; diff --git a/src/eventViewer.js b/src/eventViewer.js index 224bcce..b2a352d 100644 --- a/src/eventViewer.js +++ b/src/eventViewer.js @@ -232,7 +232,7 @@ const EventViewer = (obj) => { filterBit =