From d2882a3946b505303644a759a9f671226483e61a Mon Sep 17 00:00:00 2001 From: pshenmic Date: Sun, 5 May 2024 10:02:40 +0700 Subject: [PATCH 01/13] Upgrade dashcore-lib and zeromq --- lib/services/dashd.js | 2 +- package-lock.json | 381 ++++++++++++++++++++++++++++++++++-------- package.json | 4 +- 3 files changed, 316 insertions(+), 71 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index adc2d12bc..79c81975f 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -5,7 +5,7 @@ var path = require('path'); var spawn = require('child_process').spawn; var util = require('util'); var dashcore = require('@dashevo/dashcore-lib'); -var zmq = require('zeromq'); +var zmq = require('@pshenmic/zeromq/v5-compat'); var async = require('async'); var LRU = require('lru-cache'); var DashdRPC = require('@dashevo/dashd-rpc'); diff --git a/package-lock.json b/package-lock.json index 69e2b402b..d2f6f4570 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,9 @@ "version": "7.0.3", "license": "MIT", "dependencies": { - "@dashevo/dashcore-lib": "^0.20.9", + "@dashevo/dashcore-lib": "^0.21.1", "@dashevo/dashd-rpc": "^18.2.0", + "@pshenmic/zeromq": "6.0.0-beta.22", "async": "^2.6.1", "body-parser": "^1.18.3", "colors": "^1.3.3", @@ -22,8 +23,7 @@ "path-is-absolute": "^1.0.1", "semver": "^5.7.0", "socket.io": "^2.2.0", - "socket.io-client": "^2.2.0", - "zeromq": "^5.2.0" + "socket.io-client": "^2.2.0" }, "bin": { "dashcore-node": "bin/dashcore-node" @@ -143,9 +143,9 @@ } }, "node_modules/@dashevo/dashcore-lib": { - "version": "0.20.9", - "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.20.9.tgz", - "integrity": "sha512-VINczZ88KxM2ba5c/kbofnw47PRgNT88vQkteuTZWQW3PkgglG2FCQhyjlno1TlYaP2WbsOjr8HWm8xnVKqY2A==", + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.21.1.tgz", + "integrity": "sha512-ZRzzvIkB5NtS04QmBDOPBqyMQTV+yzrUc/T+TbsKcF5FdapQCAzN4HnTsIXKLenPk2TpW/j68yFwoA1tj3eRXA==", "dependencies": { "@dashevo/bls": "~1.2.9", "@dashevo/x11-hash-js": "^1.0.2", @@ -254,6 +254,32 @@ "node": ">= 8" } }, + "node_modules/@pshenmic/zeromq": { + "version": "6.0.0-beta.22", + "resolved": "https://registry.npmjs.org/@pshenmic/zeromq/-/zeromq-6.0.0-beta.22.tgz", + "integrity": "sha512-3P6qB1rGIAjgcpCv4oiOJ8UeBMjBiTUvkQiirJpUwaH56upuV4CrirSy/Vb0+RoaZpgN9/34d3rqo4EUy8L2Xw==", + "hasInstallScript": true, + "dependencies": { + "@aminya/node-gyp-build": "4.5.0-aminya.4", + "cross-env": "^7.0.3", + "node-addon-api": "^7.0.0", + "shelljs": "^0.8.5", + "shx": "^0.3.4" + }, + "engines": { + "node": ">= 10.2" + } + }, + "node_modules/@pshenmic/zeromq/node_modules/@aminya/node-gyp-build": { + "version": "4.5.0-aminya.4", + "resolved": "https://registry.npmjs.org/@aminya/node-gyp-build/-/node-gyp-build-4.5.0-aminya.4.tgz", + "integrity": "sha512-2c2+BqZOxfTz/m+1MNWncMyMgil2WOg8cHhKPf1qUo1t9ohOWOgSeb7TVVD4fnTxIcAcpWdmXBpFkjPRyBVS9g==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -579,8 +605,7 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/base": { "version": "0.11.2", @@ -764,7 +789,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1207,8 +1231,7 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "node_modules/console-browserify": { "version": "1.1.0", @@ -1284,6 +1307,50 @@ "node": ">=6" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/cross-spawn/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -2423,8 +2490,7 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "node_modules/fsevents": { "version": "2.3.2", @@ -2930,7 +2996,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -2946,6 +3011,14 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/ip-address": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-6.1.0.tgz", @@ -3783,8 +3856,7 @@ "node_modules/minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "node_modules/minimist-options": { "version": "4.1.0", @@ -4098,11 +4170,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "node_modules/nan": { - "version": "2.14.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", - "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==" - }, "node_modules/nanoid": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", @@ -4156,6 +4223,14 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/node-addon-api": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.0.tgz", + "integrity": "sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==", + "engines": { + "node": "^16 || ^18 || >= 20" + } + }, "node_modules/node-buffers": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/node-buffers/-/node-buffers-0.1.1.tgz", @@ -4169,6 +4244,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==", + "optional": true, "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -4355,7 +4431,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "dependencies": { "wrappy": "1" } @@ -4495,6 +4570,14 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "engines": { + "node": ">=8" + } + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -5221,6 +5304,86 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "engines": { + "node": ">=8" + } + }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/shelljs/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/shelljs/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/shx": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", + "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "dependencies": { + "minimist": "^1.2.3", + "shelljs": "^0.8.5" + }, + "bin": { + "shx": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -6228,8 +6391,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "node_modules/ws": { "version": "7.4.6", @@ -6330,19 +6492,6 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } - }, - "node_modules/zeromq": { - "version": "5.2.8", - "resolved": "https://registry.npmjs.org/zeromq/-/zeromq-5.2.8.tgz", - "integrity": "sha512-bXzsk7KOmgLSv1tC0Ms1VXBy90+Rz27ZYf27cLuldRYbpqYpuWJfxxHFhO710t22zgWBnmdUP0m3SKFpLI0u5g==", - "hasInstallScript": true, - "dependencies": { - "nan": "2.14.2", - "node-gyp-build": "^4.2.3" - }, - "engines": { - "node": ">=6.0" - } } }, "dependencies": { @@ -6424,9 +6573,9 @@ } }, "@dashevo/dashcore-lib": { - "version": "0.20.9", - "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.20.9.tgz", - "integrity": "sha512-VINczZ88KxM2ba5c/kbofnw47PRgNT88vQkteuTZWQW3PkgglG2FCQhyjlno1TlYaP2WbsOjr8HWm8xnVKqY2A==", + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.21.1.tgz", + "integrity": "sha512-ZRzzvIkB5NtS04QmBDOPBqyMQTV+yzrUc/T+TbsKcF5FdapQCAzN4HnTsIXKLenPk2TpW/j68yFwoA1tj3eRXA==", "requires": { "@dashevo/bls": "~1.2.9", "@dashevo/x11-hash-js": "^1.0.2", @@ -6527,6 +6676,25 @@ "fastq": "^1.6.0" } }, + "@pshenmic/zeromq": { + "version": "6.0.0-beta.22", + "resolved": "https://registry.npmjs.org/@pshenmic/zeromq/-/zeromq-6.0.0-beta.22.tgz", + "integrity": "sha512-3P6qB1rGIAjgcpCv4oiOJ8UeBMjBiTUvkQiirJpUwaH56upuV4CrirSy/Vb0+RoaZpgN9/34d3rqo4EUy8L2Xw==", + "requires": { + "@aminya/node-gyp-build": "4.5.0-aminya.4", + "cross-env": "^7.0.3", + "node-addon-api": "^7.0.0", + "shelljs": "^0.8.5", + "shx": "^0.3.4" + }, + "dependencies": { + "@aminya/node-gyp-build": { + "version": "4.5.0-aminya.4", + "resolved": "https://registry.npmjs.org/@aminya/node-gyp-build/-/node-gyp-build-4.5.0-aminya.4.tgz", + "integrity": "sha512-2c2+BqZOxfTz/m+1MNWncMyMgil2WOg8cHhKPf1qUo1t9ohOWOgSeb7TVVD4fnTxIcAcpWdmXBpFkjPRyBVS9g==" + } + } + }, "@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -6784,8 +6952,7 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "base": { "version": "0.11.2", @@ -6940,7 +7107,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7295,8 +7461,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "console-browserify": { "version": "1.1.0", @@ -7354,6 +7519,34 @@ "request": "^2.88.2" } }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "requires": { + "cross-spawn": "^7.0.1" + } + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "dependencies": { + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -8243,8 +8436,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "2.3.2", @@ -8647,7 +8839,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -8663,6 +8854,11 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, "ip-address": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-6.1.0.tgz", @@ -9299,8 +9495,7 @@ "minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "minimist-options": { "version": "4.1.0", @@ -9537,11 +9732,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "nan": { - "version": "2.14.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", - "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==" - }, "nanoid": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", @@ -9583,6 +9773,11 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node-addon-api": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.0.tgz", + "integrity": "sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==" + }, "node-buffers": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/node-buffers/-/node-buffers-0.1.1.tgz", @@ -9592,7 +9787,8 @@ "node-gyp-build": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", - "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==" + "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==", + "optional": true }, "nopt": { "version": "3.0.6", @@ -9730,7 +9926,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -9828,6 +10023,11 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" + }, "path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -10374,6 +10574,61 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" + }, + "shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "dependencies": { + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + } + } + }, + "shx": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", + "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "requires": { + "minimist": "^1.2.3", + "shelljs": "^0.8.5" + } + }, "side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -11185,8 +11440,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { "version": "7.4.6", @@ -11252,15 +11506,6 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true - }, - "zeromq": { - "version": "5.2.8", - "resolved": "https://registry.npmjs.org/zeromq/-/zeromq-5.2.8.tgz", - "integrity": "sha512-bXzsk7KOmgLSv1tC0Ms1VXBy90+Rz27ZYf27cLuldRYbpqYpuWJfxxHFhO710t22zgWBnmdUP0m3SKFpLI0u5g==", - "requires": { - "nan": "2.14.2", - "node-gyp-build": "^4.2.3" - } } } } diff --git a/package.json b/package.json index 570afbbe8..11985e8e8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "dashd" ], "dependencies": { - "@dashevo/dashcore-lib": "^0.20.9", + "@dashevo/dashcore-lib": "^0.21.1", "@dashevo/dashd-rpc": "^18.2.0", "async": "^2.6.1", "body-parser": "^1.18.3", @@ -57,7 +57,7 @@ "semver": "^5.7.0", "socket.io": "^2.2.0", "socket.io-client": "^2.2.0", - "zeromq": "^5.2.0" + "@pshenmic/zeromq": "6.0.0-beta.22" }, "optionalDependencies": { "bufferutil": "~4.0.1", From 4e650cbbc15037658196f9b3c6bb2c9fb1b6e982 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Sun, 5 May 2024 10:28:24 +0700 Subject: [PATCH 02/13] Fix unit test --- test/services/dashd.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/dashd.unit.js b/test/services/dashd.unit.js index 4bc07bf18..506af1846 100644 --- a/test/services/dashd.unit.js +++ b/test/services/dashd.unit.js @@ -1477,7 +1477,7 @@ describe('Dash Service', function() { return socket; }; var DashService = proxyquire('../../lib/services/dashd', { - zeromq: { + "@pshenmic/zeromq/v5-compat": { socket: socketFunc } }); From 8138e2dbab3704e7075797cce5680b6845a9756a Mon Sep 17 00:00:00 2001 From: pshenmic Date: Sun, 5 May 2024 10:31:45 +0700 Subject: [PATCH 03/13] bump version to 7.0.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d2f6f4570..8b12d3b13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dashevo/dashcore-node", - "version": "7.0.3", + "version": "7.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@dashevo/dashcore-node", - "version": "7.0.3", + "version": "7.0.4", "license": "MIT", "dependencies": { "@dashevo/dashcore-lib": "^0.21.1", diff --git a/package.json b/package.json index 11985e8e8..2c705ff8e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@dashevo/dashcore-node", "description": "Full node with extended capabilities using Dashcore and Dash Core (dashd)", "author": "BitPay ", - "version": "7.0.3", + "version": "7.0.4", "main": "./index.js", "repository": "git://github.com/dashevo/dashcore-node.git", "homepage": "https://github.com/dashevo/dashcore-node", From 4cb41a0bb8a6eb3601f013f5e1923d46ad07ab81 Mon Sep 17 00:00:00 2001 From: owl352 Date: Fri, 13 Sep 2024 00:18:08 +0500 Subject: [PATCH 04/13] initial commit --- lib/services/dashd.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 79c81975f..15e1e7f01 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2296,6 +2296,9 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { if (result.qcTx !== undefined) { tx.qcTx = result.qcTx; } + if (result.mnhfTx !== undefined) { + tx.mnhfTx = result.mnhfTx; + } } if (tx) { From 01a16e337352035c22bababc591c59814faba627 Mon Sep 17 00:00:00 2001 From: owl352 Date: Tue, 17 Sep 2024 13:43:55 +0500 Subject: [PATCH 05/13] initial commit --- lib/services/dashd.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 79c81975f..bb052fa60 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2250,10 +2250,6 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; - var address = null; - if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { - address = out.scriptPubKey.addresses[0]; - } tx.outputs.push({ satoshis: out.valueSat, script: out.scriptPubKey.hex, @@ -2261,7 +2257,7 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { spentTxId: out.spentTxId, spentIndex: out.spentIndex, spentHeight: out.spentHeight, - address: address + address: out.scriptPubKey.address }); } } From 42577fcc8105b01e10bfffb2d73e449ab9d9f4e5 Mon Sep 17 00:00:00 2001 From: owl352 Date: Tue, 17 Sep 2024 16:30:56 +0500 Subject: [PATCH 06/13] added compatibility with older nodes --- lib/services/dashd.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index bb052fa60..769264d76 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2250,6 +2250,10 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; + var address = out.scriptPubKey.address; + if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { + address = out.scriptPubKey.addresses[0]; + } tx.outputs.push({ satoshis: out.valueSat, script: out.scriptPubKey.hex, @@ -2257,7 +2261,7 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { spentTxId: out.spentTxId, spentIndex: out.spentIndex, spentHeight: out.spentHeight, - address: out.scriptPubKey.address + address: address }); } } From 9671a131f99d1e478f008386ced8ffabf63f932f Mon Sep 17 00:00:00 2001 From: owl352 Date: Fri, 20 Sep 2024 17:30:40 +0500 Subject: [PATCH 07/13] null condition --- lib/services/dashd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 769264d76..c184807a8 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2250,7 +2250,7 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; - var address = out.scriptPubKey.address; + var address = out.scriptPubKey.address ?? null; if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { address = out.scriptPubKey.addresses[0]; } From aa5f28b07801e4484ffc9ce1a0ac5c37e1ebbc5e Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 21 Sep 2024 01:44:07 +0500 Subject: [PATCH 08/13] changed to null --- lib/services/dashd.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index c184807a8..70e113e97 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2250,9 +2250,11 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; - var address = out.scriptPubKey.address ?? null; + var address = null; if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { address = out.scriptPubKey.addresses[0]; + }else{ + address = out.scriptPubKey.address; } tx.outputs.push({ satoshis: out.valueSat, From 2fb0b36d81c2d5452dbfb7ed7b6b2c4994e4de58 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 21 Sep 2024 01:46:47 +0500 Subject: [PATCH 09/13] spaces fix --- lib/services/dashd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index e25714f43..42d94132b 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2253,7 +2253,7 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { var address = null; if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { address = out.scriptPubKey.addresses[0]; - }else{ + } else { address = out.scriptPubKey.address; } tx.outputs.push({ From 2d093170c65f2a5b343ac303e1e387b0711ce94d Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 21 Sep 2024 02:43:50 +0500 Subject: [PATCH 10/13] warning fix --- lib/services/dashd.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 42d94132b..9477f3abb 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2282,23 +2282,17 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { if (result.proRegTx !== undefined) { tx.proRegTx = result.proRegTx; - } - if (result.proUpServTx !== undefined) { + }else if (result.proUpServTx !== undefined) { tx.proUpServTx = result.proUpServTx; - } - if (result.proUpRegTx !== undefined) { + }else if (result.proUpRegTx !== undefined) { tx.proUpRegTx = result.proUpRegTx; - } - if (result.proUpRevTx !== undefined) { + }else if (result.proUpRevTx !== undefined) { tx.proUpRevTx = result.proUpRevTx; - } - if (result.cbTx !== undefined) { + }else if (result.cbTx !== undefined) { tx.cbTx = result.cbTx; - } - if (result.qcTx !== undefined) { + }else if (result.qcTx !== undefined) { tx.qcTx = result.qcTx; - } - if (result.mnhfTx !== undefined) { + }else if (result.mnhfTx !== undefined) { tx.mnhfTx = result.mnhfTx; } } From 98932f563dc3c56b36c357bbb427518da1835759 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 21 Sep 2024 02:54:03 +0500 Subject: [PATCH 11/13] null fix --- lib/services/dashd.js | 905 +++++++++++++++++++++--------------------- 1 file changed, 455 insertions(+), 450 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 9477f3abb..41f84bd7a 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -10,7 +10,7 @@ var async = require('async'); var LRU = require('lru-cache'); var DashdRPC = require('@dashevo/dashd-rpc'); var $ = dashcore.util.preconditions; -var _ = dashcore.deps._; +var _ = dashcore.deps._; var Transaction = dashcore.Transaction; var Proposal = dashcore.GovObject.Proposal; @@ -21,6 +21,7 @@ var utils = require('../utils'); var Service = require('../service'); var rawtxTopicBuffer = new Buffer('7261777478', 'hex'); var rawtxlockTopicBuffer = new Buffer('72617774786c6f636b', 'hex'); + /** * Provides a friendly event driven API to dashd in Node.js. Manages starting and * stopping dashd as a child process for application support, as well as connecting @@ -59,10 +60,11 @@ function Dash(options) { // for testing purposes this._process = options.process || process; - this.on('error', function(err) { + this.on('error', function (err) { log.error(err.stack); }); } + util.inherits(Dash, Service); Dash.dependencies = []; @@ -97,7 +99,7 @@ Dash.DEFAULT_CONFIG_SETTINGS = { uacomment: 'dashcore' }; -Dash.prototype._initDefaults = function(options) { +Dash.prototype._initDefaults = function (options) { /* jshint maxcomplexity: 15 */ // limits @@ -122,30 +124,30 @@ Dash.prototype._initDefaults = function(options) { this.zmqSubscribeProgress = options.zmqSubscribeProgress || Dash.DEFAULT_ZMQ_SUBSCRIBE_PROGRESS; }; -Dash.prototype._initCaches = function() { +Dash.prototype._initCaches = function () { var CACHES = [ - {name:'utxos', lru:50000}, - {name:'txids', lru:50000}, - {name:'balance', lru:50000}, - {name:'summary', lru:50000}, - {name:'blockOverview', lru:144}, - {name:'transactionDetailed', lru:100000}, - {name:'masternodeList', lru:50000}, - {name:'sporksList', lru:50}, + {name: 'utxos', lru: 50000}, + {name: 'txids', lru: 50000}, + {name: 'balance', lru: 50000}, + {name: 'summary', lru: 50000}, + {name: 'blockOverview', lru: 144}, + {name: 'transactionDetailed', lru: 100000}, + {name: 'masternodeList', lru: 50000}, + {name: 'sporksList', lru: 50}, //governance - {name:'gov', lru:20}, + {name: 'gov', lru: 20}, //cache valid indefinitely - {name:'transaction', lru:100000}, - {name:'rawTransaction', lru:50000}, - {name:'block', lru:144}, - {name:'rawBlock', lru:72}, - {name:'blockHeader', lru:288} + {name: 'transaction', lru: 100000}, + {name: 'rawTransaction', lru: 50000}, + {name: 'block', lru: 144}, + {name: 'rawBlock', lru: 72}, + {name: 'blockHeader', lru: 288} ]; var self = this; CACHES.forEach(function (el) { - self[el.name+'Cache']=LRU(el.lru); + self[el.name + 'Cache'] = LRU(el.lru); }); // caches valid until there is a new block @@ -157,12 +159,12 @@ Dash.prototype._initCaches = function() { }; -Dash.prototype._initClients = function() { +Dash.prototype._initClients = function () { var self = this; this.nodes = []; this.nodesIndex = 0; Object.defineProperty(this, 'client', { - get: function() { + get: function () { var client = self.nodes[self.nodesIndex].client; self.nodesIndex = (self.nodesIndex + 1) % self.nodes.length; return client; @@ -175,7 +177,7 @@ Dash.prototype._initClients = function() { /** * Called by Node to determine the available API methods. */ -Dash.prototype.getAPIMethods = function() { +Dash.prototype.getAPIMethods = function () { var methods = [ ['getBlock', this, this.getBlock, 1], ['getRawBlock', this, this.getRawBlock, 1], @@ -209,7 +211,7 @@ Dash.prototype.getAPIMethods = function() { /** * Called by the Bus to determine the available events. */ -Dash.prototype.getPublishEvents = function() { +Dash.prototype.getPublishEvents = function () { return [ { name: 'dashd/rawtransaction', @@ -238,12 +240,12 @@ Dash.prototype.getPublishEvents = function() { ]; }; -Dash.prototype.subscribe = function(name, emitter) { +Dash.prototype.subscribe = function (name, emitter) { this.subscriptions[name].push(emitter); log.info(emitter.remoteAddress, 'subscribe:', 'dashd/' + name, 'total:', this.subscriptions[name].length); }; -Dash.prototype.unsubscribe = function(name, emitter) { +Dash.prototype.unsubscribe = function (name, emitter) { var index = this.subscriptions[name].indexOf(emitter); if (index > -1) { this.subscriptions[name].splice(index, 1); @@ -251,11 +253,11 @@ Dash.prototype.unsubscribe = function(name, emitter) { log.info(emitter.remoteAddress, 'unsubscribe:', 'dashd/' + name, 'total:', this.subscriptions[name].length); }; -Dash.prototype.subscribeAddress = function(emitter, addresses) { +Dash.prototype.subscribeAddress = function (emitter, addresses) { var self = this; function addAddress(addressStr) { - if(self.subscriptions.address[addressStr]) { + if (self.subscriptions.address[addressStr]) { var emitters = self.subscriptions.address[addressStr]; var index = emitters.indexOf(emitter); if (index === -1) { @@ -265,8 +267,9 @@ Dash.prototype.subscribeAddress = function(emitter, addresses) { self.subscriptions.address[addressStr] = [emitter]; } } - if(addresses){ - for(var i = 0; i < addresses.length; i++) { + + if (addresses) { + for (var i = 0; i < addresses.length; i++) { if (dashcore.Address.isValid(addresses[i], this.node.network)) { addAddress(addresses[i]); } @@ -276,16 +279,16 @@ Dash.prototype.subscribeAddress = function(emitter, addresses) { log.info(emitter.remoteAddress, 'subscribe:', 'dashd/addresstxid', 'total:', _.size(this.subscriptions.address)); }; -Dash.prototype.unsubscribeAddress = function(emitter, addresses) { +Dash.prototype.unsubscribeAddress = function (emitter, addresses) { var self = this; - if(!addresses) { + if (!addresses) { return this.unsubscribeAddressAll(emitter); } function removeAddress(addressStr) { var emitters = self.subscriptions.address[addressStr]; var index = emitters.indexOf(emitter); - if(index > -1) { + if (index > -1) { emitters.splice(index, 1); if (emitters.length === 0) { delete self.subscriptions.address[addressStr]; @@ -293,8 +296,8 @@ Dash.prototype.unsubscribeAddress = function(emitter, addresses) { } } - for(var i = 0; i < addresses.length; i++) { - if(this.subscriptions.address[addresses[i]]) { + for (var i = 0; i < addresses.length; i++) { + if (this.subscriptions.address[addresses[i]]) { removeAddress(addresses[i]); } } @@ -307,11 +310,11 @@ Dash.prototype.unsubscribeAddress = function(emitter, addresses) { * @param {String} name - The name of the event * @param {EventEmitter} emitter - An instance of an event emitter */ -Dash.prototype.unsubscribeAddressAll = function(emitter) { - for(var hashHex in this.subscriptions.address) { +Dash.prototype.unsubscribeAddressAll = function (emitter) { + for (var hashHex in this.subscriptions.address) { var emitters = this.subscriptions.address[hashHex]; var index = emitters.indexOf(emitter); - if(index > -1) { + if (index > -1) { emitters.splice(index, 1); } if (emitters.length === 0) { @@ -321,20 +324,20 @@ Dash.prototype.unsubscribeAddressAll = function(emitter) { log.info(emitter.remoteAddress, 'unsubscribe:', 'dashd/addresstxid', 'total:', _.size(this.subscriptions.address)); }; -Dash.prototype._getDefaultConfig = function() { +Dash.prototype._getDefaultConfig = function () { var config = ''; var defaults = Dash.DEFAULT_CONFIG_SETTINGS; - for(var key in defaults) { + for (var key in defaults) { config += key + '=' + defaults[key] + '\n'; } return config; }; -Dash.prototype._parseDashConf = function(configPath) { +Dash.prototype._parseDashConf = function (configPath) { var options = {}; var file = fs.readFileSync(configPath); var unparsed = file.toString().split('\n'); - for(var i = 0; i < unparsed.length; i++) { + for (var i = 0; i < unparsed.length; i++) { var line = unparsed[i]; if (!line.match(/^\#/) && line.match(/\=/)) { var option = line.split('='); @@ -350,7 +353,7 @@ Dash.prototype._parseDashConf = function(configPath) { return options; }; -Dash.prototype._expandRelativeDatadir = function() { +Dash.prototype._expandRelativeDatadir = function () { if (!utils.isAbsolutePath(this.options.spawn.datadir)) { $.checkState(this.node.configPath); $.checkState(utils.isAbsolutePath(this.node.configPath)); @@ -359,7 +362,7 @@ Dash.prototype._expandRelativeDatadir = function() { } }; -Dash.prototype._loadSpawnConfiguration = function(node) { +Dash.prototype._loadSpawnConfiguration = function (node) { /* jshint maxstatements: 25 */ $.checkArgument(this.options.spawn, 'Please specify "spawn" in dashd config options'); @@ -380,7 +383,7 @@ Dash.prototype._loadSpawnConfiguration = function(node) { this.spawn.config = {}; if (!fs.existsSync(spawnOptions.datadir)) { - fs.mkdirSync(spawnOptions.datadir, { recursive: true }); + fs.mkdirSync(spawnOptions.datadir, {recursive: true}); } if (!fs.existsSync(configPath)) { @@ -402,50 +405,50 @@ Dash.prototype._loadSpawnConfiguration = function(node) { }; -Dash.prototype._checkConfigIndexes = function(spawnConfig, node) { +Dash.prototype._checkConfigIndexes = function (spawnConfig, node) { $.checkState( spawnConfig.txindex && spawnConfig.txindex === 1, '"txindex" option is required in order to use transaction query features of dashcore-node. ' + - 'Please add "txindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "txindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.addressindex && spawnConfig.addressindex === 1, '"addressindex" option is required in order to use address query features of dashcore-node. ' + - 'Please add "addressindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "addressindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.spentindex && spawnConfig.spentindex === 1, '"spentindex" option is required in order to use spent info query features of dashcore-node. ' + - 'Please add "spentindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "spentindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.server && spawnConfig.server === 1, '"server" option is required to communicate to dashd from dashcore. ' + - 'Please add "server=1" to your configuration and restart' + 'Please add "server=1" to your configuration and restart' ); $.checkState( spawnConfig.zmqpubrawtx, '"zmqpubrawtx" option is required to get event updates from dashd. ' + - 'Please add "zmqpubrawtx=tcp://127.0.0.1:" to your configuration and restart' + 'Please add "zmqpubrawtx=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( - spawnConfig.zmqpubrawtxlock, - '"zmqpubrawtxlock" option is required to get transaction locks from dashd. ' + - 'Please add "zmqpubrawtxlock=tcp://127.0.0.1:" to your configuration and restart' + spawnConfig.zmqpubrawtxlock, + '"zmqpubrawtxlock" option is required to get transaction locks from dashd. ' + + 'Please add "zmqpubrawtxlock=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( spawnConfig.zmqpubhashblock, '"zmqpubhashblock" option is required to get event updates from dashd. ' + - 'Please add "zmqpubhashblock=tcp://127.0.0.1:" to your configuration and restart' + 'Please add "zmqpubhashblock=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( @@ -455,14 +458,14 @@ Dash.prototype._checkConfigIndexes = function(spawnConfig, node) { if (spawnConfig.reindex && spawnConfig.reindex === 1) { log.warn('Reindex option is currently enabled. This means that dashd is undergoing a reindex. ' + - 'The reindex flag will start the index from beginning every time the node is started, so it ' + - 'should be removed after the reindex has been initiated. Once the reindex is complete, the rest ' + - 'of dashcore-node services will start.'); + 'The reindex flag will start the index from beginning every time the node is started, so it ' + + 'should be removed after the reindex has been initiated. Once the reindex is complete, the rest ' + + 'of dashcore-node services will start.'); node._reindex = true; } }; -Dash.prototype._resetCaches = function() { +Dash.prototype._resetCaches = function () { this.transactionDetailedCache.reset(); this.utxosCache.reset(); this.txidsCache.reset(); @@ -482,13 +485,13 @@ Dash.prototype._resetCaches = function() { * @param callback * @private */ -Dash.prototype._tryAllClients = function(func, callback) { +Dash.prototype._tryAllClients = function (func, callback) { var self = this; //Storing current node index into closure var nextClientToTry = this.nodesIndex; //Incrementing this.nodesIndex for proper round-robin this.nodesIndex = (this.nodesIndex + 1) % self.nodes.length; - var retry = function(done) { + var retry = function (done) { var client = self.nodes[nextClientToTry].client; nextClientToTry = (nextClientToTry + 1) % self.nodes.length; func(client, done); @@ -496,33 +499,33 @@ Dash.prototype._tryAllClients = function(func, callback) { async.retry({times: this.nodes.length, interval: this.tryAllInterval || 1000}, retry, callback); }; -Dash.prototype._wrapRPCError = function(errObj) { +Dash.prototype._wrapRPCError = function (errObj) { var err = new errors.RPCError(errObj.message); err.code = errObj.code; return err; }; -Dash.prototype._initChain = function(callback) { +Dash.prototype._initChain = function (callback) { var self = this; - self.client.getBestBlockHash(function(err, response) { + self.client.getBestBlockHash(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.client.getBlock(response.result, function(err, response) { + self.client.getBlock(response.result, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } self.height = response.result.height; - self.client.getBlockHash(0, function(err, response) { + self.client.getBlockHash(0, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } var blockhash = response.result; - self.getRawBlock(blockhash, function(err, blockBuffer) { + self.getRawBlock(blockhash, function (err, blockBuffer) { if (err) { return callback(err); } @@ -537,7 +540,7 @@ Dash.prototype._initChain = function(callback) { }); }; -Dash.prototype._getDefaultConf = function() { +Dash.prototype._getDefaultConf = function () { var networkOptions = { rpcport: 9998 }; @@ -547,7 +550,7 @@ Dash.prototype._getDefaultConf = function() { return networkOptions; }; -Dash.prototype._getNetworkConfigPath = function() { +Dash.prototype._getNetworkConfigPath = function () { var networkPath; if (this.node.network === dashcore.Networks.testnet) { networkPath = 'testnet3/dash.conf'; @@ -558,7 +561,7 @@ Dash.prototype._getNetworkConfigPath = function() { return networkPath; }; -Dash.prototype._getNetworkOption = function() { +Dash.prototype._getNetworkOption = function () { var networkOption; if (this.node.network === dashcore.Networks.testnet) { networkOption = '--testnet'; @@ -569,7 +572,7 @@ Dash.prototype._getNetworkOption = function() { return networkOption; }; -Dash.prototype._zmqBlockHandler = function(node, message) { +Dash.prototype._zmqBlockHandler = function (node, message) { var self = this; // Update the current chain tip @@ -588,7 +591,7 @@ Dash.prototype._zmqBlockHandler = function(node, message) { }; -Dash.prototype._rapidProtectedUpdateTip = function(node, message) { +Dash.prototype._rapidProtectedUpdateTip = function (node, message) { var self = this; // Prevent a rapid succession of tip updates @@ -597,13 +600,13 @@ Dash.prototype._rapidProtectedUpdateTip = function(node, message) { self._updateTip(node, message); } else { clearTimeout(self.lastTipTimeout); - self.lastTipTimeout = setTimeout(function() { + self.lastTipTimeout = setTimeout(function () { self._updateTip(node, message); }, 1000); } }; -Dash.prototype._updateTip = function(node, message) { +Dash.prototype._updateTip = function (node, message) { var self = this; var hex = message.toString('hex'); @@ -613,7 +616,7 @@ Dash.prototype._updateTip = function(node, message) { // reset block valid caches self._resetCaches(); - node.client.getBlock(self.tiphash, function(err, response) { + node.client.getBlock(self.tiphash, function (err, response) { if (err) { var error = self._wrapRPCError(err); self.emit('error', error); @@ -624,8 +627,8 @@ Dash.prototype._updateTip = function(node, message) { } }); - if(!self.node.stopping) { - self.syncPercentage(function(err, percentage) { + if (!self.node.stopping) { + self.syncPercentage(function (err, percentage) { if (err) { self.emit('error', err); } else { @@ -639,7 +642,7 @@ Dash.prototype._updateTip = function(node, message) { } }; -Dash.prototype._getAddressesFromTransaction = function(transaction) { +Dash.prototype._getAddressesFromTransaction = function (transaction) { var addresses = []; for (var i = 0; i < transaction.inputs.length; i++) { @@ -665,13 +668,13 @@ Dash.prototype._getAddressesFromTransaction = function(transaction) { return _.uniq(addresses); }; -Dash.prototype._notifyAddressTxidSubscribers = function(txid, transaction) { +Dash.prototype._notifyAddressTxidSubscribers = function (txid, transaction) { var addresses = this._getAddressesFromTransaction(transaction); for (var i = 0; i < addresses.length; i++) { var address = addresses[i]; - if(this.subscriptions.address[address]) { + if (this.subscriptions.address[address]) { var emitters = this.subscriptions.address[address]; - for(var j = 0; j < emitters.length; j++) { + for (var j = 0; j < emitters.length; j++) { emitters[j].emit('dashd/addresstxid', { address: address, txid: txid @@ -681,7 +684,7 @@ Dash.prototype._notifyAddressTxidSubscribers = function(txid, transaction) { } }; -Dash.prototype._zmqTransactionHandler = function(node, message) { +Dash.prototype._zmqTransactionHandler = function (node, message) { // It happen that ZMQ is throwing 'rawtx' // We discard this as they are improper received message from ZMQ. if (message.equals(rawtxTopicBuffer)) { @@ -729,13 +732,13 @@ Dash.prototype._zmqTransactionLockHandler = function (node, message) { } }; -Dash.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { +Dash.prototype._checkSyncedAndSubscribeZmqEvents = function (node) { var self = this; var interval; function checkAndSubscribe(callback) { // update tip - node.client.getBestBlockHash(function(err, response) { + node.client.getBestBlockHash(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -744,7 +747,7 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { self._updateTip(node, blockhash); // check if synced - node.client.getBlockchainInfo(function(err, response) { + node.client.getBlockchainInfo(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -761,16 +764,16 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { }); } - checkAndSubscribe(function(err, synced) { + checkAndSubscribe(function (err, synced) { if (err) { log.error(err); } if (!synced) { - interval = setInterval(function() { + interval = setInterval(function () { if (self.node.stopping) { return clearInterval(interval); } - checkAndSubscribe(function(err) { + checkAndSubscribe(function (err) { if (err) { log.error(err); } @@ -781,12 +784,12 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { }; -Dash.prototype._subscribeZmqEvents = function(node) { +Dash.prototype._subscribeZmqEvents = function (node) { var self = this; node.zmqSubSocket.subscribe('hashblock'); node.zmqSubSocket.subscribe('rawtx'); node.zmqSubSocket.subscribe('rawtxlock'); - node.zmqSubSocket.on('message', function(topic, message) { + node.zmqSubSocket.on('message', function (topic, message) { var topicString = topic.toString('utf8'); if (topicString === 'rawtxlock') { self._zmqTransactionLockHandler(node, message); @@ -798,25 +801,25 @@ Dash.prototype._subscribeZmqEvents = function(node) { }); }; -Dash.prototype._initZmqSubSocket = function(node, zmqUrl) { +Dash.prototype._initZmqSubSocket = function (node, zmqUrl) { var self = this; node.zmqSubSocket = zmq.socket('sub'); - node.zmqSubSocket.on('connect', function(fd, endPoint) { + node.zmqSubSocket.on('connect', function (fd, endPoint) { log.info('ZMQ connected to:', endPoint); }); - node.zmqSubSocket.on('connect_delay', function(fd, endPoint) { + node.zmqSubSocket.on('connect_delay', function (fd, endPoint) { log.warn('ZMQ connection delay:', endPoint); }); - node.zmqSubSocket.on('disconnect', function(fd, endPoint) { + node.zmqSubSocket.on('disconnect', function (fd, endPoint) { log.warn('ZMQ disconnect:', endPoint); }); - node.zmqSubSocket.on('monitor_error', function(err) { + node.zmqSubSocket.on('monitor_error', function (err) { log.error('Error in monitoring: %s, will restart monitoring in 5 seconds', err); - setTimeout(function() { + setTimeout(function () { self.zmqSubSocket.monitor(500, 0); }, 5000); }); @@ -825,19 +828,21 @@ Dash.prototype._initZmqSubSocket = function(node, zmqUrl) { node.zmqSubSocket.connect(zmqUrl); }; -Dash.prototype._checkReindex = function(node, callback) { +Dash.prototype._checkReindex = function (node, callback) { var self = this; var interval; + function finish(err) { clearInterval(interval); callback(err); } + if (!node._reindex) { return callback(); } - interval = setInterval(function() { - node.client.getBlockchainInfo(function(err, response) { + interval = setInterval(function () { + node.client.getBlockchainInfo(function (err, response) { if (err) { return finish(self._wrapRPCError(err)); } @@ -853,16 +858,16 @@ Dash.prototype._checkReindex = function(node, callback) { }; -Dash.prototype._loadTipFromNode = function(node, callback) { +Dash.prototype._loadTipFromNode = function (node, callback) { var self = this; - node.client.getBestBlockHash(function(err, response) { + node.client.getBestBlockHash(function (err, response) { if (err && err.code === -28) { log.warn(err.message); return callback(self._wrapRPCError(err)); } else if (err) { return callback(self._wrapRPCError(err)); } - node.client.getBlock(response.result, function(err, response) { + node.client.getBlock(response.result, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -874,13 +879,13 @@ Dash.prototype._loadTipFromNode = function(node, callback) { }); }; -Dash.prototype._stopSpawnedDash = function(callback) { +Dash.prototype._stopSpawnedDash = function (callback) { var self = this; var spawnOptions = this.options.spawn; var pidPath = spawnOptions.datadir + '/dashd.pid'; function stopProcess() { - fs.readFile(pidPath, 'utf8', function(err, pid) { + fs.readFile(pidPath, 'utf8', function (err, pid) { if (err && err.code === 'ENOENT') { // pid file doesn't exist we can continue return callback(null); @@ -895,15 +900,15 @@ Dash.prototype._stopSpawnedDash = function(callback) { try { log.warn('Stopping existing spawned dash process with pid: ' + pid); self._process.kill(pid, 'SIGINT'); - } catch(err) { + } catch (err) { if (err && err.code === 'ESRCH') { log.warn('Unclean dash process shutdown, process not found with pid: ' + pid); return callback(null); - } else if(err) { + } else if (err) { return callback(err); } } - setTimeout(function() { + setTimeout(function () { stopProcess(); }, self.spawnStopTime); }); @@ -912,7 +917,7 @@ Dash.prototype._stopSpawnedDash = function(callback) { stopProcess(); }; -Dash.prototype._spawnChildProcess = function(callback) { +Dash.prototype._spawnChildProcess = function (callback) { var self = this; var node = {}; @@ -921,7 +926,7 @@ Dash.prototype._spawnChildProcess = function(callback) { try { self._loadSpawnConfiguration(node); - } catch(e) { + } catch (e) { return callback(e); } @@ -934,7 +939,7 @@ Dash.prototype._spawnChildProcess = function(callback) { options.push(self._getNetworkOption()); } - self._stopSpawnedDash(function(err) { + self._stopSpawnedDash(function (err) { if (err) { return callback(err); } @@ -942,16 +947,16 @@ Dash.prototype._spawnChildProcess = function(callback) { log.info('Starting dash process'); self.spawn.process = spawn(self.spawn.exec, options, {stdio: 'inherit'}); - self.spawn.process.on('error', function(err) { + self.spawn.process.on('error', function (err) { self.emit('error', err); }); - self.spawn.process.once('exit', function(code) { + self.spawn.process.once('exit', function (code) { if (!self.node.stopping) { log.warn('Dash process unexpectedly exited with code:', code); log.warn('Restarting dash child process in ' + self.spawnRestartTime + 'ms'); - setTimeout(function() { - self._spawnChildProcess(function(err) { + setTimeout(function () { + self._spawnChildProcess(function (err) { if (err) { return self.emit('error', err); } @@ -963,7 +968,7 @@ Dash.prototype._spawnChildProcess = function(callback) { var exitShutdown = false; - async.retry({times: 60, interval: self.startRetryInterval}, function(done) { + async.retry({times: 60, interval: self.startRetryInterval}, function (done) { if (self.node.stopping) { exitShutdown = true; return done(); @@ -979,7 +984,7 @@ Dash.prototype._spawnChildProcess = function(callback) { self._loadTipFromNode(node, done); - }, function(err) { + }, function (err) { if (err) { return callback(err); } @@ -989,7 +994,7 @@ Dash.prototype._spawnChildProcess = function(callback) { self._initZmqSubSocket(node, self.spawn.config.zmqpubrawtx); - self._checkReindex(node, function(err) { + self._checkReindex(node, function (err) { if (err) { return callback(err); } @@ -1003,12 +1008,12 @@ Dash.prototype._spawnChildProcess = function(callback) { }; -Dash.prototype._connectProcess = function(config, callback) { +Dash.prototype._connectProcess = function (config, callback) { var self = this; var node = {}; var exitShutdown = false; - async.retry({times: 60, interval: self.startRetryInterval}, function(done) { + async.retry({times: 60, interval: self.startRetryInterval}, function (done) { if (self.node.stopping) { exitShutdown = true; return done(); @@ -1025,7 +1030,7 @@ Dash.prototype._connectProcess = function(config, callback) { self._loadTipFromNode(node, done); - }, function(err) { + }, function (err) { if (err) { return callback(err); } @@ -1044,13 +1049,13 @@ Dash.prototype._connectProcess = function(config, callback) { * Called by Node to start the service * @param {Function} callback */ -Dash.prototype.start = function(callback) { +Dash.prototype.start = function (callback) { var self = this; async.series([ - function(next) { + function (next) { if (self.options.spawn) { - self._spawnChildProcess(function(err, node) { + self._spawnChildProcess(function (err, node) { if (err) { return next(err); } @@ -1061,13 +1066,13 @@ Dash.prototype.start = function(callback) { next(); } }, - function(next) { + function (next) { if (self.options.connect) { - async.map(self.options.connect, self._connectProcess.bind(self), function(err, nodes) { + async.map(self.options.connect, self._connectProcess.bind(self), function (err, nodes) { if (err) { return next(err); } - for(var i = 0; i < nodes.length; i++) { + for (var i = 0; i < nodes.length; i++) { self.nodes.push(nodes[i]); } next(); @@ -1076,7 +1081,7 @@ Dash.prototype.start = function(callback) { next(); } } - ], function(err) { + ], function (err) { if (err) { return callback(err); } @@ -1092,8 +1097,8 @@ Dash.prototype.start = function(callback) { * Helper to determine the state of the database. * @param {Function} callback */ -Dash.prototype.isSynced = function(callback) { - this.syncPercentage(function(err, percentage) { +Dash.prototype.isSynced = function (callback) { + this.syncPercentage(function (err, percentage) { if (err) { return callback(err); } @@ -1109,9 +1114,9 @@ Dash.prototype.isSynced = function(callback) { * Helper to determine the progress of the database. * @param {Function} callback */ -Dash.prototype.syncPercentage = function(callback) { +Dash.prototype.syncPercentage = function (callback) { var self = this; - this.client.getBlockchainInfo(function(err, response) { + this.client.getBlockchainInfo(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1120,7 +1125,7 @@ Dash.prototype.syncPercentage = function(callback) { }); }; -Dash.prototype._normalizeAddressArg = function(addressArg) { +Dash.prototype._normalizeAddressArg = function (addressArg) { var addresses = [addressArg]; if (Array.isArray(addressArg)) { addresses = addressArg; @@ -1134,17 +1139,17 @@ Dash.prototype._normalizeAddressArg = function(addressArg) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressBalance = function(addressArg, options, callback) { +Dash.prototype.getAddressBalance = function (addressArg, options, callback) { var self = this; var addresses = self._normalizeAddressArg(addressArg); var cacheKey = addresses.join(''); var balance = self.balanceCache.get(cacheKey); if (balance) { - return setImmediate(function() { + return setImmediate(function () { callback(null, balance); }); } else { - this.client.getAddressBalance({addresses: addresses}, function(err, response) { + this.client.getAddressBalance({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1160,7 +1165,7 @@ Dash.prototype.getAddressBalance = function(addressArg, options, callback) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, callback) { +Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options, callback) { var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var addresses = self._normalizeAddressArg(addressArg); @@ -1218,7 +1223,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, mempoolUnspentOutputs.reverse().concat(confirmedUtxos), fromArg, toArg, fromHeight, toHeight); if (isSpentOutputs) { - var filteredUtxos = utxos.filter(function(utxo) { + var filteredUtxos = utxos.filter(function (utxo) { if (!spentOutputs[utxo.txid]) { return true; } else { @@ -1239,11 +1244,11 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, function finish(mempoolDeltas) { if (utxos) { - return setImmediate(function() { + return setImmediate(function () { callback(null, updateWithMempool(utxos, mempoolDeltas)); }); } else { - self.client.getAddressUtxos({addresses: addresses}, function(err, response) { + self.client.getAddressUtxos({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1255,7 +1260,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function(err, response) { + self.client.getAddressMempool({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1273,7 +1278,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback) { +Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callback) { var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var addresses = self._normalizeAddressArg(addressArg); @@ -1318,7 +1323,7 @@ Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback var utxos = mempoolUnspentOutputs.reverse().concat(confirmedUtxos); if (isSpentOutputs) { - return utxos.filter(function(utxo) { + return utxos.filter(function (utxo) { if (!spentOutputs[utxo.txid]) { return true; } else { @@ -1332,11 +1337,11 @@ Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback function finish(mempoolDeltas) { if (utxos) { - return setImmediate(function() { + return setImmediate(function () { callback(null, updateWithMempool(utxos, mempoolDeltas)); }); } else { - self.client.getAddressUtxos({addresses: addresses}, function(err, response) { + self.client.getAddressUtxos({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1348,7 +1353,7 @@ Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function(err, response) { + self.client.getAddressMempool({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1360,7 +1365,7 @@ Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback }; -Dash.prototype._getBalanceFromMempool = function(deltas) { +Dash.prototype._getBalanceFromMempool = function (deltas) { var satoshis = 0; for (var i = 0; i < deltas.length; i++) { satoshis += deltas[i].satoshis; @@ -1368,7 +1373,7 @@ Dash.prototype._getBalanceFromMempool = function(deltas) { return satoshis; }; -Dash.prototype._getTxidsFromMempool = function(deltas) { +Dash.prototype._getTxidsFromMempool = function (deltas) { var mempoolTxids = []; var mempoolTxidsKnown = {}; for (var i = 0; i < deltas.length; i++) { @@ -1381,7 +1386,7 @@ Dash.prototype._getTxidsFromMempool = function(deltas) { return mempoolTxids; }; -Dash.prototype._getHeightRangeQuery = function(options, clone) { +Dash.prototype._getHeightRangeQuery = function (options, clone) { if (options.start >= 0 && options.end >= 0) { if (options.end > options.start) { throw new TypeError('"end" is expected to be less than or equal to "start"'); @@ -1402,14 +1407,14 @@ Dash.prototype._getHeightRangeQuery = function(options, clone) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressTxids = function(addressArg, options, callback) { +Dash.prototype.getAddressTxids = function (addressArg, options, callback) { /* jshint maxstatements: 16 */ var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var rangeQuery = false; try { rangeQuery = self._getHeightRangeQuery(options); - } catch(err) { + } catch (err) { return callback(err); } if (rangeQuery) { @@ -1423,7 +1428,7 @@ Dash.prototype.getAddressTxids = function(addressArg, options, callback) { function finish() { if (txids && !rangeQuery) { var allTxids = mempoolTxids.reverse().concat(txids); - return setImmediate(function() { + return setImmediate(function () { callback(null, allTxids); }); } else { @@ -1433,7 +1438,7 @@ Dash.prototype.getAddressTxids = function(addressArg, options, callback) { if (rangeQuery) { self._getHeightRangeQuery(options, txidOpts); } - self.client.getAddressTxids(txidOpts, function(err, response) { + self.client.getAddressTxids(txidOpts, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1448,7 +1453,7 @@ Dash.prototype.getAddressTxids = function(addressArg, options, callback) { } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function(err, response) { + self.client.getAddressMempool({addresses: addresses}, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1461,7 +1466,7 @@ Dash.prototype.getAddressTxids = function(addressArg, options, callback) { }; -Dash.prototype._getConfirmationsDetail = function(transaction) { +Dash.prototype._getConfirmationsDetail = function (transaction) { $.checkState(this.height > 0, 'current height is unknown'); var confirmations = 0; if (transaction.height >= 0) { @@ -1473,7 +1478,7 @@ Dash.prototype._getConfirmationsDetail = function(transaction) { return Math.max(0, confirmations); }; -Dash.prototype._getAddressDetailsForInput = function(input, inputIndex, result, addressStrings) { +Dash.prototype._getAddressDetailsForInput = function (input, inputIndex, result, addressStrings) { if (!input.address) { return; } @@ -1491,7 +1496,7 @@ Dash.prototype._getAddressDetailsForInput = function(input, inputIndex, result, } }; -Dash.prototype._getAddressDetailsForOutput = function(output, outputIndex, result, addressStrings) { +Dash.prototype._getAddressDetailsForOutput = function (output, outputIndex, result, addressStrings) { if (!output.address) { return; } @@ -1509,7 +1514,7 @@ Dash.prototype._getAddressDetailsForOutput = function(output, outputIndex, resul } }; -Dash.prototype._getAddressDetailsForTransaction = function(transaction, addressStrings) { +Dash.prototype._getAddressDetailsForTransaction = function (transaction, addressStrings) { var result = { addresses: {}, satoshis: 0 @@ -1535,12 +1540,12 @@ Dash.prototype._getAddressDetailsForTransaction = function(transaction, addressS * @param {Object} txid - A dash transaction id * @param {Function} callback */ -Dash.prototype._getAddressDetailedTransaction = function(txid, options, next) { +Dash.prototype._getAddressDetailedTransaction = function (txid, options, next) { var self = this; self.getDetailedTransaction( txid, - function(err, transaction) { + function (err, transaction) { if (err) { return next(err); } @@ -1558,7 +1563,7 @@ Dash.prototype._getAddressDetailedTransaction = function(txid, options, next) { ); }; -Dash.prototype._getAddressStrings = function(addresses) { +Dash.prototype._getAddressStrings = function (addresses) { var addressStrings = []; for (var i = 0; i < addresses.length; i++) { var address = addresses[i]; @@ -1573,7 +1578,7 @@ Dash.prototype._getAddressStrings = function(addresses) { return addressStrings; }; -Dash.prototype._paginate = function(fullArray, fromArg, toArg, fromHeight, toHeight) { +Dash.prototype._paginate = function (fullArray, fromArg, toArg, fromHeight, toHeight) { var slicedArray; var filteredArray; var from = parseInt(fromArg); @@ -1582,21 +1587,21 @@ Dash.prototype._paginate = function(fullArray, fromArg, toArg, fromHeight, toHei $.checkState( fromHeight < toHeight, '"fromHeight" (' + fromHeight + ')' + ' is expected to be less than "toHeight" (' + toHeight + ')'); - filteredArray = fullArray.filter(function(item) { + filteredArray = fullArray.filter(function (item) { if (item.height >= fromHeight && item.height <= toHeight) { return item; } }); } if (fromHeight !== undefined && toHeight === undefined) { - filteredArray = fullArray.filter(function(item) { + filteredArray = fullArray.filter(function (item) { if (item.height >= fromHeight) { return item; } }); } if (toHeight !== undefined && fromHeight === undefined) { - filteredArray = fullArray.filter(function(item) { + filteredArray = fullArray.filter(function (item) { if (item.height <= toHeight) { return item; } @@ -1617,7 +1622,7 @@ Dash.prototype._paginate = function(fullArray, fromArg, toArg, fromHeight, toHei * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressHistory = function(addressArg, options, callback) { +Dash.prototype.getAddressHistory = function (addressArg, options, callback) { var self = this; var addresses = self._normalizeAddressArg(addressArg); if (addresses.length > this.maxAddressesQuery) { @@ -1635,11 +1640,11 @@ Dash.prototype.getAddressHistory = function(addressArg, options, callback) { if ((toArg - fromArg) > self.maxTransactionHistory) { return callback(new Error( '"from" (' + options.from + ') and "to" (' + options.to + ') range should be less than or equal to ' + - self.maxTransactionHistory + self.maxTransactionHistory )); } - self.getAddressTxids(addresses, options, function(err, txids) { + self.getAddressTxids(addresses, options, function (err, txids) { if (err) { return callback(err); } @@ -1647,20 +1652,20 @@ Dash.prototype.getAddressHistory = function(addressArg, options, callback) { var totalCount = txids.length; try { txids = self._paginate(txids, fromArg, toArg, fromHeight, toHeight); - } catch(e) { + } catch (e) { return callback(e); } async.mapLimit( txids, self.transactionConcurrency, - function(txid, next) { + function (txid, next) { self._getAddressDetailedTransaction(txid, { queryMempool: queryMempool, addressStrings: addressStrings }, next); }, - function(err, transactions) { + function (err, transactions) { if (err) { return callback(err); } @@ -1679,7 +1684,7 @@ Dash.prototype.getAddressHistory = function(addressArg, options, callback) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressSummary = function(addressArg, options, callback) { +Dash.prototype.getAddressSummary = function (addressArg, options, callback) { var self = this; var summary = {}; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; @@ -1698,14 +1703,14 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { if ((toArg - fromArg) > self.maxTxids) { return callback(new Error( - '"from" (' + fromArg + ') and "to" (' + toArg + ') range should be less than or equal to ' + - self.maxTxids + '"from" (' + fromArg + ') and "to" (' + toArg + ') range should be less than or equal to ' + + self.maxTxids )); } var paginatedTxids; try { paginatedTxids = self._paginate(allTxids, fromArg, toArg, fromHeight, toHeight); - } catch(e) { + } catch (e) { return callback(e); } @@ -1720,7 +1725,7 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { function querySummary() { async.parallel([ function getTxList(done) { - self.getAddressTxids(addresses, {queryMempool: false}, function(err, txids) { + self.getAddressTxids(addresses, {queryMempool: false}, function (err, txids) { if (err) { return done(err); } @@ -1730,7 +1735,7 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { }); }, function getBalance(done) { - self.getAddressBalance(addresses, options, function(err, data) { + self.getAddressBalance(addresses, options, function (err, data) { if (err) { return done(err); } @@ -1744,7 +1749,7 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { if (!queryMempool) { return done(); } - self.client.getAddressMempool({'addresses': addresses}, function(err, response) { + self.client.getAddressMempool({'addresses': addresses}, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1754,7 +1759,7 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { done(); }); }, - ], function(err) { + ], function (err) { if (err) { return callback(err); } @@ -1783,11 +1788,11 @@ Dash.prototype.getAddressSummary = function(addressArg, options, callback) { * @param {Function} callback * @private */ -Dash.prototype._maybeGetBlockHash = function(blockArg, callback) { +Dash.prototype._maybeGetBlockHash = function (blockArg, callback) { var self = this; if (_.isNumber(blockArg) || (blockArg.length < 40 && /^[0-9]+$/.test(blockArg))) { - self._tryAllClients(function(client, done) { - client.getBlockHash(blockArg, function(err, response) { + self._tryAllClients(function (client, done) { + client.getBlockHash(blockArg, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1804,7 +1809,7 @@ Dash.prototype._maybeGetBlockHash = function(blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getRawBlock = function(blockArg, callback) { +Dash.prototype.getRawBlock = function (blockArg, callback) { // TODO apply performance patch to the RPC method for raw data var self = this; @@ -1812,8 +1817,8 @@ Dash.prototype.getRawBlock = function(blockArg, callback) { if (err) { return callback(err); } - self._tryAllClients(function(client, done) { - self.client.getBlock(blockhash, false, function(err, response) { + self._tryAllClients(function (client, done) { + self.client.getBlock(blockhash, false, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1826,7 +1831,7 @@ Dash.prototype.getRawBlock = function(blockArg, callback) { var cachedBlock = self.rawBlockCache.get(blockArg); if (cachedBlock) { - return setImmediate(function() { + return setImmediate(function () { callback(null, cachedBlock); }); } else { @@ -1839,7 +1844,7 @@ Dash.prototype.getRawBlock = function(blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getBlockOverview = function(blockArg, callback) { +Dash.prototype.getBlockOverview = function (blockArg, callback) { var self = this; function queryBlock(err, blockhash) { @@ -1848,12 +1853,12 @@ Dash.prototype.getBlockOverview = function(blockArg, callback) { } var cachedBlock = self.blockOverviewCache.get(blockhash); if (cachedBlock) { - return setImmediate(function() { + return setImmediate(function () { callback(null, cachedBlock); }); } else { - self._tryAllClients(function(client, done) { - client.getBlock(blockhash, true, function(err, response) { + self._tryAllClients(function (client, done) { + client.getBlock(blockhash, true, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1889,7 +1894,7 @@ Dash.prototype.getBlockOverview = function(blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getBlock = function(blockArg, callback) { +Dash.prototype.getBlock = function (blockArg, callback) { // TODO apply performance patch to the RPC method for raw data var self = this; @@ -1899,12 +1904,12 @@ Dash.prototype.getBlock = function(blockArg, callback) { } var cachedBlock = self.blockCache.get(blockhash); if (cachedBlock) { - return setImmediate(function() { + return setImmediate(function () { callback(null, cachedBlock); }); } else { - self._tryAllClients(function(client, done) { - client.getBlock(blockhash, false, function(err, response) { + self._tryAllClients(function (client, done) { + client.getBlock(blockhash, false, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1925,9 +1930,9 @@ Dash.prototype.getBlock = function(blockArg, callback) { * @param {Number} low - The older timestamp in seconds * @param {Function} callback */ -Dash.prototype.getBlockHashesByTimestamp = function(high, low, callback) { +Dash.prototype.getBlockHashesByTimestamp = function (high, low, callback) { var self = this; - self.client.getBlockHashes(high, low, function(err, response) { + self.client.getBlockHashes(high, low, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1955,15 +1960,15 @@ Dash.prototype.getBlockHashesByTimestamp = function(high, low, callback) { * @param {String|Number} block - A block hash or block height * @param {Function} callback */ -Dash.prototype.getBlockHeader = function(blockArg, callback) { +Dash.prototype.getBlockHeader = function (blockArg, callback) { var self = this; function queryHeader(err, blockhash) { if (err) { return callback(err); } - self._tryAllClients(function(client, done) { - client.getBlockHeader(blockhash, function(err, response) { + self._tryAllClients(function (client, done) { + client.getBlockHeader(blockhash, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2012,26 +2017,26 @@ Dash.prototype.getBlockHeader = function(blockArg, callback) { * @param {Function} callback * @param {String|Number} nbOfBlockToFetch - A value allowing to choose how many block to fetch */ -Dash.prototype.getBlockHeaders = function(blockArg, callback, nbOfBlockToFetch) { - var self = this; - var _toFetch = 25; +Dash.prototype.getBlockHeaders = function (blockArg, callback, nbOfBlockToFetch) { + var self = this; + var _toFetch = 25; - if (nbOfBlockToFetch) { + if (nbOfBlockToFetch) { - if (nbOfBlockToFetch.constructor.name === 'String' && !isNaN(parseInt(nbOfBlockToFetch))) { + if (nbOfBlockToFetch.constructor.name === 'String' && !isNaN(parseInt(nbOfBlockToFetch))) { _toFetch = parseInt(nbOfBlockToFetch); - } - if (nbOfBlockToFetch.constructor.name === 'Number') { - _toFetch = nbOfBlockToFetch; - } - if (_toFetch > 250) { - _toFetch = 250;//Limit to avoid asking to many blocks. - } - } - - self._maybeGetBlockHash(blockArg, function(err, blockhash) { - if (err) { - return callback(err); + } + if (nbOfBlockToFetch.constructor.name === 'Number') { + _toFetch = nbOfBlockToFetch; + } + if (_toFetch > 250) { + _toFetch = 250;//Limit to avoid asking to many blocks. + } + } + + self._maybeGetBlockHash(blockArg, function (err, blockhash) { + if (err) { + return callback(err); } var headers = []; var nextHash = blockhash; @@ -2061,9 +2066,9 @@ Dash.prototype.getBlockHeaders = function(blockArg, callback, nbOfBlockToFetch) * @param {Number} blocks - The number of blocks for the transaction to be confirmed. * @param {Function} callback */ -Dash.prototype.estimateFee = function(blocks, callback) { +Dash.prototype.estimateFee = function (blocks, callback) { var self = this; - this.client.estimateFee(blocks, function(err, response) { + this.client.estimateFee(blocks, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2078,28 +2083,28 @@ Dash.prototype.estimateFee = function(blocks, callback) { * @param {Boolean=} options.maxFeeRate - Cap large fees (0 for unlimited) * @param {Function} callback */ -Dash.prototype.sendTransaction = function(tx, options, callback) { +Dash.prototype.sendTransaction = function (tx, options, callback) { var self = this; var maxFeeRate = 0.00015000; // duff/kB (typically 1000) var isInstantSend = false; if (_.isFunction(options) && _.isUndefined(callback)) { callback = options; } else if (_.isObject(options)) { - if(options.hasOwnProperty('maxFeeRate')){ - maxFeeRate = options.maxFeeRate; + if (options.hasOwnProperty('maxFeeRate')) { + maxFeeRate = options.maxFeeRate; } - if(options.hasOwnProperty('allowAbsurdFees')){ + if (options.hasOwnProperty('allowAbsurdFees')) { console.warn(`the boolean 'allowAbsurdFees' has been replaced by the int 'maxFeeRate'`); - if(true === options.allowAbsurdFees) { + if (true === options.allowAbsurdFees) { maxFeeRate = 0; // unlimited } } - if(options.hasOwnProperty('isInstantSend')){ - isInstantSend = options.isInstantSend; + if (options.hasOwnProperty('isInstantSend')) { + isInstantSend = options.isInstantSend; } } - this.client.sendRawTransaction(tx, maxFeeRate, isInstantSend, function(err, response) { + this.client.sendRawTransaction(tx, maxFeeRate, isInstantSend, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2108,10 +2113,10 @@ Dash.prototype.sendTransaction = function(tx, options, callback) { }; -Dash.prototype._getRawTransactionData = function(txid, callback) { +Dash.prototype._getRawTransactionData = function (txid, callback) { var self = this; - self._tryAllClients(function(client, done) { - client.getRawTransaction(txid, function(err, response) { + self._tryAllClients(function (client, done) { + client.getRawTransaction(txid, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2125,15 +2130,15 @@ Dash.prototype._getRawTransactionData = function(txid, callback) { * @param {String} txid - The transaction hash * @param {Function} callback */ -Dash.prototype.getRawTransaction = function(txid, callback) { +Dash.prototype.getRawTransaction = function (txid, callback) { var self = this; var tx = self.rawTransactionCache.get(txid); if (tx) { - return setImmediate(function() { + return setImmediate(function () { callback(null, tx); }); } else { - self._getRawTransactionData(txid, function(err, transactionData) { + self._getRawTransactionData(txid, function (err, transactionData) { if (err) { return callback(err); } @@ -2150,15 +2155,15 @@ Dash.prototype.getRawTransaction = function(txid, callback) { * @param {Boolean} queryMempool - Include the mempool * @param {Function} callback */ -Dash.prototype.getTransaction = function(txid, callback) { +Dash.prototype.getTransaction = function (txid, callback) { var self = this; var tx = self.transactionCache.get(txid); if (tx) { - return setImmediate(function() { + return setImmediate(function () { callback(null, tx); }); } else { - self._getRawTransactionData(txid, function(err, transactionData) { + self._getRawTransactionData(txid, function (err, transactionData) { if (err) { return callback(err); } @@ -2212,14 +2217,14 @@ Dash.prototype.getTransaction = function(txid, callback) { * @param {String} txid - The hex string of the transaction * @param {Function} callback */ -Dash.prototype.getDetailedTransaction = function(txid, callback) { +Dash.prototype.getDetailedTransaction = function (txid, callback) { var self = this; var tx = self.transactionDetailedCache.get(txid); function addInputsToTx(tx, result) { tx.inputs = []; tx.inputSatoshis = 0; - for(var inputIndex = 0; inputIndex < result.vin.length; inputIndex++) { + for (var inputIndex = 0; inputIndex < result.vin.length; inputIndex++) { var input = result.vin[inputIndex]; if (!tx.coinbase) { tx.inputSatoshis += input.valueSat; @@ -2247,14 +2252,14 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { function addOutputsToTx(tx, result) { tx.outputs = []; tx.outputSatoshis = 0; - for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { + for (var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; var address = null; if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { address = out.scriptPubKey.addresses[0]; } else { - address = out.scriptPubKey.address; + address = out.scriptPubKey.address ?? null; } tx.outputs.push({ satoshis: out.valueSat, @@ -2282,28 +2287,28 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { if (result.proRegTx !== undefined) { tx.proRegTx = result.proRegTx; - }else if (result.proUpServTx !== undefined) { + } else if (result.proUpServTx !== undefined) { tx.proUpServTx = result.proUpServTx; - }else if (result.proUpRegTx !== undefined) { + } else if (result.proUpRegTx !== undefined) { tx.proUpRegTx = result.proUpRegTx; - }else if (result.proUpRevTx !== undefined) { + } else if (result.proUpRevTx !== undefined) { tx.proUpRevTx = result.proUpRevTx; - }else if (result.cbTx !== undefined) { + } else if (result.cbTx !== undefined) { tx.cbTx = result.cbTx; - }else if (result.qcTx !== undefined) { + } else if (result.qcTx !== undefined) { tx.qcTx = result.qcTx; - }else if (result.mnhfTx !== undefined) { + } else if (result.mnhfTx !== undefined) { tx.mnhfTx = result.mnhfTx; } } if (tx) { - return setImmediate(function() { + return setImmediate(function () { callback(null, tx); }); } else { - self._tryAllClients(function(client, done) { - client.getRawTransaction(txid, 1, function(err, response) { + self._tryAllClients(function (client, done) { + client.getRawTransaction(txid, 1, function (err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2348,9 +2353,9 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { * @param options - should be either "1" or "2", used to filter the object type * @param callback */ -Dash.prototype.govObjectList = function(options, callback) { +Dash.prototype.govObjectList = function (options, callback) { var self = this; - this.client.gobject('list', function(err, response) { + this.client.gobject('list', function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2361,23 +2366,23 @@ Dash.prototype.govObjectList = function(options, callback) { var proposal = new Proposal(response.result[gobjects[i]].DataHex); if ((options.type && proposal.type === options.type)) { - result.push({ - Hash: gobjects[i], - DataHex: response.result.DataHex, - DataObject: { - end_epoch: proposal.end_epoch, - name: proposal.name, - payment_address: proposal.payment_address, - payment_amount: proposal.payment_amount, - start_epoch: proposal.start_epoch, - type: proposal.type, - url: proposal.url - }, - AbsoluteYesCount: response.result[gobjects[i]].AbsoluteYesCount, - YesCount: response.result[gobjects[i]].YesCount, - NoCount: response.result[gobjects[i]].NoCount, - AbstainCount: response.result[gobjects[i]].AbstainCount - }); + result.push({ + Hash: gobjects[i], + DataHex: response.result.DataHex, + DataObject: { + end_epoch: proposal.end_epoch, + name: proposal.name, + payment_address: proposal.payment_address, + payment_amount: proposal.payment_amount, + start_epoch: proposal.start_epoch, + type: proposal.type, + url: proposal.url + }, + AbsoluteYesCount: response.result[gobjects[i]].AbsoluteYesCount, + YesCount: response.result[gobjects[i]].YesCount, + NoCount: response.result[gobjects[i]].NoCount, + AbstainCount: response.result[gobjects[i]].AbstainCount + }); } } @@ -2389,7 +2394,7 @@ Dash.prototype.govObjectList = function(options, callback) { Dash.prototype.getCurrentVotes = function (govhash, callback) { var self = this; - this.client.gobject('getcurrentvotes', govhash, function(err, response) { + this.client.gobject('getcurrentvotes', govhash, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2399,7 +2404,7 @@ Dash.prototype.getCurrentVotes = function (govhash, callback) { Dash.prototype.getVotes = function (govhash, callback) { var self = this; - this.client.gobject('getvotes', govhash, function(err, response) { + this.client.gobject('getvotes', govhash, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2409,7 +2414,7 @@ Dash.prototype.getVotes = function (govhash, callback) { Dash.prototype.getSuperBlockBudget = function (blockindex, callback) { var self = this; - this.client.getsuperblockbudget(blockindex, function(err, response) { + this.client.getsuperblockbudget(blockindex, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2419,7 +2424,7 @@ Dash.prototype.getSuperBlockBudget = function (blockindex, callback) { /*jshint maxparams: 6 */ Dash.prototype.govObjectSubmit = function (parentHash, revision, time, dataHex, feeTxId, callback) { var self = this; - this.client.gobject('submit', parentHash, revision, time, dataHex, feeTxId, function(err, response) { + this.client.gobject('submit', parentHash, revision, time, dataHex, feeTxId, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2429,7 +2434,7 @@ Dash.prototype.govObjectSubmit = function (parentHash, revision, time, dataHex, Dash.prototype.govObjectDeserialize = function (hexdata, callback) { var self = this; - this.client.gobject('deserialize', hexdata, function(err, response) { + this.client.gobject('deserialize', hexdata, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2437,10 +2442,10 @@ Dash.prototype.govObjectDeserialize = function (hexdata, callback) { }); }; -Dash.prototype.govObjectCheck = function(hexdata, callback){ +Dash.prototype.govObjectCheck = function (hexdata, callback) { var self = this; - this.client.gobject('check', hexdata, function(err, response) { + this.client.gobject('check', hexdata, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2450,15 +2455,15 @@ Dash.prototype.govObjectCheck = function(hexdata, callback){ Dash.prototype.govObjectInfo = function (callback) { var self = this; var result = self.govCache.get('info'); - if(result){ + if (result) { callback(null, result); - }else{ - this.client.getgovernanceinfo(function(err, response) { + } else { + this.client.getgovernanceinfo(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.govCache.set('info',response); + self.govCache.set('info', response); callback(null, response); }); } @@ -2466,44 +2471,44 @@ Dash.prototype.govObjectInfo = function (callback) { Dash.prototype.govCount = function (callback) { var self = this; var result = self.govCache.get('count'); - if(result){ + if (result) { callback(null, result); - }else{ - this.client.gobject('count',function(err, response) { + } else { + this.client.gobject('count', function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.govCache.set('count',response); + self.govCache.set('count', response); callback(null, response); }); } }; -Dash.prototype.getSpork = function(callback){ - var self = this; - var SporksList = {}; - self.client.spork('show', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = {sporks:response.result}; - var SporksData = self.sporksListCache.get(''); - if (SporksData) { - return setImmediate(function() { - callback(null, SporksData); - }); - }else{ - SporksList=result; - self.sporksListCache.set('', SporksList); - return callback(null, SporksList); - } - }else{ - return callback(new Error('Impossible to get Sporks Data'),null); - } - }); -}; - -Dash.prototype.getMNList = function(callback){ +Dash.prototype.getSpork = function (callback) { + var self = this; + var SporksList = {}; + self.client.spork('show', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = {sporks: response.result}; + var SporksData = self.sporksListCache.get(''); + if (SporksData) { + return setImmediate(function () { + callback(null, SporksData); + }); + } else { + SporksList = result; + self.sporksListCache.set('', SporksList); + return callback(null, SporksList); + } + } else { + return callback(new Error('Impossible to get Sporks Data'), null); + } + }); +}; + +Dash.prototype.getMNList = function (callback) { var self = this; - var rawResults= {}; + var rawResults = {}; var MNList = []; var checkSync = function checkSync(next) { @@ -2518,124 +2523,124 @@ Dash.prototype.getMNList = function(callback){ }); }; - var getRank = function(next){ - self.client.masternodelist('rank', function(err, response){ - if(response && response.hasOwnProperty('result')){ + var getRank = function (next) { + self.client.masternodelist('rank', function (err, response) { + if (response && response.hasOwnProperty('result')) { var result = response.result; - rawResults.rank=result; + rawResults.rank = result; } - next(); + next(); }); }; - var getProtocol = function(next){ - self.client.masternodelist('protocol', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.protocol=result; - } - next(); - }); + var getProtocol = function (next) { + self.client.masternodelist('protocol', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.protocol = result; + } + next(); + }); }; - var getPayee = function(next){ - self.client.masternodelist('payee', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.payee=result; - } - next(); - }); + var getPayee = function (next) { + self.client.masternodelist('payee', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.payee = result; + } + next(); + }); }; - var getLastSeen = function(next){ - self.client.masternodelist('lastseen', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.lastseen=result; - } - next(); - }); + var getLastSeen = function (next) { + self.client.masternodelist('lastseen', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.lastseen = result; + } + next(); + }); }; - var getActiveSeconds=function(next){ - self.client.masternodelist('activeseconds', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.activeseconds=result; - } - next(); - }); + var getActiveSeconds = function (next) { + self.client.masternodelist('activeseconds', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.activeseconds = result; + } + next(); + }); }; - var getIP = function(next){ - self.client.masternodelist('addr', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.addr=result; - } - next(); - }); + var getIP = function (next) { + self.client.masternodelist('addr', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.addr = result; + } + next(); + }); }; - var getStatus = function(next){ - self.client.masternodelist('status', function(err, response){ - if(response && response.hasOwnProperty('result')){ - var result = response.result; - rawResults.status=result; - } - next(); - }); + var getStatus = function (next) { + self.client.masternodelist('status', function (err, response) { + if (response && response.hasOwnProperty('result')) { + var result = response.result; + rawResults.status = result; + } + next(); + }); }; - var prepareResponse = function(err){ - if(err){ - return callback(self._wrapRPCError(err),null); + var prepareResponse = function (err) { + if (err) { + return callback(self._wrapRPCError(err), null); } var keys = Object.keys(rawResults); - if( - keys.indexOf('rank') > -1 && - keys.indexOf('protocol')> -1 && - keys.indexOf('payee')> -1 && - keys.indexOf('lastseen')> -1 && - keys.indexOf('activeseconds')> -1 && - keys.indexOf('addr')> -1 - ){ - var rankKeys = Object.keys(rawResults.lastseen); - var rankLength = rankKeys.length; - - //We get threw all vins by rank - for(var i = 0; i -1 && + keys.indexOf('protocol') > -1 && + keys.indexOf('payee') > -1 && + keys.indexOf('lastseen') > -1 && + keys.indexOf('activeseconds') > -1 && + keys.indexOf('addr') > -1 + ) { + var rankKeys = Object.keys(rawResults.lastseen); + var rankLength = rankKeys.length; + + //We get threw all vins by rank + for (var i = 0; i < rankLength; i++) { + var vin = rankKeys[i]; + var MN = { + vin: vin, + status: rawResults.status[vin], + rank: i + 1, + ip: rawResults.addr[vin], + protocol: rawResults.protocol[vin], + payee: rawResults.payee[vin], + activeseconds: rawResults.activeseconds[vin], + lastseen: rawResults.lastseen[vin], + }; + MNList.push(MN); + } + } else { + return callback(new Error('Invalid MasternodeList'), null); } - self.masternodeListCache.set('', MNList); - return callback(null, MNList); + self.masternodeListCache.set('', MNList); + return callback(null, MNList); }; var MNListData = self.masternodeListCache.get(''); if (MNListData) { - return setImmediate(function() { - callback(null, MNListData); - }); + return setImmediate(function () { + callback(null, MNListData); + }); } else { - return async.series([ - checkSync, - getRank, - getProtocol, - getPayee, - getLastSeen, - getActiveSeconds, - getIP, - getStatus - ], - prepareResponse); + return async.series([ + checkSync, + getRank, + getProtocol, + getPayee, + getLastSeen, + getActiveSeconds, + getIP, + getStatus + ], + prepareResponse); } }; @@ -2645,40 +2650,40 @@ Dash.prototype.getMNList = function(callback){ * @param hash * @param callback */ -Dash.prototype.govObjectHash = function(hash, callback) { +Dash.prototype.govObjectHash = function (hash, callback) { var self = this; - this.client.gobject('get', hash, function(err, response) { - if (err) { - return callback(self._wrapRPCError(err)); - } + this.client.gobject('get', hash, function (err, response) { + if (err) { + return callback(self._wrapRPCError(err)); + } - var result = []; - - var proposal = new Proposal(response.result.DataHex); - - // TODO: serialize proposal back to Hex to verify it's consistent with RPC - result.push({ - Hash: response.result.Hash, - CollateralHash: response.result.CollateralHash, - DataHex: response.result.DataHex, - DataObject: { - end_epoch: proposal.end_epoch, - name: proposal.name, - payment_address: proposal.payment_address, - payment_amount: proposal.payment_amount, - start_epoch: proposal.start_epoch, - type: proposal.type, - url: proposal.url - }, - CreationTime: response.result.CreationTime, - FundingResult: response.result.FundingResult, - ValidResult: response.result.ValidResult, - DeleteResult: response.result.DeleteResult, - EndorsedResult: response.result.EndorsedResult - }); + var result = []; + + var proposal = new Proposal(response.result.DataHex); + + // TODO: serialize proposal back to Hex to verify it's consistent with RPC + result.push({ + Hash: response.result.Hash, + CollateralHash: response.result.CollateralHash, + DataHex: response.result.DataHex, + DataObject: { + end_epoch: proposal.end_epoch, + name: proposal.name, + payment_address: proposal.payment_address, + payment_amount: proposal.payment_amount, + start_epoch: proposal.start_epoch, + type: proposal.type, + url: proposal.url + }, + CreationTime: response.result.CreationTime, + FundingResult: response.result.FundingResult, + ValidResult: response.result.ValidResult, + DeleteResult: response.result.DeleteResult, + EndorsedResult: response.result.EndorsedResult + }); - callback(null, result); + callback(null, result); }); @@ -2703,9 +2708,9 @@ Dash.prototype.govObjectCheck = function govObjectCheck(hexdata, callback) { * Will get the best block hash for the chain. * @param {Function} callback */ -Dash.prototype.getBestBlockHash = function(callback) { +Dash.prototype.getBestBlockHash = function (callback) { var self = this; - this.client.getBestBlockHash(function(err, response) { + this.client.getBestBlockHash(function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2732,9 +2737,9 @@ Dash.prototype.getBestChainLock = function (callback) { * Will give the txid and inputIndex that spent an output * @param {Function} callback */ -Dash.prototype.getSpentInfo = function(options, callback) { +Dash.prototype.getSpentInfo = function (options, callback) { var self = this; - this.client.getSpentInfo(options, function(err, response) { + this.client.getSpentInfo(options, function (err, response) { if (err && err.code === -5) { return callback(null, {}); } else if (err) { @@ -2760,17 +2765,17 @@ Dash.prototype.getSpentInfo = function(options, callback) { * } * @param {Function} callback */ -Dash.prototype.getInfo = function(callback) { +Dash.prototype.getInfo = function (callback) { var self = this; var client = this.client; - client.getNetworkInfo(function (err, networkResponse){ + client.getNetworkInfo(function (err, networkResponse) { if (err) { return callback(self._wrapRPCError(err)); } const networkInfo = networkResponse.result; - client.getBlockchainInfo(function (err, blockchainResponse){ - if(err){ + client.getBlockchainInfo(function (err, blockchainResponse) { + if (err) { return callback(self._wrapRPCError(err)); } const blockchainInfo = blockchainResponse.result; @@ -2793,9 +2798,9 @@ Dash.prototype.getInfo = function(callback) { }); }; -Dash.prototype.generateBlock = function(num, callback) { +Dash.prototype.generateBlock = function (num, callback) { var self = this; - this.client.generate(num, function(err, response) { + this.client.generate(num, function (err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2807,10 +2812,10 @@ Dash.prototype.generateBlock = function(num, callback) { * Called by Node to stop the service. * @param {Function} callback */ -Dash.prototype.stop = function(callback) { +Dash.prototype.stop = function (callback) { if (this.spawn && this.spawn.process) { var exited = false; - this.spawn.process.once('exit', function(code) { + this.spawn.process.once('exit', function (code) { if (!exited) { exited = true; if (code !== 0) { @@ -2823,7 +2828,7 @@ Dash.prototype.stop = function(callback) { } }); this.spawn.process.kill('SIGINT'); - setTimeout(function() { + setTimeout(function () { if (!exited) { exited = true; return callback(new Error('dashd process did not exit')); From 60db30b7e5dc2381bce63958a9302ddc78865725 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 21 Sep 2024 02:54:54 +0500 Subject: [PATCH 12/13] lint fix --- lib/services/dashd.js | 903 +++++++++++++++++++++--------------------- 1 file changed, 449 insertions(+), 454 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 41f84bd7a..335d162bc 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -10,7 +10,7 @@ var async = require('async'); var LRU = require('lru-cache'); var DashdRPC = require('@dashevo/dashd-rpc'); var $ = dashcore.util.preconditions; -var _ = dashcore.deps._; +var _ = dashcore.deps._; var Transaction = dashcore.Transaction; var Proposal = dashcore.GovObject.Proposal; @@ -21,7 +21,6 @@ var utils = require('../utils'); var Service = require('../service'); var rawtxTopicBuffer = new Buffer('7261777478', 'hex'); var rawtxlockTopicBuffer = new Buffer('72617774786c6f636b', 'hex'); - /** * Provides a friendly event driven API to dashd in Node.js. Manages starting and * stopping dashd as a child process for application support, as well as connecting @@ -60,11 +59,10 @@ function Dash(options) { // for testing purposes this._process = options.process || process; - this.on('error', function (err) { + this.on('error', function(err) { log.error(err.stack); }); } - util.inherits(Dash, Service); Dash.dependencies = []; @@ -99,7 +97,7 @@ Dash.DEFAULT_CONFIG_SETTINGS = { uacomment: 'dashcore' }; -Dash.prototype._initDefaults = function (options) { +Dash.prototype._initDefaults = function(options) { /* jshint maxcomplexity: 15 */ // limits @@ -124,30 +122,30 @@ Dash.prototype._initDefaults = function (options) { this.zmqSubscribeProgress = options.zmqSubscribeProgress || Dash.DEFAULT_ZMQ_SUBSCRIBE_PROGRESS; }; -Dash.prototype._initCaches = function () { +Dash.prototype._initCaches = function() { var CACHES = [ - {name: 'utxos', lru: 50000}, - {name: 'txids', lru: 50000}, - {name: 'balance', lru: 50000}, - {name: 'summary', lru: 50000}, - {name: 'blockOverview', lru: 144}, - {name: 'transactionDetailed', lru: 100000}, - {name: 'masternodeList', lru: 50000}, - {name: 'sporksList', lru: 50}, + {name:'utxos', lru:50000}, + {name:'txids', lru:50000}, + {name:'balance', lru:50000}, + {name:'summary', lru:50000}, + {name:'blockOverview', lru:144}, + {name:'transactionDetailed', lru:100000}, + {name:'masternodeList', lru:50000}, + {name:'sporksList', lru:50}, //governance - {name: 'gov', lru: 20}, + {name:'gov', lru:20}, //cache valid indefinitely - {name: 'transaction', lru: 100000}, - {name: 'rawTransaction', lru: 50000}, - {name: 'block', lru: 144}, - {name: 'rawBlock', lru: 72}, - {name: 'blockHeader', lru: 288} + {name:'transaction', lru:100000}, + {name:'rawTransaction', lru:50000}, + {name:'block', lru:144}, + {name:'rawBlock', lru:72}, + {name:'blockHeader', lru:288} ]; var self = this; CACHES.forEach(function (el) { - self[el.name + 'Cache'] = LRU(el.lru); + self[el.name+'Cache']=LRU(el.lru); }); // caches valid until there is a new block @@ -159,12 +157,12 @@ Dash.prototype._initCaches = function () { }; -Dash.prototype._initClients = function () { +Dash.prototype._initClients = function() { var self = this; this.nodes = []; this.nodesIndex = 0; Object.defineProperty(this, 'client', { - get: function () { + get: function() { var client = self.nodes[self.nodesIndex].client; self.nodesIndex = (self.nodesIndex + 1) % self.nodes.length; return client; @@ -177,7 +175,7 @@ Dash.prototype._initClients = function () { /** * Called by Node to determine the available API methods. */ -Dash.prototype.getAPIMethods = function () { +Dash.prototype.getAPIMethods = function() { var methods = [ ['getBlock', this, this.getBlock, 1], ['getRawBlock', this, this.getRawBlock, 1], @@ -211,7 +209,7 @@ Dash.prototype.getAPIMethods = function () { /** * Called by the Bus to determine the available events. */ -Dash.prototype.getPublishEvents = function () { +Dash.prototype.getPublishEvents = function() { return [ { name: 'dashd/rawtransaction', @@ -240,12 +238,12 @@ Dash.prototype.getPublishEvents = function () { ]; }; -Dash.prototype.subscribe = function (name, emitter) { +Dash.prototype.subscribe = function(name, emitter) { this.subscriptions[name].push(emitter); log.info(emitter.remoteAddress, 'subscribe:', 'dashd/' + name, 'total:', this.subscriptions[name].length); }; -Dash.prototype.unsubscribe = function (name, emitter) { +Dash.prototype.unsubscribe = function(name, emitter) { var index = this.subscriptions[name].indexOf(emitter); if (index > -1) { this.subscriptions[name].splice(index, 1); @@ -253,11 +251,11 @@ Dash.prototype.unsubscribe = function (name, emitter) { log.info(emitter.remoteAddress, 'unsubscribe:', 'dashd/' + name, 'total:', this.subscriptions[name].length); }; -Dash.prototype.subscribeAddress = function (emitter, addresses) { +Dash.prototype.subscribeAddress = function(emitter, addresses) { var self = this; function addAddress(addressStr) { - if (self.subscriptions.address[addressStr]) { + if(self.subscriptions.address[addressStr]) { var emitters = self.subscriptions.address[addressStr]; var index = emitters.indexOf(emitter); if (index === -1) { @@ -267,9 +265,8 @@ Dash.prototype.subscribeAddress = function (emitter, addresses) { self.subscriptions.address[addressStr] = [emitter]; } } - - if (addresses) { - for (var i = 0; i < addresses.length; i++) { + if(addresses){ + for(var i = 0; i < addresses.length; i++) { if (dashcore.Address.isValid(addresses[i], this.node.network)) { addAddress(addresses[i]); } @@ -279,16 +276,16 @@ Dash.prototype.subscribeAddress = function (emitter, addresses) { log.info(emitter.remoteAddress, 'subscribe:', 'dashd/addresstxid', 'total:', _.size(this.subscriptions.address)); }; -Dash.prototype.unsubscribeAddress = function (emitter, addresses) { +Dash.prototype.unsubscribeAddress = function(emitter, addresses) { var self = this; - if (!addresses) { + if(!addresses) { return this.unsubscribeAddressAll(emitter); } function removeAddress(addressStr) { var emitters = self.subscriptions.address[addressStr]; var index = emitters.indexOf(emitter); - if (index > -1) { + if(index > -1) { emitters.splice(index, 1); if (emitters.length === 0) { delete self.subscriptions.address[addressStr]; @@ -296,8 +293,8 @@ Dash.prototype.unsubscribeAddress = function (emitter, addresses) { } } - for (var i = 0; i < addresses.length; i++) { - if (this.subscriptions.address[addresses[i]]) { + for(var i = 0; i < addresses.length; i++) { + if(this.subscriptions.address[addresses[i]]) { removeAddress(addresses[i]); } } @@ -310,11 +307,11 @@ Dash.prototype.unsubscribeAddress = function (emitter, addresses) { * @param {String} name - The name of the event * @param {EventEmitter} emitter - An instance of an event emitter */ -Dash.prototype.unsubscribeAddressAll = function (emitter) { - for (var hashHex in this.subscriptions.address) { +Dash.prototype.unsubscribeAddressAll = function(emitter) { + for(var hashHex in this.subscriptions.address) { var emitters = this.subscriptions.address[hashHex]; var index = emitters.indexOf(emitter); - if (index > -1) { + if(index > -1) { emitters.splice(index, 1); } if (emitters.length === 0) { @@ -324,20 +321,20 @@ Dash.prototype.unsubscribeAddressAll = function (emitter) { log.info(emitter.remoteAddress, 'unsubscribe:', 'dashd/addresstxid', 'total:', _.size(this.subscriptions.address)); }; -Dash.prototype._getDefaultConfig = function () { +Dash.prototype._getDefaultConfig = function() { var config = ''; var defaults = Dash.DEFAULT_CONFIG_SETTINGS; - for (var key in defaults) { + for(var key in defaults) { config += key + '=' + defaults[key] + '\n'; } return config; }; -Dash.prototype._parseDashConf = function (configPath) { +Dash.prototype._parseDashConf = function(configPath) { var options = {}; var file = fs.readFileSync(configPath); var unparsed = file.toString().split('\n'); - for (var i = 0; i < unparsed.length; i++) { + for(var i = 0; i < unparsed.length; i++) { var line = unparsed[i]; if (!line.match(/^\#/) && line.match(/\=/)) { var option = line.split('='); @@ -353,7 +350,7 @@ Dash.prototype._parseDashConf = function (configPath) { return options; }; -Dash.prototype._expandRelativeDatadir = function () { +Dash.prototype._expandRelativeDatadir = function() { if (!utils.isAbsolutePath(this.options.spawn.datadir)) { $.checkState(this.node.configPath); $.checkState(utils.isAbsolutePath(this.node.configPath)); @@ -362,7 +359,7 @@ Dash.prototype._expandRelativeDatadir = function () { } }; -Dash.prototype._loadSpawnConfiguration = function (node) { +Dash.prototype._loadSpawnConfiguration = function(node) { /* jshint maxstatements: 25 */ $.checkArgument(this.options.spawn, 'Please specify "spawn" in dashd config options'); @@ -383,7 +380,7 @@ Dash.prototype._loadSpawnConfiguration = function (node) { this.spawn.config = {}; if (!fs.existsSync(spawnOptions.datadir)) { - fs.mkdirSync(spawnOptions.datadir, {recursive: true}); + fs.mkdirSync(spawnOptions.datadir, { recursive: true }); } if (!fs.existsSync(configPath)) { @@ -405,50 +402,50 @@ Dash.prototype._loadSpawnConfiguration = function (node) { }; -Dash.prototype._checkConfigIndexes = function (spawnConfig, node) { +Dash.prototype._checkConfigIndexes = function(spawnConfig, node) { $.checkState( spawnConfig.txindex && spawnConfig.txindex === 1, '"txindex" option is required in order to use transaction query features of dashcore-node. ' + - 'Please add "txindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "txindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.addressindex && spawnConfig.addressindex === 1, '"addressindex" option is required in order to use address query features of dashcore-node. ' + - 'Please add "addressindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "addressindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.spentindex && spawnConfig.spentindex === 1, '"spentindex" option is required in order to use spent info query features of dashcore-node. ' + - 'Please add "spentindex=1" to your configuration and reindex an existing database if ' + - 'necessary with reindex=1' + 'Please add "spentindex=1" to your configuration and reindex an existing database if ' + + 'necessary with reindex=1' ); $.checkState( spawnConfig.server && spawnConfig.server === 1, '"server" option is required to communicate to dashd from dashcore. ' + - 'Please add "server=1" to your configuration and restart' + 'Please add "server=1" to your configuration and restart' ); $.checkState( spawnConfig.zmqpubrawtx, '"zmqpubrawtx" option is required to get event updates from dashd. ' + - 'Please add "zmqpubrawtx=tcp://127.0.0.1:" to your configuration and restart' + 'Please add "zmqpubrawtx=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( - spawnConfig.zmqpubrawtxlock, - '"zmqpubrawtxlock" option is required to get transaction locks from dashd. ' + - 'Please add "zmqpubrawtxlock=tcp://127.0.0.1:" to your configuration and restart' + spawnConfig.zmqpubrawtxlock, + '"zmqpubrawtxlock" option is required to get transaction locks from dashd. ' + + 'Please add "zmqpubrawtxlock=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( spawnConfig.zmqpubhashblock, '"zmqpubhashblock" option is required to get event updates from dashd. ' + - 'Please add "zmqpubhashblock=tcp://127.0.0.1:" to your configuration and restart' + 'Please add "zmqpubhashblock=tcp://127.0.0.1:" to your configuration and restart' ); $.checkState( @@ -458,14 +455,14 @@ Dash.prototype._checkConfigIndexes = function (spawnConfig, node) { if (spawnConfig.reindex && spawnConfig.reindex === 1) { log.warn('Reindex option is currently enabled. This means that dashd is undergoing a reindex. ' + - 'The reindex flag will start the index from beginning every time the node is started, so it ' + - 'should be removed after the reindex has been initiated. Once the reindex is complete, the rest ' + - 'of dashcore-node services will start.'); + 'The reindex flag will start the index from beginning every time the node is started, so it ' + + 'should be removed after the reindex has been initiated. Once the reindex is complete, the rest ' + + 'of dashcore-node services will start.'); node._reindex = true; } }; -Dash.prototype._resetCaches = function () { +Dash.prototype._resetCaches = function() { this.transactionDetailedCache.reset(); this.utxosCache.reset(); this.txidsCache.reset(); @@ -485,13 +482,13 @@ Dash.prototype._resetCaches = function () { * @param callback * @private */ -Dash.prototype._tryAllClients = function (func, callback) { +Dash.prototype._tryAllClients = function(func, callback) { var self = this; //Storing current node index into closure var nextClientToTry = this.nodesIndex; //Incrementing this.nodesIndex for proper round-robin this.nodesIndex = (this.nodesIndex + 1) % self.nodes.length; - var retry = function (done) { + var retry = function(done) { var client = self.nodes[nextClientToTry].client; nextClientToTry = (nextClientToTry + 1) % self.nodes.length; func(client, done); @@ -499,33 +496,33 @@ Dash.prototype._tryAllClients = function (func, callback) { async.retry({times: this.nodes.length, interval: this.tryAllInterval || 1000}, retry, callback); }; -Dash.prototype._wrapRPCError = function (errObj) { +Dash.prototype._wrapRPCError = function(errObj) { var err = new errors.RPCError(errObj.message); err.code = errObj.code; return err; }; -Dash.prototype._initChain = function (callback) { +Dash.prototype._initChain = function(callback) { var self = this; - self.client.getBestBlockHash(function (err, response) { + self.client.getBestBlockHash(function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.client.getBlock(response.result, function (err, response) { + self.client.getBlock(response.result, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } self.height = response.result.height; - self.client.getBlockHash(0, function (err, response) { + self.client.getBlockHash(0, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } var blockhash = response.result; - self.getRawBlock(blockhash, function (err, blockBuffer) { + self.getRawBlock(blockhash, function(err, blockBuffer) { if (err) { return callback(err); } @@ -540,7 +537,7 @@ Dash.prototype._initChain = function (callback) { }); }; -Dash.prototype._getDefaultConf = function () { +Dash.prototype._getDefaultConf = function() { var networkOptions = { rpcport: 9998 }; @@ -550,7 +547,7 @@ Dash.prototype._getDefaultConf = function () { return networkOptions; }; -Dash.prototype._getNetworkConfigPath = function () { +Dash.prototype._getNetworkConfigPath = function() { var networkPath; if (this.node.network === dashcore.Networks.testnet) { networkPath = 'testnet3/dash.conf'; @@ -561,7 +558,7 @@ Dash.prototype._getNetworkConfigPath = function () { return networkPath; }; -Dash.prototype._getNetworkOption = function () { +Dash.prototype._getNetworkOption = function() { var networkOption; if (this.node.network === dashcore.Networks.testnet) { networkOption = '--testnet'; @@ -572,7 +569,7 @@ Dash.prototype._getNetworkOption = function () { return networkOption; }; -Dash.prototype._zmqBlockHandler = function (node, message) { +Dash.prototype._zmqBlockHandler = function(node, message) { var self = this; // Update the current chain tip @@ -591,7 +588,7 @@ Dash.prototype._zmqBlockHandler = function (node, message) { }; -Dash.prototype._rapidProtectedUpdateTip = function (node, message) { +Dash.prototype._rapidProtectedUpdateTip = function(node, message) { var self = this; // Prevent a rapid succession of tip updates @@ -600,13 +597,13 @@ Dash.prototype._rapidProtectedUpdateTip = function (node, message) { self._updateTip(node, message); } else { clearTimeout(self.lastTipTimeout); - self.lastTipTimeout = setTimeout(function () { + self.lastTipTimeout = setTimeout(function() { self._updateTip(node, message); }, 1000); } }; -Dash.prototype._updateTip = function (node, message) { +Dash.prototype._updateTip = function(node, message) { var self = this; var hex = message.toString('hex'); @@ -616,7 +613,7 @@ Dash.prototype._updateTip = function (node, message) { // reset block valid caches self._resetCaches(); - node.client.getBlock(self.tiphash, function (err, response) { + node.client.getBlock(self.tiphash, function(err, response) { if (err) { var error = self._wrapRPCError(err); self.emit('error', error); @@ -627,8 +624,8 @@ Dash.prototype._updateTip = function (node, message) { } }); - if (!self.node.stopping) { - self.syncPercentage(function (err, percentage) { + if(!self.node.stopping) { + self.syncPercentage(function(err, percentage) { if (err) { self.emit('error', err); } else { @@ -642,7 +639,7 @@ Dash.prototype._updateTip = function (node, message) { } }; -Dash.prototype._getAddressesFromTransaction = function (transaction) { +Dash.prototype._getAddressesFromTransaction = function(transaction) { var addresses = []; for (var i = 0; i < transaction.inputs.length; i++) { @@ -668,13 +665,13 @@ Dash.prototype._getAddressesFromTransaction = function (transaction) { return _.uniq(addresses); }; -Dash.prototype._notifyAddressTxidSubscribers = function (txid, transaction) { +Dash.prototype._notifyAddressTxidSubscribers = function(txid, transaction) { var addresses = this._getAddressesFromTransaction(transaction); for (var i = 0; i < addresses.length; i++) { var address = addresses[i]; - if (this.subscriptions.address[address]) { + if(this.subscriptions.address[address]) { var emitters = this.subscriptions.address[address]; - for (var j = 0; j < emitters.length; j++) { + for(var j = 0; j < emitters.length; j++) { emitters[j].emit('dashd/addresstxid', { address: address, txid: txid @@ -684,7 +681,7 @@ Dash.prototype._notifyAddressTxidSubscribers = function (txid, transaction) { } }; -Dash.prototype._zmqTransactionHandler = function (node, message) { +Dash.prototype._zmqTransactionHandler = function(node, message) { // It happen that ZMQ is throwing 'rawtx' // We discard this as they are improper received message from ZMQ. if (message.equals(rawtxTopicBuffer)) { @@ -732,13 +729,13 @@ Dash.prototype._zmqTransactionLockHandler = function (node, message) { } }; -Dash.prototype._checkSyncedAndSubscribeZmqEvents = function (node) { +Dash.prototype._checkSyncedAndSubscribeZmqEvents = function(node) { var self = this; var interval; function checkAndSubscribe(callback) { // update tip - node.client.getBestBlockHash(function (err, response) { + node.client.getBestBlockHash(function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -747,7 +744,7 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function (node) { self._updateTip(node, blockhash); // check if synced - node.client.getBlockchainInfo(function (err, response) { + node.client.getBlockchainInfo(function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -764,16 +761,16 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function (node) { }); } - checkAndSubscribe(function (err, synced) { + checkAndSubscribe(function(err, synced) { if (err) { log.error(err); } if (!synced) { - interval = setInterval(function () { + interval = setInterval(function() { if (self.node.stopping) { return clearInterval(interval); } - checkAndSubscribe(function (err) { + checkAndSubscribe(function(err) { if (err) { log.error(err); } @@ -784,12 +781,12 @@ Dash.prototype._checkSyncedAndSubscribeZmqEvents = function (node) { }; -Dash.prototype._subscribeZmqEvents = function (node) { +Dash.prototype._subscribeZmqEvents = function(node) { var self = this; node.zmqSubSocket.subscribe('hashblock'); node.zmqSubSocket.subscribe('rawtx'); node.zmqSubSocket.subscribe('rawtxlock'); - node.zmqSubSocket.on('message', function (topic, message) { + node.zmqSubSocket.on('message', function(topic, message) { var topicString = topic.toString('utf8'); if (topicString === 'rawtxlock') { self._zmqTransactionLockHandler(node, message); @@ -801,25 +798,25 @@ Dash.prototype._subscribeZmqEvents = function (node) { }); }; -Dash.prototype._initZmqSubSocket = function (node, zmqUrl) { +Dash.prototype._initZmqSubSocket = function(node, zmqUrl) { var self = this; node.zmqSubSocket = zmq.socket('sub'); - node.zmqSubSocket.on('connect', function (fd, endPoint) { + node.zmqSubSocket.on('connect', function(fd, endPoint) { log.info('ZMQ connected to:', endPoint); }); - node.zmqSubSocket.on('connect_delay', function (fd, endPoint) { + node.zmqSubSocket.on('connect_delay', function(fd, endPoint) { log.warn('ZMQ connection delay:', endPoint); }); - node.zmqSubSocket.on('disconnect', function (fd, endPoint) { + node.zmqSubSocket.on('disconnect', function(fd, endPoint) { log.warn('ZMQ disconnect:', endPoint); }); - node.zmqSubSocket.on('monitor_error', function (err) { + node.zmqSubSocket.on('monitor_error', function(err) { log.error('Error in monitoring: %s, will restart monitoring in 5 seconds', err); - setTimeout(function () { + setTimeout(function() { self.zmqSubSocket.monitor(500, 0); }, 5000); }); @@ -828,21 +825,19 @@ Dash.prototype._initZmqSubSocket = function (node, zmqUrl) { node.zmqSubSocket.connect(zmqUrl); }; -Dash.prototype._checkReindex = function (node, callback) { +Dash.prototype._checkReindex = function(node, callback) { var self = this; var interval; - function finish(err) { clearInterval(interval); callback(err); } - if (!node._reindex) { return callback(); } - interval = setInterval(function () { - node.client.getBlockchainInfo(function (err, response) { + interval = setInterval(function() { + node.client.getBlockchainInfo(function(err, response) { if (err) { return finish(self._wrapRPCError(err)); } @@ -858,16 +853,16 @@ Dash.prototype._checkReindex = function (node, callback) { }; -Dash.prototype._loadTipFromNode = function (node, callback) { +Dash.prototype._loadTipFromNode = function(node, callback) { var self = this; - node.client.getBestBlockHash(function (err, response) { + node.client.getBestBlockHash(function(err, response) { if (err && err.code === -28) { log.warn(err.message); return callback(self._wrapRPCError(err)); } else if (err) { return callback(self._wrapRPCError(err)); } - node.client.getBlock(response.result, function (err, response) { + node.client.getBlock(response.result, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -879,13 +874,13 @@ Dash.prototype._loadTipFromNode = function (node, callback) { }); }; -Dash.prototype._stopSpawnedDash = function (callback) { +Dash.prototype._stopSpawnedDash = function(callback) { var self = this; var spawnOptions = this.options.spawn; var pidPath = spawnOptions.datadir + '/dashd.pid'; function stopProcess() { - fs.readFile(pidPath, 'utf8', function (err, pid) { + fs.readFile(pidPath, 'utf8', function(err, pid) { if (err && err.code === 'ENOENT') { // pid file doesn't exist we can continue return callback(null); @@ -900,15 +895,15 @@ Dash.prototype._stopSpawnedDash = function (callback) { try { log.warn('Stopping existing spawned dash process with pid: ' + pid); self._process.kill(pid, 'SIGINT'); - } catch (err) { + } catch(err) { if (err && err.code === 'ESRCH') { log.warn('Unclean dash process shutdown, process not found with pid: ' + pid); return callback(null); - } else if (err) { + } else if(err) { return callback(err); } } - setTimeout(function () { + setTimeout(function() { stopProcess(); }, self.spawnStopTime); }); @@ -917,7 +912,7 @@ Dash.prototype._stopSpawnedDash = function (callback) { stopProcess(); }; -Dash.prototype._spawnChildProcess = function (callback) { +Dash.prototype._spawnChildProcess = function(callback) { var self = this; var node = {}; @@ -926,7 +921,7 @@ Dash.prototype._spawnChildProcess = function (callback) { try { self._loadSpawnConfiguration(node); - } catch (e) { + } catch(e) { return callback(e); } @@ -939,7 +934,7 @@ Dash.prototype._spawnChildProcess = function (callback) { options.push(self._getNetworkOption()); } - self._stopSpawnedDash(function (err) { + self._stopSpawnedDash(function(err) { if (err) { return callback(err); } @@ -947,16 +942,16 @@ Dash.prototype._spawnChildProcess = function (callback) { log.info('Starting dash process'); self.spawn.process = spawn(self.spawn.exec, options, {stdio: 'inherit'}); - self.spawn.process.on('error', function (err) { + self.spawn.process.on('error', function(err) { self.emit('error', err); }); - self.spawn.process.once('exit', function (code) { + self.spawn.process.once('exit', function(code) { if (!self.node.stopping) { log.warn('Dash process unexpectedly exited with code:', code); log.warn('Restarting dash child process in ' + self.spawnRestartTime + 'ms'); - setTimeout(function () { - self._spawnChildProcess(function (err) { + setTimeout(function() { + self._spawnChildProcess(function(err) { if (err) { return self.emit('error', err); } @@ -968,7 +963,7 @@ Dash.prototype._spawnChildProcess = function (callback) { var exitShutdown = false; - async.retry({times: 60, interval: self.startRetryInterval}, function (done) { + async.retry({times: 60, interval: self.startRetryInterval}, function(done) { if (self.node.stopping) { exitShutdown = true; return done(); @@ -984,7 +979,7 @@ Dash.prototype._spawnChildProcess = function (callback) { self._loadTipFromNode(node, done); - }, function (err) { + }, function(err) { if (err) { return callback(err); } @@ -994,7 +989,7 @@ Dash.prototype._spawnChildProcess = function (callback) { self._initZmqSubSocket(node, self.spawn.config.zmqpubrawtx); - self._checkReindex(node, function (err) { + self._checkReindex(node, function(err) { if (err) { return callback(err); } @@ -1008,12 +1003,12 @@ Dash.prototype._spawnChildProcess = function (callback) { }; -Dash.prototype._connectProcess = function (config, callback) { +Dash.prototype._connectProcess = function(config, callback) { var self = this; var node = {}; var exitShutdown = false; - async.retry({times: 60, interval: self.startRetryInterval}, function (done) { + async.retry({times: 60, interval: self.startRetryInterval}, function(done) { if (self.node.stopping) { exitShutdown = true; return done(); @@ -1030,7 +1025,7 @@ Dash.prototype._connectProcess = function (config, callback) { self._loadTipFromNode(node, done); - }, function (err) { + }, function(err) { if (err) { return callback(err); } @@ -1049,13 +1044,13 @@ Dash.prototype._connectProcess = function (config, callback) { * Called by Node to start the service * @param {Function} callback */ -Dash.prototype.start = function (callback) { +Dash.prototype.start = function(callback) { var self = this; async.series([ - function (next) { + function(next) { if (self.options.spawn) { - self._spawnChildProcess(function (err, node) { + self._spawnChildProcess(function(err, node) { if (err) { return next(err); } @@ -1066,13 +1061,13 @@ Dash.prototype.start = function (callback) { next(); } }, - function (next) { + function(next) { if (self.options.connect) { - async.map(self.options.connect, self._connectProcess.bind(self), function (err, nodes) { + async.map(self.options.connect, self._connectProcess.bind(self), function(err, nodes) { if (err) { return next(err); } - for (var i = 0; i < nodes.length; i++) { + for(var i = 0; i < nodes.length; i++) { self.nodes.push(nodes[i]); } next(); @@ -1081,7 +1076,7 @@ Dash.prototype.start = function (callback) { next(); } } - ], function (err) { + ], function(err) { if (err) { return callback(err); } @@ -1097,8 +1092,8 @@ Dash.prototype.start = function (callback) { * Helper to determine the state of the database. * @param {Function} callback */ -Dash.prototype.isSynced = function (callback) { - this.syncPercentage(function (err, percentage) { +Dash.prototype.isSynced = function(callback) { + this.syncPercentage(function(err, percentage) { if (err) { return callback(err); } @@ -1114,9 +1109,9 @@ Dash.prototype.isSynced = function (callback) { * Helper to determine the progress of the database. * @param {Function} callback */ -Dash.prototype.syncPercentage = function (callback) { +Dash.prototype.syncPercentage = function(callback) { var self = this; - this.client.getBlockchainInfo(function (err, response) { + this.client.getBlockchainInfo(function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1125,7 +1120,7 @@ Dash.prototype.syncPercentage = function (callback) { }); }; -Dash.prototype._normalizeAddressArg = function (addressArg) { +Dash.prototype._normalizeAddressArg = function(addressArg) { var addresses = [addressArg]; if (Array.isArray(addressArg)) { addresses = addressArg; @@ -1139,17 +1134,17 @@ Dash.prototype._normalizeAddressArg = function (addressArg) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressBalance = function (addressArg, options, callback) { +Dash.prototype.getAddressBalance = function(addressArg, options, callback) { var self = this; var addresses = self._normalizeAddressArg(addressArg); var cacheKey = addresses.join(''); var balance = self.balanceCache.get(cacheKey); if (balance) { - return setImmediate(function () { + return setImmediate(function() { callback(null, balance); }); } else { - this.client.getAddressBalance({addresses: addresses}, function (err, response) { + this.client.getAddressBalance({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1165,7 +1160,7 @@ Dash.prototype.getAddressBalance = function (addressArg, options, callback) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options, callback) { +Dash.prototype.getAddressUnspentOutputsPaginated = function(addressArg, options, callback) { var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var addresses = self._normalizeAddressArg(addressArg); @@ -1223,7 +1218,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options mempoolUnspentOutputs.reverse().concat(confirmedUtxos), fromArg, toArg, fromHeight, toHeight); if (isSpentOutputs) { - var filteredUtxos = utxos.filter(function (utxo) { + var filteredUtxos = utxos.filter(function(utxo) { if (!spentOutputs[utxo.txid]) { return true; } else { @@ -1244,11 +1239,11 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options function finish(mempoolDeltas) { if (utxos) { - return setImmediate(function () { + return setImmediate(function() { callback(null, updateWithMempool(utxos, mempoolDeltas)); }); } else { - self.client.getAddressUtxos({addresses: addresses}, function (err, response) { + self.client.getAddressUtxos({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1260,7 +1255,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function (err, response) { + self.client.getAddressMempool({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1278,7 +1273,7 @@ Dash.prototype.getAddressUnspentOutputsPaginated = function (addressArg, options * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callback) { +Dash.prototype.getAddressUnspentOutputs = function(addressArg, options, callback) { var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var addresses = self._normalizeAddressArg(addressArg); @@ -1323,7 +1318,7 @@ Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callbac var utxos = mempoolUnspentOutputs.reverse().concat(confirmedUtxos); if (isSpentOutputs) { - return utxos.filter(function (utxo) { + return utxos.filter(function(utxo) { if (!spentOutputs[utxo.txid]) { return true; } else { @@ -1337,11 +1332,11 @@ Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callbac function finish(mempoolDeltas) { if (utxos) { - return setImmediate(function () { + return setImmediate(function() { callback(null, updateWithMempool(utxos, mempoolDeltas)); }); } else { - self.client.getAddressUtxos({addresses: addresses}, function (err, response) { + self.client.getAddressUtxos({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1353,7 +1348,7 @@ Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callbac } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function (err, response) { + self.client.getAddressMempool({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1365,7 +1360,7 @@ Dash.prototype.getAddressUnspentOutputs = function (addressArg, options, callbac }; -Dash.prototype._getBalanceFromMempool = function (deltas) { +Dash.prototype._getBalanceFromMempool = function(deltas) { var satoshis = 0; for (var i = 0; i < deltas.length; i++) { satoshis += deltas[i].satoshis; @@ -1373,7 +1368,7 @@ Dash.prototype._getBalanceFromMempool = function (deltas) { return satoshis; }; -Dash.prototype._getTxidsFromMempool = function (deltas) { +Dash.prototype._getTxidsFromMempool = function(deltas) { var mempoolTxids = []; var mempoolTxidsKnown = {}; for (var i = 0; i < deltas.length; i++) { @@ -1386,7 +1381,7 @@ Dash.prototype._getTxidsFromMempool = function (deltas) { return mempoolTxids; }; -Dash.prototype._getHeightRangeQuery = function (options, clone) { +Dash.prototype._getHeightRangeQuery = function(options, clone) { if (options.start >= 0 && options.end >= 0) { if (options.end > options.start) { throw new TypeError('"end" is expected to be less than or equal to "start"'); @@ -1407,14 +1402,14 @@ Dash.prototype._getHeightRangeQuery = function (options, clone) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressTxids = function (addressArg, options, callback) { +Dash.prototype.getAddressTxids = function(addressArg, options, callback) { /* jshint maxstatements: 16 */ var self = this; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var rangeQuery = false; try { rangeQuery = self._getHeightRangeQuery(options); - } catch (err) { + } catch(err) { return callback(err); } if (rangeQuery) { @@ -1428,7 +1423,7 @@ Dash.prototype.getAddressTxids = function (addressArg, options, callback) { function finish() { if (txids && !rangeQuery) { var allTxids = mempoolTxids.reverse().concat(txids); - return setImmediate(function () { + return setImmediate(function() { callback(null, allTxids); }); } else { @@ -1438,7 +1433,7 @@ Dash.prototype.getAddressTxids = function (addressArg, options, callback) { if (rangeQuery) { self._getHeightRangeQuery(options, txidOpts); } - self.client.getAddressTxids(txidOpts, function (err, response) { + self.client.getAddressTxids(txidOpts, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1453,7 +1448,7 @@ Dash.prototype.getAddressTxids = function (addressArg, options, callback) { } if (queryMempool) { - self.client.getAddressMempool({addresses: addresses}, function (err, response) { + self.client.getAddressMempool({addresses: addresses}, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1466,7 +1461,7 @@ Dash.prototype.getAddressTxids = function (addressArg, options, callback) { }; -Dash.prototype._getConfirmationsDetail = function (transaction) { +Dash.prototype._getConfirmationsDetail = function(transaction) { $.checkState(this.height > 0, 'current height is unknown'); var confirmations = 0; if (transaction.height >= 0) { @@ -1478,7 +1473,7 @@ Dash.prototype._getConfirmationsDetail = function (transaction) { return Math.max(0, confirmations); }; -Dash.prototype._getAddressDetailsForInput = function (input, inputIndex, result, addressStrings) { +Dash.prototype._getAddressDetailsForInput = function(input, inputIndex, result, addressStrings) { if (!input.address) { return; } @@ -1496,7 +1491,7 @@ Dash.prototype._getAddressDetailsForInput = function (input, inputIndex, result, } }; -Dash.prototype._getAddressDetailsForOutput = function (output, outputIndex, result, addressStrings) { +Dash.prototype._getAddressDetailsForOutput = function(output, outputIndex, result, addressStrings) { if (!output.address) { return; } @@ -1514,7 +1509,7 @@ Dash.prototype._getAddressDetailsForOutput = function (output, outputIndex, resu } }; -Dash.prototype._getAddressDetailsForTransaction = function (transaction, addressStrings) { +Dash.prototype._getAddressDetailsForTransaction = function(transaction, addressStrings) { var result = { addresses: {}, satoshis: 0 @@ -1540,12 +1535,12 @@ Dash.prototype._getAddressDetailsForTransaction = function (transaction, address * @param {Object} txid - A dash transaction id * @param {Function} callback */ -Dash.prototype._getAddressDetailedTransaction = function (txid, options, next) { +Dash.prototype._getAddressDetailedTransaction = function(txid, options, next) { var self = this; self.getDetailedTransaction( txid, - function (err, transaction) { + function(err, transaction) { if (err) { return next(err); } @@ -1563,7 +1558,7 @@ Dash.prototype._getAddressDetailedTransaction = function (txid, options, next) { ); }; -Dash.prototype._getAddressStrings = function (addresses) { +Dash.prototype._getAddressStrings = function(addresses) { var addressStrings = []; for (var i = 0; i < addresses.length; i++) { var address = addresses[i]; @@ -1578,7 +1573,7 @@ Dash.prototype._getAddressStrings = function (addresses) { return addressStrings; }; -Dash.prototype._paginate = function (fullArray, fromArg, toArg, fromHeight, toHeight) { +Dash.prototype._paginate = function(fullArray, fromArg, toArg, fromHeight, toHeight) { var slicedArray; var filteredArray; var from = parseInt(fromArg); @@ -1587,21 +1582,21 @@ Dash.prototype._paginate = function (fullArray, fromArg, toArg, fromHeight, toHe $.checkState( fromHeight < toHeight, '"fromHeight" (' + fromHeight + ')' + ' is expected to be less than "toHeight" (' + toHeight + ')'); - filteredArray = fullArray.filter(function (item) { + filteredArray = fullArray.filter(function(item) { if (item.height >= fromHeight && item.height <= toHeight) { return item; } }); } if (fromHeight !== undefined && toHeight === undefined) { - filteredArray = fullArray.filter(function (item) { + filteredArray = fullArray.filter(function(item) { if (item.height >= fromHeight) { return item; } }); } if (toHeight !== undefined && fromHeight === undefined) { - filteredArray = fullArray.filter(function (item) { + filteredArray = fullArray.filter(function(item) { if (item.height <= toHeight) { return item; } @@ -1622,7 +1617,7 @@ Dash.prototype._paginate = function (fullArray, fromArg, toArg, fromHeight, toHe * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressHistory = function (addressArg, options, callback) { +Dash.prototype.getAddressHistory = function(addressArg, options, callback) { var self = this; var addresses = self._normalizeAddressArg(addressArg); if (addresses.length > this.maxAddressesQuery) { @@ -1640,11 +1635,11 @@ Dash.prototype.getAddressHistory = function (addressArg, options, callback) { if ((toArg - fromArg) > self.maxTransactionHistory) { return callback(new Error( '"from" (' + options.from + ') and "to" (' + options.to + ') range should be less than or equal to ' + - self.maxTransactionHistory + self.maxTransactionHistory )); } - self.getAddressTxids(addresses, options, function (err, txids) { + self.getAddressTxids(addresses, options, function(err, txids) { if (err) { return callback(err); } @@ -1652,20 +1647,20 @@ Dash.prototype.getAddressHistory = function (addressArg, options, callback) { var totalCount = txids.length; try { txids = self._paginate(txids, fromArg, toArg, fromHeight, toHeight); - } catch (e) { + } catch(e) { return callback(e); } async.mapLimit( txids, self.transactionConcurrency, - function (txid, next) { + function(txid, next) { self._getAddressDetailedTransaction(txid, { queryMempool: queryMempool, addressStrings: addressStrings }, next); }, - function (err, transactions) { + function(err, transactions) { if (err) { return callback(err); } @@ -1684,7 +1679,7 @@ Dash.prototype.getAddressHistory = function (addressArg, options, callback) { * @param {Object} options * @param {Function} callback */ -Dash.prototype.getAddressSummary = function (addressArg, options, callback) { +Dash.prototype.getAddressSummary = function(addressArg, options, callback) { var self = this; var summary = {}; var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; @@ -1703,14 +1698,14 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { if ((toArg - fromArg) > self.maxTxids) { return callback(new Error( - '"from" (' + fromArg + ') and "to" (' + toArg + ') range should be less than or equal to ' + - self.maxTxids + '"from" (' + fromArg + ') and "to" (' + toArg + ') range should be less than or equal to ' + + self.maxTxids )); } var paginatedTxids; try { paginatedTxids = self._paginate(allTxids, fromArg, toArg, fromHeight, toHeight); - } catch (e) { + } catch(e) { return callback(e); } @@ -1725,7 +1720,7 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { function querySummary() { async.parallel([ function getTxList(done) { - self.getAddressTxids(addresses, {queryMempool: false}, function (err, txids) { + self.getAddressTxids(addresses, {queryMempool: false}, function(err, txids) { if (err) { return done(err); } @@ -1735,7 +1730,7 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { }); }, function getBalance(done) { - self.getAddressBalance(addresses, options, function (err, data) { + self.getAddressBalance(addresses, options, function(err, data) { if (err) { return done(err); } @@ -1749,7 +1744,7 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { if (!queryMempool) { return done(); } - self.client.getAddressMempool({'addresses': addresses}, function (err, response) { + self.client.getAddressMempool({'addresses': addresses}, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1759,7 +1754,7 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { done(); }); }, - ], function (err) { + ], function(err) { if (err) { return callback(err); } @@ -1788,11 +1783,11 @@ Dash.prototype.getAddressSummary = function (addressArg, options, callback) { * @param {Function} callback * @private */ -Dash.prototype._maybeGetBlockHash = function (blockArg, callback) { +Dash.prototype._maybeGetBlockHash = function(blockArg, callback) { var self = this; if (_.isNumber(blockArg) || (blockArg.length < 40 && /^[0-9]+$/.test(blockArg))) { - self._tryAllClients(function (client, done) { - client.getBlockHash(blockArg, function (err, response) { + self._tryAllClients(function(client, done) { + client.getBlockHash(blockArg, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1809,7 +1804,7 @@ Dash.prototype._maybeGetBlockHash = function (blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getRawBlock = function (blockArg, callback) { +Dash.prototype.getRawBlock = function(blockArg, callback) { // TODO apply performance patch to the RPC method for raw data var self = this; @@ -1817,8 +1812,8 @@ Dash.prototype.getRawBlock = function (blockArg, callback) { if (err) { return callback(err); } - self._tryAllClients(function (client, done) { - self.client.getBlock(blockhash, false, function (err, response) { + self._tryAllClients(function(client, done) { + self.client.getBlock(blockhash, false, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1831,7 +1826,7 @@ Dash.prototype.getRawBlock = function (blockArg, callback) { var cachedBlock = self.rawBlockCache.get(blockArg); if (cachedBlock) { - return setImmediate(function () { + return setImmediate(function() { callback(null, cachedBlock); }); } else { @@ -1844,7 +1839,7 @@ Dash.prototype.getRawBlock = function (blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getBlockOverview = function (blockArg, callback) { +Dash.prototype.getBlockOverview = function(blockArg, callback) { var self = this; function queryBlock(err, blockhash) { @@ -1853,12 +1848,12 @@ Dash.prototype.getBlockOverview = function (blockArg, callback) { } var cachedBlock = self.blockOverviewCache.get(blockhash); if (cachedBlock) { - return setImmediate(function () { + return setImmediate(function() { callback(null, cachedBlock); }); } else { - self._tryAllClients(function (client, done) { - client.getBlock(blockhash, true, function (err, response) { + self._tryAllClients(function(client, done) { + client.getBlock(blockhash, true, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1894,7 +1889,7 @@ Dash.prototype.getBlockOverview = function (blockArg, callback) { * @param {String|Number} block - A block hash or block height number * @param {Function} callback */ -Dash.prototype.getBlock = function (blockArg, callback) { +Dash.prototype.getBlock = function(blockArg, callback) { // TODO apply performance patch to the RPC method for raw data var self = this; @@ -1904,12 +1899,12 @@ Dash.prototype.getBlock = function (blockArg, callback) { } var cachedBlock = self.blockCache.get(blockhash); if (cachedBlock) { - return setImmediate(function () { + return setImmediate(function() { callback(null, cachedBlock); }); } else { - self._tryAllClients(function (client, done) { - client.getBlock(blockhash, false, function (err, response) { + self._tryAllClients(function(client, done) { + client.getBlock(blockhash, false, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -1930,9 +1925,9 @@ Dash.prototype.getBlock = function (blockArg, callback) { * @param {Number} low - The older timestamp in seconds * @param {Function} callback */ -Dash.prototype.getBlockHashesByTimestamp = function (high, low, callback) { +Dash.prototype.getBlockHashesByTimestamp = function(high, low, callback) { var self = this; - self.client.getBlockHashes(high, low, function (err, response) { + self.client.getBlockHashes(high, low, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -1960,15 +1955,15 @@ Dash.prototype.getBlockHashesByTimestamp = function (high, low, callback) { * @param {String|Number} block - A block hash or block height * @param {Function} callback */ -Dash.prototype.getBlockHeader = function (blockArg, callback) { +Dash.prototype.getBlockHeader = function(blockArg, callback) { var self = this; function queryHeader(err, blockhash) { if (err) { return callback(err); } - self._tryAllClients(function (client, done) { - client.getBlockHeader(blockhash, function (err, response) { + self._tryAllClients(function(client, done) { + client.getBlockHeader(blockhash, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2017,26 +2012,26 @@ Dash.prototype.getBlockHeader = function (blockArg, callback) { * @param {Function} callback * @param {String|Number} nbOfBlockToFetch - A value allowing to choose how many block to fetch */ -Dash.prototype.getBlockHeaders = function (blockArg, callback, nbOfBlockToFetch) { - var self = this; - var _toFetch = 25; +Dash.prototype.getBlockHeaders = function(blockArg, callback, nbOfBlockToFetch) { + var self = this; + var _toFetch = 25; - if (nbOfBlockToFetch) { + if (nbOfBlockToFetch) { - if (nbOfBlockToFetch.constructor.name === 'String' && !isNaN(parseInt(nbOfBlockToFetch))) { + if (nbOfBlockToFetch.constructor.name === 'String' && !isNaN(parseInt(nbOfBlockToFetch))) { _toFetch = parseInt(nbOfBlockToFetch); - } - if (nbOfBlockToFetch.constructor.name === 'Number') { - _toFetch = nbOfBlockToFetch; - } - if (_toFetch > 250) { - _toFetch = 250;//Limit to avoid asking to many blocks. - } - } - - self._maybeGetBlockHash(blockArg, function (err, blockhash) { - if (err) { - return callback(err); + } + if (nbOfBlockToFetch.constructor.name === 'Number') { + _toFetch = nbOfBlockToFetch; + } + if (_toFetch > 250) { + _toFetch = 250;//Limit to avoid asking to many blocks. + } + } + + self._maybeGetBlockHash(blockArg, function(err, blockhash) { + if (err) { + return callback(err); } var headers = []; var nextHash = blockhash; @@ -2066,9 +2061,9 @@ Dash.prototype.getBlockHeaders = function (blockArg, callback, nbOfBlockToFetch) * @param {Number} blocks - The number of blocks for the transaction to be confirmed. * @param {Function} callback */ -Dash.prototype.estimateFee = function (blocks, callback) { +Dash.prototype.estimateFee = function(blocks, callback) { var self = this; - this.client.estimateFee(blocks, function (err, response) { + this.client.estimateFee(blocks, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2083,28 +2078,28 @@ Dash.prototype.estimateFee = function (blocks, callback) { * @param {Boolean=} options.maxFeeRate - Cap large fees (0 for unlimited) * @param {Function} callback */ -Dash.prototype.sendTransaction = function (tx, options, callback) { +Dash.prototype.sendTransaction = function(tx, options, callback) { var self = this; var maxFeeRate = 0.00015000; // duff/kB (typically 1000) var isInstantSend = false; if (_.isFunction(options) && _.isUndefined(callback)) { callback = options; } else if (_.isObject(options)) { - if (options.hasOwnProperty('maxFeeRate')) { - maxFeeRate = options.maxFeeRate; + if(options.hasOwnProperty('maxFeeRate')){ + maxFeeRate = options.maxFeeRate; } - if (options.hasOwnProperty('allowAbsurdFees')) { + if(options.hasOwnProperty('allowAbsurdFees')){ console.warn(`the boolean 'allowAbsurdFees' has been replaced by the int 'maxFeeRate'`); - if (true === options.allowAbsurdFees) { + if(true === options.allowAbsurdFees) { maxFeeRate = 0; // unlimited } } - if (options.hasOwnProperty('isInstantSend')) { - isInstantSend = options.isInstantSend; + if(options.hasOwnProperty('isInstantSend')){ + isInstantSend = options.isInstantSend; } } - this.client.sendRawTransaction(tx, maxFeeRate, isInstantSend, function (err, response) { + this.client.sendRawTransaction(tx, maxFeeRate, isInstantSend, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2113,10 +2108,10 @@ Dash.prototype.sendTransaction = function (tx, options, callback) { }; -Dash.prototype._getRawTransactionData = function (txid, callback) { +Dash.prototype._getRawTransactionData = function(txid, callback) { var self = this; - self._tryAllClients(function (client, done) { - client.getRawTransaction(txid, function (err, response) { + self._tryAllClients(function(client, done) { + client.getRawTransaction(txid, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2130,15 +2125,15 @@ Dash.prototype._getRawTransactionData = function (txid, callback) { * @param {String} txid - The transaction hash * @param {Function} callback */ -Dash.prototype.getRawTransaction = function (txid, callback) { +Dash.prototype.getRawTransaction = function(txid, callback) { var self = this; var tx = self.rawTransactionCache.get(txid); if (tx) { - return setImmediate(function () { + return setImmediate(function() { callback(null, tx); }); } else { - self._getRawTransactionData(txid, function (err, transactionData) { + self._getRawTransactionData(txid, function(err, transactionData) { if (err) { return callback(err); } @@ -2155,15 +2150,15 @@ Dash.prototype.getRawTransaction = function (txid, callback) { * @param {Boolean} queryMempool - Include the mempool * @param {Function} callback */ -Dash.prototype.getTransaction = function (txid, callback) { +Dash.prototype.getTransaction = function(txid, callback) { var self = this; var tx = self.transactionCache.get(txid); if (tx) { - return setImmediate(function () { + return setImmediate(function() { callback(null, tx); }); } else { - self._getRawTransactionData(txid, function (err, transactionData) { + self._getRawTransactionData(txid, function(err, transactionData) { if (err) { return callback(err); } @@ -2217,14 +2212,14 @@ Dash.prototype.getTransaction = function (txid, callback) { * @param {String} txid - The hex string of the transaction * @param {Function} callback */ -Dash.prototype.getDetailedTransaction = function (txid, callback) { +Dash.prototype.getDetailedTransaction = function(txid, callback) { var self = this; var tx = self.transactionDetailedCache.get(txid); function addInputsToTx(tx, result) { tx.inputs = []; tx.inputSatoshis = 0; - for (var inputIndex = 0; inputIndex < result.vin.length; inputIndex++) { + for(var inputIndex = 0; inputIndex < result.vin.length; inputIndex++) { var input = result.vin[inputIndex]; if (!tx.coinbase) { tx.inputSatoshis += input.valueSat; @@ -2252,7 +2247,7 @@ Dash.prototype.getDetailedTransaction = function (txid, callback) { function addOutputsToTx(tx, result) { tx.outputs = []; tx.outputSatoshis = 0; - for (var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { + for(var outputIndex = 0; outputIndex < result.vout.length; outputIndex++) { var out = result.vout[outputIndex]; tx.outputSatoshis += out.valueSat; var address = null; @@ -2287,28 +2282,28 @@ Dash.prototype.getDetailedTransaction = function (txid, callback) { if (result.proRegTx !== undefined) { tx.proRegTx = result.proRegTx; - } else if (result.proUpServTx !== undefined) { + }else if (result.proUpServTx !== undefined) { tx.proUpServTx = result.proUpServTx; - } else if (result.proUpRegTx !== undefined) { + }else if (result.proUpRegTx !== undefined) { tx.proUpRegTx = result.proUpRegTx; - } else if (result.proUpRevTx !== undefined) { + }else if (result.proUpRevTx !== undefined) { tx.proUpRevTx = result.proUpRevTx; - } else if (result.cbTx !== undefined) { + }else if (result.cbTx !== undefined) { tx.cbTx = result.cbTx; - } else if (result.qcTx !== undefined) { + }else if (result.qcTx !== undefined) { tx.qcTx = result.qcTx; - } else if (result.mnhfTx !== undefined) { + }else if (result.mnhfTx !== undefined) { tx.mnhfTx = result.mnhfTx; } } if (tx) { - return setImmediate(function () { + return setImmediate(function() { callback(null, tx); }); } else { - self._tryAllClients(function (client, done) { - client.getRawTransaction(txid, 1, function (err, response) { + self._tryAllClients(function(client, done) { + client.getRawTransaction(txid, 1, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } @@ -2353,9 +2348,9 @@ Dash.prototype.getDetailedTransaction = function (txid, callback) { * @param options - should be either "1" or "2", used to filter the object type * @param callback */ -Dash.prototype.govObjectList = function (options, callback) { +Dash.prototype.govObjectList = function(options, callback) { var self = this; - this.client.gobject('list', function (err, response) { + this.client.gobject('list', function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2366,23 +2361,23 @@ Dash.prototype.govObjectList = function (options, callback) { var proposal = new Proposal(response.result[gobjects[i]].DataHex); if ((options.type && proposal.type === options.type)) { - result.push({ - Hash: gobjects[i], - DataHex: response.result.DataHex, - DataObject: { - end_epoch: proposal.end_epoch, - name: proposal.name, - payment_address: proposal.payment_address, - payment_amount: proposal.payment_amount, - start_epoch: proposal.start_epoch, - type: proposal.type, - url: proposal.url - }, - AbsoluteYesCount: response.result[gobjects[i]].AbsoluteYesCount, - YesCount: response.result[gobjects[i]].YesCount, - NoCount: response.result[gobjects[i]].NoCount, - AbstainCount: response.result[gobjects[i]].AbstainCount - }); + result.push({ + Hash: gobjects[i], + DataHex: response.result.DataHex, + DataObject: { + end_epoch: proposal.end_epoch, + name: proposal.name, + payment_address: proposal.payment_address, + payment_amount: proposal.payment_amount, + start_epoch: proposal.start_epoch, + type: proposal.type, + url: proposal.url + }, + AbsoluteYesCount: response.result[gobjects[i]].AbsoluteYesCount, + YesCount: response.result[gobjects[i]].YesCount, + NoCount: response.result[gobjects[i]].NoCount, + AbstainCount: response.result[gobjects[i]].AbstainCount + }); } } @@ -2394,7 +2389,7 @@ Dash.prototype.govObjectList = function (options, callback) { Dash.prototype.getCurrentVotes = function (govhash, callback) { var self = this; - this.client.gobject('getcurrentvotes', govhash, function (err, response) { + this.client.gobject('getcurrentvotes', govhash, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2404,7 +2399,7 @@ Dash.prototype.getCurrentVotes = function (govhash, callback) { Dash.prototype.getVotes = function (govhash, callback) { var self = this; - this.client.gobject('getvotes', govhash, function (err, response) { + this.client.gobject('getvotes', govhash, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2414,7 +2409,7 @@ Dash.prototype.getVotes = function (govhash, callback) { Dash.prototype.getSuperBlockBudget = function (blockindex, callback) { var self = this; - this.client.getsuperblockbudget(blockindex, function (err, response) { + this.client.getsuperblockbudget(blockindex, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2424,7 +2419,7 @@ Dash.prototype.getSuperBlockBudget = function (blockindex, callback) { /*jshint maxparams: 6 */ Dash.prototype.govObjectSubmit = function (parentHash, revision, time, dataHex, feeTxId, callback) { var self = this; - this.client.gobject('submit', parentHash, revision, time, dataHex, feeTxId, function (err, response) { + this.client.gobject('submit', parentHash, revision, time, dataHex, feeTxId, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2434,7 +2429,7 @@ Dash.prototype.govObjectSubmit = function (parentHash, revision, time, dataHex, Dash.prototype.govObjectDeserialize = function (hexdata, callback) { var self = this; - this.client.gobject('deserialize', hexdata, function (err, response) { + this.client.gobject('deserialize', hexdata, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2442,10 +2437,10 @@ Dash.prototype.govObjectDeserialize = function (hexdata, callback) { }); }; -Dash.prototype.govObjectCheck = function (hexdata, callback) { +Dash.prototype.govObjectCheck = function(hexdata, callback){ var self = this; - this.client.gobject('check', hexdata, function (err, response) { + this.client.gobject('check', hexdata, function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } @@ -2455,15 +2450,15 @@ Dash.prototype.govObjectCheck = function (hexdata, callback) { Dash.prototype.govObjectInfo = function (callback) { var self = this; var result = self.govCache.get('info'); - if (result) { + if(result){ callback(null, result); - } else { - this.client.getgovernanceinfo(function (err, response) { + }else{ + this.client.getgovernanceinfo(function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.govCache.set('info', response); + self.govCache.set('info',response); callback(null, response); }); } @@ -2471,44 +2466,44 @@ Dash.prototype.govObjectInfo = function (callback) { Dash.prototype.govCount = function (callback) { var self = this; var result = self.govCache.get('count'); - if (result) { + if(result){ callback(null, result); - } else { - this.client.gobject('count', function (err, response) { + }else{ + this.client.gobject('count',function(err, response) { if (err) { return callback(self._wrapRPCError(err)); } - self.govCache.set('count', response); + self.govCache.set('count',response); callback(null, response); }); } }; -Dash.prototype.getSpork = function (callback) { - var self = this; - var SporksList = {}; - self.client.spork('show', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = {sporks: response.result}; - var SporksData = self.sporksListCache.get(''); - if (SporksData) { - return setImmediate(function () { - callback(null, SporksData); - }); - } else { - SporksList = result; - self.sporksListCache.set('', SporksList); - return callback(null, SporksList); - } - } else { - return callback(new Error('Impossible to get Sporks Data'), null); - } - }); -}; - -Dash.prototype.getMNList = function (callback) { +Dash.prototype.getSpork = function(callback){ + var self = this; + var SporksList = {}; + self.client.spork('show', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = {sporks:response.result}; + var SporksData = self.sporksListCache.get(''); + if (SporksData) { + return setImmediate(function() { + callback(null, SporksData); + }); + }else{ + SporksList=result; + self.sporksListCache.set('', SporksList); + return callback(null, SporksList); + } + }else{ + return callback(new Error('Impossible to get Sporks Data'),null); + } + }); +}; + +Dash.prototype.getMNList = function(callback){ var self = this; - var rawResults = {}; + var rawResults= {}; var MNList = []; var checkSync = function checkSync(next) { @@ -2523,124 +2518,124 @@ Dash.prototype.getMNList = function (callback) { }); }; - var getRank = function (next) { - self.client.masternodelist('rank', function (err, response) { - if (response && response.hasOwnProperty('result')) { + var getRank = function(next){ + self.client.masternodelist('rank', function(err, response){ + if(response && response.hasOwnProperty('result')){ var result = response.result; - rawResults.rank = result; + rawResults.rank=result; } - next(); + next(); }); }; - var getProtocol = function (next) { - self.client.masternodelist('protocol', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.protocol = result; - } - next(); - }); + var getProtocol = function(next){ + self.client.masternodelist('protocol', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.protocol=result; + } + next(); + }); }; - var getPayee = function (next) { - self.client.masternodelist('payee', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.payee = result; - } - next(); - }); + var getPayee = function(next){ + self.client.masternodelist('payee', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.payee=result; + } + next(); + }); }; - var getLastSeen = function (next) { - self.client.masternodelist('lastseen', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.lastseen = result; - } - next(); - }); + var getLastSeen = function(next){ + self.client.masternodelist('lastseen', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.lastseen=result; + } + next(); + }); }; - var getActiveSeconds = function (next) { - self.client.masternodelist('activeseconds', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.activeseconds = result; - } - next(); - }); + var getActiveSeconds=function(next){ + self.client.masternodelist('activeseconds', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.activeseconds=result; + } + next(); + }); }; - var getIP = function (next) { - self.client.masternodelist('addr', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.addr = result; - } - next(); - }); + var getIP = function(next){ + self.client.masternodelist('addr', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.addr=result; + } + next(); + }); }; - var getStatus = function (next) { - self.client.masternodelist('status', function (err, response) { - if (response && response.hasOwnProperty('result')) { - var result = response.result; - rawResults.status = result; - } - next(); - }); + var getStatus = function(next){ + self.client.masternodelist('status', function(err, response){ + if(response && response.hasOwnProperty('result')){ + var result = response.result; + rawResults.status=result; + } + next(); + }); }; - var prepareResponse = function (err) { - if (err) { - return callback(self._wrapRPCError(err), null); + var prepareResponse = function(err){ + if(err){ + return callback(self._wrapRPCError(err),null); } var keys = Object.keys(rawResults); - if ( - keys.indexOf('rank') > -1 && - keys.indexOf('protocol') > -1 && - keys.indexOf('payee') > -1 && - keys.indexOf('lastseen') > -1 && - keys.indexOf('activeseconds') > -1 && - keys.indexOf('addr') > -1 - ) { - var rankKeys = Object.keys(rawResults.lastseen); - var rankLength = rankKeys.length; - - //We get threw all vins by rank - for (var i = 0; i < rankLength; i++) { - var vin = rankKeys[i]; - var MN = { - vin: vin, - status: rawResults.status[vin], - rank: i + 1, - ip: rawResults.addr[vin], - protocol: rawResults.protocol[vin], - payee: rawResults.payee[vin], - activeseconds: rawResults.activeseconds[vin], - lastseen: rawResults.lastseen[vin], - }; - MNList.push(MN); - } - } else { - return callback(new Error('Invalid MasternodeList'), null); + if( + keys.indexOf('rank') > -1 && + keys.indexOf('protocol')> -1 && + keys.indexOf('payee')> -1 && + keys.indexOf('lastseen')> -1 && + keys.indexOf('activeseconds')> -1 && + keys.indexOf('addr')> -1 + ){ + var rankKeys = Object.keys(rawResults.lastseen); + var rankLength = rankKeys.length; + + //We get threw all vins by rank + for(var i = 0; i Date: Sat, 21 Sep 2024 02:55:27 +0500 Subject: [PATCH 13/13] condition fix --- lib/services/dashd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/services/dashd.js b/lib/services/dashd.js index 335d162bc..07503c2e0 100644 --- a/lib/services/dashd.js +++ b/lib/services/dashd.js @@ -2253,8 +2253,8 @@ Dash.prototype.getDetailedTransaction = function(txid, callback) { var address = null; if (out.scriptPubKey && out.scriptPubKey.addresses && out.scriptPubKey.addresses.length === 1) { address = out.scriptPubKey.addresses[0]; - } else { - address = out.scriptPubKey.address ?? null; + } else if(out.scriptPubKey.address){ + address = out.scriptPubKey.address; } tx.outputs.push({ satoshis: out.valueSat,