Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: find solana-wallet on path, fold into api/api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnygleason committed Jul 19, 2019
1 parent 0dfd534 commit a182ee7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import redis from 'redis';
import WebSocket from 'ws';
import _ from 'lodash';
import './inbound-stream';
import './uptime-crawler';
import geoip from 'geoip-lite';
import YAML from 'yaml';
import fs from 'fs';
Expand Down
12 changes: 9 additions & 3 deletions api/uptime-crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import YAML from 'yaml';
import redis from 'redis';
import {promisify} from 'util';
import {exec} from 'child_process';
import {sync as commandExistsSync} from 'command-exists';

import config from './config';

const SOLANA_WALLET_PATH =
process.env.SOLANA_WALLET_PATH || '../solana/target/debug';
const FULLNODE_URL = process.env.FULLNODE_URL || 'http://localhost:8899';

const REFRESH_INTERVAL = 10 * 60 * 1000; // 10min

if (!commandExistsSync('solana-wallet')) {
throw 'solana-wallet command not found!';
}


function getClient() {
let props = config.redis.path
? {path: config.redis.path}
Expand All @@ -29,7 +33,7 @@ function getVoteAccountUptime(x) {

const p = new Promise((resolve, reject) => {
exec(
`${SOLANA_WALLET_PATH}/solana-wallet -u ${FULLNODE_URL} show-vote-account ${x.votePubkey}`,
`solana-wallet -u ${FULLNODE_URL} show-vote-account ${x.votePubkey}`,
(err, stdout, stderr) => {
const t2 = new Date().getTime();

Expand Down Expand Up @@ -75,6 +79,7 @@ function getVoteAccountUptime(x) {
}

async function refreshUptime() {
console.log('uptime updater: updating...');
const connection = new solanaWeb3.Connection(FULLNODE_URL);
let voting = await connection.getEpochVoteAccounts();

Expand All @@ -84,6 +89,7 @@ async function refreshUptime() {

Promise.all(allTasks).then(async results => {
await setAsync('!uptime', JSON.stringify(results));
console.log('uptime updater: updated successfully.');
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"babel-plugin-transform-runtime": "^6.23.0",
"base-58": "^0.0.1",
"classnames": "^2.2.6",
"command-exists": "^1.2.8",
"copy-to-clipboard": "^3.2.0",
"cors": "^2.8.5",
"date-fns": "^1.30.1",
Expand Down Expand Up @@ -99,7 +100,6 @@
"prepack": "set -ex; npm run lint; npm run build",
"pretty": "prettier --write '{,{api,proxy,src}/**/}*.js{,x}'",
"re": "semantic-release --repository-url [email protected]:solana-labs/blockexplorer.git",
"start:uptime-crawler": "set -ex; redis-cli ping; babel-node --presets env api/uptime-crawler.js",
"start:api": "set -ex; redis-cli ping; babel-node --presets env api/api.js",
"start:proxy": "babel-node --presets env proxy",
"start:ui": "react-app-rewired start",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4604,6 +4604,11 @@ comma-separated-tokens@^1.0.0:
dependencies:
trim "0.0.1"

command-exists@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==

commander@2, commander@^2.11.0, commander@^2.12.2, commander@^2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
Expand Down

0 comments on commit a182ee7

Please sign in to comment.