Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script

After the overflow blunder of my main witness server and failure of the failover script that was in place to prevent such block missing I set out to create my own missed block application to sign over keys to my backup in case of main server failure. Here it is!

Witness Server Sentry v0.0.1

You'll need a box capable of running NodeJS and the SteemJS library installed for this script to work properly. You can grab the required software and dependencies from the links below:

NodeJS - https://nodejs.org
SteemJS - https://www.npmjs.com/package/steem

I won't go into detail here on how to setup NodeJS or SteemJS at this point. A quick google search should yield the required information needed in order to get these 2 software offerings on your box. Once you have the above installed you can copy the code below:

//=============================================================================
//-----------------------------------------------------------------------------
//----- Witness Server Sentry v0.0.1 ----- Coded by: @KLYE ----- Open Source!
//----- Requires NodeJS + steemjs || Install with: npm install steem -u
//-----------------------------------------------------------------------------
//=============================================================================

// Load the steemjs library
var steem = require('steem');

// NOTE: Edit these 3 variables below with your own information!
var accountName = ""; // Witness Account Name
var wif = ""; // Posting Private Key
var blockSigningKey = ""; // Signing Key of Backup Witness

// No need to modify these variables!
var url;
var props;
var fee;
var initmissed;
var scanmissed;

// Start up Witness Server Sentry
console.log("NodeJS Witness Server Sentry v0.0.1 Starting...");
console.log("Design & Development by: @KLYE - Open Source");

// Retrieve total missed blocks of given witness & save to variables
steem.api.getWitnessByAccount(accountName, function(err, result) {
    if (err) {
        console.log("An Error Occured Fetching Init Missed Blocks!")
    };
    if (result) {
        url = result["url"];
        props = result["props"];
        fee = props["account_creation_fee"];
        initmissed = result["total_missed"];
    }
});

// Start up the real time Witness Server Sentry functionality
console.log("Firing Up Witness Server Sentry Block Detector");

// misswatcher function compares initial missed blocks to current
function misswatcher() {
    sleep(3000);
    steem.api.getWitnessByAccount(accountName, function(err, result) {
        if (err) {
            console.log("An Error Occured Fetching Missed Blocks!")
            console.log(err);
        };

        if (result) {
            console.log("SCAN - Total Missed by @" + accountName + " is " + result["total_missed"]);
            scanmissed = result["total_missed"];
            if (scanmissed > initmissed) {
                console.log("MISS - A Missed Block Was Detected!");
                steem.broadcast.witnessUpdate(wif, accountName, url, blockSigningKey, props, fee, function(err, result) {
                    if (err) {
                        console.log("Error Switching to Backup Witness! Please Check Your Variables!");
                        console.log(err);
                    }
                    if (result) {
                        console.log("Successfully Switched to Backup Witness!");
                        console.log(result);
                    }
                });
            }
            misswatcher();
        }
    });
}

// Call misswatcher() function again to loop
misswatcher();

// SLEEP Function to unfuck some nodeJS things - NO modify
function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
};



Make sure to add the required information in lines 10 through 13. You'll need your witness account name, it's active private key and the signing key for your backup witness in order for this script to function properly. Once you've got your variables set it's just a matter of running the script and letting it handle your key signing to backup server in the event it detects you've missed a block. This script is only good for 1 use and will have to be reset/restarted in the event it signs over to your backup key. Keep in mind this script has had minimum amounts of testing done and can likely be improved on. This is version 0.0.1... So it MAY contain bugs!

Github Link: https://github.com/klye-steem/Witness-Server-Sentry-v0.0.1

@KLYE takes no responsibility for loses caused by this software!


VOTE
KLYE

for Witness!
H2
H3
H4
3 columns
2 columns
1 column
14 Comments