Skip to content

Commit

Permalink
Added backup_mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyIce committed Mar 1, 2018
1 parent 29dcbd7 commit 9b10e04
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -23,6 +23,7 @@ Then set the following options in config.json:
"https://steemd.privex.io",
"https://gtg.steem.house:8090"
],
"backup_mode": false, // Put the bot in "backup mode" where it will process all bids and account state but not vote or transact
"disabled_mode": false, // Set this to true to refund all funds sent to the bot
"detailed_logging": false, // Whether or not detailed logging is enabled
"owner_account": "bot_owner_account", // The name of the bot owner account (can be left null or blank)
Expand Down
1 change: 1 addition & 0 deletions config-example.json
Expand Up @@ -6,6 +6,7 @@
"https://steemd.privex.io",
"https://gtg.steem.house:8090"
],
"backup_mode": false,
"disabled_mode": false,
"detailed_logging": false,
"owner_account": "bot_owner_account_name",
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "postpromoter",
"version": "1.8.7",
"version": "1.8.8",
"description": "Steem bid-based voting bot written in JavaScript",
"main": "index.js",
"scripts": {
Expand Down
25 changes: 21 additions & 4 deletions postpromoter.js
Expand Up @@ -14,7 +14,7 @@ var last_withdrawal = null;
var use_delegators = false;
var steem_price = 1; // This will get overridden with actual prices if a price_feed_url is specified in settings
var sbd_price = 1; // This will get overridden with actual prices if a price_feed_url is specified in settings
var version = '1.8.7';
var version = '1.8.8';

// Load the settings from the config file
loadConfig();
Expand All @@ -26,6 +26,9 @@ steem.api.setOptions({ transport: 'http', uri: rpc_node, url: rpc_node });
utils.log("* START - Version: " + version + " *");
utils.log("Connected to: " + rpc_node);

if(config.backup_mode)
utils.log('*** RUNNING IN BACKUP MODE ***');

// Load Steem global variables
utils.updateSteemVariables();

Expand Down Expand Up @@ -122,7 +125,7 @@ function startProcess() {
if(config.detailed_logging) {
var bids_steem = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency == 'STEEM') ? b.amount : 0); }, 0), 3);
var bids_sbd = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency == 'SBD') ? b.amount : 0); }, 0), 3);
utils.log('Voting Power: ' + utils.format(vp / 100) + '% | Time until next round: ' + utils.toTimer(utils.timeTilFullPower(vp)) + ' | Bids: ' + outstanding_bids.length + ' | ' + bids_sbd + ' SBD | ' + bids_steem + ' STEEM');
utils.log((config.backup_mode ? '* BACKUP MODE *' : '') + 'Voting Power: ' + utils.format(vp / 100) + '% | Time until next round: ' + utils.toTimer(utils.timeTilFullPower(vp)) + ' | Bids: ' + outstanding_bids.length + ' | ' + bids_sbd + ' SBD | ' + bids_steem + ' STEEM');
}

// We are at 100% voting power - time to vote!
Expand Down Expand Up @@ -152,6 +155,12 @@ function startProcess() {
}

function startVoting(bids) {
if(config.backup_mode) {
utils.log('Bidding Round End - Backup Mode, no voting');
isVoting = false;
return;
}

// Sum the amounts of all of the bids
var total = bids.reduce(function(total, bid) {
return total + getUsdValue(bid);
Expand Down Expand Up @@ -473,7 +482,7 @@ function checkPost(memo, amount, currency, sender, retries) {
} else if(existing_bid.currency == 'SBD') {
new_amount = existing_bid.amount + amount * steem_price / sbd_price;
}

var max_bid = config.max_bid ? parseFloat(config.max_bid) : 9999;

// Check that the new total doesn't exceed the max bid amount per post
Expand Down Expand Up @@ -570,6 +579,11 @@ function saveDelegators() {
}

function refund(sender, amount, currency, reason, retries, data) {
if(config.backup_mode) {
utils.log('Backup Mode - not sending refund of ' + amount + ' ' + currency + ' to @' + sender + ' for reason: ' + reason);
return;
}

if(!retries)
retries = 0;

Expand Down Expand Up @@ -611,7 +625,7 @@ function refund(sender, amount, currency, reason, retries, data) {
}

function claimRewards() {
if (!config.auto_claim_rewards)
if (!config.auto_claim_rewards || config.backup_mode)
return;

// Make api call only if you have actual reward
Expand Down Expand Up @@ -660,6 +674,9 @@ function checkAutoWithdraw() {
}

function processWithdrawals() {
if(config.backup_mode)
return;

var has_sbd = config.currencies_accepted.indexOf('SBD') >= 0 && parseFloat(account.sbd_balance) > 0;
var has_steem = config.currencies_accepted.indexOf('STEEM') >= 0 && parseFloat(account.balance) > 0;

Expand Down

0 comments on commit 9b10e04

Please sign in to comment.