Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Put your parameters here:
- // The Gmail address should be a mock one you don't use
- var yourGmailAddress = 'xxx@gmail.com'
- var yourGmailPassword = 'xxx'
- // This is your normal email, that will receive the email alerts when Antpool claims a block
- var yourEmail = 'xxx@xxx.xxx'
- // Open an account in AntPool and create an API key, follow their documentation: https://www.antpool.com/user/apiGuild.htm
- var yourApiKey = 'xxx'
- // You will have to encrypt the autentication message in SHA256, go to https://www.freeformatter.com/hmac-generator.html and introduce:
- // a) In "string" type (without spaces in between): your_userID + your_api_key + 2
- // b) In "secret" type the secret key the Antpool API registering page returned you when you were creating the API
- // Then wite down here as "yourHMAC" the resulting encrypted message
- var yourHMAC = 'xxx'
- var fs = require('fs');
- var request = require('C:/nodejs/node_modules/request');
- var nodemailer = require('C:/nodejs/node_modules/nodemailer');
- var cron = require('C:/nodejs/node_modules/cron');
- var transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: yourGmailAddress,
- pass: yourGmailPassword
- }
- });
- // Loading the log file here
- var data1 = '';
- var chunk1;
- var stream1 = fs.createReadStream("antpoolblocks.json")
- stream1.on('readable', function() { //Function just to read the whole file before proceeding
- while ((chunk1=stream1.read()) != null) {
- data1 += chunk1;}
- });
- stream1.on('end', function() {
- if (data1 != "") {
- var antpoolReports = JSON.parse(data1)
- } else {
- var antpoolReports = [] // Empty array
- }
- if (antpoolReports.length > 0) {
- knownBlocks = antpoolReports[antpoolReports.length-1].reportedblocks
- } else {
- knownBlocks = 0
- }
- // Calling the API every 5 minutes
- var cronJob = cron.job("00 0,5,10,15,20,25,30,35,40,45,50,55 * * * *", function(){
- var sign = yourHMAC.toUpperCase()
- var now = Date.now();
- request.post({
- url: 'https://antpool.com/api/poolStats.htm',
- json: true,
- form: {
- key: yourApiKey,
- nonce: 2,
- signature: sign,
- coin: 'SC'
- }
- }, function (err, httpResponse, body) {
- var newReportedBlocks = body.data.totalBlockNumber
- if (newReportedBlocks > knownBlocks) {
- console.log("Reported a block!!")
- entry = {"time": now, "reportedblocks": newReportedBlocks}
- console.log(entry)
- antpoolReports.push(entry)
- knownBlocks = newReportedBlocks
- // Save file
- var stream2 = fs.createWriteStream("antpoolblocks.json")
- var string2 = JSON.stringify(antpoolReports)
- stream2.write(string2)
- var emailText = 'Antpool found blocks at: ' + now + ". Total count: " + knownBlocks
- // Email
- var mailOptions = {
- from: yourGmailAddress,
- to: yourEmail,
- subject: 'Antpool found blocks!',
- text: emailText
- }
- transporter.sendMail(mailOptions, function(error, info){
- if (error) {
- console.log(error);
- } else {
- console.log('Email sent: ' + info.response);
- }
- });
- } else {
- console.log("Nothing new at: " + now + " --> " + newReportedBlocks)
- }
- })
- })
- cronJob.start();
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement