Last active
January 9, 2018 10:35
-
-
Save perry-mitchell/9dfb5af1d58d0d11671881dbd60b587d to your computer and use it in GitHub Desktop.
ZEC/Flypool Mining monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require("node-fetch"); | |
const chalk = require("chalk"); | |
const prettyMs = require("pretty-ms"); | |
const VError = require("verror"); | |
const pruddy = require("pruddy-error"); | |
const API = "https://api-zcash.flypool.org"; | |
const DELAY = 60; | |
const MINER = "t1R21Uq3HQRiyj6ff1kFQcPusqPXiBaAc2U"; | |
//const PAYOUT_MIN = 0.03; | |
//const WALLET_API = "https://api.zcha.in"; | |
const WALLET_API = "https://zcashnetwork.info/api/addr"; | |
function handleBadAPIResponse(err) { | |
const errorInfo = { | |
cause: err, | |
name: "APIResponseError" | |
}; | |
const error = new VError(errorInfo, "Bad API response"); | |
throw error; | |
} | |
function process() { | |
return Promise | |
.all([ | |
fetch(`${API}/miner/${MINER}/currentStats`) | |
.then(res => res.json()) | |
.then(stats => stats.data) | |
.catch(handleBadAPIResponse), | |
fetch(`${API}/miner/${MINER}/settings`) | |
.then(res => res.json()) | |
.then(info => info.data) | |
.catch(handleBadAPIResponse), | |
//fetch(`${WALLET_API}/v2/mainnet/accounts/${MINER}`) | |
fetch(`${WALLET_API}/${MINER}?noTxList=1`) | |
.then(res => res.json()) | |
.catch(handleBadAPIResponse), | |
fetch(`https://api.coinmarketcap.com/v1/ticker/zcash/`) | |
.then(res => res.json()) | |
.then(res => res.shift()) | |
.catch(handleBadAPIResponse), | |
fetch(`https://api.cryptonator.com/api/full/zec-eur`) | |
.then(res => res.json()) | |
.then(res => res.ticker) | |
.catch(handleBadAPIResponse) | |
]) | |
.then(([stats, settings, wallet, zecStatsUSD, zecStatsEuro]) => { | |
const { | |
currentHashrate, | |
averageHashrate, | |
coinsPerMin, | |
usdPerMin, | |
btcPerMin, | |
activeWorkers, | |
unconfirmed, | |
unpaid | |
} = stats; | |
const { | |
minPayout | |
} = settings; | |
const { | |
balance | |
} = wallet; | |
const { | |
price_usd: priceUSDStr | |
} = zecStatsUSD; | |
const { | |
price: priceEuroStr | |
} = zecStatsEuro; | |
const payoutMinimum = minPayout / 100000000; | |
const realUnconfirmed = unconfirmed / 100000000; | |
const realUnpaid = unpaid / 100000000; | |
const coinsPerDay = parseFloat(coinsPerMin * 60 * 24).toFixed(4); | |
const usdPerDay = parseFloat(usdPerMin * 60 * 24).toFixed(2); | |
const btcPerDay = parseFloat(btcPerMin * 60 * 24).toFixed(5); | |
const unconfCoins = parseFloat(realUnconfirmed).toFixed(5); | |
const unpaidCoins = parseFloat(realUnpaid).toFixed(5); | |
const payoutCompletion = parseFloat(((realUnconfirmed + realUnpaid) / payoutMinimum) * 100).toFixed(2); | |
const smallBalance = parseFloat(balance).toFixed(5); | |
const priceUSD = parseFloat(priceUSDStr); | |
const balanceUSD = parseFloat(priceUSD * balance).toFixed(2); | |
const priceEuro = parseFloat(priceEuroStr); | |
const balanceEuro = parseFloat(priceEuro * balance).toFixed(2); | |
// tricky | |
const coinsToPayout = payoutMinimum - (realUnpaid + realUnconfirmed); | |
let minsToPayout = coinsToPayout / coinsPerMin; | |
if (minsToPayout < 0) { | |
minsToPayout = 0; | |
} | |
const timeToPayout = prettyMs(minsToPayout * 60 * 1000); | |
// log | |
console.log( | |
chalk.blue("Current:"), | |
`${Math.floor(currentHashrate)} Sol/s,`, | |
chalk.green("Average:"), | |
`${Math.floor(averageHashrate)} Sol/s,`, | |
chalk.underline("Income/Day:"), | |
`${chalk.cyan(coinsPerDay)} ${chalk.cyan("ZEC")}`, | |
`${chalk.magenta("$")}${chalk.magenta(usdPerDay)}`, | |
`${chalk.gray(btcPerDay)} ${chalk.gray("BTC")},`, | |
chalk.underline("Pending/Unpaid:"), | |
`${chalk.yellow(unconfCoins)}/${chalk.blue(unpaidCoins)} ZEC (${payoutCompletion}% - ${timeToPayout}),`, | |
// chalk.underline("Workers:"), | |
// chalk.green(activeWorkers) | |
chalk.underline("Wallet:"), | |
chalk.green(`${smallBalance} ZEC`), | |
chalk.gray(`$${balanceUSD}`), | |
`€${balanceEuro}` | |
); | |
}) | |
.then(() => { | |
setTimeout(process, DELAY * 1000); | |
}) | |
.catch(err => { | |
console.log(pruddy(err)); | |
setTimeout(process, DELAY * 1000); | |
}); | |
} | |
process(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "miner", | |
"version": "1.0.0", | |
"description": "", | |
"main": "miner.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "UNLICENSED", | |
"dependencies": { | |
"chalk": "^2.1.0", | |
"node-fetch": "^1.7.2", | |
"pretty-ms": "^3.0.0", | |
"pruddy-error": "^1.0.2", | |
"verror": "^1.10.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Designed to work with NodeJS 8. Simply change miner address to use.
Looks something like:
