create account

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

View this thread on: hive.blogpeakd.comecency.com
· @klye · (edited)
$44.40
Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script
<center>![](https://steemitimages.com/DQmNV7fUUgvXVtLLVpkscs3hQjwQF7RD1FJVWgy1RA47eFU/image.png)</center>

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!

<center><h1>Witness Server Sentry v0.0.1</h1></center>

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:

<b>NodeJS</b> - https://nodejs.org
<b>SteemJS</b> - 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;
        }
    }
};
``` 
<br>
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

<b>@KLYE takes no responsibility for loses caused by this software!</b>

<hr />
<table>
<thead>
<tr><th><img src="https://steemitimages.com/0x0/http://puu.sh/rRLx4/cb96668c43.png" /></th><th><center><a href="https://steemit.com/~witnesses"><b><h2>VOTE<br>KLYE</h2></b><sub>for Witness!</sub></a></center></th><th><img src="https://steemitimages.com/0x0/http://puu.sh/rRLx4/cb96668c43.png" /></th></tr>
</thead>
<tbody>
</tbody>
</table>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 31 others
properties (23)
authorklye
permlinkwitness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script
categorywitness-category
json_metadata{"tags":["witness-category","witness","fail-over","script","steemjs"],"users":["klye"],"image":["https://steemitimages.com/DQmNV7fUUgvXVtLLVpkscs3hQjwQF7RD1FJVWgy1RA47eFU/image.png","https://steemitimages.com/0x0/http://puu.sh/rRLx4/cb96668c43.png"],"links":["https://nodejs.org","https://www.npmjs.com/package/steem","https://github.com/klye-steem/Witness-Server-Sentry-v0.0.1","https://steemit.com/~witnesses"],"app":"steemit/0.1","format":"markdown"}
created2017-10-05 04:33:42
last_update2017-10-05 04:55:21
depth0
children14
last_payout2017-10-12 04:33:42
cashout_time1969-12-31 23:59:59
total_payout_value35.188 HBD
curator_payout_value9.215 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,186
author_reputation412,341,527,771,769
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,823,833
net_rshares18,082,017,107,227
author_curate_reward""
vote details (95)
@aijay ·
Interesting!!!
properties (22)
authoraijay
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t054945821z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 05:49:51
last_update2017-10-05 05:49:51
depth1
children0
last_payout2017-10-12 05:49:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation2,546,055,482
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,828,692
net_rshares0
@bayareacoins ·
Mmmm bb such wizard!
👍  ,
properties (23)
authorbayareacoins
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t043558592z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 04:36:00
last_update2017-10-05 04:36:00
depth1
children1
last_payout2017-10-12 04:36:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length20
author_reputation8,774,872,728,250
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,823,959
net_rshares6,283,426,650
author_curate_reward""
vote details (2)
@klye ·
mmmm bb. * *adjusts wizard hat * *
properties (22)
authorklye
permlinkre-bayareacoins-re-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t043740245z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 04:37:42
last_update2017-10-05 04:37:42
depth2
children0
last_payout2017-10-12 04:37:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation412,341,527,771,769
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,824,074
net_rshares0
@braxton101 ·
Interesting. I wish I understood wizard language.
👍  
properties (23)
authorbraxton101
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t051455676z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 05:14:54
last_update2017-10-05 05:14:54
depth1
children1
last_payout2017-10-12 05:14:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length49
author_reputation5,211,856,126,324
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,826,384
net_rshares5,851,018,306
author_curate_reward""
vote details (1)
@klye ·
If my half fried brain can figure this stuff out I imagine you can as well. :)
properties (22)
authorklye
permlinkre-braxton101-re-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t051812942z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 05:18:12
last_update2017-10-05 05:18:12
depth2
children0
last_payout2017-10-12 05:18:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length78
author_reputation412,341,527,771,769
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,826,583
net_rshares0
@happyphoenix ·
Phyton language ?
properties (22)
authorhappyphoenix
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171009t031155411z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-09 03:11:57
last_update2017-10-09 03:11:57
depth1
children0
last_payout2017-10-16 03:11:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length17
author_reputation70,114,248,253,623
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id17,158,210
net_rshares0
@inquiringtimes ·
well, aren't you fancY!
👍  
properties (23)
authorinquiringtimes
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t043516623z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 04:35:15
last_update2017-10-05 04:35:15
depth1
children3
last_payout2017-10-12 04:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length23
author_reputation22,511,044,719,347
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,823,922
net_rshares5,850,470,786
author_curate_reward""
vote details (1)
@klye ·
lol, this was written out of necessity not because I wanted to be fancy.. :D

Figured I'd share the code in hopes others may be able to use it to protect against missed blocks.. It likely does contain bugs... But was able to test it earlier and it appears to work, surely it can be improved upon though!
👍  
properties (23)
authorklye
permlinkre-inquiringtimes-re-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t043656341z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 04:37:00
last_update2017-10-05 04:37:00
depth2
children2
last_payout2017-10-12 04:37:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length303
author_reputation412,341,527,771,769
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,824,022
net_rshares0
author_curate_reward""
vote details (1)
@inquiringtimes ·
I was not being sarcastic... this is very cool and I dropped it in steemdevs post promotion
👍  
properties (23)
authorinquiringtimes
permlinkre-klye-re-inquiringtimes-re-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t043900010z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 04:39:00
last_update2017-10-05 04:39:00
depth3
children1
last_payout2017-10-12 04:39:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length91
author_reputation22,511,044,719,347
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,824,143
net_rshares5,849,727,722
author_curate_reward""
vote details (1)
@iwod ·
this is a very interesting post.
properties (22)
authoriwod
permlinkre-klye-2017106t24122383z
categorywitness-category
json_metadata{"tags":"witness-category","app":"esteem/1.4.6","format":"markdown+html","community":"esteem"}
created2017-10-05 19:42:18
last_update2017-10-05 19:42:18
depth1
children0
last_payout2017-10-12 19:42:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length32
author_reputation34,077,674,480
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries
0.
accountesteemapp
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,887,213
net_rshares0
@mdpavel ·
Nice
👍  
properties (23)
authormdpavel
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171005t115401817z
categorywitness-category
json_metadata{"tags":["witness-category"],"app":"steemit/0.1"}
created2017-10-05 11:54:15
last_update2017-10-05 11:54:15
depth1
children0
last_payout2017-10-12 11:54:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4
author_reputation466,824,337,982
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,852,142
net_rshares0
author_curate_reward""
vote details (1)
@sargento ·
<div class="pull-right">

<center>https://steemitimages.com/DQmcFCwV4cf7kA7PtQJJMQAPH5K2zyagQJ64gaMQhtwq6Xa/Bildschirmfoto%202017-09-22%20um%2012.01.42.png** </center>
</div>

You coders fascinate me. I wrote, I guess what you could call code, for [DBase II ](http://www.eweek.com/database/30-years-ago-the-rise-fall-and-survival-of-ashton-tate-s-dbase) years ago around the mid-1980s after tearing up my leg in a training accident. 

The Corps was justing starting to implement the use of computers. I was serving as an *Operations Clerk* while recuperating from my skiing accident.

I don't know much about these things, but good looking out for people that do!
👍  
properties (23)
authorsargento
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171008t085854446z
categorywitness-category
json_metadata{"tags":["witness-category"],"image":["https://steemitimages.com/DQmcFCwV4cf7kA7PtQJJMQAPH5K2zyagQJ64gaMQhtwq6Xa/Bildschirmfoto%202017-09-22%20um%2012.01.42.png**"],"links":["http://www.eweek.com/database/30-years-ago-the-rise-fall-and-survival-of-ashton-tate-s-dbase"],"app":"steemit/0.1"}
created2017-10-08 08:58:54
last_update2017-10-08 08:58:54
depth1
children0
last_payout2017-10-15 08:58:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length663
author_reputation-270,084,212,179
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id17,084,159
net_rshares1,026,424,232
author_curate_reward""
vote details (1)
@shanishah ·
![thumbs-up (1).jpg](https://steemitimages.com/DQmTYXjRKdgwXEc6qig7QPvR6fXApwoSLP9B8kApg1mV963/thumbs-up%20(1).jpg)
👍  
properties (23)
authorshanishah
permlinkre-klye-witness-server-sentry-v0-0-1-or-an-open-source-nodejs-steemjs-witness-failover-script-20171116t061949654z
categorywitness-category
json_metadata{"tags":["witness-category"],"image":["https://steemitimages.com/DQmTYXjRKdgwXEc6qig7QPvR6fXApwoSLP9B8kApg1mV963/thumbs-up%20(1).jpg"],"app":"steemit/0.1"}
created2017-11-16 06:19:48
last_update2017-11-16 06:19:48
depth1
children0
last_payout2017-11-23 06:19:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length115
author_reputation9,291,167,932,357
root_title"Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id20,540,892
net_rshares128,652,273
author_curate_reward""
vote details (1)