diff --git a/delegators.js b/delegators.js index 3d5f9a2..b88015b 100644 --- a/delegators.js +++ b/delegators.js @@ -1,32 +1,32 @@ -const steem = require('steem'); -var utils = require('./utils'); -var dsteem = require('dsteem'); +//const steem = require('steem'); +let utils = require('./utils'); +//let dsteem = require('dsteem'); -var delegation_transactions = []; +let delegation_transactions = []; function loadDelegations(client, account, callback) { getTransactions(client, account, -1, callback); } function getTransactions(client, account, start, callback) { - var last_trans = start; + let last_trans = start; utils.log('Loading history for delegators at transaction: ' + (start < 0 ? 'latest' : start)); client.database.call('get_account_history', [account, start, (start < 0) ? 10000 : Math.min(start, 10000)]).then(function (result) { result.reverse(); - for(var i = 0; i < result.length; i++) { - var trans = result[i]; - var op = trans[1].op; + for(let i = 0; i < result.length; i++) { + let trans = result[i]; + let op = trans[1].op; - if(op[0] == 'delegate_vesting_shares' && op[1].delegatee == account) + if(op[0] === 'delegate_vesting_shares' && op[1].delegatee === account) delegation_transactions.push({ id: trans[0], data: op[1] }); // Save the ID of the last transaction that was processed. last_trans = trans[0]; } - if(last_trans > 0 && last_trans != start) + if(last_trans > 0 && last_trans !== start) getTransactions(client, account, last_trans, callback); else { if(last_trans > 0) { @@ -40,16 +40,16 @@ function getTransactions(client, account, start, callback) { } function processDelegations(callback) { - var delegations = []; + let delegations = []; // Go through the delegation transactions from oldest to newest to find the final delegated amount from each account delegation_transactions.reverse(); - for(var i = 0; i < delegation_transactions.length; i++) { - var trans = delegation_transactions[i]; + for(let i = 0; i < delegation_transactions.length; i++) { + let trans = delegation_transactions[i]; // Check if this is a new delegation or an update to an existing delegation from this account - var delegation = delegations.find(d => d.delegator == trans.data.delegator); + let delegation = delegations.find(d => d.delegator === trans.data.delegator); if(delegation) { delegation.vesting_shares = trans.data.vesting_shares; @@ -67,4 +67,4 @@ function processDelegations(callback) { module.exports = { loadDelegations: loadDelegations -} +}; diff --git a/package-lock.json b/package-lock.json index 9f9da10..5f80692 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "postpromoter", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -14,7 +14,7 @@ "resolved": "https://registry.npmjs.org/@steemit/rpc-auth/-/rpc-auth-1.1.1.tgz", "integrity": "sha512-Eb8BW3O1y4+/+Dbf+LqGVmgXYqyfHxP9mBlmzkpjXiIepTpxoK90NIGrneqcnEGq0TR2nSt4BVv9Ur9c+hxoig==", "requires": { - "@steemit/libcrypto": "1.0.1" + "@steemit/libcrypto": "^1.0.1" } }, "accepts": { @@ -22,7 +22,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", "requires": { - "mime-types": "2.1.20", + "mime-types": "~2.1.18", "negotiator": "0.6.1" } }, @@ -31,10 +31,10 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "requires": { - "co": "4.6.0", - "fast-deep-equal": "1.0.0", - "fast-json-stable-stringify": "2.0.0", - "json-schema-traverse": "0.3.1" + "co": "^4.6.0", + "fast-deep-equal": "^1.0.0", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.3.0" } }, "array-flatten": { @@ -43,9 +43,12 @@ "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "asn1": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "requires": { + "safer-buffer": "~2.1.0" + } }, "assert-plus": { "version": "1.0.0", @@ -72,7 +75,7 @@ "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.4.tgz", "integrity": "sha512-UYOadoSIkEI/VrRGSG6qp93rp2WdokiAiNYDfGW5qURAY8GiAQkvMbwNNSDYiVJopqv4gCna7xqf4rrNGp+5AA==", "requires": { - "safe-buffer": "5.1.1" + "safe-buffer": "^5.0.1" } }, "base64-js": { @@ -81,12 +84,11 @@ "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" }, "bcrypt-pbkdf": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", - "optional": true, + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "requires": { - "tweetnacl": "0.14.5" + "tweetnacl": "^0.14.3" } }, "bigi": { @@ -95,16 +97,16 @@ "integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU=" }, "bindings": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", - "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==" + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.1.tgz", + "integrity": "sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==" }, "bip66": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz", "integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=", "requires": { - "safe-buffer": "5.1.1" + "safe-buffer": "^5.0.1" } }, "bluebird": { @@ -123,15 +125,15 @@ "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", "requires": { "bytes": "3.0.0", - "content-type": "1.0.4", + "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "1.1.2", - "http-errors": "1.6.3", + "depd": "~1.1.1", + "http-errors": "~1.6.2", "iconv-lite": "0.4.19", - "on-finished": "2.3.0", + "on-finished": "~2.3.0", "qs": "6.5.1", "raw-body": "2.3.2", - "type-is": "1.6.16" + "type-is": "~1.6.15" } }, "brorand": { @@ -144,12 +146,12 @@ "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "requires": { - "buffer-xor": "1.0.3", - "cipher-base": "1.0.4", - "create-hash": "1.2.0", - "evp_bytestokey": "1.0.3", - "inherits": "2.0.3", - "safe-buffer": "5.1.1" + "buffer-xor": "^1.0.3", + "cipher-base": "^1.0.0", + "create-hash": "^1.1.0", + "evp_bytestokey": "^1.0.3", + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" } }, "bs58": { @@ -157,7 +159,7 @@ "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", "requires": { - "base-x": "3.0.4" + "base-x": "^3.0.2" } }, "buffer": { @@ -165,8 +167,8 @@ "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.1.0.tgz", "integrity": "sha512-YkIRgwsZwJWTnyQrsBTWefizHh+8GYj3kbL1BTiAQ/9pwpino0G7B2gp5tx/FUBqUlvtxV85KNR3mwfAtv15Yw==", "requires": { - "base64-js": "1.3.0", - "ieee754": "1.1.12" + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" } }, "buffer-xor": { @@ -179,7 +181,7 @@ "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", "requires": { - "long": "3.2.0" + "long": "~3" } }, "bytes": { @@ -197,8 +199,8 @@ "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" } }, "co": { @@ -227,9 +229,9 @@ "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "core-js": { - "version": "2.5.7", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", - "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.1.tgz", + "integrity": "sha512-L72mmmEayPJBejKIWe2pYtGis5r0tQ5NaJekdhyXgeMQTpJoBsH0NL4ElY2LfSoV15xeQWKQ+XTTOZdyero5Xg==" }, "core-util-is": { "version": "1.0.2", @@ -241,11 +243,11 @@ "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "requires": { - "cipher-base": "1.0.4", - "inherits": "2.0.3", - "md5.js": "1.3.4", - "ripemd160": "2.0.2", - "sha.js": "2.4.11" + "cipher-base": "^1.0.1", + "inherits": "^2.0.1", + "md5.js": "^1.3.4", + "ripemd160": "^2.0.1", + "sha.js": "^2.4.0" } }, "create-hmac": { @@ -253,12 +255,12 @@ "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", "requires": { - "cipher-base": "1.0.4", - "create-hash": "1.2.0", - "inherits": "2.0.3", - "ripemd160": "2.0.2", - "safe-buffer": "5.1.1", - "sha.js": "2.4.11" + "cipher-base": "^1.0.3", + "create-hash": "^1.1.0", + "inherits": "^2.0.1", + "ripemd160": "^2.0.0", + "safe-buffer": "^5.0.1", + "sha.js": "^2.4.8" } }, "cross-env": { @@ -266,8 +268,8 @@ "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.2.0.tgz", "integrity": "sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==", "requires": { - "cross-spawn": "6.0.5", - "is-windows": "1.0.2" + "cross-spawn": "^6.0.5", + "is-windows": "^1.0.0" } }, "cross-fetch": { @@ -284,11 +286,11 @@ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "requires": { - "nice-try": "1.0.4", - "path-key": "2.0.1", - "semver": "5.5.0", - "shebang-command": "1.2.0", - "which": "1.3.1" + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" } }, "dashdash": { @@ -296,7 +298,7 @@ "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" } }, "debug": { @@ -332,39 +334,39 @@ "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", "integrity": "sha1-Pja2xCs3BDgjzbwzLVjzHiRFSAs=", "requires": { - "browserify-aes": "1.2.0", - "create-hash": "1.2.0", - "create-hmac": "1.1.7" + "browserify-aes": "^1.0.6", + "create-hash": "^1.1.2", + "create-hmac": "^1.1.4" } }, "dsteem": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/dsteem/-/dsteem-0.10.0.tgz", - "integrity": "sha512-Aq0FB6eRAXoQlRRoAU+oVJdcSatfX4eSpaQs5S/s8LM9Kb41jCTWg7TjbxIaO+KAepWRsV6tAwoaQ87IYE+93g==", + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/dsteem/-/dsteem-0.10.1.tgz", + "integrity": "sha512-IF8yMagK+id3qHABEmQSrn7FjNiCTZzbohzig8jE09TBUpwePBxx+1UUedms/EY4oUlziaDa6h7Znb/Pp2dXgQ==", "requires": { - "bs58": "4.0.1", - "bytebuffer": "5.0.1", - "core-js": "2.5.7", - "node-fetch": "2.2.0", - "secp256k1": "3.5.2", - "verror": "1.10.0", - "whatwg-fetch": "2.0.3" + "bs58": "^4.0.1", + "bytebuffer": "^5.0.1", + "core-js": "^2.5.0", + "node-fetch": "^2.1.2", + "secp256k1": "^3.3.1", + "verror": "^1.10.0", + "whatwg-fetch": "^2.0.3" }, "dependencies": { "node-fetch": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.2.0.tgz", - "integrity": "sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA==" + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz", + "integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==" } } }, "ecc-jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", - "optional": true, + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "requires": { - "jsbn": "0.1.1" + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" } }, "ecurve": { @@ -372,8 +374,8 @@ "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", "integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==", "requires": { - "bigi": "1.4.2", - "safe-buffer": "5.1.1" + "bigi": "^1.1.0", + "safe-buffer": "^5.0.1" } }, "ee-first": { @@ -386,13 +388,13 @@ "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", "integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==", "requires": { - "bn.js": "4.11.8", - "brorand": "1.1.0", - "hash.js": "1.1.5", - "hmac-drbg": "1.0.1", - "inherits": "2.0.3", - "minimalistic-assert": "1.0.1", - "minimalistic-crypto-utils": "1.0.1" + "bn.js": "^4.4.0", + "brorand": "^1.0.1", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.0", + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.0" } }, "encodeurl": { @@ -405,7 +407,7 @@ "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", "requires": { - "iconv-lite": "0.4.19" + "iconv-lite": "~0.4.13" } }, "escape-html": { @@ -423,8 +425,8 @@ "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", "requires": { - "md5.js": "1.3.4", - "safe-buffer": "5.1.1" + "md5.js": "^1.3.4", + "safe-buffer": "^5.1.1" } }, "express": { @@ -432,36 +434,36 @@ "resolved": "http://registry.npmjs.org/express/-/express-4.16.3.tgz", "integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=", "requires": { - "accepts": "1.3.5", + "accepts": "~1.3.5", "array-flatten": "1.1.1", "body-parser": "1.18.2", "content-disposition": "0.5.2", - "content-type": "1.0.4", + "content-type": "~1.0.4", "cookie": "0.3.1", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "1.1.2", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "etag": "1.8.1", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", "finalhandler": "1.1.1", "fresh": "0.5.2", "merge-descriptors": "1.0.1", - "methods": "1.1.2", - "on-finished": "2.3.0", - "parseurl": "1.3.2", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", "path-to-regexp": "0.1.7", - "proxy-addr": "2.0.4", + "proxy-addr": "~2.0.3", "qs": "6.5.1", - "range-parser": "1.2.0", + "range-parser": "~1.2.0", "safe-buffer": "5.1.1", "send": "0.16.2", "serve-static": "1.13.2", "setprototypeof": "1.1.0", - "statuses": "1.4.0", - "type-is": "1.6.16", + "statuses": "~1.4.0", + "type-is": "~1.6.16", "utils-merge": "1.0.1", - "vary": "1.1.2" + "vary": "~1.1.2" } }, "extsprintf": { @@ -485,12 +487,12 @@ "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", "requires": { "debug": "2.6.9", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "statuses": "1.4.0", - "unpipe": "1.0.0" + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "statuses": "~1.4.0", + "unpipe": "~1.0.0" } }, "forever-agent": { @@ -513,7 +515,7 @@ "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" } }, "har-schema": { @@ -526,17 +528,17 @@ "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" } }, "hash.js": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.5.tgz", - "integrity": "sha512-eWI5HG9Np+eHV1KQhisXWwM+4EPPYe5dFX1UZZH7k/E3JzDEazVH+VGlZi6R94ZqImq+A3D1mCEtrFIfg/E7sA==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", "requires": { - "inherits": "2.0.3", - "minimalistic-assert": "1.0.1" + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" } }, "hmac-drbg": { @@ -544,9 +546,9 @@ "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", "requires": { - "hash.js": "1.1.5", - "minimalistic-assert": "1.0.1", - "minimalistic-crypto-utils": "1.0.1" + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" } }, "http-errors": { @@ -554,10 +556,10 @@ "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", "requires": { - "depd": "1.1.2", + "depd": "~1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.0", - "statuses": "1.4.0" + "statuses": ">= 1.4.0 < 2" } }, "http-signature": { @@ -565,9 +567,9 @@ "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", "requires": { - "assert-plus": "1.0.0", - "jsprim": "1.4.1", - "sshpk": "1.13.1" + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" } }, "iconv-lite": { @@ -618,8 +620,7 @@ "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, "json-schema": { "version": "0.2.3", @@ -662,8 +663,8 @@ "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=", "requires": { - "hash-base": "3.0.4", - "inherits": "2.0.3" + "hash-base": "^3.0.0", + "inherits": "^2.0.1" } }, "media-typer": { @@ -696,7 +697,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.20.tgz", "integrity": "sha512-HrkrPaP9vGuWbLK1B1FfgAkbqNjIuy4eHlIYnFi7kamZyLLrGlo2mpcx0bBmNpKqBtYtAfGbodDddIgddSJC2A==", "requires": { - "mime-db": "1.36.0" + "mime-db": "~1.36.0" } }, "minimalistic-assert": { @@ -715,9 +716,9 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "nan": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.11.0.tgz", - "integrity": "sha512-F4miItu2rGnV2ySkXOQoA8FKz/SR2Q2sWP0sbTxNxz/tuokeC8WxOhPMcwi0qIyGtVn/rrSeLbvVkznqCdwYnw==" + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.12.1.tgz", + "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" }, "negotiator": { "version": "0.6.1", @@ -734,8 +735,8 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "requires": { - "encoding": "0.1.12", - "is-stream": "1.1.0" + "encoding": "^0.1.11", + "is-stream": "^1.0.1" } }, "on-finished": { @@ -771,7 +772,7 @@ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==", "requires": { - "forwarded": "0.1.2", + "forwarded": "~0.1.2", "ipaddr.js": "1.8.0" } }, @@ -819,7 +820,7 @@ "depd": "1.1.1", "inherits": "2.0.3", "setprototypeof": "1.0.3", - "statuses": "1.4.0" + "statuses": ">= 1.3.1 < 2" } }, "setprototypeof": { @@ -834,26 +835,26 @@ "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", "requires": { - "aws-sign2": "0.7.0", - "aws4": "1.8.0", - "caseless": "0.12.0", - "combined-stream": "1.0.6", - "extend": "3.0.2", - "forever-agent": "0.6.1", - "form-data": "2.3.2", - "har-validator": "5.1.0", - "http-signature": "1.2.0", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.19", - "oauth-sign": "0.9.0", - "performance-now": "2.1.0", - "qs": "6.5.2", - "safe-buffer": "5.1.2", - "tough-cookie": "2.4.3", - "tunnel-agent": "0.6.0", - "uuid": "3.3.2" + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.0", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.4.3", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" }, "dependencies": { "aws4": { @@ -866,7 +867,7 @@ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", "requires": { - "delayed-stream": "1.0.0" + "delayed-stream": "~1.0.0" } }, "extend": { @@ -879,9 +880,9 @@ "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz", "integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=", "requires": { - "asynckit": "0.4.0", + "asynckit": "^0.4.0", "combined-stream": "1.0.6", - "mime-types": "2.1.19" + "mime-types": "^2.1.12" } }, "har-validator": { @@ -889,8 +890,8 @@ "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.0.tgz", "integrity": "sha512-+qnmNjI4OfH2ipQ9VQOw23bBd/ibtfbVdK2fYbY4acTDqKTW/YDp9McimZdDbG8iV9fZizUqQMD5xvriB146TA==", "requires": { - "ajv": "5.5.2", - "har-schema": "2.0.0" + "ajv": "^5.3.0", + "har-schema": "^2.0.0" } }, "mime-db": { @@ -903,7 +904,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.19.tgz", "integrity": "sha512-P1tKYHVSZ6uFo26mtnve4HQFE3koh1UWVkp8YUC+ESBHe945xWSoXuHHiGarDqcEZ+whpCDnlNw5LON0kLo+sw==", "requires": { - "mime-db": "1.35.0" + "mime-db": "~1.35.0" } }, "oauth-sign": { @@ -926,8 +927,8 @@ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", "requires": { - "psl": "1.1.29", - "punycode": "1.4.1" + "psl": "^1.1.24", + "punycode": "^1.4.1" } }, "uuid": { @@ -942,8 +943,8 @@ "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", "requires": { - "hash-base": "3.0.4", - "inherits": "2.0.3" + "hash-base": "^3.0.0", + "inherits": "^2.0.1" } }, "safe-buffer": { @@ -951,19 +952,24 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "secp256k1": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.5.2.tgz", - "integrity": "sha512-iin3kojdybY6NArd+UFsoTuapOF7bnJNf2UbcWXaY3z+E1sJDipl60vtzB5hbO/uquBu7z0fd4VC4Irp+xoFVQ==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.6.0.tgz", + "integrity": "sha512-a+oKfu2XWhq6Zzj7TexlYpwdnCEtJUUdLaujUclplPkV+INdMaV9D+81wYldm/g4/2PTFoNYZf/+0rHhTPgzjQ==", "requires": { - "bindings": "1.3.0", - "bip66": "1.1.5", - "bn.js": "4.11.8", - "create-hash": "1.2.0", - "drbg.js": "1.0.1", - "elliptic": "6.4.1", - "nan": "2.11.0", - "safe-buffer": "5.1.1" + "bindings": "^1.2.1", + "bip66": "^1.1.3", + "bn.js": "^4.11.3", + "create-hash": "^1.1.2", + "drbg.js": "^1.0.1", + "elliptic": "^6.2.3", + "nan": "^2.2.1", + "safe-buffer": "^5.1.0" } }, "secure-random": { @@ -982,18 +988,18 @@ "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", "requires": { "debug": "2.6.9", - "depd": "1.1.2", - "destroy": "1.0.4", - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "etag": "1.8.1", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "1.6.3", + "http-errors": "~1.6.2", "mime": "1.4.1", "ms": "2.0.0", - "on-finished": "2.3.0", - "range-parser": "1.2.0", - "statuses": "1.4.0" + "on-finished": "~2.3.0", + "range-parser": "~1.2.0", + "statuses": "~1.4.0" } }, "serve-static": { @@ -1001,9 +1007,9 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", "requires": { - "encodeurl": "1.0.2", - "escape-html": "1.0.3", - "parseurl": "1.3.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.2", "send": "0.16.2" } }, @@ -1017,8 +1023,8 @@ "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" } }, "shebang-command": { @@ -1026,7 +1032,7 @@ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "requires": { - "shebang-regex": "1.0.0" + "shebang-regex": "^1.0.0" } }, "shebang-regex": { @@ -1035,18 +1041,19 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" }, "sshpk": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", - "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.0.tgz", + "integrity": "sha512-Zhev35/y7hRMcID/upReIvRse+I9SVhyVre/KTJSJQWMz3C3+G+HpO7m1wK/yckEtujKZ7dS4hkVxAnmHaIGVQ==", "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" } }, "statuses": { @@ -1059,23 +1066,23 @@ "resolved": "https://registry.npmjs.org/steem/-/steem-0.7.1.tgz", "integrity": "sha512-bS3i/M7E0X38P3G7cwdVbtF2eCWlq6WLvVnpmVFHYGLovSx4zz2WLwG694qHVDtAZmxQGWuGMSSf/TPqVY/1mg==", "requires": { - "@steemit/rpc-auth": "1.1.1", - "bigi": "1.4.2", - "bluebird": "3.5.1", - "browserify-aes": "1.2.0", - "bs58": "4.0.1", - "buffer": "5.1.0", - "bytebuffer": "5.0.1", - "create-hash": "1.2.0", - "create-hmac": "1.1.7", - "cross-env": "5.2.0", - "cross-fetch": "1.1.1", - "debug": "2.6.9", - "detect-node": "2.0.3", - "ecurve": "1.0.6", - "lodash": "4.17.10", - "secure-random": "1.1.1", - "ws": "3.3.3" + "@steemit/rpc-auth": "^1.1.0", + "bigi": "^1.4.2", + "bluebird": "^3.4.6", + "browserify-aes": "^1.0.6", + "bs58": "^4.0.0", + "buffer": "^5.0.6", + "bytebuffer": "^5.0.1", + "create-hash": "^1.1.2", + "create-hmac": "^1.1.4", + "cross-env": "^5.0.0", + "cross-fetch": "^1.1.1", + "debug": "^2.6.8", + "detect-node": "^2.0.3", + "ecurve": "^1.0.5", + "lodash": "^4.16.4", + "secure-random": "^1.1.1", + "ws": "^3.3.2" } }, "tunnel-agent": { @@ -1083,14 +1090,13 @@ "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", "requires": { - "safe-buffer": "5.1.1" + "safe-buffer": "^5.0.1" } }, "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "optional": true + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "type-is": { "version": "1.6.16", @@ -1098,7 +1104,7 @@ "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", "requires": { "media-typer": "0.3.0", - "mime-types": "2.1.20" + "mime-types": "~2.1.18" } }, "ultron": { @@ -1126,9 +1132,9 @@ "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "requires": { - "assert-plus": "1.0.0", + "assert-plus": "^1.0.0", "core-util-is": "1.0.2", - "extsprintf": "1.3.0" + "extsprintf": "^1.2.0" } }, "whatwg-fetch": { @@ -1141,7 +1147,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "requires": { - "isexe": "2.0.0" + "isexe": "^2.0.0" } }, "ws": { @@ -1149,9 +1155,9 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "requires": { - "async-limiter": "1.0.0", - "safe-buffer": "5.1.1", - "ultron": "1.1.1" + "async-limiter": "~1.0.0", + "safe-buffer": "~5.1.0", + "ultron": "~1.1.0" } } } diff --git a/package.json b/package.json index 23e8d89..aa111dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postpromoter", - "version": "2.1.1", + "version": "2.1.2", "description": "Steem bid-based voting bot written in JavaScript", "main": "index.js", "scripts": { diff --git a/postpromoter.js b/postpromoter.js index a2ff2b1..7963184 100644 --- a/postpromoter.js +++ b/postpromoter.js @@ -1,28 +1,29 @@ -var fs = require("fs"); -var request = require("request"); -var steem = require('steem'); -var dsteem = require('dsteem'); -var utils = require('./utils'); - -var account = null; -var transactions = []; -var outstanding_bids = []; -var delegators = []; -var last_round = []; -var next_round = []; -var blacklist = []; -var whitelist = []; -var config = null; -var first_load = true; -var isVoting = false; -var last_withdrawal = null; -var use_delegators = false; -var round_end_timeout = -1; -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 = '2.1.1'; -var client = null; -var rpc_node = null; +const fs = require("fs"); +const request = require("request"); +const steem = require('steem'); +const dsteem = require('dsteem'); +const utils = require('./utils'); +const express = require('express'); + +let account = null; +let transactions = []; +let outstanding_bids = []; +let delegators = []; +let last_round = []; +let next_round = []; +let blacklist = []; +let whitelist = []; +let config = null; +let first_load = true; +let isVoting = false; +let last_withdrawal = null; +let use_delegators = false; +let round_end_timeout = -1; +let steem_price = 1; // This will get overridden with actual prices if a price_feed_url is specified in settings +let sbd_price = 1; // This will get overridden with actual prices if a price_feed_url is specified in settings +let version = '2.1.2'; +let client = null; +let rpc_node = null; startup(); @@ -31,13 +32,13 @@ function startup() { loadConfig(); // Connect to the specified RPC node - rpc_node = config.rpc_nodes ? config.rpc_nodes[0] : (config.rpc_node ? config.rpc_node : 'https://api.steemit.com'); + rpc_node = config['rpc_nodes'] ? config['rpc_nodes'][0] : (config['rpc_node'] ? config['rpc_node'] : 'https://api.steemit.com'); client = new dsteem.Client(rpc_node); utils.log("* START - Version: " + version + " *"); utils.log("Connected to: " + rpc_node); - if(config.backup_mode) + if(config['backup_mode']) utils.log('*** RUNNING IN BACKUP MODE ***'); // Load Steem global variables @@ -45,9 +46,8 @@ function startup() { // If the API is enabled, start the web server if(config.api && config.api.enabled) { - var express = require('express'); - var app = express(); - var port = process.env.PORT || config.api.port + let app = express(); + let port = process.env.PORT || config.api.port; app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); @@ -61,7 +61,7 @@ function startup() { // Check if bot state has been saved to disk, in which case load it if (fs.existsSync('state.json')) { - var state = JSON.parse(fs.readFileSync("state.json")); + let state = JSON.parse(String(fs.readFileSync('state.json'))); if (state.transactions) transactions = state.transactions; @@ -86,23 +86,23 @@ function startup() { } // Check whether or not auto-withdrawals are set to be paid to delegators. - use_delegators = config.auto_withdrawal && config.auto_withdrawal.active && config.auto_withdrawal.accounts.find(a => a.name == '$delegators'); + use_delegators = config['auto_withdrawal'] && config['auto_withdrawal'].active && config['auto_withdrawal']['accounts'].find(a => a.name === '$delegators'); // If so then we need to load the list of delegators to the account if(use_delegators) { if(fs.existsSync('delegators.json')) { - delegators = JSON.parse(fs.readFileSync("delegators.json")); + delegators = JSON.parse(String(fs.readFileSync("delegators.json"))); - var vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); + let vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); utils.log('Delegators Loaded (from disk) - ' + delegators.length + ' delegators and ' + vests + ' VESTS in total!'); } else { - var del = require('./delegators'); + let del = require('./delegators'); utils.log('Started loading delegators from account history...'); del.loadDelegations(client, config.account, function(d) { delegators = d; - var vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); + let vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); utils.log('Delegators Loaded (from account history) - ' + delegators.length + ' delegators and ' + vests + ' VESTS in total!'); // Save the list of delegators to disk @@ -128,12 +128,12 @@ function startProcess() { account = result[0]; if (account && !isVoting) { - var vp = utils.getVPHF20(account); + let vp = utils.getVPHF20(account); - 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((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'); + if(config['detailed_logging']) { + let bids_steem = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency === 'STEEM') ? b.amount : 0); }, 0), 3); + let bids_sbd = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency === 'SBD') ? b.amount : 0); }, 0), 3); + 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! @@ -157,7 +157,7 @@ function startProcess() { next_round = []; // Send out earnings if frequency is set to every round - if (config.auto_withdrawal.frequency == 'round_end') + if (config['auto_withdrawal'].frequency === 'round_end') processWithdrawals(); // Save the state of the bot to disk @@ -172,7 +172,7 @@ function startProcess() { claimRewards(); // Check if it is time to withdraw funds. - if (config.auto_withdrawal.frequency == 'daily') + if (config['auto_withdrawal'].frequency === 'daily') checkAutoWithdraw(); } }, function(err) { @@ -181,40 +181,40 @@ function startProcess() { } function startVoting(bids) { - if(config.backup_mode) { + if(config['backup_mode']) { utils.log('*** Bidding Round End - Backup Mode, no voting ***'); setTimeout(function () { isVoting = false; first_load = true; }, 5 * 60 * 1000); return; } // Sum the amounts of all of the bids - var total = bids.reduce(function(total, bid) { + let total = bids.reduce(function(total, bid) { return total + getUsdValue(bid); }, 0); - 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); + let bids_steem = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency === 'STEEM') ? b.amount : 0); }, 0), 3); + let bids_sbd = utils.format(outstanding_bids.reduce(function(t, b) { return t + ((b.currency === 'SBD') ? b.amount : 0); }, 0), 3); utils.log('======================================================='); utils.log('Bidding Round End! Starting to vote! Total bids: ' + bids.length + ' - $' + total + ' | ' + bids_sbd + ' SBD | ' + bids_steem + ' STEEM'); - var adjusted_weight = 1; + let adjusted_weight = 1; - if(config.max_roi != null && config.max_roi != undefined && !isNaN(config.max_roi)) { - var vote_value = utils.getVoteValue(100, account, 10000, steem_price); - var vote_value_usd = utils.getVoteValueUSD(vote_value, sbd_price) + if(config['max_roi'] != null && config['max_roi'] !== undefined && !isNaN(config['max_roi'])) { + let vote_value = utils.getVoteValue(100, account, 10000, steem_price); + let vote_value_usd = utils.getVoteValueUSD(vote_value, sbd_price); //min_total_bids_value_usd: calculates the minimum value in USD that the total bids must have to represent a maximum ROI defined in config.json //'max_roi' in config.json = 10 represents a maximum ROI of 10% - var min_total_bids_value_usd = vote_value_usd * 0.75 * ((100 - config.max_roi) / 100 ); + let min_total_bids_value_usd = vote_value_usd * 0.75 * ((100 - config['max_roi']) / 100 ); // calculates the value of the weight of the vote needed to give the maximum ROI defined adjusted_weight = (total < min_total_bids_value_usd) ? (total / min_total_bids_value_usd) : 1; - utils.log('Total vote weight: ' + (config.batch_vote_weight * adjusted_weight)); + utils.log('Total vote weight: ' + (config['batch_vote_weight'] * adjusted_weight)); } utils.log('======================================================='); - for(var i = 0; i < bids.length; i++) { + for(let i = 0; i < bids.length; i++) { // Calculate the vote weight to be used for each bid based on the amount bid as a percentage of the total bids - bids[i].weight = Math.round(config.batch_vote_weight * adjusted_weight * 100 * (getUsdValue(bids[i]) / total)); + bids[i].weight = Math.round(config['batch_vote_weight'] * adjusted_weight * 100 * (getUsdValue(bids[i]) / total)); } comment(bids.slice()); @@ -256,7 +256,7 @@ function sendVote(bid, retries, callback) { if(callback) callback(); } else { - client.broadcast.vote({ voter: account.name, author: bid.author, permlink: bid.permlink, weight: bid.weight }, dsteem.PrivateKey.fromString(config.posting_key)).then(function(result) { + client.broadcast.vote({ voter: account.name, author: bid.author, permlink: bid.permlink, weight: bid.weight }, dsteem.PrivateKey.fromString(config['posting_key'])).then(function(result) { if (result) { utils.log(utils.format(bid.weight / 100) + '% vote cast for: @' + bid.author + '/' + bid.permlink); @@ -282,24 +282,24 @@ function sendVote(bid, retries, callback) { } function sendComment(bid) { - var content = null; + let content = null; - if(config.comment_location && config.comment_location != '') { - content = fs.readFileSync(config.comment_location, "utf8"); - } else if (config.promotion_content && config.promotion_content != '') { - content = config.promotion_content; + if(config['comment_location'] && config['comment_location'] !== '') { + content = fs.readFileSync(config['comment_location'], "utf8"); + } else if (config['promotion_content'] && config['promotion_content'] !== '') { + content = config['promotion_content']; } // If promotion content is specified in the config then use it to comment on the upvoted post - if (content && content != '') { + if (content && content !== '') { // Generate the comment permlink via steemit standard convention - var permlink = 're-' + bid.author.replace(/\./g, '') + '-' + bid.permlink + '-' + new Date().toISOString().replace(/-|:|\./g, '').toLowerCase(); + let permlink = 're-' + bid.author.replace(/\./g, '') + '-' + bid.permlink + '-' + new Date().toISOString().replace(/-|:|\./g, '').toLowerCase(); // Replace variables in the promotion content content = content.replace(/\{weight\}/g, utils.format(bid.weight / 100)).replace(/\{botname\}/g, config.account).replace(/\{sender\}/g, bid.sender); - var comment = { + let comment = { author: account.name, permlink: permlink, parent_author: bid.author, @@ -310,38 +310,37 @@ function sendComment(bid) { }; // Broadcast the comment - client.broadcast.comment(comment, dsteem.PrivateKey.fromString(config.posting_key)).then(function (result) { + client.broadcast.comment(comment, dsteem.PrivateKey.fromString(config['posting_key'])).then(function (result) { if (result) utils.log('Posted comment: ' + permlink); - }, function(err) { logError('Error posting comment: ' + permlink); }); + }, function(err) { logError('Error posting comment: ' + permlink + ': ' + err); }); } // Check if the bot should resteem this post - if (config.min_resteem && bid.amount >= config.min_resteem) - resteem(bid); + if (config['min_resteem'] && bid.amount >= config['min_resteem']) resteem(bid); } function resteem(bid) { - var json = JSON.stringify(['reblog', { + let json = JSON.stringify(['reblog', { account: config.account, author: bid.author, permlink: bid.permlink }]); - client.broadcast.json({ id: 'follow', json: json, required_auths: [], required_posting_auths: [config.account] }, dsteem.PrivateKey.fromString(config.posting_key)).then(function(result) { + client.broadcast.json({ id: 'follow', json: json, required_auths: [], required_posting_auths: [config.account] }, dsteem.PrivateKey.fromString(config['posting_key'])).then(function(result) { if (result) utils.log('Resteemed Post: @' + bid.sender + '/' + bid.permlink); }, function(err) { - utils.log('Error resteeming post: @' + bid.sender + '/' + bid.permlink); + utils.log('Error resteeming post: @' + bid.sender + '/' + bid.permlink + ', Error message : ' + err); }); } function getTransactions(callback) { - var last_trx_id = null; - var num_trans = 50; + let last_trx_id = null; + let num_trans = 50; // If this is the first time the bot is ever being run, start with just the most recent transaction - if (first_load && transactions.length == 0) { + if (first_load && transactions.length === 0) { utils.log('First run - starting with last transaction on account.'); } @@ -354,8 +353,8 @@ function getTransactions(callback) { client.database.call('get_account_history', [account.name, -1, num_trans]).then(function (result) { // On first load, just record the list of the past 50 transactions so we don't double-process them. - if (first_load && transactions.length == 0) { - transactions = result.map(r => r[1].trx_id).filter(t => t != '0000000000000000000000000000000000000000'); + if (first_load && transactions.length === 0) { + transactions = result.map(r => r[1].trx_id).filter(t => String(t) !== String('0000000000000000000000000000000000000000')); first_load = false; utils.log(transactions.length + ' previous trx_ids recorded.'); @@ -367,14 +366,14 @@ function getTransactions(callback) { } first_load = false; - var reached_starting_trx = false; + let reached_starting_trx = false; - for (var i = 0; i < result.length; i++) { - var trans = result[i]; - var op = trans[1].op; + for (let i = 0; i < result.length; i++) { + let trans = result[i]; + let op = trans[1].op; // Don't need to process virtual ops - if(trans[1].trx_id == '0000000000000000000000000000000000000000') + if(trans[1].trx_id === '0000000000000000000000000000000000000000') continue; // Check that this is a new transaction that we haven't processed already @@ -382,32 +381,32 @@ function getTransactions(callback) { // If the bot was restarted after being stopped for a while, don't process transactions until we're past the last trx_id that was processed if(last_trx_id && !reached_starting_trx) { - if(trans[1].trx_id == last_trx_id) + if(trans[1].trx_id === last_trx_id) reached_starting_trx = true; continue; } - if(config.debug_logging) + if(config['debug_logging']) utils.log('Processing Transaction: ' + JSON.stringify(trans)); // We only care about transfers to the bot - if (op[0] == 'transfer' && op[1].to == config.account) { - var amount = parseFloat(op[1].amount); - var currency = utils.getCurrency(op[1].amount); + if (op[0] === 'transfer' && op[1].to === config.account) { + let amount = parseFloat(op[1].amount); + let currency = utils.getCurrency(op[1].amount); utils.log("Incoming Bid! From: " + op[1].from + ", Amount: " + op[1].amount + ", memo: " + op[1].memo); // Check for min and max bid values in configuration settings - var min_bid = config.min_bid ? parseFloat(config.min_bid) : 0; - var max_bid = config.max_bid ? parseFloat(config.max_bid) : 9999; - var max_bid_whitelist = config.max_bid_whitelist ? parseFloat(config.max_bid_whitelist) : 9999; + let min_bid = config['min_bid'] ? parseFloat(config['min_bid']) : 0; + let max_bid = config['max_bid'] ? parseFloat(config['max_bid']) : 9999; + let max_bid_whitelist = config['max_bid_whitelist'] ? parseFloat(config['max_bid_whitelist']) : 9999; - if(config.disabled_mode) { + if(config['disabled_mode']) { // Bot is disabled, refund all Bids refund(op[1].from, amount, currency, 'bot_disabled'); } else if(amount < min_bid) { // Bid amount is too low (make sure it's above the min_refund_amount setting) - if(!config.min_refund_amount || amount >= config.min_refund_amount) + if(!config['min_refund_amount'] || amount >= config['min_refund_amount']) refund(op[1].from, amount, currency, 'below_min_bid'); else { utils.log('Invalid bid - below min bid amount and too small to refund.'); @@ -418,16 +417,16 @@ function getTransactions(callback) { } else if (amount > max_bid_whitelist) { // Bid amount is too high even for whitelisted users! refund(op[1].from, amount, currency, 'above_max_bid_whitelist'); - } else if(config.currencies_accepted && config.currencies_accepted.indexOf(currency) < 0) { + } else if(config['currencies_accepted'] && config['currencies_accepted'].indexOf(currency) < 0) { // Sent an unsupported currency refund(op[1].from, amount, currency, 'invalid_currency'); } else { // Bid amount is just right! - checkPost(op[1].memo, amount, currency, op[1].from, 0); + checkPost(op[1].memo, amount, currency, op[1].from); } - } else if(use_delegators && op[0] == 'delegate_vesting_shares' && op[1].delegatee == account.name) { + } else if(use_delegators && op[0] === 'delegate_vesting_shares' && op[1].delegatee === account.name) { // If we are paying out to delegators, then update the list of delegators when new delegation transactions come in - var delegator = delegators.find(d => d.delegator == op[1].delegator); + let delegator = delegators.find(d => d.delegator === op[1].delegator); if(delegator) delegator.new_vesting_shares = op[1].vesting_shares; @@ -440,7 +439,7 @@ function getTransactions(callback) { saveDelegators(); // Check if we should send a delegation message - if(parseFloat(delegator.new_vesting_shares) > parseFloat(delegator.vesting_shares) && config.transfer_memos['delegation'] && config.transfer_memos['delegation'] != '') + if(parseFloat(delegator.new_vesting_shares) > parseFloat(delegator.vesting_shares) && config['transfer_memos']['delegation'] && config['transfer_memos']['delegation'] !== '') refund(op[1].delegator, 0.001, 'SBD', 'delegation', 0, utils.vestsToSP(parseFloat(delegator.new_vesting_shares)).toFixed()); utils.log('*** Delegation Update - ' + op[1].delegator + ' has delegated ' + op[1].vesting_shares); @@ -466,24 +465,25 @@ function getTransactions(callback) { } function checkRoundFillLimit(round, amount, currency) { - if(config.round_fill_limit == null || config.round_fill_limit == undefined || isNaN(config.round_fill_limit)) + if(config['round_fill_limit'] === null || config['round_fill_limit'] === undefined || isNaN(config['round_fill_limit'])) return false; - var vote_value = utils.getVoteValue(100, account, 10000, steem_price); - var vote_value_usd = utils.getVoteValueUSD(vote_value, sbd_price) - var bid_value = round.reduce(function(t, b) { return t + b.amount * ((b.currency == 'SBD') ? sbd_price : steem_price) }, 0); - var new_bid_value = amount * ((currency == 'SBD') ? sbd_price : steem_price); + let vote_value = utils.getVoteValue(100, account, 10000, steem_price); + let vote_value_usd = utils.getVoteValueUSD(vote_value, sbd_price); + let bid_value = round.reduce(function(t, b) { return t + b.amount * ((b.currency === 'SBD') ? sbd_price : steem_price) }, 0); + let new_bid_value = amount * ((currency === 'SBD') ? sbd_price : steem_price); // Check if the value of the bids is over the round fill limit - return (vote_value_usd * 0.75 * config.round_fill_limit < bid_value + new_bid_value); + return ((vote_value_usd * 0.75 * config['round_fill_limit']) < (bid_value + new_bid_value)); } function validatePost(author, permlink, isVoting, callback, retries) { + const memo = '@' + author + '/' + permlink; client.database.call('get_content', [author, permlink]).then(function (result) { if (result && result.id > 0) { // If comments are not allowed then we need to first check if the post is a comment - if(!config.allow_comments && (result.parent_author != null && result.parent_author != '')) { + if(!config['allow_comments'] && (result.parent_author != null && result.parent_author !== '')) { if(callback) callback('no_comments'); @@ -491,11 +491,11 @@ function validatePost(author, permlink, isVoting, callback, retries) { } // Check if any tags on this post are blacklisted in the settings - if (config.blacklist_settings.blacklisted_tags && config.blacklist_settings.blacklisted_tags.length > 0 && result.json_metadata && result.json_metadata != '') { - var tags = JSON.parse(result.json_metadata).tags; + if (config.blacklist_settings.blacklisted_tags && config.blacklist_settings.blacklisted_tags.length > 0 && result.json_metadata && result.json_metadata !== '') { + let tags = JSON.parse(result.json_metadata)['tags']; if (tags && tags.length > 0) { - var tag = tags.find(t => config.blacklist_settings.blacklisted_tags.indexOf(t) >= 0); + let tag = tags.find(t => config.blacklist_settings.blacklisted_tags.indexOf(t) >= 0); if(tag) { if(callback) @@ -506,13 +506,13 @@ function validatePost(author, permlink, isVoting, callback, retries) { } } - var created = new Date(result.created + 'Z'); - var time_until_vote = isVoting ? 0 : utils.timeTilFullPower(utils.getVPHF20(account)); + let created = new Date(result.created + 'Z'); + let time_until_vote = isVoting ? 0 : utils.timeTilFullPower(utils.getVPHF20(account)); // Get the list of votes on this post to make sure the bot didn't already vote on it (you'd be surprised how often people double-submit!) - var votes = result.active_votes.filter(function(vote) { return vote.voter == account.name; }); + let votes = result.active_votes.filter(function(vote) { return vote.voter === account.name; }); - if (votes.length > 0 || ((new Date() - created) >= (config.max_post_age * 60 * 60 * 1000) && !isVoting)) { + if (votes.length > 0 || ((new Date() - created) >= (config['max_post_age'] * 60 * 60 * 1000) && !isVoting)) { // This post is already voted on by this bot or the post is too old to be voted on if(callback) callback(((votes.length > 0) ? 'already_voted' : 'max_age')); @@ -522,7 +522,7 @@ function validatePost(author, permlink, isVoting, callback, retries) { // Check if this post has been flagged by any flag signal accounts if(config.blacklist_settings.flag_signal_accounts) { - var flags = result.active_votes.filter(function(v) { return v.percent < 0 && config.blacklist_settings.flag_signal_accounts.indexOf(v.voter) >= 0; }); + let flags = result.active_votes.filter(function(v) { return v.percent < 0 && config.blacklist_settings.flag_signal_accounts.indexOf(v.voter) >= 0; }); if(flags.length > 0) { if(callback) @@ -533,7 +533,7 @@ function validatePost(author, permlink, isVoting, callback, retries) { } // Check if this post is below the minimum post age - if(config.min_post_age && config.min_post_age > 0 && (new Date() - created + (time_until_vote * 1000)) < (config.min_post_age * 60 * 1000)) { + if(config['min_post_age'] && config['min_post_age'] > 0 && (new Date() - created + (time_until_vote * 1000)) < (config['min_post_age'] * 60 * 1000)) { if(callback) callback('min_age'); @@ -547,8 +547,6 @@ function validatePost(author, permlink, isVoting, callback, retries) { // Invalid memo if(callback) callback('invalid_post_url'); - - return; } }, function(err) { logError('Error loading post: ' + memo + ', Error: ' + err); @@ -561,19 +559,17 @@ function validatePost(author, permlink, isVoting, callback, retries) { if(callback) callback('invalid_post_url'); - - return; } }); } -function checkPost(memo, amount, currency, sender, retries) { - var affiliate = null; +function checkPost(memo, amount, currency, sender) { + let affiliate = null; // Check if this bid is through an affiliate service - if(config.affiliates && config.affiliates.length > 0) { - for(var i = 0; i < config.affiliates.length; i++) { - var cur = config.affiliates[i]; + if(config['affiliates'] && config['affiliates'].length > 0) { + for(let i = 0; i < config['affiliates'].length; i++) { + let cur = config['affiliates'][i]; if(memo.startsWith(cur.name)) { memo = memo.split(' ')[1]; @@ -584,20 +580,21 @@ function checkPost(memo, amount, currency, sender, retries) { } // Parse the author and permlink from the memo URL - var permLink = memo.substr(memo.lastIndexOf('/') + 1); - var site = memo.substring(memo.indexOf('://')+3,memo.indexOf('/', memo.indexOf('://')+3)); + let permLink = memo.substr(memo.lastIndexOf('/') + 1); + let site = memo.substring(memo.indexOf('://')+3,memo.indexOf('/', memo.indexOf('://')+3)); + let author = ''; switch(site) { case 'd.tube': - var author = memo.substring(memo.indexOf("/v/")+3,memo.lastIndexOf('/')); + author = memo.substring(memo.indexOf("/v/")+3,memo.lastIndexOf('/')); break; case 'dmania.lol': - var author = memo.substring(memo.indexOf("/post/")+6,memo.lastIndexOf('/')); + author = memo.substring(memo.indexOf("/post/")+6,memo.lastIndexOf('/')); break; default: - var author = memo.substring(memo.lastIndexOf('@') + 1, memo.lastIndexOf('/')); + author = memo.substring(memo.lastIndexOf('@') + 1, memo.lastIndexOf('/')); } - if (author == '' || permLink == '') { + if (author === '' || permLink === '') { refund(sender, amount, currency, 'invalid_post_url'); return; } @@ -610,21 +607,21 @@ function checkPost(memo, amount, currency, sender, retries) { } // If this bot is whitelist-only then make sure the sender is on the whitelist - if(config.blacklist_settings.whitelist_only && whitelist.indexOf(sender) < 0) { + if(config.blacklist_settings['whitelist_only'] && whitelist.indexOf(sender) < 0) { refund(sender, amount, currency, 'whitelist_only'); return; } // Check if this author has gone over the max bids per author per round - if(config.max_per_author_per_round && config.max_per_author_per_round > 0) { - if(outstanding_bids.filter(b => b.author == author).length >= config.max_per_author_per_round) + if(config['max_per_author_per_round'] && config['max_per_author_per_round'] > 0) { + if(outstanding_bids.filter(b => b.author === author).length >= config['max_per_author_per_round']) { refund(sender, amount, currency, 'bids_per_round'); return; } } - var push_to_next_round = false; + let push_to_next_round = false; checkGlobalBlacklist(author, sender, function(onBlacklist) { if(onBlacklist) { handleBlacklist(author, sender, amount, currency); @@ -632,7 +629,7 @@ function checkPost(memo, amount, currency, sender, retries) { } validatePost(author, permLink, false, function(error) { - if(error && error != 'min_age') { + if(error && error !== 'min_age') { refund(sender, amount, currency, error); return; } @@ -649,26 +646,31 @@ function checkPost(memo, amount, currency, sender, retries) { } // Add the bid to the current round or the next round if the current one is full or the post is too new - var round = (push_to_next_round || error == 'min_age') ? next_round : outstanding_bids; + let round = (push_to_next_round || error === 'min_age') ? next_round : outstanding_bids; // Check if there is already a bid for this post in the current round - var existing_bid = round.find(bid => bid.url == memo); + let existing_bid = round.find(bid => bid.url === memo); + + // Check if there is already a bid for this post in the next round + if (!existing_bid){ + existing_bid = next_round.find(bid => bid.url === memo); + } if(existing_bid) { // There is already a bid for this post in the current round utils.log('Existing Bid Found - New Amount: ' + amount + ', Total Amount: ' + (existing_bid.amount + amount)); - var new_amount = 0; + let new_amount = 0; - if(existing_bid.currency == currency) { + if(existing_bid.currency === currency) { new_amount = existing_bid.amount + amount; - } else if(existing_bid.currency == 'STEEM') { + } else if(existing_bid.currency === 'STEEM') { new_amount = existing_bid.amount + amount * sbd_price / steem_price; - } else if(existing_bid.currency == 'SBD') { + } 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; + let max_bid = config['max_bid'] ? parseFloat(config['max_bid']) : 9999; // Check that the new total doesn't exceed the max bid amount per post if (new_amount > max_bid) @@ -682,14 +684,14 @@ function checkPost(memo, amount, currency, sender, retries) { // If this bid is through an affiliate service, send the fee payout if(affiliate) { - refund(affiliate.beneficiary, amount * (affiliate.fee_pct / 10000), currency, 'affiliate', 0, 'Sender: @' + sender + ', Post: ' + memo); + refund(affiliate['beneficiary'], amount * (affiliate['fee_pct'] / 10000), currency, 'affiliate', 0, 'Sender: @' + sender + ', Post: ' + memo); } } // If a witness_vote transfer memo is set, check if the sender votes for the bot owner as witness and send them a message if not - if (config.transfer_memos['witness_vote'] && config.transfer_memos['witness_vote'] != '') { + if (config['transfer_memos']['witness_vote'] && config['transfer_memos']['witness_vote'] !== '') { checkWitnessVote(sender, sender, currency); - } else if(!push_to_next_round && config.transfer_memos['bid_confirmation'] && config.transfer_memos['bid_confirmation'] != '') { + } else if(!push_to_next_round && config['transfer_memos']['bid_confirmation'] && config['transfer_memos']['bid_confirmation'] !== '') { // Send bid confirmation transfer memo if one is specified refund(sender, 0.001, currency, 'bid_confirmation', 0); } @@ -698,24 +700,24 @@ function checkPost(memo, amount, currency, sender, retries) { } function checkGlobalBlacklist(author, sender, callback) { - if(!config.blacklist_settings || !config.blacklist_settings.global_api_blacklists || !Array.isArray(config.blacklist_settings.global_api_blacklists)) { + if(!config.blacklist_settings || !config.blacklist_settings['global_api_blacklists'] || !Array.isArray(config.blacklist_settings['global_api_blacklists'])) { callback(null); return; } request.get('http://blacklist.usesteem.com/user/' + author, function(e, r, data) { try { - var result = JSON.parse(data); + let result = JSON.parse(data); - if(!result.blacklisted || !Array.isArray(result.blacklisted)) { + if(!result['blacklisted'] || !Array.isArray(result['blacklisted'])) { callback(null); return; } - if(author != sender) { + if(author !== sender) { checkGlobalBlacklist(sender, sender, callback); } else - callback(config.blacklist_settings.global_api_blacklists.find(b => result.blacklisted.indexOf(b) >= 0)); + callback(config.blacklist_settings['global_api_blacklists'].find(b => result['blacklisted'].indexOf(b) >= 0)); } catch(err) { utils.log('Error loading global blacklist info for user @' + author + ', Error: ' + err); callback(null); @@ -724,14 +726,14 @@ function checkGlobalBlacklist(author, sender, callback) { } function handleBlacklist(author, sender, amount, currency) { - utils.log('Invalid Bid - @' + author + ((author != sender) ? ' or @' + sender : '') + ' is on the blacklist!'); + utils.log('Invalid Bid - @' + author + ((author !== sender) ? ' or @' + sender : '') + ' is on the blacklist!'); // Refund the bid only if blacklist_refunds are enabled in config if (config.blacklist_settings.refund_blacklist) refund(sender, amount, currency, 'blacklist_refund', 0); else { // Otherwise just send a 0.001 transaction with blacklist memo - if (config.transfer_memos['blacklist_no_refund'] && config.transfer_memos['blacklist_no_refund'] != '') + if (config['transfer_memos']['blacklist_no_refund'] && config['transfer_memos']['blacklist_no_refund'] !== '') refund(sender, 0.001, currency, 'blacklist_no_refund', 0); // If a blacklist donation account is specified then send funds from blacklisted users there @@ -740,6 +742,7 @@ function handleBlacklist(author, sender, amount, currency) { } } +/* function handleFlag(sender, amount, currency) { utils.log('Invalid Bid - This post has been flagged by one or more spam / abuse indicator accounts.'); @@ -748,29 +751,29 @@ function handleFlag(sender, amount, currency) { refund(sender, amount, currency, 'flag_refund', 0); else { // Otherwise just send a 0.001 transaction with blacklist memo - if (config.transfer_memos['flag_no_refund'] && config.transfer_memos['flag_no_refund'] != '') + if (config['transfer_memos']['flag_no_refund'] && config['transfer_memos']['flag_no_refund'] !== '') refund(sender, 0.001, currency, 'flag_no_refund', 0); // If a blacklist donation account is specified then send funds from blacklisted users there if (config.blacklist_settings.blacklist_donation_account) refund(config.blacklist_settings.blacklist_donation_account, amount - 0.001, currency, 'blacklist_donation', 0); } -} +}*/ function checkWitnessVote(sender, voter, currency) { - if(!config.owner_account || config.owner_account == '') + if(!config['owner_account'] || config['owner_account'] === '') return; client.database.getAccounts([voter]).then(function (result) { if (result) { - if (result[0].proxy && result[0].proxy != '') { + if (result[0].proxy && result[0].proxy !== '') { checkWitnessVote(sender, result[0].proxy, currency); return; } - if(result[0].witness_votes.indexOf(config.owner_account) < 0) + if(result[0].witness_votes.indexOf(config['owner_account']) < 0) refund(sender, 0.001, currency, 'witness_vote', 0); - else if(config.transfer_memos['bid_confirmation'] && config.transfer_memos['bid_confirmation'] != '') { + else if(config['transfer_memos']['bid_confirmation'] && config['transfer_memos']['bid_confirmation'] !== '') { // Send bid confirmation transfer memo if one is specified refund(sender, 0.001, currency, 'bid_confirmation', 0); } @@ -781,7 +784,7 @@ function checkWitnessVote(sender, voter, currency) { } function saveState() { - var state = { + let state = { outstanding_bids: outstanding_bids, last_round: last_round, next_round: next_round, @@ -791,12 +794,10 @@ function saveState() { }; // Save the state of the bot to disk - fs.writeFile('state.json', JSON.stringify(state, null, 2), function (err) { - if (err) - utils.log(err); - }); + fs.writeFileSync('state.json', JSON.stringify(state, null, 2)); } +/* function updateVersion(old_version, new_version) { utils.log('**** Performing Update Steps from version: ' + old_version + ' to version: ' + new_version); @@ -810,7 +811,7 @@ function updateVersion(old_version, new_version) { }); } } -} +}/*/ function saveDelegators() { // Save the list of delegators to disk @@ -821,7 +822,7 @@ function saveDelegators() { } function refund(sender, amount, currency, reason, retries, data) { - if(config.backup_mode) { + if(config['backup_mode']) { utils.log('Backup Mode - not sending refund of ' + amount + ' ' + currency + ' to @' + sender + ' for reason: ' + reason); return; } @@ -830,39 +831,39 @@ function refund(sender, amount, currency, reason, retries, data) { retries = 0; // Make sure refunds are enabled and the sender isn't on the no-refund list (for exchanges and things like that). - if (reason != 'forward_payment' && (!config.refunds_enabled || sender == config.account || (config.no_refund && config.no_refund.indexOf(sender) >= 0))) { + if (reason !== 'forward_payment' && (!config['refunds_enabled'] || sender === config.account || (config['no_refund'] && config['no_refund'].indexOf(sender) >= 0))) { utils.log("Invalid bid - " + reason + ' NO REFUND'); // If this is a payment from an account on the no_refund list, forward the payment to the post_rewards_withdrawal_account - if(config.no_refund && config.no_refund.indexOf(sender) >= 0 && config.post_rewards_withdrawal_account && config.post_rewards_withdrawal_account != '' && sender != config.post_rewards_withdrawal_account) - refund(config.post_rewards_withdrawal_account, amount, currency, 'forward_payment', 0, sender); + if(config['no_refund'] && config['no_refund'].indexOf(sender) >= 0 && config['post_rewards_withdrawal_account'] && config['post_rewards_withdrawal_account'] !== '' && sender !== config['post_rewards_withdrawal_account']) + refund(config['post_rewards_withdrawal_account'], amount, currency, 'forward_payment', 0, sender); return; } // Replace variables in the memo text - var memo = config.transfer_memos[reason]; + let memo = config['transfer_memos'][reason]; if(!memo) memo = reason; memo = memo.replace(/{amount}/g, utils.format(amount, 3) + ' ' + currency); memo = memo.replace(/{currency}/g, currency); - memo = memo.replace(/{min_bid}/g, config.min_bid); - memo = memo.replace(/{max_bid}/g, config.max_bid); - memo = memo.replace(/{max_bid_whitelist}/g, config.max_bid_whitelist); + memo = memo.replace(/{min_bid}/g, config['min_bid']); + memo = memo.replace(/{max_bid}/g, config['max_bid']); + memo = memo.replace(/{max_bid_whitelist}/g, config['max_bid_whitelist']); memo = memo.replace(/{account}/g, config.account); - memo = memo.replace(/{owner}/g, config.owner_account); - memo = memo.replace(/{min_age}/g, config.min_post_age); + memo = memo.replace(/{owner}/g, config['owner_account']); + memo = memo.replace(/{min_age}/g, config['min_post_age']); memo = memo.replace(/{sender}/g, sender); memo = memo.replace(/{tag}/g, data); - var days = Math.floor(config.max_post_age / 24); - var hours = (config.max_post_age % 24); + let days = Math.floor(config['max_post_age'] / 24); + let hours = (config['max_post_age'] % 24); memo = memo.replace(/{max_age}/g, days + ' Day(s)' + ((hours > 0) ? ' ' + hours + ' Hour(s)' : '')); // Issue the refund. - client.broadcast.transfer({ amount: utils.format(amount, 3) + ' ' + currency, from: config.account, to: sender, memo: memo }, dsteem.PrivateKey.fromString(config.active_key)).then(function(response) { + client.broadcast.transfer({ amount: utils.format(amount, 3) + ' ' + currency, from: config.account, to: sender, memo: memo }, dsteem.PrivateKey.fromString(config['active_key'])).then(function() { utils.log('Refund of ' + amount + ' ' + currency + ' sent to @' + sender + ' for reason: ' + reason); }, function(err) { logError('Error sending refund to @' + sender + ' for: ' + amount + ' ' + currency + ', Error: ' + err); @@ -876,16 +877,16 @@ function refund(sender, amount, currency, reason, retries, data) { } function claimRewards() { - if (!config.auto_claim_rewards || config.backup_mode) + if (!config['auto_claim_rewards'] || config['backup_mode']) return; // Make api call only if you have actual reward if (parseFloat(account.reward_steem_balance) > 0 || parseFloat(account.reward_sbd_balance) > 0 || parseFloat(account.reward_vesting_balance) > 0) { - var op = ['claim_reward_balance', { account: config.account, reward_sbd: account.reward_sbd_balance, reward_steem: account.reward_steem_balance, reward_vests: account.reward_vesting_balance }]; - client.broadcast.sendOperations([op], dsteem.PrivateKey.fromString(config.posting_key)).then(function(result) { + let op = ['claim_reward_balance', { account: config.account, reward_sbd: account.reward_sbd_balance, reward_steem: account.reward_steem_balance, reward_vests: account.reward_vesting_balance }]; + client.broadcast.sendOperations([op], dsteem.PrivateKey.fromString(config['posting_key'])).then(function(result) { if (result) { - if(config.detailed_logging) { - var rewards_message = "$$$ ==> Rewards Claim"; + if(config['detailed_logging']) { + let rewards_message = "$$$ ==> Rewards Claim"; if (parseFloat(account.reward_sbd_balance) > 0) { rewards_message = rewards_message + ' SBD: ' + parseFloat(account.reward_sbd_balance); } if (parseFloat(account.reward_steem_balance) > 0) { rewards_message = rewards_message + ' STEEM: ' + parseFloat(account.reward_steem_balance); } if (parseFloat(account.reward_vesting_balance) > 0) { rewards_message = rewards_message + ' VESTS: ' + parseFloat(account.reward_vesting_balance); } @@ -894,68 +895,68 @@ function claimRewards() { } // If there are liquid SBD rewards, withdraw them to the specified account - if(parseFloat(account.reward_sbd_balance) > 0 && config.post_rewards_withdrawal_account && config.post_rewards_withdrawal_account != '') { + if(parseFloat(account.reward_sbd_balance) > 0 && config['post_rewards_withdrawal_account'] && config['post_rewards_withdrawal_account'] !== '') { // Send liquid post rewards to the specified account - client.broadcast.transfer({ amount: account.reward_sbd_balance, from: config.account, to: config.post_rewards_withdrawal_account, memo: 'Liquid Post Rewards Withdrawal' }, dsteem.PrivateKey.fromString(config.active_key)).then(function(response) { - utils.log('$$$ Auto withdrawal - liquid post rewards: ' + account.reward_sbd_balance + ' sent to @' + config.post_rewards_withdrawal_account); + client.broadcast.transfer({ amount: account.reward_sbd_balance, from: config.account, to: config['post_rewards_withdrawal_account'], memo: 'Liquid Post Rewards Withdrawal' }, dsteem.PrivateKey.fromString(config['active_key'])).then(function() { + utils.log('$$$ Auto withdrawal - liquid post rewards: ' + account.reward_sbd_balance + ' sent to @' + config['post_rewards_withdrawal_account']); }, function(err) { utils.log('Error transfering liquid SBD post rewards: ' + err); }); } // If there are liquid STEEM rewards, withdraw them to the specified account - if(parseFloat(account.reward_steem_balance) > 0 && config.post_rewards_withdrawal_account && config.post_rewards_withdrawal_account != '') { + if(parseFloat(account.reward_steem_balance) > 0 && config['post_rewards_withdrawal_account'] && config['post_rewards_withdrawal_account'] !== '') { // Send liquid post rewards to the specified account - client.broadcast.transfer({ amount: account.reward_steem_balance, from: config.account, to: config.post_rewards_withdrawal_account, memo: 'Liquid Post Rewards Withdrawal' }, dsteem.PrivateKey.fromString(config.active_key)).then(function(response) { - utils.log('$$$ Auto withdrawal - liquid post rewards: ' + account.reward_steem_balance + ' sent to @' + config.post_rewards_withdrawal_account); + client.broadcast.transfer({ amount: account.reward_steem_balance, from: config.account, to: config['post_rewards_withdrawal_account'], memo: 'Liquid Post Rewards Withdrawal' }, dsteem.PrivateKey.fromString(config['active_key'])).then(function() { + utils.log('$$$ Auto withdrawal - liquid post rewards: ' + account.reward_steem_balance + ' sent to @' + config['post_rewards_withdrawal_account']); }, function(err) { utils.log('Error transfering liquid STEEM post rewards: ' + err); }); } } - }, function(err) { utils.log('Error claiming rewards...will try again next time.'); }); + }, function(err) { utils.log('Error claiming rewards...will try again next time., error message: ' + err); }); } } function checkAutoWithdraw() { // Check if auto-withdraw is active - if (!config.auto_withdrawal.active) + if (!config['auto_withdrawal'].active) return; // If it's past the withdrawal time and we haven't made a withdrawal today, then process the withdrawal - if (new Date(new Date().toDateString()) > new Date(last_withdrawal) && new Date().getHours() >= config.auto_withdrawal.execute_time) { + if (new Date(new Date().toDateString()) > new Date(last_withdrawal) && new Date().getHours() >= config['auto_withdrawal']['execute_time']) { processWithdrawals(); } } function processWithdrawals() { - if(config.backup_mode) + 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; + let has_sbd = config['currencies_accepted'].indexOf('SBD') >= 0 && parseFloat(account.sbd_balance) > 0; + let has_steem = config['currencies_accepted'].indexOf('STEEM') >= 0 && parseFloat(account.balance) > 0; if (has_sbd || has_steem) { // Save the date of the last withdrawal last_withdrawal = new Date().toDateString(); - var total_stake = config.auto_withdrawal.accounts.reduce(function (total, info) { return total + info.stake; }, 0); + let total_stake = config['auto_withdrawal']['accounts'].reduce(function (total, info) { return total + info['stake']; }, 0); - var withdrawals = []; + let withdrawals = []; - for(var i = 0; i < config.auto_withdrawal.accounts.length; i++) { - var withdrawal_account = config.auto_withdrawal.accounts[i]; + for(let i = 0; i < config['auto_withdrawal']['accounts'].length; i++) { + let withdrawal_account = config['auto_withdrawal']['accounts'][i]; // If this is the special $delegators account, split it between all delegators to the bot - if(withdrawal_account.name == '$delegators') { + if(withdrawal_account.name === '$delegators') { // Check if/where we should send payout for SP in the bot account directly - if(withdrawal_account.overrides) { - var bot_override = withdrawal_account.overrides.find(o => o.name == config.account); + if(withdrawal_account['overrides']) { + let bot_override = withdrawal_account['overrides'].find(o => o.name === config.account); - if(bot_override && bot_override.beneficiary) { - var bot_delegator = delegators.find(d => d.delegator == config.account); + if(bot_override && bot_override['beneficiary']) { + let bot_delegator = delegators.find(d => d.delegator === config.account); // Calculate the amount of SP in the bot account and add/update it in the list of delegators - var bot_vesting_shares = (parseFloat(account.vesting_shares) - parseFloat(account.delegated_vesting_shares)).toFixed(6) + ' VESTS'; + let bot_vesting_shares = (parseFloat(account.vesting_shares) - parseFloat(account.delegated_vesting_shares)).toFixed(6) + ' VESTS'; if(bot_delegator) bot_delegator.vesting_shares = bot_vesting_shares; @@ -965,47 +966,47 @@ function processWithdrawals() { } // Get the total amount delegated by all delegators - var total_vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); + let total_vests = delegators.reduce(function (total, v) { return total + parseFloat(v.vesting_shares); }, 0); // Send the withdrawal to each delegator based on their delegation amount - for(var j = 0; j < delegators.length; j++) { - var delegator = delegators[j]; - var to_account = delegator.delegator; + for(let j = 0; j < delegators.length; j++) { + let delegator = delegators[j]; + let to_account = delegator.delegator; // Check if this delegator has an override and if so send the payment to the beneficiary instead - if(withdrawal_account.overrides) { - var override = withdrawal_account.overrides.find(o => o.name == to_account); + if(withdrawal_account['overrides']) { + let override = withdrawal_account['overrides'].find(o => o.name === to_account); - if(override && override.beneficiary) - to_account = override.beneficiary; + if(override && override['beneficiary']) + to_account = override['beneficiary']; } if(has_sbd) { // Check if there is already an SBD withdrawal to this account - var withdrawal = withdrawals.find(w => w.to == to_account && w.currency == 'SBD'); + let withdrawal = withdrawals.find(w => w.to === to_account && w.currency === 'SBD'); if(withdrawal) { - withdrawal.amount += parseFloat(account.sbd_balance) * (withdrawal_account.stake / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001; + withdrawal.amount += parseFloat(account.sbd_balance) * (withdrawal_account['stake'] / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001; } else { withdrawals.push({ to: to_account, currency: 'SBD', - amount: parseFloat(account.sbd_balance) * (withdrawal_account.stake / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001 + amount: parseFloat(account.sbd_balance) * (withdrawal_account['stake'] / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001 }); } } if(has_steem) { // Check if there is already a STEEM withdrawal to this account - var withdrawal = withdrawals.find(w => w.to == to_account && w.currency == 'STEEM'); + let withdrawal = withdrawals.find(w => w.to === to_account && w.currency === 'STEEM'); if(withdrawal) { - withdrawal.amount += parseFloat(account.balance) * (withdrawal_account.stake / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001; + withdrawal.amount += parseFloat(account.balance) * (withdrawal_account['stake'] / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001; } else { withdrawals.push({ to: to_account, currency: 'STEEM', - amount: parseFloat(account.balance) * (withdrawal_account.stake / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001 + amount: parseFloat(account.balance) * (withdrawal_account['stake'] / total_stake) * (parseFloat(delegator.vesting_shares) / total_vests) - 0.001 }); } } @@ -1013,30 +1014,30 @@ function processWithdrawals() { } else { if(has_sbd) { // Check if there is already an SBD withdrawal to this account - var withdrawal = withdrawals.find(w => w.to == withdrawal_account.name && w.currency == 'SBD'); + let withdrawal = withdrawals.find(w => w.to === withdrawal_account.name && w.currency === 'SBD'); if(withdrawal) { - withdrawal.amount += parseFloat(account.sbd_balance) * withdrawal_account.stake / total_stake - 0.001; + withdrawal.amount += parseFloat(account.sbd_balance) * withdrawal_account['stake'] / total_stake - 0.001; } else { withdrawals.push({ to: withdrawal_account.name, currency: 'SBD', - amount: parseFloat(account.sbd_balance) * withdrawal_account.stake / total_stake - 0.001 + amount: parseFloat(account.sbd_balance) * withdrawal_account['stake'] / total_stake - 0.001 }); } } if(has_steem) { // Check if there is already a STEEM withdrawal to this account - var withdrawal = withdrawals.find(w => w.to == withdrawal_account.name && w.currency == 'STEEM'); + let withdrawal = withdrawals.find(w => w.to === withdrawal_account.name && w.currency === 'STEEM'); if(withdrawal) { - withdrawal.amount += parseFloat(account.balance) * withdrawal_account.stake / total_stake - 0.001; + withdrawal.amount += parseFloat(account.balance) * withdrawal_account['stake'] / total_stake - 0.001; } else { withdrawals.push({ to: withdrawal_account.name, currency: 'STEEM', - amount: parseFloat(account.balance) * withdrawal_account.stake / total_stake - 0.001 + amount: parseFloat(account.balance) * withdrawal_account['stake'] / total_stake - 0.001 }); } } @@ -1044,20 +1045,20 @@ function processWithdrawals() { } // Check if the memo should be encrypted - var encrypt = (config.auto_withdrawal.memo.startsWith('#') && config.memo_key && config.memo_key != ''); + let encrypt = (config['auto_withdrawal'].memo.startsWith('#') && config.memo_key && config.memo_key !== ''); if(encrypt) { // Get list of unique withdrawal account names - var account_names = withdrawals.map(w => w.to).filter((v, i, s) => s.indexOf(v) === i); + let account_names = withdrawals.map(w => w.to).filter((v, i, s) => s.indexOf(v) === i); // Load account info to get memo keys for encryption client.database.getAccounts(account_names).then(function (result) { if (result) { - for(var i = 0; i < result.length; i++) { - var withdrawal_account = result[i]; - var matches = withdrawals.filter(w => w.to == withdrawal_account.name); + for(let i = 0; i < result.length; i++) { + let withdrawal_account = result[i]; + let matches = withdrawals.filter(w => w.to === withdrawal_account.name); - for(var j = 0; j < matches.length; j++) { + for(let j = 0; j < matches.length; j++) { matches[j].memo_key = withdrawal_account.memo_key; } } @@ -1075,10 +1076,10 @@ function processWithdrawals() { } function updateDelegations() { - var updates = delegators.filter(d => parseFloat(d.new_vesting_shares) >= 0); + let updates = delegators.filter(d => parseFloat(d.new_vesting_shares) >= 0); - for (var i = 0; i < updates.length; i++) { - var delegator = updates[i]; + for (let i = 0; i < updates.length; i++) { + let delegator = updates[i]; delegator.vesting_shares = delegator.new_vesting_shares; delegator.new_vesting_shares = null; @@ -1106,15 +1107,15 @@ function sendWithdrawal(withdrawal, retries, callback) { return; } - var formatted_amount = utils.format(withdrawal.amount, 3).replace(/,/g, '') + ' ' + withdrawal.currency; - var memo = config.auto_withdrawal.memo.replace(/\{balance\}/g, formatted_amount); + let formatted_amount = utils.format(withdrawal.amount, 3).replace(/,/g, '') + ' ' + withdrawal.currency; + let memo = config['auto_withdrawal'].memo.replace(/\{balance\}/g, formatted_amount); // Encrypt memo - if (memo.startsWith('#') && config.memo_key && config.memo_key != '') + if (memo.startsWith('#') && config.memo_key && config.memo_key !== '') memo = steem.memo.encode(config.memo_key, withdrawal.memo_key, memo); // Send the withdrawal amount to the specified account - client.broadcast.transfer({ amount: formatted_amount, from: config.account, to: withdrawal.to, memo: memo }, dsteem.PrivateKey.fromString(config.active_key)).then(function(response) { + client.broadcast.transfer({ amount: formatted_amount, from: config.account, to: withdrawal.to, memo: memo }, dsteem.PrivateKey.fromString(config['active_key'])).then(function() { utils.log('$$$ Auto withdrawal: ' + formatted_amount + ' sent to @' + withdrawal.to); if(callback) @@ -1135,11 +1136,11 @@ function sendWithdrawal(withdrawal, retries, callback) { } function loadPrices() { - if(config.price_source == 'coinmarketcap') { + if(config['price_source'] === 'coinmarketcap') { // Load the price feed data request.get('https://api.coinmarketcap.com/v1/ticker/steem/', function (e, r, data) { try { - steem_price = parseFloat(JSON.parse(data)[0].price_usd); + steem_price = parseFloat(JSON.parse(data)[0]['price_usd']); utils.log("Loaded STEEM price: " + steem_price); } catch (err) { @@ -1150,18 +1151,18 @@ function loadPrices() { // Load the price feed data request.get('https://api.coinmarketcap.com/v1/ticker/steem-dollars/', function (e, r, data) { try { - sbd_price = parseFloat(JSON.parse(data)[0].price_usd); + sbd_price = parseFloat(JSON.parse(data)[0]['price_usd']); utils.log("Loaded SBD price: " + sbd_price); } catch (err) { utils.log('Error loading SBD price: ' + err); } }); - } else if (config.price_source && config.price_source.startsWith('http')) { - request.get(config.price_source, function (e, r, data) { + } else if (config['price_source'] && config['price_source'].startsWith('http')) { + request.get(config['price_source'], function (e, r, data) { try { - sbd_price = parseFloat(JSON.parse(data).sbd_price); - steem_price = parseFloat(JSON.parse(data).steem_price); + sbd_price = parseFloat(JSON.parse(data)['sbd_price']); + steem_price = parseFloat(JSON.parse(data)['steem_price']); utils.log("Loaded STEEM price: " + steem_price); utils.log("Loaded SBD price: " + sbd_price); @@ -1174,7 +1175,7 @@ function loadPrices() { request.get('https://api.coinmarketcap.com/v1/ticker/bitcoin/', function (e, r, data) { request.get('https://bittrex.com/api/v1.1/public/getticker?market=BTC-STEEM', function (e, r, btc_data) { try { - steem_price = parseFloat(JSON.parse(data)[0].price_usd) * parseFloat(JSON.parse(btc_data).result.Last); + steem_price = parseFloat(JSON.parse(data)[0]['price_usd']) * parseFloat(JSON.parse(btc_data).result['Last']); utils.log('Loaded STEEM Price from Bittrex: ' + steem_price); } catch (err) { utils.log('Error loading STEEM price from Bittrex: ' + err); @@ -1183,7 +1184,7 @@ function loadPrices() { request.get('https://bittrex.com/api/v1.1/public/getticker?market=BTC-SBD', function (e, r, btc_data) { try { - sbd_price = parseFloat(JSON.parse(data)[0].price_usd) * parseFloat(JSON.parse(btc_data).result.Last); + sbd_price = parseFloat(JSON.parse(data)[0]['price_usd']) * parseFloat(JSON.parse(btc_data).result['Last']); utils.log('Loaded SBD Price from Bittrex: ' + sbd_price); } catch (err) { utils.log('Error loading SBD price from Bittrex: ' + err); @@ -1193,7 +1194,7 @@ function loadPrices() { } } -function getUsdValue(bid) { return bid.amount * ((bid.currency == 'SBD') ? sbd_price : steem_price); } +function getUsdValue(bid) { return bid.amount * ((bid.currency === 'SBD') ? sbd_price : steem_price); } function logFailedBid(bid, message) { try { @@ -1202,10 +1203,10 @@ function logFailedBid(bid, message) { if (message.indexOf('assert_exception') >= 0 && message.indexOf('ERR_ASSERTION') >= 0) return; - var failed_bids = []; + let failed_bids = []; if(fs.existsSync("failed-bids.json")) - failed_bids = JSON.parse(fs.readFileSync("failed-bids.json")); + failed_bids = JSON.parse(String(fs.readFileSync("failed-bids.json"))); bid.error = message; failed_bids.push(bid); @@ -1220,7 +1221,7 @@ function logFailedBid(bid, message) { } function loadConfig() { - config = JSON.parse(fs.readFileSync("config.json")); + config = JSON.parse(String(fs.readFileSync("config.json"))); // Backwards compatibility for blacklist settings if(!config.blacklist_settings) { @@ -1233,17 +1234,15 @@ function loadConfig() { }; } - var newBlacklist = []; - // Load the blacklist utils.loadUserList(config.blacklist_settings.blacklist_location, function(list1) { - var list = []; + let list = []; if(list1) list = list1; // Load the shared blacklist - utils.loadUserList(config.blacklist_settings.shared_blacklist_location, function(list2) { + utils.loadUserList(config.blacklist_settings['shared_blacklist_location'], function(list2) { if(list2) list = list.concat(list2.filter(i => list.indexOf(i) < 0)); @@ -1253,23 +1252,23 @@ function loadConfig() { }); // Load the whitelist - utils.loadUserList(config.blacklist_settings.whitelist_location, function(list) { + utils.loadUserList(config.blacklist_settings['whitelist_location'], function(list) { if(list) whitelist = list; }); } function failover() { - if(config.rpc_nodes && config.rpc_nodes.length > 1) { + if(config['rpc_nodes'] && config['rpc_nodes'].length > 1) { // Give it a minute after the failover to account for more errors coming in from the original node setTimeout(function() { error_count = 0; }, 60 * 1000); - var cur_node_index = config.rpc_nodes.indexOf(rpc_node) + 1; + let cur_node_index = config['rpc_nodes'].indexOf(rpc_node) + 1; - if(cur_node_index == config.rpc_nodes.length) + if(cur_node_index === config['rpc_nodes'].length) cur_node_index = 0; - rpc_node = config.rpc_nodes[cur_node_index]; + rpc_node = config['rpc_nodes'][cur_node_index]; client = new dsteem.Client(rpc_node); utils.log(''); @@ -1280,7 +1279,7 @@ function failover() { } } -var error_count = 0; +let error_count = 0; function logError(message) { // Don't count assert exceptions for node failover if (message.indexOf('assert_exception') < 0 && message.indexOf('ERR_ASSERTION') < 0) diff --git a/utils.js b/utils.js index 754e56f..a05d660 100644 --- a/utils.js +++ b/utils.js @@ -1,30 +1,31 @@ -var fs = require("fs"); -var dsteem = require('dsteem'); - -var STEEMIT_100_PERCENT = 10000; -var STEEMIT_VOTE_REGENERATION_SECONDS = (5 * 60 * 60 * 24); -var HOURS = 60 * 60; - - var steemPrice; - var rewardBalance; - var recentClaims; - var currentUserAccount; - var votePowerReserveRate; - var totalVestingFund; - var totalVestingShares; - var steem_per_mvests; - var sbd_print_percentage; +const fs = require('fs'); +//const dsteem = require('dsteem'); + + +const STEEMIT_100_PERCENT = 10000; +const STEEMIT_VOTE_REGENERATION_SECONDS = (5 * 60 * 60 * 24); +const HOURS = 60 * 60; + + let steemPrice; + let rewardBalance; + let recentClaims; +// let currentUserAccount; + let votePowerReserveRate; + let totalVestingFund; + let totalVestingShares; + let steem_per_mvests; + let sbd_print_percentage; function updateSteemVariables(client) { client.database.call('get_reward_fund', ['post']).then(function (t) { - rewardBalance = parseFloat(t.reward_balance.replace(" STEEM", "")); - recentClaims = t.recent_claims; + rewardBalance = parseFloat(t['reward_balance'].replace(" STEEM", "")); + recentClaims = t['recent_claims']; }, function(e) { log('Error loading reward fund: ' + e); }); client.database.getCurrentMedianHistoryPrice().then(function (t) { - steemPrice = parseFloat(t.base) / parseFloat(t.quote); + steemPrice = parseFloat(t['base']) / parseFloat(t['quote']); }, function(e) { log('Error loading steem price: ' + e); }); @@ -44,28 +45,28 @@ var HOURS = 60 * 60; function vestsToSP(vests) { return vests / 1000000 * steem_per_mvests; } + /* function getVotingPower(account) { - var voting_power = account.voting_power; - var last_vote_time = new Date((account.last_vote_time) + 'Z'); - var elapsed_seconds = (new Date() - last_vote_time) / 1000; - var regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS); - var current_power = Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT); - return current_power; - } + let voting_power = account.voting_power; + let last_vote_time = new Date((account.last_vote_time) + 'Z'); + let elapsed_seconds = (new Date() - last_vote_time) / 1000; + let regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS); + return Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT); + }*/ function getVPHF20(account) { - var totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares); + let totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares); - var elapsed = Date.now() / 1000 - account.voting_manabar.last_update_time; - var maxMana = totalShares * 1000000; + let elapsed = Date.now() / 1000 - account['voting_manabar']['last_update_time']; + let maxMana = totalShares * 1000000; // 432000 sec = 5 days - var currentMana = parseFloat(account.voting_manabar.current_mana) + elapsed * maxMana / 432000; + let currentMana = parseFloat(account['voting_manabar']['current_mana']) + elapsed * maxMana / 432000; if (currentMana > maxMana) { currentMana = maxMana; } - var currentManaPerc = currentMana * 100 / maxMana; + let currentManaPerc = currentMana * 100 / maxMana; return Math.round(currentManaPerc * 100); } @@ -77,22 +78,20 @@ var HOURS = 60 * 60; if (rewardBalance && recentClaims && steemPrice && votePowerReserveRate) { - var effective_vesting_shares = Math.round(getVestingShares(account) * 1000000); - var voting_power = account.voting_power; - var weight = voteWeight * 100; - var last_vote_time = new Date((account.last_vote_time) + 'Z'); + let effective_vesting_shares = Math.round(getVestingShares(account) * 1000000); + let voting_power = account.voting_power; + let weight = voteWeight * 100; + let last_vote_time = new Date((account.last_vote_time) + 'Z'); - var elapsed_seconds = (new Date() - last_vote_time) / 1000; - var regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS); - var current_power = power || Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT); - var max_vote_denom = votePowerReserveRate * STEEMIT_VOTE_REGENERATION_SECONDS / (60 * 60 * 24); - var used_power = Math.round((current_power * weight) / STEEMIT_100_PERCENT); + let elapsed_seconds = (new Date() - last_vote_time) / 1000; + let regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS); + let current_power = power || Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT); + let max_vote_denom = votePowerReserveRate * STEEMIT_VOTE_REGENERATION_SECONDS / (60 * 60 * 24); + let used_power = Math.round((current_power * weight) / STEEMIT_100_PERCENT); used_power = Math.round((used_power + max_vote_denom - 1) / max_vote_denom); - var rshares = Math.round((effective_vesting_shares * used_power) / (STEEMIT_100_PERCENT)) - - return rshares; + return Math.round((effective_vesting_shares * used_power) / (STEEMIT_100_PERCENT)); } } @@ -102,21 +101,19 @@ var HOURS = 60 * 60; return; } if (rewardBalance && recentClaims && steemPrice && votePowerReserveRate) { - var voteValue = getVoteRShares(voteWeight, account, power) + return getVoteRShares(voteWeight, account, power) * rewardBalance / recentClaims * steem_price; - return voteValue; - } } function getVoteValueUSD(vote_value, sbd_price) { - const steempower_value = vote_value * 0.5 - const sbd_print_percentage_half = (0.5 * sbd_print_percentage) - const sbd_value = vote_value * sbd_print_percentage_half - const steem_value = vote_value * (0.5 - sbd_print_percentage_half) - return (sbd_value * sbd_price) + steem_value + steempower_value + const steempower_value = vote_value * 0.5; + const sbd_print_percentage_half = (0.5 * sbd_print_percentage); + const sbd_value = vote_value * sbd_print_percentage_half; + const steem_value = vote_value * (0.5 - sbd_print_percentage_half); + return (sbd_value * sbd_price) + steem_value + steempower_value; } function timeTilFullPower(cur_power){ @@ -124,10 +121,9 @@ function timeTilFullPower(cur_power){ } function getVestingShares(account) { - var effective_vesting_shares = parseFloat(account.vesting_shares.replace(" VESTS", "")) + return parseFloat(account.vesting_shares.replace(" VESTS", "")) + parseFloat(account.received_vesting_shares.replace(" VESTS", "")) - parseFloat(account.delegated_vesting_shares.replace(" VESTS", "")); - return effective_vesting_shares; } function getCurrency(amount) { @@ -144,7 +140,7 @@ function loadUserList(location, callback) { if (location.startsWith('http://') || location.startsWith('https://')) { // Require the "request" library for making HTTP requests - var request = require("request"); + let request = require("request"); request.get(location, function (e, r, data) { try { @@ -165,26 +161,26 @@ function loadUserList(location, callback) { } function format(n, c, d, t) { - var c = isNaN(c = Math.abs(c)) ? 2 : c, - d = d == undefined ? "." : d, - t = t == undefined ? "," : t, - s = n < 0 ? "-" : "", + c = isNaN(c = Math.abs(c)) ? 2 : c; + d = d === undefined ? "." : d; + t = t === undefined ? "," : t; + let s = n < 0 ? "-" : "", i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), - j = (j = i.length) > 3 ? j % 3 : 0; + j = (i.length > 3) ? (i % 3) : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); } function toTimer(ts) { - var h = Math.floor(ts / HOURS); - var m = Math.floor((ts % HOURS) / 60); - var s = Math.floor((ts % 60)); + let h = Math.floor(ts / HOURS); + let m = Math.floor((ts % HOURS) / 60); + let s = Math.floor((ts % 60)); return padLeft(h, 2) + ':' + padLeft(m, 2) + ':' + padLeft(s, 2); } function padLeft(v, d) { - var l = (v + '').length; + let l = (v + '').length; if (l >= d) return v + ''; - for(var i = l; i < d; i++) + for(let i = l; i < d; i++) v = '0' + v; return v; } @@ -193,11 +189,11 @@ function format(n, c, d, t) { module.exports = { updateSteemVariables: updateSteemVariables, - getVotingPower: getVotingPower, +// getVotingPower: getVotingPower, getVoteValue: getVoteValue, getVoteValueUSD: getVoteValueUSD, timeTilFullPower: timeTilFullPower, - getVestingShares: getVestingShares, +// getVestingShares: getVestingShares, vestsToSP: vestsToSP, loadUserList: loadUserList, getCurrency: getCurrency, @@ -205,4 +201,4 @@ function format(n, c, d, t) { toTimer: toTimer, log: log, getVPHF20: getVPHF20 - } + }; \ No newline at end of file