diff --git a/.nycrc b/.nycrc deleted file mode 100644 index dc1b7136..00000000 --- a/.nycrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "nyc":{ - "check-coverage": false, - "watermarks": { - "lines": [80, 95], - "functions": [80, 95], - "branches": [80, 95], - "statements": [80, 95] - } - }, - "reporter": ["text","html"] - -} \ No newline at end of file diff --git a/.nycrc.yml b/.nycrc.yml new file mode 100644 index 00000000..cd9cb438 --- /dev/null +++ b/.nycrc.yml @@ -0,0 +1,9 @@ +nyc: + check-coverage: false + watermarks: + lines: [80, 95] + functions: [80, 95] + branches: [80, 95] + statements: [80, 95] +reporter: + - text diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 5d5962bc..4da7450b 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -52,7 +52,7 @@ Nothing force you to do so, this is mostly an helper provided to you. Quick note : - If no mnemonic is provided (nor any privatekey, HDPubKey,...) or if mnemonic is `null`, a mnemonic will be created for you automatically. -- **By default, if not provided, network value will be `testnet`**. +- **By default, if not provided, network value will be `evonet`**. - If no adapter specified, Wallet-lib will use a in-memory store (and warn you about it). - If no transport specified, Wallet-lib will connect to DAPI. - `wallet.getAccount()` is by default equivalent to `wallet.getAccount(0)`, where 0 correspond of the account index as per [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki). diff --git a/docs/storage/createWallet.md b/docs/storage/createWallet.md index 53ca0c5d..1b50da74 100644 --- a/docs/storage/createWallet.md +++ b/docs/storage/createWallet.md @@ -7,7 +7,7 @@ Parameters: | parameters | type | required | Description | |------------------------|-------------------|------------------| ------------------------------------------------------------------------| | **walletId** | String | yes | The wallet id to create | -| **network** | Network/String | no (Def: testnet)| The network for the wallet | +| **network** | Network/String | no (Def: evonet) | The network for the wallet | | **mnemonic** | Mnemonic/String | no (Def: null) | When applicable, the mnemonic used to generate the wallet | | **type** | String | no (Def: null) | The wallet type to create | diff --git a/docs/wallet/Wallet.md b/docs/wallet/Wallet.md index bf4063b4..9f469782 100644 --- a/docs/wallet/Wallet.md +++ b/docs/wallet/Wallet.md @@ -7,7 +7,7 @@ Parameters: | parameters | type | required | Description | |------------------------------------------|--------------------|--------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| **walletOpts.network** | string/Network | no (def:'testnet') | Use either a string reference to Networks ('livenet', 'testnet') or it's Networks representation | +| **walletOpts.network** | string/Network | no (def:'evonet') | Use either a string reference to Networks ('livenet', 'testnet') or it's Networks representation | | **walletOpts.mnemonic** | string/Mnemonic | no | If sets at null, generate a new mnemonic. If sets to a valid value, create wallet from mnemonic | | **walletOpts.passphrase** | string | no | If sets at null, generate a new privateKey. It sets to a valid privateKey, uses it (with the passphrase if provided) to unlock the seed | | **walletOpts.offlineMode** | boolean | no (def: false) | Set to true to not perform any request to the network | diff --git a/examples/wallet-plugins.js b/examples/wallet-plugins.js index d9b71ac4..47f74f8c 100644 --- a/examples/wallet-plugins.js +++ b/examples/wallet-plugins.js @@ -13,7 +13,6 @@ const coldStorageAddress = 'yb67GKjkk4AMrJcqoedCjeemFGo9bDovNS'; const wallet = new Wallet({ mode: 'light', - transporter: 'insight', injectDefaultPlugins: false, // Will not inject default plugins (BIP44, SyncWorker) // Will add these plugin instead, one is already init to show that both are fine to used. // The order has it's importance, here ColdStorageWorker will use WalletConsolidator as a depts. diff --git a/fixtures/FakeNet/FakeNet.js b/fixtures/FakeNet/FakeNet.js deleted file mode 100644 index 52686fa8..00000000 --- a/fixtures/FakeNet/FakeNet.js +++ /dev/null @@ -1,75 +0,0 @@ -const blocksData = require('./data/blocks/blocks.js'); -const BaseTransporter = require('../../src/transporters/types/BaseTransporter/BaseTransporter'); - -const bestBlockDataHeight = 21546; -/** - * This is a saved snapshot of some selected blocks and transactions - * Meant to be used as replacement of DAPIClientWrapper. - * Read more on the specificities on Readme.md and the things that are saved - * - */ -class FakeNet extends BaseTransporter { - constructor(props) { - super({ ...props, type: 'DAPIClient' }); - - this.height = bestBlockDataHeight; - this.blockHash = blocksData.heights[this.height]; - - this.relayFee = 0.00001; - this.difficulty = 0.00171976818884149; - this.network = 'testnet'; - } - - setHeight(height) { - if (!height) throw new Error('Height needed'); - this.height = height; - - if (!blocksData.heights[this.height]) { - throw new Error(`Missing block ${this.height}`); - } - this.blockHash = blocksData.heights[this.height]; - } - - rewindBlock(step = 1) { - this.height -= step; - if (!blocksData.heights[this.height]) { - throw new Error(`Missing block ${this.height}`); - } - this.blockHash = blocksData.heights[this.height]; - } - - forwardBlock(step = 1) { - this.height += step; - if (!blocksData.heights[this.height]) { - throw new Error(`Missing block ${this.height}`); - } - this.blockHash = blocksData.heights[this.height]; - } - - // eslint-disable-next-line class-methods-use-this - getMnemonicList() { - return [ - 'nerve iron scrap chronic error wild glue sound range hurdle alter dwarf', - ]; - } -} - -// FakeNet.prototype.getAddressSummary = require('./methods/getAddressSummary'); -FakeNet.prototype.getBestBlock = require('./methods/getBestBlock'); -FakeNet.prototype.getBestBlockHash = require('./methods/getBestBlockHash'); -FakeNet.prototype.getBestBlockHeader = require('./methods/getBestBlockHeader'); -FakeNet.prototype.getBestBlockHeight = require('./methods/getBestBlockHeight'); -FakeNet.prototype.getBlockByHash = require('./methods/getBlockByHash'); -FakeNet.prototype.getBlockByHeight = require('./methods/getBlockByHeight'); -FakeNet.prototype.getBlockHeaderByHash = require('./methods/getBlockHeaderByHash'); -FakeNet.prototype.getBlockHeaderByHeight = require('./methods/getBlockHeaderByHeight'); -FakeNet.prototype.getStatus = require('./methods/getStatus'); -FakeNet.prototype.getAddressSummary = require('./methods/getAddressSummary'); -FakeNet.prototype.getTransaction = require('./methods/getTransaction'); -FakeNet.prototype.getUTXO = require('./methods/getUTXO'); -FakeNet.prototype.sendTransaction = require('./methods/sendTransaction'); -FakeNet.prototype.subscribeToAddressesTransactions = require('./methods/subscribeToAddressesTransactions'); -FakeNet.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders'); -FakeNet.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks'); - -module.exports = FakeNet; diff --git a/fixtures/transporters/FakeInvalidTransporter.js b/fixtures/transporters/FakeInvalidTransporter.js deleted file mode 100644 index c364b006..00000000 --- a/fixtures/transporters/FakeInvalidTransporter.js +++ /dev/null @@ -1,21 +0,0 @@ -const { BaseTransporter } = require('../../src/transporters'); - -const methods = [ - 'getAddressSummary', - 'getTransaction', - 'getUTXO', - 'subscribeToAddresses', -]; -class FakeInvalidTransporter extends BaseTransporter { - constructor() { - super({ type: 'FakeInvalidTransporter' }); - } -} -[...methods] - .forEach((key) => { - FakeInvalidTransporter.prototype[key] = function () { - return new Error('DummyFunction'); - }; - }); - -module.exports = FakeInvalidTransporter; diff --git a/fixtures/transporters/FakeValidTransporter.js b/fixtures/transporters/FakeValidTransporter.js deleted file mode 100644 index f1d13c5b..00000000 --- a/fixtures/transporters/FakeValidTransporter.js +++ /dev/null @@ -1,22 +0,0 @@ -const { BaseTransporter } = require('../../src/transporters'); - -const methods = [ - 'getAddressSummary', - 'getTransaction', - 'getUTXO', - 'sendTransaction', - 'getIdentityIdByFirstPublicKey', -]; -class FakeValidTransporter extends BaseTransporter { - constructor() { - super({ type: 'FakeValidTransporter' }); - } -} -[...methods] - .forEach((key) => { - FakeValidTransporter.prototype[key] = function () { - return new Error('DummyFunction'); - }; - }); - -module.exports = FakeValidTransporter; diff --git a/package-lock.json b/package-lock.json index 1605f868..3f6fe67c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,9 @@ { "name": "@dashevo/wallet-lib", - "version": "7.13.4", + "version": "7.14.0-dev.1", "lockfileVersion": 1, "requires": true, "dependencies": { - "@apidevtools/json-schema-ref-parser": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-8.0.0.tgz", - "integrity": "sha512-n4YBtwQhdpLto1BaUCyAeflizmIbaloGShsPyRtFf5qdFJxfssj+GgLavczgKJFa3Bq+3St2CKcpRJdjtB4EBw==", - "requires": { - "@jsdevtools/ono": "^7.1.0", - "call-me-maybe": "^1.0.1", - "js-yaml": "^3.13.1" - } - }, "@babel/code-frame": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz", @@ -132,15 +122,6 @@ "integrity": "sha512-0fKu/QqildpXmPVaRBoXOlyBb3MC+J0A66x97qEfLOMkn3u6nfY5esWogQwi/K0BjASYy4DbnsEWnpNL6qT5Mw==", "dev": true }, - "@babel/polyfill": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.10.4.tgz", - "integrity": "sha512-8BYcnVqQ5kMD2HXoHInBH7H1b/uP3KdnwCYXOqFnXqguOyuu443WXusbIUbWEfY3Z0Txk0M1uG/8YuAMhNl6zg==", - "requires": { - "core-js": "^2.6.5", - "regenerator-runtime": "^0.13.4" - } - }, "@babel/template": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.8.3.tgz", @@ -198,25 +179,21 @@ } }, "@dashevo/dapi-client": { - "version": "0.13.6", - "resolved": "https://registry.npmjs.org/@dashevo/dapi-client/-/dapi-client-0.13.6.tgz", - "integrity": "sha512-ENhjIW0XFK+Na+pJByd4GbEnbUuUwz9V4NN6dZgtUjBN8toIAFmD1m+eDrglXPqGfoMVzh7Cj+eRPdoEXClPmQ==", + "version": "0.14.0-dev.7", + "resolved": "https://registry.npmjs.org/@dashevo/dapi-client/-/dapi-client-0.14.0-dev.7.tgz", + "integrity": "sha512-AlX17VrCXpLPTmmw0VmtVg4GMpZ4VqvRG/faWNlp1CUxkhWykExLNtI4sgVDGjcCfLihdQq0K3/F0Lg0KzdJyg==", "requires": { - "@babel/polyfill": "^7.8.3", - "@dashevo/dapi-grpc": "~0.13.0", - "@dashevo/dash-spv": "^1.1.6", + "@dashevo/dapi-grpc": "~0.14.0-dev.1", "@dashevo/dashcore-lib": "~0.18.11", - "@dashevo/dpp": "~0.13.0", "axios": "^0.19.2", "cbor": "^5.0.1", - "lodash": "^4.17.15", - "lowdb": "^1.0.0" + "lodash.sample": "^4.2.1" } }, "@dashevo/dapi-grpc": { - "version": "0.13.0", - "resolved": "https://registry.npmjs.org/@dashevo/dapi-grpc/-/dapi-grpc-0.13.0.tgz", - "integrity": "sha512-w6oyQsHO5/m56DNS9Z41qelJWhT9vh9AOE8tBzv6Zd5mI+wV+LhM95r9xwpb0x6CufXCK1K9kLkBOFuOp/C2Pg==", + "version": "0.14.0-dev.1", + "resolved": "https://registry.npmjs.org/@dashevo/dapi-grpc/-/dapi-grpc-0.14.0-dev.1.tgz", + "integrity": "sha512-o5l5nH7ZuIMv9fSOScy6orPyAxTR//EsxMP3SGfrybCOf0fjS2FttlbHGdMbC5A21a/Og4ms1zQgf0QquaFfgw==", "requires": { "@dashevo/grpc-common": "^0.3.0", "google-protobuf": "^3.8.0", @@ -225,49 +202,6 @@ "protobufjs": "^6.8.8" } }, - "@dashevo/dark-gravity-wave": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@dashevo/dark-gravity-wave/-/dark-gravity-wave-1.1.1.tgz", - "integrity": "sha512-rt0PzGzqplqERWVIMLlBxm4mJqjFTYNUFRhIccbfaF/MDyd0/585krGOWIhe0Sis9XQNA/FJlxxRjtPXIcyyCg==" - }, - "@dashevo/dash-spv": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/@dashevo/dash-spv/-/dash-spv-1.1.6.tgz", - "integrity": "sha512-pAZlwN4UJkht68zSq7MmqMZIHcvuah69UT7KM6RBeGrSEPaw1wxiz772tJ3Q/Px4FOHf3Uwc63ylOe7Vnbk1qA==", - "requires": { - "@dashevo/dark-gravity-wave": "^1.1.1", - "@dashevo/dash-util": "^2.0.3", - "@dashevo/dashcore-lib": "^0.17.4", - "levelup": "^4.0.1", - "memdown": "^3.0.0" - }, - "dependencies": { - "@dashevo/dashcore-lib": { - "version": "0.17.12", - "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.17.12.tgz", - "integrity": "sha512-ZZFlWqzGTklW9uSsj4QNe1k3e5vrqDTfeaZwt2oU0dbmMltkFgNifx7Rq6ij5erRDKFoIkOG1ZM6Q4brc9eWUw==", - "requires": { - "@dashevo/x11-hash-js": "^1.0.2", - "bloom-filter": "^0.2.0", - "bn.js": "=4.11.8", - "bs58": "=4.0.1", - "elliptic": "=6.4.1", - "inherits": "=2.0.1", - "lodash": "^4.17.15", - "unorm": "^1.4.1" - } - } - } - }, - "@dashevo/dash-util": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@dashevo/dash-util/-/dash-util-2.0.3.tgz", - "integrity": "sha512-fnc76NYVBhuTLhuUVidnV9sKSsMxmkxkhUOjiD/ny6Ipyo+qxwKeFAn8SvdVzlEpflNA613B+hsxmTBBGazl4A==", - "requires": { - "bn.js": "^4.6.4", - "buffer-reverse": "^1.0.1" - } - }, "@dashevo/dashcore-lib": { "version": "0.18.11", "resolved": "https://registry.npmjs.org/@dashevo/dashcore-lib/-/dashcore-lib-0.18.11.tgz", @@ -292,22 +226,6 @@ } } }, - "@dashevo/dpp": { - "version": "0.13.1", - "resolved": "https://registry.npmjs.org/@dashevo/dpp/-/dpp-0.13.1.tgz", - "integrity": "sha512-4OFyRnyjE0m4Hx9hY5WC8KcEopJZJKeWP7T1celToairZwhyAnomlIC4XehNB6FFGwBHvUCct6TfNgF6KwHncw==", - "requires": { - "@apidevtools/json-schema-ref-parser": "^8.0.0", - "@dashevo/dashcore-lib": "~0.18.1", - "ajv": "^6.12.0", - "bs58": "^4.0.1", - "cbor": "^5.0.1", - "lodash.get": "^4.4.2", - "lodash.mergewith": "^4.6.2", - "lodash.set": "^4.3.2", - "multihashes": "^0.4.19" - } - }, "@dashevo/grpc-common": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@dashevo/grpc-common/-/grpc-common-0.3.0.tgz", @@ -422,11 +340,6 @@ "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", "dev": true }, - "@jsdevtools/ono": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.2.tgz", - "integrity": "sha512-qS/a24RA5FEoiJS9wiv6Pwg2c/kiUo3IVUQcfeM9JvsR6pM8Yx+yl/6xWYLckZCT5jpLNhslgjiA8p/XcGyMRQ==" - }, "@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -698,29 +611,6 @@ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, - "abstract-leveldown": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz", - "integrity": "sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==", - "requires": { - "buffer": "^5.5.0", - "immediate": "^3.2.3", - "level-concat-iterator": "~2.0.0", - "level-supports": "~1.0.0", - "xtend": "~4.0.0" - }, - "dependencies": { - "buffer": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", - "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - } - } - }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -763,6 +653,7 @@ "version": "6.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", "integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", + "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -888,6 +779,7 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -1120,7 +1012,8 @@ "base64-js": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", + "dev": true }, "base64id": { "version": "2.0.0", @@ -1390,11 +1283,6 @@ "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, - "buffer-reverse": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/buffer-reverse/-/buffer-reverse-1.0.1.tgz", - "integrity": "sha1-SSg8jvpvkBvAH6MwTQYCeXGuL2A=" - }, "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -1488,11 +1376,6 @@ "write-file-atomic": "^3.0.0" } }, - "call-me-maybe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.1.tgz", - "integrity": "sha1-JtII6onje1y95gJQoV8DHBak1ms=" - }, "callsite": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", @@ -1916,11 +1799,6 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=", "dev": true }, - "core-js": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -2087,22 +1965,6 @@ } } }, - "deferred-leveldown": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-5.3.0.tgz", - "integrity": "sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==", - "requires": { - "abstract-leveldown": "~6.2.1", - "inherits": "^2.0.3" - }, - "dependencies": { - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - } - } - }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -2530,6 +2392,7 @@ "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", "integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==", + "dev": true, "requires": { "prr": "~1.0.1" } @@ -2821,7 +2684,8 @@ "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true }, "esquery": { "version": "1.1.0", @@ -3055,12 +2919,14 @@ "fast-deep-equal": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", - "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", + "dev": true }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "fast-levenshtein": { "version": "2.0.6", @@ -3649,7 +3515,8 @@ "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=" + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true }, "gauge": { "version": "2.7.4", @@ -3773,7 +3640,8 @@ "graceful-fs": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", - "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" + "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", + "dev": true }, "growl": { "version": "1.10.5", @@ -4059,7 +3927,8 @@ "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", + "dev": true }, "iferr": { "version": "0.1.5", @@ -4081,11 +3950,6 @@ "minimatch": "^3.0.4" } }, - "immediate": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", - "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==" - }, "import-fresh": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", @@ -4438,7 +4302,8 @@ "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true }, "is-regex": { "version": "1.0.5", @@ -4683,6 +4548,7 @@ "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -4703,7 +4569,8 @@ "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -5104,56 +4971,6 @@ "invert-kv": "^1.0.0" } }, - "level-concat-iterator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", - "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==" - }, - "level-errors": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-2.0.1.tgz", - "integrity": "sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==", - "requires": { - "errno": "~0.1.1" - } - }, - "level-iterator-stream": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-4.0.2.tgz", - "integrity": "sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==", - "requires": { - "inherits": "^2.0.4", - "readable-stream": "^3.4.0", - "xtend": "^4.0.2" - }, - "dependencies": { - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - } - } - }, - "level-supports": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", - "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", - "requires": { - "xtend": "^4.0.2" - } - }, - "levelup": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/levelup/-/levelup-4.4.0.tgz", - "integrity": "sha512-94++VFO3qN95cM/d6eBXvd894oJE0w3cInq9USsyQzzoJxmiYzPAocNcuGCPGGjoXqDVJcr3C1jzt1TSjyaiLQ==", - "requires": { - "deferred-leveldown": "~5.3.0", - "level-errors": "~2.0.0", - "level-iterator-stream": "~4.0.0", - "level-supports": "~1.0.0", - "xtend": "~4.0.0" - } - }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -5280,15 +5097,10 @@ "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" }, - "lodash.mergewith": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", - "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==" - }, - "lodash.set": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz", - "integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=" + "lodash.sample": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/lodash.sample/-/lodash.sample-4.2.1.tgz", + "integrity": "sha1-XkKRsMdT+hq+sKq4+ynfG2bwf20=" }, "log-symbols": { "version": "3.0.0", @@ -5340,18 +5152,6 @@ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, - "lowdb": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz", - "integrity": "sha512-2+x8esE/Wb9SQ1F9IHaYWfsC9FIecLOPrK4g17FGEayjUWH172H6nwicRovGvSE2CPZouc2MCIqCI7h9d+GftQ==", - "requires": { - "graceful-fs": "^4.1.3", - "is-promise": "^2.1.0", - "lodash": "4", - "pify": "^3.0.0", - "steno": "^0.4.1" - } - }, "lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -5361,11 +5161,6 @@ "yallist": "^3.0.2" } }, - "ltgt": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", - "integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=" - }, "make-dir": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.2.tgz", @@ -5426,39 +5221,6 @@ "p-is-promise": "^2.0.0" } }, - "memdown": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/memdown/-/memdown-3.0.0.tgz", - "integrity": "sha512-tbV02LfZMWLcHcq4tw++NuqMO+FZX8tNJEiD2aNRm48ZZusVg5N8NART+dmBkepJVye986oixErf7jfXboMGMA==", - "requires": { - "abstract-leveldown": "~5.0.0", - "functional-red-black-tree": "~1.0.1", - "immediate": "~3.2.3", - "inherits": "~2.0.1", - "ltgt": "~2.2.0", - "safe-buffer": "~5.1.1" - }, - "dependencies": { - "abstract-leveldown": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-5.0.0.tgz", - "integrity": "sha512-5mU5P1gXtsMIXg65/rsYGsi93+MlogXZ9FA8JnwKurHQg64bfXwGYVdVdijNTVNOlAsuIiOwHdvFFD5JqCJQ7A==", - "requires": { - "xtend": "~4.0.0" - } - }, - "immediate": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.2.3.tgz", - "integrity": "sha1-0UD6j2FGWb1lQSMwl92qwlzdmRw=" - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - } - } - }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -5976,47 +5738,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "multibase": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/multibase/-/multibase-0.7.0.tgz", - "integrity": "sha512-TW8q03O0f6PNFTQDvh3xxH03c8CjGaaYrjkl9UQPG6rz53TQzzxJVCIWVjzcbN/Q5Y53Zd0IBQBMVktVgNx4Fg==", - "requires": { - "base-x": "^3.0.8", - "buffer": "^5.5.0" - }, - "dependencies": { - "buffer": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", - "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - } - } - }, - "multihashes": { - "version": "0.4.21", - "resolved": "https://registry.npmjs.org/multihashes/-/multihashes-0.4.21.tgz", - "integrity": "sha512-uVSvmeCWf36pU2nB4/1kzYZjsXD9vofZKpgudqkceYY5g2aZZXJ5r9lxuzoRLl1OAp28XljXsEJ/X/85ZsKmKw==", - "requires": { - "buffer": "^5.5.0", - "multibase": "^0.7.0", - "varint": "^5.0.0" - }, - "dependencies": { - "buffer": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", - "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - } - } - }, "mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", @@ -6999,11 +6720,6 @@ "integrity": "sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA==", "dev": true }, - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" - }, "pkg-dir": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", @@ -7080,7 +6796,8 @@ "prr": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", - "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=" + "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=", + "dev": true }, "public-encrypt": { "version": "4.0.3", @@ -7138,7 +6855,8 @@ "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true }, "qjobs": { "version": "1.2.0", @@ -7266,11 +6984,6 @@ "picomatch": "^2.0.4" } }, - "regenerator-runtime": { - "version": "0.13.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz", - "integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==" - }, "regex-not": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz", @@ -8008,7 +7721,8 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true }, "ssri": { "version": "6.0.1", @@ -8051,14 +7765,6 @@ "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", "dev": true }, - "steno": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz", - "integrity": "sha1-BxEFvfwobmYVwEA8J+nXtdy4Vcs=", - "requires": { - "graceful-fs": "^4.1.3" - } - }, "stream-browserify": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz", @@ -8812,6 +8518,7 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, "requires": { "punycode": "^2.1.0" } @@ -8896,11 +8603,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "varint": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/varint/-/varint-5.0.0.tgz", - "integrity": "sha1-2Ca4n3SQcy+rwMDtaT7Uddyynr8=" - }, "vm-browserify": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", @@ -9369,7 +9071,8 @@ }, "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, "os-locale": { @@ -9687,7 +9390,8 @@ "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "dev": true }, "y18n": { "version": "3.2.1", diff --git a/package.json b/package.json index 9dd5d684..50c91547 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/wallet-lib", - "version": "7.13.4", + "version": "7.14.0-dev.1", "description": "Light wallet library for Dash", "main": "src/index.js", "unpkg": "dist/wallet-lib.min.js", @@ -39,7 +39,7 @@ }, "homepage": "https://github.com/dashevo/wallet-lib#readme", "dependencies": { - "@dashevo/dapi-client": "~0.13.6", + "@dashevo/dapi-client": "~0.14.0-dev.7", "@dashevo/dashcore-lib": "~0.18.11", "cbor": "^5.0.2", "crypto-js": "^4.0.0", diff --git a/src/CONSTANTS.js b/src/CONSTANTS.js index fa5236c4..1c84e89d 100644 --- a/src/CONSTANTS.js +++ b/src/CONSTANTS.js @@ -78,7 +78,7 @@ const CONSTANTS = { ], SAFE_PROPERTIES: [ 'offlineMode', - 'transporter', + 'transport', 'walletId', ], }, diff --git a/src/plugins/Plugins/ChainPlugin.js b/src/plugins/Plugins/ChainPlugin.js index d5d3c349..d594187e 100644 --- a/src/plugins/Plugins/ChainPlugin.js +++ b/src/plugins/Plugins/ChainPlugin.js @@ -15,7 +15,7 @@ class ChainPlugin extends StandardPlugin { firstExecutionRequired: defaultOpts.firstExecutionRequired, dependencies: [ 'storage', - 'transporter', + 'transport', 'fetchStatus', 'walletId', ], @@ -32,14 +32,14 @@ class ChainPlugin extends StandardPlugin { async execBlockListener() { const self = this; if (!this.isSubscribedToBlocks) { - self.transporter.on(EVENTS.BLOCK, async (ev) => { + self.transport.on(EVENTS.BLOCK, async (ev) => { // const { network } = self.storage.store.wallets[self.walletId]; const { payload: block } = ev; this.parentEvents.emit(EVENTS.BLOCK, { type: EVENTS.BLOCK, payload: block }); // We do not announce BLOCKHEADER as this is done by Storage await self.storage.importBlockHeader(block.header); }); - await self.transporter.subscribeToBlocks(); + await self.transport.subscribeToBlocks(); } } @@ -58,7 +58,7 @@ class ChainPlugin extends StandardPlugin { logger.debug('ChainPlugin - Setting up starting blockHeight', blocks); this.storage.store.chains[network.toString()].blockHeight = blocks; - const bestBlock = await this.transporter.getBlockHeaderByHeight(blocks); + const bestBlock = await this.transport.getBlockHeaderByHeight(blocks); await this.storage.importBlockHeader(bestBlock); return true; diff --git a/src/plugins/Workers/IdentitySyncWorker.js b/src/plugins/Workers/IdentitySyncWorker.js index ec9dcc81..72c0d0a2 100644 --- a/src/plugins/Workers/IdentitySyncWorker.js +++ b/src/plugins/Workers/IdentitySyncWorker.js @@ -15,7 +15,7 @@ class IdentitySyncWorker extends Worker { gapLimit: 10, dependencies: [ 'storage', - 'transporter', + 'transport', 'walletId', 'getIdentityHDKeyByIndex', ], @@ -63,7 +63,7 @@ class IdentitySyncWorker extends Worker { const publicKey = privateKey.toPublicKey(); // eslint-disable-next-line no-await-in-loop - const fetchedId = await this.transporter.getIdentityIdByFirstPublicKey(publicKey.hash); + const fetchedId = await this.transport.getIdentityIdByFirstPublicKey(publicKey.hash); // if identity id is not preset then increment gap count // and stop sync if gap limit is reached diff --git a/src/plugins/Workers/SyncWorker/SyncWorker.js b/src/plugins/Workers/SyncWorker/SyncWorker.js index ec4c946a..bf01babd 100644 --- a/src/plugins/Workers/SyncWorker/SyncWorker.js +++ b/src/plugins/Workers/SyncWorker/SyncWorker.js @@ -29,7 +29,7 @@ class SyncWorker extends Worker { dependencies: [ 'walletType', 'storage', - 'transporter', + 'transport', 'fetchStatus', 'getTransaction', 'fetchAddressInfo', @@ -60,13 +60,13 @@ class SyncWorker extends Worker { async execute() { if (this.isInitialized) { - // We will need to update the transporter about the addresses we need to listen + // We will need to update the transport about the addresses we need to listen // which is something that can change over the course of the use of the lib. const addrList = this.getAddressListToSync().map((addr) => addr.address); - // Setup listener that will listen for Events from transporter + // Setup listener that will listen for Events from transport // and handle them (mostly for addition request to storage) - await this.transporter.subscribeToAddressesTransactions(addrList); + await this.transport.subscribeToAddressesTransactions(addrList); } } } diff --git a/src/plugins/Workers/SyncWorker/setupTransporterListeners.js b/src/plugins/Workers/SyncWorker/setupTransporterListeners.js index d659834b..2bab5414 100644 --- a/src/plugins/Workers/SyncWorker/setupTransporterListeners.js +++ b/src/plugins/Workers/SyncWorker/setupTransporterListeners.js @@ -1,18 +1,18 @@ const EVENTS = require('../../../EVENTS'); module.exports = function setupListeners() { - const { storage, transporter } = this; + const { storage, transport } = this; - // For each new transaction emitted by transporter, we import to storage + // For each new transaction emitted by transport, we import to storage // It will also look-up for UTXO - transporter.on(EVENTS.FETCHED_TRANSACTION, async (ev) => { + transport.on(EVENTS.FETCHED_TRANSACTION, async (ev) => { const { payload: transaction } = ev; // Storage.importTransaction will announce the TX to parent await storage.importTransaction(transaction); }); // The same is being done for fetch_address, but we also announce it. - transporter.on(EVENTS.FETCHED_ADDRESS, async (ev) => { + transport.on(EVENTS.FETCHED_ADDRESS, async (ev) => { const { payload: address } = ev; this.announce(EVENTS.FETCHED_ADDRESS, address); }); diff --git a/src/plugins/Workers/SyncWorker/utils/fetchAddressTransactions.js b/src/plugins/Workers/SyncWorker/utils/fetchAddressTransactions.js index 6be3b47e..483be197 100644 --- a/src/plugins/Workers/SyncWorker/utils/fetchAddressTransactions.js +++ b/src/plugins/Workers/SyncWorker/utils/fetchAddressTransactions.js @@ -1,11 +1,11 @@ -module.exports = async function fetchAndStoreAddressTransactions(address, transporter) { +module.exports = async function fetchAndStoreAddressTransactions(address, transport) { const promises = []; - const summary = await transporter.getAddressSummary(address); + const summary = await transport.getAddressSummary(address); if (summary.transactions.length) { summary.transactions .forEach((txid) => { - promises.push(transporter.getTransaction(txid)); + promises.push(transport.getTransaction(txid)); }); } diff --git a/src/plugins/Workers/SyncWorker/utils/processAddressList.js b/src/plugins/Workers/SyncWorker/utils/processAddressList.js index 1190ead7..345e9cbd 100644 --- a/src/plugins/Workers/SyncWorker/utils/processAddressList.js +++ b/src/plugins/Workers/SyncWorker/utils/processAddressList.js @@ -3,9 +3,9 @@ const fetchAddressTransactions = require('./fetchAddressTransactions'); const TransactionOrderer = require('./TransactionOrderer/TransactionOrderer'); module.exports = async function processAddressList(addressList) { - const { transporter, storage } = this; + const { transport, storage } = this; - const boundFetchAddressTransactions = _.bind(fetchAddressTransactions, null, _, transporter); + const boundFetchAddressTransactions = _.bind(fetchAddressTransactions, null, _, transport); const transactionPromises = addressList.map(boundFetchAddressTransactions); const transactionsByAddresses = await Promise.all(transactionPromises); @@ -16,7 +16,7 @@ module.exports = async function processAddressList(addressList) { transactions.forEach((tx) => ordered.insert(tx)); - const boundImportTransaction = _.bind(storage.importTransaction, storage, _, transporter); + const boundImportTransaction = _.bind(storage.importTransaction, storage, _, transport); const importPromises = ordered.transactions.map(boundImportTransaction); await Promise.all(importPromises); diff --git a/src/transport/AbstractTransport.js b/src/transport/AbstractTransport.js new file mode 100644 index 00000000..bdb6fe3f --- /dev/null +++ b/src/transport/AbstractTransport.js @@ -0,0 +1,63 @@ +const EventEmitter = require('events'); + +const EVENTS = require('../EVENTS'); +const logger = require('../logger'); + +/** + * @abstract + */ +class AbstractTransport extends EventEmitter { + constructor() { + super(); + + this.state = { + block: null, + blockHeaders: null, + // Executors are Interval + executors: { + blocks: null, + blockHeaders: null, + addresses: null, + }, + addressesTransactionsMap: {}, + subscriptions: { + addresses: {}, + }, + }; + } + + announce(eventName, args) { + logger.silly(`Transporter.announce(${eventName})`); + switch (eventName) { + case EVENTS.BLOCKHEADER: + case EVENTS.BLOCK: + case EVENTS.TRANSACTION: + case EVENTS.FETCHED_TRANSACTION: + case EVENTS.FETCHED_ADDRESS: + this.emit(eventName, { type: eventName, payload: args }); + break; + default: + this.emit(eventName, { type: eventName, payload: args }); + logger.warn('Transporter - Not implemented, announce of ', eventName, args); + } + } + + disconnect() { + const { executors, subscriptions } = this.state; + + clearInterval(subscriptions.blocks); + clearInterval(subscriptions.blockHeaders); + + // eslint-disable-next-line guard-for-in,no-restricted-syntax + for (const addr in subscriptions.addresses) { + clearInterval(addr); + delete this.state.subscriptions.addresses[addr]; + } + + clearInterval(executors.blocks); + clearInterval(executors.blockHeaders); + clearInterval(executors.addresses); + } +} + +module.exports = AbstractTransport; diff --git a/src/transport/DAPIClientTransport/DAPIClientTransport.js b/src/transport/DAPIClientTransport/DAPIClientTransport.js new file mode 100644 index 00000000..363788d4 --- /dev/null +++ b/src/transport/DAPIClientTransport/DAPIClientTransport.js @@ -0,0 +1,33 @@ +const AbstractTransport = require('../AbstractTransport'); + +/** + * @implements {Transport} + */ +class DAPIClientTransport extends AbstractTransport { + constructor(client) { + super(); + + this.client = client; + } +} + +DAPIClientTransport.prototype.getAddressSummary = require('./methods/getAddressSummary'); +DAPIClientTransport.prototype.getBestBlock = require('./methods/getBestBlock'); +DAPIClientTransport.prototype.getBestBlockHeader = require('./methods/getBestBlockHeader'); +DAPIClientTransport.prototype.getBestBlockHash = require('./methods/getBestBlockHash'); +DAPIClientTransport.prototype.getBestBlockHeight = require('./methods/getBestBlockHeight'); +DAPIClientTransport.prototype.getBlockByHash = require('./methods/getBlockByHash'); +DAPIClientTransport.prototype.getBlockByHeight = require('./methods/getBlockByHeight'); +DAPIClientTransport.prototype.getBlockHeaderByHash = require('./methods/getBlockHeaderByHash'); +DAPIClientTransport.prototype.getBlockHeaderByHeight = require('./methods/getBlockHeaderByHeight'); +DAPIClientTransport.prototype.getStatus = require('./methods/getStatus'); +DAPIClientTransport.prototype.getTransaction = require('./methods/getTransaction'); +DAPIClientTransport.prototype.getUTXO = require('./methods/getUTXO'); +DAPIClientTransport.prototype.sendTransaction = require('./methods/sendTransaction'); +DAPIClientTransport.prototype.subscribeToAddressesTransactions = require('./methods/subscribeToAddressesTransactions'); +DAPIClientTransport.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders'); +DAPIClientTransport.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks'); +DAPIClientTransport.prototype.getIdentityIdByFirstPublicKey = require('./methods/getIdentityIdByFirstPublicKey'); + + +module.exports = DAPIClientTransport; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.js b/src/transport/DAPIClientTransport/methods/getAddressSummary.js similarity index 66% rename from src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.js rename to src/transport/DAPIClientTransport/methods/getAddressSummary.js index 8b1f8d28..e72ea0bd 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.js +++ b/src/transport/DAPIClientTransport/methods/getAddressSummary.js @@ -1,16 +1,19 @@ -const { is } = require('../../../../utils'); -const logger = require('../../../../logger'); +const { is } = require('../../../utils'); +const logger = require('../../../logger'); module.exports = async function getAddressSummary(address) { if (!is.address(address)) throw new Error('Received an invalid address to fetch'); + logger.silly(`DAPIClient.getAddressSummary[${address}]`); - const summary = await this.client.getAddressSummary(address); + + const summary = await this.client.core.getAddressSummary(address); if (summary.transactions && summary.transactions.length) { // With DAPI, the oldest is the last element of the array - // We do not want to force other transporter to also do the same, + // We do not want to force other transport to also do the same, // therefore we reverse it directly here summary.transactions.reverse(); } + return summary; }; diff --git a/src/transport/DAPIClientTransport/methods/getAddressSummary.spec.js b/src/transport/DAPIClientTransport/methods/getAddressSummary.spec.js new file mode 100644 index 00000000..33d1debf --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getAddressSummary.spec.js @@ -0,0 +1,48 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getAddressSummary', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = { + addrStr: 'yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN', + balance: 10, + balanceSat: 1000000000, + totalReceived: 10, + totalReceivedSat: 1000000000, + totalSent: 0, + totalSentSat: 0, + unconfirmedBalance: 0, + unconfirmedBalanceSat: 0, + unconfirmedTxApperances: 0, + unconfirmedAppearances: 0, + txApperances: 1, + txAppearances: 1, + transactions: [ + '3ab6ebc86b9cdea1580d376510e54a904f74fcaf38dfe9363fb44bcf33f83703', + ], + }; + + clientMock = { + core: { + getAddressSummary: () => fixture, + }, + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getAddressSummary('yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN'); + + expect(res).to.deep.equal(fixture); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlock.js b/src/transport/DAPIClientTransport/methods/getBestBlock.js similarity index 54% rename from src/transporters/types/DAPIClientWrapper/methods/getBestBlock.js rename to src/transport/DAPIClientTransport/methods/getBestBlock.js index 7bd0311b..8ea7095c 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlock.js +++ b/src/transport/DAPIClientTransport/methods/getBestBlock.js @@ -1,6 +1,7 @@ -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBestBlock() { - logger.silly('DAPIClientWrapper.getBestBlock'); + logger.silly('DAPIClientTransport.getBestBlock'); + return this.getBlockByHash(await this.getBestBlockHash()); }; diff --git a/src/transport/DAPIClientTransport/methods/getBestBlock.spec.js b/src/transport/DAPIClientTransport/methods/getBestBlock.spec.js new file mode 100644 index 00000000..0026b712 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBestBlock.spec.js @@ -0,0 +1,43 @@ +const { expect } = require('chai'); +const { Block } = require('@dashevo/dashcore-lib'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBestBlock', function suite() { + let bestBlockHash; + let block; + let transport; + let clientMock; + + beforeEach(() => { + bestBlockHash = '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad'; + block = { + header: { + hash: '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad', version: 536870912, prevHash: '000002243e872509388a6bd9c1c69c719bdcee2a780262f00c3cf75060f7adae', merkleRoot: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', time: 1585673611, bits: 503479478, nonce: 24664, + }, + transactions: [], + }; + + clientMock = { + core: { + getBestBlockHash: () => bestBlockHash, + getBlockByHash: (hash) => { + if (hash === bestBlockHash) return block; + return null; + }, + }, + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBestBlock(); + + expect(res).to.deep.equal(new Block(block)); + }); +}); diff --git a/src/transport/DAPIClientTransport/methods/getBestBlockHash.js b/src/transport/DAPIClientTransport/methods/getBestBlockHash.js new file mode 100644 index 00000000..6fdd38fa --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHash.js @@ -0,0 +1,7 @@ +const logger = require('../../../logger'); + +module.exports = async function getBestBlockHash() { + logger.silly('DAPIClientTransport.getBestBlockHash'); + + return this.client.core.getBestBlockHash(); +}; diff --git a/src/transport/DAPIClientTransport/methods/getBestBlockHash.spec.js b/src/transport/DAPIClientTransport/methods/getBestBlockHash.spec.js new file mode 100644 index 00000000..d75034a4 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHash.spec.js @@ -0,0 +1,31 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBestBlockHash', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'; + + clientMock = { + core: { + getBestBlockHash: () => fixture, + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBestBlockHash(); + + expect(res).to.deep.equal(fixture); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.js b/src/transport/DAPIClientTransport/methods/getBestBlockHeader.js similarity index 55% rename from src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.js rename to src/transport/DAPIClientTransport/methods/getBestBlockHeader.js index 52bfc581..2a81ceb4 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.js +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHeader.js @@ -1,6 +1,7 @@ -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBestBlockHeader() { - logger.silly('DAPIClientWrapper.getBestBlockHeader'); + logger.silly('DAPIClientTransport.getBestBlockHeader'); + return this.getBlockHeaderByHash(await this.getBestBlockHash()); }; diff --git a/src/transport/DAPIClientTransport/methods/getBestBlockHeader.spec.js b/src/transport/DAPIClientTransport/methods/getBestBlockHeader.spec.js new file mode 100644 index 00000000..bf034065 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHeader.spec.js @@ -0,0 +1,54 @@ +const { expect } = require('chai'); +const { Block } = require('@dashevo/dashcore-lib'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBestBlockHeader', function suite() { + let bestBlockHash; + let block; + let transport; + let clientMock; + + beforeEach(() => { + bestBlockHash = '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad'; + block = { + header: { + hash: '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad', version: 536870912, prevHash: '000002243e872509388a6bd9c1c69c719bdcee2a780262f00c3cf75060f7adae', merkleRoot: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', time: 1585673611, bits: 503479478, nonce: 24664, + }, + transactions: [{ + hash: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', + version: 3, + inputs: [{ + prevTxId: '0000000000000000000000000000000000000000000000000000000000000000', outputIndex: 4294967295, sequenceNumber: 4294967295, script: '028c300109', + }], + outputs: [{ satoshis: 6885000000, script: '76a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac' }, { satoshis: 6885000000, script: '76a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac' }], + nLockTime: 0, + type: 5, + extraPayload: '02008c300000cead425668f38cfbb8dc028ad53d163fcee7282ede84d9a577ac6851a847ebc80000000000000000000000000000000000000000000000000000000000000000', + }], + }; + + + clientMock = { + core: { + getBestBlockHash: () => bestBlockHash, + getBlockByHash: (hash) => { + if (hash === bestBlockHash) return block; + return null; + }, + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBestBlockHeader(); + + expect(res).to.deep.equal(new Block(block).header); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.js b/src/transport/DAPIClientTransport/methods/getBestBlockHeight.js similarity index 60% rename from src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.js rename to src/transport/DAPIClientTransport/methods/getBestBlockHeight.js index 309a2d2d..d4787cb1 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.js +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHeight.js @@ -1,7 +1,8 @@ -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBestBlockHeight() { - logger.silly('DAPIClientWrapper.getBestBlockHeight'); + logger.silly('DAPIClientTransport.getBestBlockHeight'); + // Previously we would have done getBlock(hash).height return (await this.getStatus()).blocks; }; diff --git a/src/transport/DAPIClientTransport/methods/getBestBlockHeight.spec.js b/src/transport/DAPIClientTransport/methods/getBestBlockHeight.spec.js new file mode 100644 index 00000000..f5935c9f --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBestBlockHeight.spec.js @@ -0,0 +1,33 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBestBlockHeight', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = { + coreVersion: 150000, protocolVersion: 70216, blocks: 9495, timeOffset: 0, connections: 16, proxy: '', difficulty: 0.001447319555790497, testnet: false, relayFee: 0.00001, errors: '', network: 'testnet', + } + + clientMock = { + core: { + getStatus: () => fixture, + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBestBlockHeight(); + + expect(res).to.deep.equal(fixture.blocks); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.js b/src/transport/DAPIClientTransport/methods/getBlockByHash.js similarity index 60% rename from src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.js rename to src/transport/DAPIClientTransport/methods/getBlockByHash.js index 31d936bf..260fd6fe 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.js +++ b/src/transport/DAPIClientTransport/methods/getBlockByHash.js @@ -1,7 +1,8 @@ const { Block } = require('@dashevo/dashcore-lib'); -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBlockByHash(blockHash) { logger.silly(`DAPIClient.getBlockByHash[${blockHash}]`); - return new Block(await this.client.getBlockByHash(blockHash)); + + return new Block(await this.client.core.getBlockByHash(blockHash)); }; diff --git a/src/transport/DAPIClientTransport/methods/getBlockByHash.spec.js b/src/transport/DAPIClientTransport/methods/getBlockByHash.spec.js new file mode 100644 index 00000000..bd0a3db7 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBlockByHash.spec.js @@ -0,0 +1,31 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBlockByHash', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '00000020e2bddfb998d7be4cc4c6b126f04d6e4bd201687523ded527987431707e0200005520320b4e263bec33e08944656f7ce17efbc2c60caab7c8ed8a73d413d02d3a169d555ecdd6021e56d000000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050219250102ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020019250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010019250000010001d02e9ee1b14c022ad6895450f3375a8e9a87f214912d4332fa997996d2000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; + + clientMock = { + core: { + getBlockByHash: () => new Buffer.from(fixture, 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBlockByHash('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); + + expect(res.hash).to.equal('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.js b/src/transport/DAPIClientTransport/methods/getBlockByHeight.js similarity index 60% rename from src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.js rename to src/transport/DAPIClientTransport/methods/getBlockByHeight.js index e303d4e8..67323259 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.js +++ b/src/transport/DAPIClientTransport/methods/getBlockByHeight.js @@ -1,7 +1,8 @@ const { Block } = require('@dashevo/dashcore-lib'); -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBlockByHeight(height) { logger.silly(`DAPIClient.getBlockByHeight[${height}]`); - return new Block(await this.client.getBlockByHeight(height)); + + return new Block(await this.client.core.getBlockByHeight(height)); }; diff --git a/src/transport/DAPIClientTransport/methods/getBlockByHeight.spec.js b/src/transport/DAPIClientTransport/methods/getBlockByHeight.spec.js new file mode 100644 index 00000000..de384167 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBlockByHeight.spec.js @@ -0,0 +1,31 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getBlockByHeight', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '0000002008f7ac5b0e2df33ac233fef59549075ed24aa893ffc1d7b7067256da420000006670782820f19b64f011c55815c9315946573ac92bd5cce6deda684edcba1472c1904e5eae0d021e953d00000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050238180101ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020038180000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; + + clientMock = { + core: { + getBlockByHeight: () => new Buffer.from(fixture, 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBlockByHeight(6200); + + expect(res.hash).to.equal('000000c33ad38337e9bf648842f3cc08b146739d561ce468bd373ee815595436'); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.js b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.js similarity index 80% rename from src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.js rename to src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.js index 49a2622d..270d79f0 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.js +++ b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.js @@ -1,6 +1,7 @@ -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBlockHeaderByHash(blockHash) { logger.silly(`DAPIClient.getBlockHeaderByHash[${blockHash}]`); + return (await this.getBlockByHash(blockHash)).header; }; diff --git a/src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.spec.js b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.spec.js new file mode 100644 index 00000000..1c42d4f0 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHash.spec.js @@ -0,0 +1,34 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport .getBlockHeaderByHash', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '00000020e2bddfb998d7be4cc4c6b126f04d6e4bd201687523ded527987431707e0200005520320b4e263bec33e08944656f7ce17efbc2c60caab7c8ed8a73d413d02d3a169d555ecdd6021e56d000000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050219250102ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020019250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010019250000010001d02e9ee1b14c022ad6895450f3375a8e9a87f214912d4332fa997996d2000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; + + clientMock = { + core: { + getBlockByHash: () => new Buffer.from(fixture, 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + + it('should work', async () => { + const res = await transport.getBlockHeaderByHash('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); + + expect(res.hash).to.equal('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); + expect(res.nonce).to.equal(53334); + expect(res.timestamp).to.equal(1582669078); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.js b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.js similarity index 81% rename from src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.js rename to src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.js index 88ba89d8..8be7557c 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.js +++ b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.js @@ -1,4 +1,4 @@ -const logger = require('../../../../logger'); +const logger = require('../../../logger'); module.exports = async function getBlockHeaderByHeight(blockHeight) { logger.silly(`DAPIClient.getBlockHeaderByHeight[${blockHeight}]`); diff --git a/src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.spec.js b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.spec.js new file mode 100644 index 00000000..80679fbc --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getBlockHeaderByHeight.spec.js @@ -0,0 +1,34 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + + +describe('transports - DAPIClientTransport .getBlockHeaderByHash', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '0000002008f7ac5b0e2df33ac233fef59549075ed24aa893ffc1d7b7067256da420000006670782820f19b64f011c55815c9315946573ac92bd5cce6deda684edcba1472c1904e5eae0d021e953d00000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050238180101ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020038180000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; + + clientMock = { + core: { + getBlockByHeight: () => new Buffer.from(fixture, 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getBlockHeaderByHeight(6200); + + expect(res.hash).to.equal('000000c33ad38337e9bf648842f3cc08b146739d561ce468bd373ee815595436'); + expect(res.nonce).to.equal(15765); + expect(res.timestamp).to.equal(1582207169); + }); +}); diff --git a/src/transport/DAPIClientTransport/methods/getIdentityIdByFirstPublicKey.js b/src/transport/DAPIClientTransport/methods/getIdentityIdByFirstPublicKey.js new file mode 100644 index 00000000..3bb8588d --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getIdentityIdByFirstPublicKey.js @@ -0,0 +1,7 @@ +const logger = require('../../../logger'); + +module.exports = async function getIdentityIdByFirstPublicKey(publicKeyHash) { + logger.silly('DAPIClientTransport.getIdentityIdByFirstPublicKey'); + + return this.client.platform.getIdentityIdByFirstPublicKey(publicKeyHash); +}; diff --git a/src/transport/DAPIClientTransport/methods/getStatus.js b/src/transport/DAPIClientTransport/methods/getStatus.js new file mode 100644 index 00000000..a28d0d24 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getStatus.js @@ -0,0 +1,6 @@ +const logger = require('../../../logger'); + +module.exports = async function getStatus() { + logger.silly('DAPIClientTransport.getStatus'); + return this.client.core.getStatus(); +}; diff --git a/src/transport/DAPIClientTransport/methods/getStatus.spec.js b/src/transport/DAPIClientTransport/methods/getStatus.spec.js new file mode 100644 index 00000000..fd43867d --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getStatus.spec.js @@ -0,0 +1,33 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getStatus', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = { + coreVersion: 150000, protocolVersion: 70216, blocks: 9495, timeOffset: 0, connections: 16, proxy: '', difficulty: 0.001447319555790497, testnet: false, relayFee: 0.00001, errors: '', network: 'testnet', + }; + + clientMock = { + core: { + getStatus: () => fixture, + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getStatus(); + + expect(res).to.deep.equal(fixture); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getTransaction.js b/src/transport/DAPIClientTransport/methods/getTransaction.js similarity index 62% rename from src/transporters/types/DAPIClientWrapper/methods/getTransaction.js rename to src/transport/DAPIClientTransport/methods/getTransaction.js index ca9e7093..65bcf495 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getTransaction.js +++ b/src/transport/DAPIClientTransport/methods/getTransaction.js @@ -1,9 +1,9 @@ const { Transaction } = require('@dashevo/dashcore-lib'); -const { is } = require('../../../../utils'); -const logger = require('../../../../logger'); +const { is } = require('../../../utils'); +const logger = require('../../../logger'); module.exports = async function getTransaction(txid) { logger.silly(`DAPIClient.getTransaction[${txid}]`); if (!is.txid(txid)) throw new Error(`Received an invalid txid to fetch : ${txid}`); - return new Transaction(await this.client.getTransaction(txid)); + return new Transaction(await this.client.core.getTransaction(txid)); }; diff --git a/src/transport/DAPIClientTransport/methods/getTransaction.spec.js b/src/transport/DAPIClientTransport/methods/getTransaction.spec.js new file mode 100644 index 00000000..208e8f52 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getTransaction.spec.js @@ -0,0 +1,31 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport .getTransaction', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = '03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff0502b924010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac00000000460200b9240000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; + + clientMock = { + core: { + getTransaction: () => new Buffer.from(fixture, 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getTransaction('2c0ee853b91b23d881f96f0128bbb5ebb90c9ef7e7bdb4eda360b0e5abf97239'); + + expect(res.hash).to.equal('2c0ee853b91b23d881f96f0128bbb5ebb90c9ef7e7bdb4eda360b0e5abf97239'); + }); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getUTXO.js b/src/transport/DAPIClientTransport/methods/getUTXO.js similarity index 88% rename from src/transporters/types/DAPIClientWrapper/methods/getUTXO.js rename to src/transport/DAPIClientTransport/methods/getUTXO.js index 18551946..40910504 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/getUTXO.js +++ b/src/transport/DAPIClientTransport/methods/getUTXO.js @@ -1,5 +1,5 @@ -const { is } = require('../../../../utils'); -const logger = require('../../../../logger'); +const { is } = require('../../../utils'); +const logger = require('../../../logger'); module.exports = async function getUTXO(address) { logger.silly(`DAPIClient.getUTXO[${address}]`); @@ -11,7 +11,7 @@ module.exports = async function getUTXO(address) { const fetchAndReturnUTXO = async (_from, _to) => { try { - const req = await this.client.getUTXO(address, _from, _to); + const req = await this.client.core.getUTXO(address, { from: _from, to: _to }); return { ...req, size: req.items.length }; } catch (e) { throw new Error(`Error fetching UTXO ${address}:{_from}:{_to} - ${e.message}`); diff --git a/src/transport/DAPIClientTransport/methods/getUTXO.spec.js b/src/transport/DAPIClientTransport/methods/getUTXO.spec.js new file mode 100644 index 00000000..1dd8b606 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/getUTXO.spec.js @@ -0,0 +1,45 @@ +const { expect } = require('chai'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .getUTXO', function suite() { + let fixture; + let transport; + let clientMock; + + beforeEach(() => { + fixture = { + totalItems: 1, + from: 0, + to: 1, + items: [ + { + address: 'yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN', + txid: '3ab6ebc86b9cdea1580d376510e54a904f74fcaf38dfe9363fb44bcf33f83703', + outputIndex: 0, + script: '76a914891da44c4bb40cbc32a186a99bb5f935ae92750288ac', + satoshis: 1000000000, + height: 9484, + }, + ], + } + + clientMock = { + core: { + getUTXO: () => fixture, + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => { + const res = await transport.getUTXO('yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN'); + + expect(res).to.deep.equal(fixture.items); + }); +}); diff --git a/src/transport/DAPIClientTransport/methods/sendTransaction.js b/src/transport/DAPIClientTransport/methods/sendTransaction.js new file mode 100644 index 00000000..b81da5d5 --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/sendTransaction.js @@ -0,0 +1,8 @@ +const { is } = require('../../../utils'); +const logger = require('../../../logger'); + +module.exports = async function sendTransaction(serializedTransaction) { + logger.silly('DAPIClientTransport.sendTransaction'); + if (!is.string(serializedTransaction)) throw new Error('Received an invalid rawtx'); + return this.client.core.broadcastTransaction(Buffer.from(serializedTransaction, 'hex')); +}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/subscribeToAddressesTransactions.js b/src/transport/DAPIClientTransport/methods/subscribeToAddressesTransactions.js similarity index 87% rename from src/transporters/types/DAPIClientWrapper/methods/subscribeToAddressesTransactions.js rename to src/transport/DAPIClientTransport/methods/subscribeToAddressesTransactions.js index 62a6a4ab..97d6e4a5 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/subscribeToAddressesTransactions.js +++ b/src/transport/DAPIClientTransport/methods/subscribeToAddressesTransactions.js @@ -1,5 +1,5 @@ -const EVENTS = require('../../../../EVENTS'); -const logger = require('../../../../logger'); +const EVENTS = require('../../../EVENTS'); +const logger = require('../../../logger'); // Artifact from previous optimisation made in SyncWorker plugin // Kept for reminder when Bloomfilters @@ -45,12 +45,12 @@ async function executor(forcedAddressList = null) { function startExecutor() { const self = this; - logger.silly('DAPIClientWrapper.subscribeToAddressesTransactions.startExecutor'); + logger.silly('DAPIClientTransport.subscribeToAddressesTransactions.startExecutor'); this.state.executors.addresses = setInterval(() => { try { executor.call(self); } catch (e) { - logger.error('DAPIClientWrapper.subscribeToAddressesTransactions.executor failed', e); + logger.error('DAPIClientTransport.subscribeToAddressesTransactions.executor failed', e); throw e; } }, fastFetchThreshold); @@ -75,7 +75,7 @@ module.exports = async function subscribeToAddressesTransactions(addressList) { try { startExecutor.call(this); } catch (e) { - logger.error('DAPIClientWrapper.subscribeToAddressesTransactions.startingExecutor failed', e); + logger.error('DAPIClientTransport.subscribeToAddressesTransactions.startingExecutor failed', e); throw e; } } diff --git a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.js b/src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.js similarity index 92% rename from src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.js rename to src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.js index 19742add..4fa4ffbb 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.js +++ b/src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.js @@ -1,4 +1,4 @@ -const EVENTS = require('../../../../EVENTS'); +const EVENTS = require('../../../EVENTS'); module.exports = async function subscribeToBlockHeaders() { const self = this; diff --git a/src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.spec.js b/src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.spec.js new file mode 100644 index 00000000..3263f17e --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/subscribeToBlockHeaders.spec.js @@ -0,0 +1,60 @@ +const { expect } = require('chai'); +const EVENTS = require('../../../EVENTS'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .subscribeToBlockHeaders', function suite() { + this.timeout(15000); + + let fixtures; + let transport; + let clientMock; + let getBestBlockHashCalled; + let blockHeaderAnnounced; + + beforeEach(() => { + fixtures = [ + ['00000120f4203130375fe8684b6b85415594c7a9374074026e59dbb46da42489', '00000020a586b835e3d642fb81f6624163e50ec381c7dcd11832e8cdbd670510a200000082bd70bf47542dbed1dacf9e5dc67f44c553a0bd5a1abdd5fc7198e8361b8f7cbdb2555ecaaf011ebcfe00000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024525010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020045250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010045250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ['000000b2832efed61899f1800542722bc9acb688937027824ff012ab0d3aca06', '000000208924a46db4db596e02744037a9c7945541856b4b68e85f37303120f42001000079500e16a28a2c049657174c5df6e409246abbae40d5ebe73b5e652a3f8128862bb4555ef0af011ec98200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024625010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020046250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010046250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ['000000cd464d3f00fea2c3e92a24d0edec1cc2a2579397bfcb9a7f6d994e7508', '0000002006ca3a0dab12f04f8227709388b6acc92b72420580f19918d6fe2e83b2000000ee66f18278bf8c4cc2ff47a8404e30ccd3372424fe1a63f3d236f602adb730eb92b4555e01b6011e032200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024725010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020047250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010047250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ] + + getBestBlockHashCalled = 0; + blockHeaderAnnounced = []; + + clientMock = { + core: { + getBestBlockHash: () => { + const blockHash = fixtures[getBestBlockHashCalled][0]; + + getBestBlockHashCalled += 1; + + return blockHash; + }, + getBlockByHash: (hash) => new Buffer.from(fixtures.find((el) => el[0] === hash)[1], 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => new Promise(async (resolve, reject) => { + transport.on(EVENTS.BLOCKHEADER, (ev) => { + expect(ev.type).to.equal(EVENTS.BLOCKHEADER); + blockHeaderAnnounced.push(ev.payload); + + if (getBestBlockHashCalled === 2) { + blockHeaderAnnounced.forEach((blockHeader, index) => { + expect(fixtures[index][1].startsWith(blockHeader.toString('hex'))).to.equal(true); + }); + resolve(); + } + }); + + await transport.subscribeToBlockHeaders(); + })); +}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.js b/src/transport/DAPIClientTransport/methods/subscribeToBlocks.js similarity index 92% rename from src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.js rename to src/transport/DAPIClientTransport/methods/subscribeToBlocks.js index 32108749..a906f457 100644 --- a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.js +++ b/src/transport/DAPIClientTransport/methods/subscribeToBlocks.js @@ -1,4 +1,4 @@ -const EVENTS = require('../../../../EVENTS'); +const EVENTS = require('../../../EVENTS'); module.exports = async function subscribeToBlocks() { const self = this; diff --git a/src/transport/DAPIClientTransport/methods/subscribeToBlocks.spec.js b/src/transport/DAPIClientTransport/methods/subscribeToBlocks.spec.js new file mode 100644 index 00000000..93f917fc --- /dev/null +++ b/src/transport/DAPIClientTransport/methods/subscribeToBlocks.spec.js @@ -0,0 +1,59 @@ +const { expect } = require('chai'); +const EVENTS = require('../../../EVENTS'); + +const DAPIClientTransport = require('../DAPIClientTransport'); + +describe('transports - DAPIClientTransport - .subscribeToBlocks', function suite() { + let fixtures; + let transport; + let clientMock; + let getBestBlockHashCalled; + let blockAnnounced; + + beforeEach(() => { + fixtures = [ + ['00000120f4203130375fe8684b6b85415594c7a9374074026e59dbb46da42489', '00000020a586b835e3d642fb81f6624163e50ec381c7dcd11832e8cdbd670510a200000082bd70bf47542dbed1dacf9e5dc67f44c553a0bd5a1abdd5fc7198e8361b8f7cbdb2555ecaaf011ebcfe00000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024525010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020045250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010045250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ['000000b2832efed61899f1800542722bc9acb688937027824ff012ab0d3aca06', '000000208924a46db4db596e02744037a9c7945541856b4b68e85f37303120f42001000079500e16a28a2c049657174c5df6e409246abbae40d5ebe73b5e652a3f8128862bb4555ef0af011ec98200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024625010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020046250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010046250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ['000000cd464d3f00fea2c3e92a24d0edec1cc2a2579397bfcb9a7f6d994e7508', '0000002006ca3a0dab12f04f8227709388b6acc92b72420580f19918d6fe2e83b2000000ee66f18278bf8c4cc2ff47a8404e30ccd3372424fe1a63f3d236f602adb730eb92b4555e01b6011e032200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024725010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020047250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010047250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], + ]; + + getBestBlockHashCalled = 0; + blockAnnounced = []; + + clientMock = { + core: { + getBestBlockHash: () => { + const blockHash = fixtures[getBestBlockHashCalled][0]; + + getBestBlockHashCalled += 1; + + return blockHash; + }, + + getBlockByHash: (hash) => new Buffer.from(fixtures.find((el) => el[0] === hash)[1], 'hex'), + } + } + + transport = new DAPIClientTransport(clientMock); + }) + + afterEach(() => { + transport.disconnect(); + }) + + it('should work', async () => new Promise(async (resolve, reject) => { + transport.on(EVENTS.BLOCK, (ev) => { + expect(ev.type).to.equal(EVENTS.BLOCK); + blockAnnounced.push(ev.payload); + + if (getBestBlockHashCalled === 2) { + blockAnnounced.forEach((block, index) => { + expect(fixtures[index + 1][1]).to.equal(block.toString('hex')); + }); + resolve(); + } + }); + + await transport.subscribeToBlocks(); + })); +}); diff --git a/src/transport/FixtureTransport/FixtureTransport.js b/src/transport/FixtureTransport/FixtureTransport.js new file mode 100644 index 00000000..fff15c8a --- /dev/null +++ b/src/transport/FixtureTransport/FixtureTransport.js @@ -0,0 +1,76 @@ +const blocksData = require('./data/blocks/blocks.js'); +const AbstractTransport = require('../AbstractTransport'); + +const bestBlockDataHeight = 21546; + +/** + * This is a saved snapshot of some selected blocks and transactions + * Meant to be used as replacement of DAPIClientTransport. + * Read more on the specificities on Readme.md and the things that are saved + * + */ +class FixtureTransport extends AbstractTransport { + constructor() { + super(); + + this.height = bestBlockDataHeight; + this.blockHash = blocksData.heights[this.height]; + + this.relayFee = 0.00001; + this.difficulty = 0.00171976818884149; + this.network = 'testnet'; + } + + setHeight(height) { + if (!height) throw new Error('Height needed'); + this.height = height; + + if (!blocksData.heights[this.height]) { + throw new Error(`Missing block ${this.height}`); + } + this.blockHash = blocksData.heights[this.height]; + } + + rewindBlock(step = 1) { + this.height -= step; + if (!blocksData.heights[this.height]) { + throw new Error(`Missing block ${this.height}`); + } + this.blockHash = blocksData.heights[this.height]; + } + + forwardBlock(step = 1) { + this.height += step; + if (!blocksData.heights[this.height]) { + throw new Error(`Missing block ${this.height}`); + } + this.blockHash = blocksData.heights[this.height]; + } + + // eslint-disable-next-line class-methods-use-this + getMnemonicList() { + return [ + 'nerve iron scrap chronic error wild glue sound range hurdle alter dwarf', + ]; + } +} + +// FixtureTransport.prototype.getAddressSummary = require('./methods/getAddressSummary'); +FixtureTransport.prototype.getBestBlock = require('./methods/getBestBlock'); +FixtureTransport.prototype.getBestBlockHash = require('./methods/getBestBlockHash'); +FixtureTransport.prototype.getBestBlockHeader = require('./methods/getBestBlockHeader'); +FixtureTransport.prototype.getBestBlockHeight = require('./methods/getBestBlockHeight'); +FixtureTransport.prototype.getBlockByHash = require('./methods/getBlockByHash'); +FixtureTransport.prototype.getBlockByHeight = require('./methods/getBlockByHeight'); +FixtureTransport.prototype.getBlockHeaderByHash = require('./methods/getBlockHeaderByHash'); +FixtureTransport.prototype.getBlockHeaderByHeight = require('./methods/getBlockHeaderByHeight'); +FixtureTransport.prototype.getStatus = require('./methods/getStatus'); +FixtureTransport.prototype.getAddressSummary = require('./methods/getAddressSummary'); +FixtureTransport.prototype.getTransaction = require('./methods/getTransaction'); +FixtureTransport.prototype.getUTXO = require('./methods/getUTXO'); +FixtureTransport.prototype.sendTransaction = require('./methods/sendTransaction'); +FixtureTransport.prototype.subscribeToAddressesTransactions = require('./methods/subscribeToAddressesTransactions'); +FixtureTransport.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders'); +FixtureTransport.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks'); + +module.exports = FixtureTransport; diff --git a/fixtures/FakeNet/README.md b/src/transport/FixtureTransport/README.md similarity index 100% rename from fixtures/FakeNet/README.md rename to src/transport/FixtureTransport/README.md diff --git a/fixtures/FakeNet/data/blocks/21539.json b/src/transport/FixtureTransport/data/blocks/21539.json similarity index 100% rename from fixtures/FakeNet/data/blocks/21539.json rename to src/transport/FixtureTransport/data/blocks/21539.json diff --git a/fixtures/FakeNet/data/blocks/21543.json b/src/transport/FixtureTransport/data/blocks/21543.json similarity index 100% rename from fixtures/FakeNet/data/blocks/21543.json rename to src/transport/FixtureTransport/data/blocks/21543.json diff --git a/fixtures/FakeNet/data/blocks/21546.json b/src/transport/FixtureTransport/data/blocks/21546.json similarity index 100% rename from fixtures/FakeNet/data/blocks/21546.json rename to src/transport/FixtureTransport/data/blocks/21546.json diff --git a/fixtures/FakeNet/data/blocks/21635.json b/src/transport/FixtureTransport/data/blocks/21635.json similarity index 100% rename from fixtures/FakeNet/data/blocks/21635.json rename to src/transport/FixtureTransport/data/blocks/21635.json diff --git a/fixtures/FakeNet/data/blocks/21638.json b/src/transport/FixtureTransport/data/blocks/21638.json similarity index 100% rename from fixtures/FakeNet/data/blocks/21638.json rename to src/transport/FixtureTransport/data/blocks/21638.json diff --git a/fixtures/FakeNet/data/blocks/3798.json b/src/transport/FixtureTransport/data/blocks/3798.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3798.json rename to src/transport/FixtureTransport/data/blocks/3798.json diff --git a/fixtures/FakeNet/data/blocks/3799.json b/src/transport/FixtureTransport/data/blocks/3799.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3799.json rename to src/transport/FixtureTransport/data/blocks/3799.json diff --git a/fixtures/FakeNet/data/blocks/3800.json b/src/transport/FixtureTransport/data/blocks/3800.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3800.json rename to src/transport/FixtureTransport/data/blocks/3800.json diff --git a/fixtures/FakeNet/data/blocks/3801.json b/src/transport/FixtureTransport/data/blocks/3801.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3801.json rename to src/transport/FixtureTransport/data/blocks/3801.json diff --git a/fixtures/FakeNet/data/blocks/3802.json b/src/transport/FixtureTransport/data/blocks/3802.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3802.json rename to src/transport/FixtureTransport/data/blocks/3802.json diff --git a/fixtures/FakeNet/data/blocks/3803.json b/src/transport/FixtureTransport/data/blocks/3803.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3803.json rename to src/transport/FixtureTransport/data/blocks/3803.json diff --git a/fixtures/FakeNet/data/blocks/3804.json b/src/transport/FixtureTransport/data/blocks/3804.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3804.json rename to src/transport/FixtureTransport/data/blocks/3804.json diff --git a/fixtures/FakeNet/data/blocks/3805.json b/src/transport/FixtureTransport/data/blocks/3805.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3805.json rename to src/transport/FixtureTransport/data/blocks/3805.json diff --git a/fixtures/FakeNet/data/blocks/3806.json b/src/transport/FixtureTransport/data/blocks/3806.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3806.json rename to src/transport/FixtureTransport/data/blocks/3806.json diff --git a/fixtures/FakeNet/data/blocks/3807.json b/src/transport/FixtureTransport/data/blocks/3807.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3807.json rename to src/transport/FixtureTransport/data/blocks/3807.json diff --git a/fixtures/FakeNet/data/blocks/3808.json b/src/transport/FixtureTransport/data/blocks/3808.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3808.json rename to src/transport/FixtureTransport/data/blocks/3808.json diff --git a/fixtures/FakeNet/data/blocks/3809.json b/src/transport/FixtureTransport/data/blocks/3809.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3809.json rename to src/transport/FixtureTransport/data/blocks/3809.json diff --git a/fixtures/FakeNet/data/blocks/3810.json b/src/transport/FixtureTransport/data/blocks/3810.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3810.json rename to src/transport/FixtureTransport/data/blocks/3810.json diff --git a/fixtures/FakeNet/data/blocks/3811.json b/src/transport/FixtureTransport/data/blocks/3811.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3811.json rename to src/transport/FixtureTransport/data/blocks/3811.json diff --git a/fixtures/FakeNet/data/blocks/3812.json b/src/transport/FixtureTransport/data/blocks/3812.json similarity index 100% rename from fixtures/FakeNet/data/blocks/3812.json rename to src/transport/FixtureTransport/data/blocks/3812.json diff --git a/fixtures/FakeNet/data/blocks/blocks.js b/src/transport/FixtureTransport/data/blocks/blocks.js similarity index 100% rename from fixtures/FakeNet/data/blocks/blocks.js rename to src/transport/FixtureTransport/data/blocks/blocks.js diff --git a/fixtures/FakeNet/data/transactions/05e8107d56c8c2635232f29967da1bcac709c34358a6f4e7bfb6840bc69da6b5.json b/src/transport/FixtureTransport/data/transactions/05e8107d56c8c2635232f29967da1bcac709c34358a6f4e7bfb6840bc69da6b5.json similarity index 100% rename from fixtures/FakeNet/data/transactions/05e8107d56c8c2635232f29967da1bcac709c34358a6f4e7bfb6840bc69da6b5.json rename to src/transport/FixtureTransport/data/transactions/05e8107d56c8c2635232f29967da1bcac709c34358a6f4e7bfb6840bc69da6b5.json diff --git a/fixtures/FakeNet/data/transactions/1039026788f80b4199cc685c5ba9335aac976e25b65a59c816108cbdb6234eb6.json b/src/transport/FixtureTransport/data/transactions/1039026788f80b4199cc685c5ba9335aac976e25b65a59c816108cbdb6234eb6.json similarity index 100% rename from fixtures/FakeNet/data/transactions/1039026788f80b4199cc685c5ba9335aac976e25b65a59c816108cbdb6234eb6.json rename to src/transport/FixtureTransport/data/transactions/1039026788f80b4199cc685c5ba9335aac976e25b65a59c816108cbdb6234eb6.json diff --git a/fixtures/FakeNet/data/transactions/2521faaf1006c41f0520be6ab3b2bdadf558a23124ba964c756dbdb0ffc177ef.json b/src/transport/FixtureTransport/data/transactions/2521faaf1006c41f0520be6ab3b2bdadf558a23124ba964c756dbdb0ffc177ef.json similarity index 100% rename from fixtures/FakeNet/data/transactions/2521faaf1006c41f0520be6ab3b2bdadf558a23124ba964c756dbdb0ffc177ef.json rename to src/transport/FixtureTransport/data/transactions/2521faaf1006c41f0520be6ab3b2bdadf558a23124ba964c756dbdb0ffc177ef.json diff --git a/fixtures/FakeNet/data/transactions/410d43dde088a5ea41956b96471a7ec317b7a8f7a9c69b07eed6326f42ff446a.json b/src/transport/FixtureTransport/data/transactions/410d43dde088a5ea41956b96471a7ec317b7a8f7a9c69b07eed6326f42ff446a.json similarity index 100% rename from fixtures/FakeNet/data/transactions/410d43dde088a5ea41956b96471a7ec317b7a8f7a9c69b07eed6326f42ff446a.json rename to src/transport/FixtureTransport/data/transactions/410d43dde088a5ea41956b96471a7ec317b7a8f7a9c69b07eed6326f42ff446a.json diff --git a/fixtures/FakeNet/data/transactions/4fe7485a000db585c5fe2864fc8686f0c0e9b6b3af01b800d8fc367400848998.json b/src/transport/FixtureTransport/data/transactions/4fe7485a000db585c5fe2864fc8686f0c0e9b6b3af01b800d8fc367400848998.json similarity index 100% rename from fixtures/FakeNet/data/transactions/4fe7485a000db585c5fe2864fc8686f0c0e9b6b3af01b800d8fc367400848998.json rename to src/transport/FixtureTransport/data/transactions/4fe7485a000db585c5fe2864fc8686f0c0e9b6b3af01b800d8fc367400848998.json diff --git a/fixtures/FakeNet/data/transactions/ebce1b53a190e930755b12db091aed4ec45b9f51f96cbbb82b8da720fec2d335.json b/src/transport/FixtureTransport/data/transactions/ebce1b53a190e930755b12db091aed4ec45b9f51f96cbbb82b8da720fec2d335.json similarity index 100% rename from fixtures/FakeNet/data/transactions/ebce1b53a190e930755b12db091aed4ec45b9f51f96cbbb82b8da720fec2d335.json rename to src/transport/FixtureTransport/data/transactions/ebce1b53a190e930755b12db091aed4ec45b9f51f96cbbb82b8da720fec2d335.json diff --git a/fixtures/FakeNet/data/utxos/yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22.json b/src/transport/FixtureTransport/data/utxos/yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22.json similarity index 100% rename from fixtures/FakeNet/data/utxos/yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22.json rename to src/transport/FixtureTransport/data/utxos/yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22.json diff --git a/fixtures/FakeNet/methods/getAddressSummary.js b/src/transport/FixtureTransport/methods/getAddressSummary.js similarity index 100% rename from fixtures/FakeNet/methods/getAddressSummary.js rename to src/transport/FixtureTransport/methods/getAddressSummary.js diff --git a/fixtures/FakeNet/methods/getBestBlock.js b/src/transport/FixtureTransport/methods/getBestBlock.js similarity index 76% rename from fixtures/FakeNet/methods/getBestBlock.js rename to src/transport/FixtureTransport/methods/getBestBlock.js index 4fc44820..f9525010 100644 --- a/fixtures/FakeNet/methods/getBestBlock.js +++ b/src/transport/FixtureTransport/methods/getBestBlock.js @@ -1,4 +1,4 @@ -const logger = require('../../../src/logger'); +const logger = require('../../../logger'); module.exports = async function getBestBlock() { logger.silly('FakeNet.getBestBlock'); diff --git a/fixtures/FakeNet/methods/getBestBlockHash.js b/src/transport/FixtureTransport/methods/getBestBlockHash.js similarity index 100% rename from fixtures/FakeNet/methods/getBestBlockHash.js rename to src/transport/FixtureTransport/methods/getBestBlockHash.js diff --git a/fixtures/FakeNet/methods/getBestBlockHeader.js b/src/transport/FixtureTransport/methods/getBestBlockHeader.js similarity index 78% rename from fixtures/FakeNet/methods/getBestBlockHeader.js rename to src/transport/FixtureTransport/methods/getBestBlockHeader.js index 764395e0..5b66ae8f 100644 --- a/fixtures/FakeNet/methods/getBestBlockHeader.js +++ b/src/transport/FixtureTransport/methods/getBestBlockHeader.js @@ -1,4 +1,4 @@ -const logger = require('../../../src/logger'); +const logger = require('../../../logger'); module.exports = async function getBestBlockHeader() { logger.silly('FakeNet.getBestBlockHeader'); diff --git a/fixtures/FakeNet/methods/getBestBlockHeight.js b/src/transport/FixtureTransport/methods/getBestBlockHeight.js similarity index 100% rename from fixtures/FakeNet/methods/getBestBlockHeight.js rename to src/transport/FixtureTransport/methods/getBestBlockHeight.js diff --git a/fixtures/FakeNet/methods/getBlockByHash.js b/src/transport/FixtureTransport/methods/getBlockByHash.js similarity index 74% rename from fixtures/FakeNet/methods/getBlockByHash.js rename to src/transport/FixtureTransport/methods/getBlockByHash.js index 7631425e..1865926f 100644 --- a/fixtures/FakeNet/methods/getBlockByHash.js +++ b/src/transport/FixtureTransport/methods/getBlockByHash.js @@ -4,6 +4,6 @@ const blocks = require('../data/blocks/blocks'); module.exports = async function getBlockByHash(hash) { const height = blocks.hashes[hash]; - const blockfile = JSON.parse(fs.readFileSync(`./fixtures/FakeNet/data/blocks/${height}.json`)); + const blockfile = JSON.parse(fs.readFileSync(`${__dirname}/../data/blocks/${height}.json`)); return new Block(Buffer.from(blockfile.block, 'hex')); }; diff --git a/fixtures/FakeNet/methods/getBlockByHeight.js b/src/transport/FixtureTransport/methods/getBlockByHeight.js similarity index 100% rename from fixtures/FakeNet/methods/getBlockByHeight.js rename to src/transport/FixtureTransport/methods/getBlockByHeight.js diff --git a/fixtures/FakeNet/methods/getBlockHeaderByHash.js b/src/transport/FixtureTransport/methods/getBlockHeaderByHash.js similarity index 100% rename from fixtures/FakeNet/methods/getBlockHeaderByHash.js rename to src/transport/FixtureTransport/methods/getBlockHeaderByHash.js diff --git a/fixtures/FakeNet/methods/getBlockHeaderByHeight.js b/src/transport/FixtureTransport/methods/getBlockHeaderByHeight.js similarity index 100% rename from fixtures/FakeNet/methods/getBlockHeaderByHeight.js rename to src/transport/FixtureTransport/methods/getBlockHeaderByHeight.js diff --git a/fixtures/FakeNet/methods/getStatus.js b/src/transport/FixtureTransport/methods/getStatus.js similarity index 100% rename from fixtures/FakeNet/methods/getStatus.js rename to src/transport/FixtureTransport/methods/getStatus.js diff --git a/fixtures/FakeNet/methods/getTransaction.js b/src/transport/FixtureTransport/methods/getTransaction.js similarity index 66% rename from fixtures/FakeNet/methods/getTransaction.js rename to src/transport/FixtureTransport/methods/getTransaction.js index a5cc55fa..531ff911 100644 --- a/fixtures/FakeNet/methods/getTransaction.js +++ b/src/transport/FixtureTransport/methods/getTransaction.js @@ -2,6 +2,6 @@ const { Transaction } = require('@dashevo/dashcore-lib'); const fs = require('fs'); module.exports = async function getTransaction(transactionHash) { - const txFile = JSON.parse(fs.readFileSync(`./fixtures/FakeNet/data/transactions/${transactionHash}.json`)); + const txFile = JSON.parse(fs.readFileSync(`${__dirname}/../data/transactions/${transactionHash}.json`)); return new Transaction(Buffer.from(txFile.transaction, 'hex')); }; diff --git a/fixtures/FakeNet/methods/getUTXO.js b/src/transport/FixtureTransport/methods/getUTXO.js similarity index 84% rename from fixtures/FakeNet/methods/getUTXO.js rename to src/transport/FixtureTransport/methods/getUTXO.js index 07fc1f28..e1fb3e93 100644 --- a/fixtures/FakeNet/methods/getUTXO.js +++ b/src/transport/FixtureTransport/methods/getUTXO.js @@ -1,10 +1,10 @@ const { Transaction } = require('@dashevo/dashcore-lib'); const fs = require('fs'); -const { is } = require('../../../src/utils'); +const { is } = require('../../../utils'); function getUtxoOfAddressAtHeight(address, height) { let utxos = []; - const path = `./fixtures/FakeNet/data/utxos/${address}.json`; + const path = `${__dirname}/../data/utxos/${address}.json`; if (!fs.existsSync(path)) { return utxos; } @@ -15,9 +15,7 @@ function getUtxoOfAddressAtHeight(address, height) { utxos = utxos.concat(el); } } - return utxos.map((utxo)=> { - return new Transaction.UnspentOutput(utxo) - });; + return utxos.map((utxo) => new Transaction.UnspentOutput(utxo)); } module.exports = async function getUTXO(addresses) { diff --git a/fixtures/FakeNet/methods/sendTransaction.js b/src/transport/FixtureTransport/methods/sendTransaction.js similarity index 100% rename from fixtures/FakeNet/methods/sendTransaction.js rename to src/transport/FixtureTransport/methods/sendTransaction.js diff --git a/fixtures/FakeNet/methods/subscribeToAddressesTransactions.js b/src/transport/FixtureTransport/methods/subscribeToAddressesTransactions.js similarity index 96% rename from fixtures/FakeNet/methods/subscribeToAddressesTransactions.js rename to src/transport/FixtureTransport/methods/subscribeToAddressesTransactions.js index 52c4c3da..f6630eb3 100644 --- a/fixtures/FakeNet/methods/subscribeToAddressesTransactions.js +++ b/src/transport/FixtureTransport/methods/subscribeToAddressesTransactions.js @@ -1,5 +1,5 @@ -const EVENTS = require('../../../src/EVENTS'); -const logger = require('../../../src/logger'); +const EVENTS = require('../../../EVENTS'); +const logger = require('../../../logger'); // Artifact from previous optimisation made in SyncWorker plugin // Kept for reminder when Bloomfilters diff --git a/fixtures/FakeNet/methods/subscribeToBlockHeaders.js b/src/transport/FixtureTransport/methods/subscribeToBlockHeaders.js similarity index 92% rename from fixtures/FakeNet/methods/subscribeToBlockHeaders.js rename to src/transport/FixtureTransport/methods/subscribeToBlockHeaders.js index c3857523..4fa4ffbb 100644 --- a/fixtures/FakeNet/methods/subscribeToBlockHeaders.js +++ b/src/transport/FixtureTransport/methods/subscribeToBlockHeaders.js @@ -1,4 +1,4 @@ -const EVENTS = require('../../../src/EVENTS'); +const EVENTS = require('../../../EVENTS'); module.exports = async function subscribeToBlockHeaders() { const self = this; diff --git a/fixtures/FakeNet/methods/subscribeToBlocks.js b/src/transport/FixtureTransport/methods/subscribeToBlocks.js similarity index 92% rename from fixtures/FakeNet/methods/subscribeToBlocks.js rename to src/transport/FixtureTransport/methods/subscribeToBlocks.js index d1ac8ba3..a906f457 100644 --- a/fixtures/FakeNet/methods/subscribeToBlocks.js +++ b/src/transport/FixtureTransport/methods/subscribeToBlocks.js @@ -1,4 +1,4 @@ -const EVENTS = require('../../../src/EVENTS'); +const EVENTS = require('../../../EVENTS'); module.exports = async function subscribeToBlocks() { const self = this; diff --git a/src/transport/Transport.d.ts b/src/transport/Transport.d.ts new file mode 100644 index 00000000..86cec1de --- /dev/null +++ b/src/transport/Transport.d.ts @@ -0,0 +1,41 @@ +import {Block, BlockHeader, Transaction} from "@dashevo/dashcore-lib"; + +export declare interface Transport { + announce(eventName, args) + + disconnect() + + getAddressSummary(address) + + getBestBlock(): Promise<Block> + + getBestBlockHash(): Promise<string> + + getBestBlockHeader(): Promise<BlockHeader> + + getBestBlockHeight(): Promise<number> + + getBlockByHash(hash): Promise<Block> + + getBlockByHeight(height): Promise<Block> + + getBlockHeaderByHash(hash): Promise<BlockHeader> + + getBlockHeaderByHeight(height): Promise<BlockHeader> + + getIdentityIdByFirstPublicKey(publicKeyHash): Promise<string> + + getStatus(): Promise<object> + + getTransaction(txid): Promise<Transaction> + + getUTXO(address): Promise<object> + + sendTransaction(serializedTransaction): Promise<string> + + subscribeToAddressesTransactions() + + subscribeToBlockHeaders() + + subscribeToBlocks() +} diff --git a/src/transport/createTransportFromOptions.js b/src/transport/createTransportFromOptions.js new file mode 100644 index 00000000..03f2e926 --- /dev/null +++ b/src/transport/createTransportFromOptions.js @@ -0,0 +1,23 @@ +const DAPIClient = require('@dashevo/dapi-client'); + +const _ = require('lodash'); + +const DAPIClientTransport = require('./DAPIClientTransport/DAPIClientTransport'); + +/** + * + * @param {DAPIClientOptions|Transport} options + * @returns {Transport} + */ +function createTransportFromOptions(options) { + if (!_.isPlainObject(options)) { + // Return transport instance + return options; + } + + const client = new DAPIClient(options); + + return new DAPIClientTransport(client); +} + +module.exports = createTransportFromOptions; diff --git a/src/transporters/index.js b/src/transporters/index.js deleted file mode 100644 index a3079ec2..00000000 --- a/src/transporters/index.js +++ /dev/null @@ -1,16 +0,0 @@ -const BaseTransporter = require('./types/BaseTransporter/BaseTransporter'); -const DAPIClientWrapper = require('./types/DAPIClientWrapper/DAPIClientWrapper'); -const RPCClient = require('./types/RPCClient/RPCClient'); -const ProtocolClient = require('./types/ProtocolClient/ProtocolClient'); - -const Transporters = { - BaseTransporter, - DAPIClientWrapper, - RPCClient, - ProtocolClient, -}; -Transporters.getByName = require('./methods/getByName'); -Transporters.resolve = require('./methods/resolve'); -Transporters.validate = require('./methods/validate'); - -module.exports = Transporters; diff --git a/src/transporters/methods/getByName.js b/src/transporters/methods/getByName.js deleted file mode 100644 index 5d37ef6f..00000000 --- a/src/transporters/methods/getByName.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function getByName(transporterName) { - let Transporter; - const name = transporterName.toString().toLowerCase(); - if (name.startsWith('dapi')) { - Transporter = this.DAPIClientWrapper; - } else if (name.startsWith('rpc')) { - Transporter = this.RPCClient; - } else if (name.startsWith('protocol')) { - Transporter = this.ProtocolClient; - } else if (name.startsWith('base')) { - Transporter = this.BaseTransporter; - } else if (!this[name]) { - throw new Error(`Not supported : Transport ${transporterName}`); - } - return Transporter; -}; diff --git a/src/transporters/methods/getByName.spec.js b/src/transporters/methods/getByName.spec.js deleted file mode 100644 index ec1e7097..00000000 --- a/src/transporters/methods/getByName.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../index'); - -describe('transporters',function suite() { - this.timeout(10000); - it('should warn on unfound Transporter class', () => { - const expectedException1 = 'Not supported : Transport StarlinkClient'; - expect(() => transporters.getByName('StarlinkClient')).to.throw(expectedException1); - }); - it('should get Transporter class by name', () => { - expect(transporters.getByName('dapi')).to.equal(transporters.DAPIClientWrapper); - expect(transporters.getByName('DAPI')).to.equal(transporters.DAPIClientWrapper); - expect(transporters.getByName('DAPIClient')).to.equal(transporters.DAPIClientWrapper); - expect(transporters.getByName('DAPIClientWrapper')).to.equal(transporters.DAPIClientWrapper); - }); -}); diff --git a/src/transporters/methods/resolve.js b/src/transporters/methods/resolve.js deleted file mode 100644 index b22a6db8..00000000 --- a/src/transporters/methods/resolve.js +++ /dev/null @@ -1,52 +0,0 @@ -const { is } = require('../../utils'); - - -const defaultTransporterType = 'DAPIClientWrapper'; -/** - * A number, or a string containing a number. - * @typedef {(DAPIClient|DAPIClientWrapper|RPCClient|ProtocolClient)} Transporter - */ - -/** - * Resolves a valid transporter. - * By default, return a DAPI transporter - * @param {string|object|function|Transporter} [props] - name of the transporter or options object - * @param {string} props.type - name of the transporter - * @return {object} - */ -module.exports = function resolve(props = { type: defaultTransporterType }) { - // Used to hold a transporter constructor - let Transporter; - - // If an instance is created, will be hold in order to be validated - let transporter; - if (!props) { - throw new Error('Unexpected null parameter'); - } - - const isConstructor = !!props.prototype; - // We passed a constructor that we expect being returned as instance so we init it. - if (isConstructor) { - Transporter = props; - transporter = new Transporter(); - } else { - const isObjectProps = props.constructor === Object; - // We allow to pass the name in props.type - if (isObjectProps) { - Transporter = this.getByName(props.type || defaultTransporterType); - transporter = new Transporter(props); - } else if (!is.string(props)) { - // Then it's simply an already initialized instance that we return; - transporter = props; - } else { - // At this point, props can only be string - Transporter = this.getByName(props); - transporter = new Transporter(props); - } - } - - // Validation is helpful to inform dev about missing needed key and for Account - // to know if it's should default on offlineMode and avoid trying use transport layer - transporter.isValid = this.validate(transporter); - return transporter; -}; diff --git a/src/transporters/methods/resolve.spec.js b/src/transporters/methods/resolve.spec.js deleted file mode 100644 index 9b2339b3..00000000 --- a/src/transporters/methods/resolve.spec.js +++ /dev/null @@ -1,117 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../index'); - -describe('transporters', function suite() { - this.timeout(10000); - it('should resolve dapi as default transporter', () => { - const defaultTransporter = transporters.resolve(); - expect(defaultTransporter).to.be.instanceOf(transporters.DAPIClientWrapper); - - const opts = { - seeds: [{ service: '18.236.131.253:3000' }], - } - const defaultTransporterWithOpts = transporters.resolve(opts); - expect(defaultTransporterWithOpts).to.be.instanceOf(transporters.DAPIClientWrapper); - - const seeds = defaultTransporterWithOpts.client.MNDiscovery - .masternodeListProvider.jsonRpcTransport - .mnDiscovery.mnList.map((seed) => { - delete seed.getIp; - return seed; - }); - - expect(seeds).to.be.deep.equal(opts.seeds); - }); - it('should resolve transporters from string', () => { - const opts = 'dapi'; - const dapiTransporter = transporters.resolve(opts); - expect(dapiTransporter).to.be.instanceOf(transporters.DAPIClientWrapper); - - const rpcTransporter = transporters.resolve('RPCClient'); - expect(rpcTransporter).to.be.instanceOf(transporters.RPCClient); - expect(rpcTransporter.ip).to.equal('127.0.0.1'); - }); - it('should resolve transporters from object', () => { - const optsRPC = { - type: 'RPC', - ip: '0.0.0.0', - }; - const rpcTransporter = transporters.resolve(optsRPC); - expect(rpcTransporter).to.be.instanceOf(transporters.RPCClient); - expect(rpcTransporter.ip).to.equal(optsRPC.ip); - - const optsDAPI = { - type: 'DAPIClient' , - }; - const dapiTransporter = transporters.resolve(optsDAPI); - expect(dapiTransporter).to.be.instanceOf(transporters.DAPIClientWrapper); - - const optsDAPIWithSeeds = { - type: 'DAPIClientWrapper', - seeds: [{ service: '18.236.131.253:3000' }], - }; - const dapiTransporterWithSeeds = transporters.resolve(optsDAPIWithSeeds); - expect(dapiTransporterWithSeeds).to.be.instanceOf(transporters.DAPIClientWrapper); - - let seeds = dapiTransporterWithSeeds.client.MNDiscovery - .masternodeListProvider.jsonRpcTransport - .mnDiscovery.mnList.map((seed) => { - delete seed.getIp; - return seed; - }); - - expect(seeds).to.be.deep.equal(optsDAPIWithSeeds.seeds); - - const optsDAPI2 = { type: 'dapi', seeds: [{ service: '18.236.131.254' }] }; - const dapiTransporter2 = transporters.resolve(optsDAPI2); - expect(dapiTransporter2).to.be.instanceOf(transporters.DAPIClientWrapper); - expect(dapiTransporter2.type).to.be.equal('DAPIClientWrapper'); - - seeds = dapiTransporter2.client.MNDiscovery - .masternodeListProvider.jsonRpcTransport - .mnDiscovery.mnList.map((seed) => { - delete seed.getIp; - return seed; - }); - - expect(seeds).to.be.deep.equal(optsDAPI2.seeds); - }); - it('should extend passed options', () => { - const options = { - type: 'DAPIClientWrapper', - seeds: [{ service: '123.4.5.6' }], - }; - - const transporter = transporters.resolve(options); - expect(transporter.type).to.be.equal('DAPIClientWrapper'); - - const seeds = transporter.client.MNDiscovery - .masternodeListProvider.jsonRpcTransport - .mnDiscovery.mnList.map((seed) => { - delete seed.getIp; - return seed; - }); - - expect(seeds).to.be.deep.equal(options.seeds); - }); - it('should resolves the transporter passed as a props', () => { - const opts = { - seeds: [{ service: '123.4.5.6' }], - timeout: 1000, - retries: 5, - network: 'testnet', - }; - const client = new transporters.DAPIClientWrapper(opts); - const transporter = transporters.resolve(client); - expect(transporter).to.deep.equal(client); - - const seeds = transporter.client.MNDiscovery - .masternodeListProvider.jsonRpcTransport - .mnDiscovery.mnList.map((seed) => { - delete seed.getIp; - return seed; - }); - - expect(seeds).to.be.deep.equal(opts.seeds); - }); -}); diff --git a/src/transporters/methods/validate.js b/src/transporters/methods/validate.js deleted file mode 100644 index 325c900b..00000000 --- a/src/transporters/methods/validate.js +++ /dev/null @@ -1,31 +0,0 @@ -const logger = require('../../logger'); - -module.exports = function validate(transporter, silent = false) { - const { BaseTransporter } = this; - let isValid = true; - const expectedKeys = [ - 'getAddressSummary', - 'getTransaction', - 'getUTXO', - 'sendTransaction', - 'getIdentityIdByFirstPublicKey', - ]; - - expectedKeys.forEach((key) => { - if (!transporter[key] && !(transporter.client && transporter.client[key])) { - isValid = false; - if (!silent) { - logger.error(`Invalid Transporter. Expected key :${key}`); - } - } - // BaseTransporter throw only errors (as a template), so if similar it's not implemented - // as we requires it, we warn and invalid the transporter - if (transporter[key] === BaseTransporter.prototype[key]) { - isValid = false; - if (!silent) { - logger.error(`Invalid Transporter. Implementation missing for key :${key}`); - } - } - }); - return isValid; -}; diff --git a/src/transporters/transporters.spec.js b/src/transporters/transporters.spec.js deleted file mode 100644 index 6a18b89b..00000000 --- a/src/transporters/transporters.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -const { expect } = require('chai'); -const DAPIClient = require('@dashevo/dapi-client'); -const transporters = require('./index'); - -const FakeInvalidTransporter = require('../../fixtures/transporters/FakeInvalidTransporter'); -const FakeValidTransporter = require('../../fixtures/transporters/FakeValidTransporter'); -describe('Transporter', function suite() { - this.timeout(10000); - it('should create a new transporter', () => { - const transporterDAPI = transporters.resolve('dapi'); - expect(transporterDAPI.isValid).to.equal(true); - const dapiClient = new DAPIClient(); - - const transporterDAPI2 = transporters.resolve(dapiClient); - expect(transporterDAPI2.isValid).to.equal(true); - - const transporterInvalidFake = transporters.resolve(FakeInvalidTransporter); - expect(transporterInvalidFake.isValid).to.equal(false); - - const transporterValidFake = transporters.resolve(FakeValidTransporter); - expect(transporterValidFake.isValid).to.equal(true); - }); - it('should handle invalid transporter', () => { - const expectedExpection = 'Not supported : Transport dummmyName'; - expect(()=>transporters.resolve('dummmyName')).to.throw(expectedExpection); - }); -}); diff --git a/src/transporters/types/BaseTransporter/BaseTransporter.js b/src/transporters/types/BaseTransporter/BaseTransporter.js deleted file mode 100644 index abb52626..00000000 --- a/src/transporters/types/BaseTransporter/BaseTransporter.js +++ /dev/null @@ -1,43 +0,0 @@ -const EventEmitter = require('events'); - -class BaseTransporter extends EventEmitter { - constructor(props) { - super(); - this.type = props.type; - this.state = { - block: null, - blockHeaders: null, - // Executors are Interval - executors: { - blocks: null, - blockHeaders: null, - addresses: null, - }, - addressesTransactionsMap: {}, - subscriptions: { - addresses: {}, - }, - }; - } -} -BaseTransporter.prototype.announce = require('./methods/announce'); -BaseTransporter.prototype.disconnect = require('./methods/disconnect'); -BaseTransporter.prototype.getAddressSummary = require('./methods/getAddressSummary'); -BaseTransporter.prototype.getBestBlock = require('./methods/getBestBlock'); -BaseTransporter.prototype.getBestBlockHeader = require('./methods/getBestBlockHeader'); -BaseTransporter.prototype.getBestBlockHash = require('./methods/getBestBlockHash'); -BaseTransporter.prototype.getBestBlockHeight = require('./methods/getBestBlockHeight'); -BaseTransporter.prototype.getBlockByHash = require('./methods/getBlockByHash'); -BaseTransporter.prototype.getBlockByHeight = require('./methods/getBlockByHeight'); -BaseTransporter.prototype.getBlockHeaderByHash = require('./methods/getBlockHeaderByHash'); -BaseTransporter.prototype.getBlockHeaderByHeight = require('./methods/getBlockHeaderByHeight'); -BaseTransporter.prototype.getStatus = require('./methods/getStatus'); -BaseTransporter.prototype.getTransaction = require('./methods/getTransaction'); -BaseTransporter.prototype.getUTXO = require('./methods/getUTXO'); -BaseTransporter.prototype.sendTransaction = require('./methods/sendTransaction'); -BaseTransporter.prototype.subscribeToAddressesTransactions = require('./methods/subscribeToAddressesTransactions'); -BaseTransporter.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders'); -BaseTransporter.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks'); -BaseTransporter.prototype.getIdentityIdByFirstPublicKey = require('./methods/getIdentityIdByFirstPublicKey'); - -module.exports = BaseTransporter; diff --git a/src/transporters/types/BaseTransporter/methods/announce.js b/src/transporters/types/BaseTransporter/methods/announce.js deleted file mode 100644 index 2729d12b..00000000 --- a/src/transporters/types/BaseTransporter/methods/announce.js +++ /dev/null @@ -1,18 +0,0 @@ -const EVENTS = require('../../../../EVENTS'); -const logger = require('../../../../logger'); - -module.exports = function announce(eventName, args) { - logger.silly(`Transporter.announce(${eventName})`); - switch (eventName) { - case EVENTS.BLOCKHEADER: - case EVENTS.BLOCK: - case EVENTS.TRANSACTION: - case EVENTS.FETCHED_TRANSACTION: - case EVENTS.FETCHED_ADDRESS: - this.emit(eventName, { type: eventName, payload: args }); - break; - default: - this.emit(eventName, { type: eventName, payload: args }); - logger.warn('Transporter - Not implemented, announce of ', eventName, args); - } -}; diff --git a/src/transporters/types/BaseTransporter/methods/disconnect.js b/src/transporters/types/BaseTransporter/methods/disconnect.js deleted file mode 100644 index fdfea029..00000000 --- a/src/transporters/types/BaseTransporter/methods/disconnect.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = function disconnect() { - clearInterval(this.state.subscriptions.blocks); - clearInterval(this.state.subscriptions.blockHeaders); - // eslint-disable-next-line guard-for-in,no-restricted-syntax - for (const addr in this.state.subscriptions.addresses) { - clearInterval(addr); - delete this.state.subscriptions.addresses[addr]; - } - return true; -}; diff --git a/src/transporters/types/BaseTransporter/methods/getAddressSummary.js b/src/transporters/types/BaseTransporter/methods/getAddressSummary.js deleted file mode 100644 index e58523ed..00000000 --- a/src/transporters/types/BaseTransporter/methods/getAddressSummary.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getAddressSummary(address) { - if (!is.address(address)) throw new Error('Received an invalid address ot fetch'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBestBlock.js b/src/transporters/types/BaseTransporter/methods/getBestBlock.js deleted file mode 100644 index 8379643a..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBestBlock.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function getBestBlock() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBestBlockHash.js b/src/transporters/types/BaseTransporter/methods/getBestBlockHash.js deleted file mode 100644 index afac3032..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBestBlockHash.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function getBestBlockByHash() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBestBlockHeader.js b/src/transporters/types/BaseTransporter/methods/getBestBlockHeader.js deleted file mode 100644 index d40d92ce..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBestBlockHeader.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function getBestBlockHeader() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBestBlockHeight.js b/src/transporters/types/BaseTransporter/methods/getBestBlockHeight.js deleted file mode 100644 index afac3032..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBestBlockHeight.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function getBestBlockByHash() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBlockByHash.js b/src/transporters/types/BaseTransporter/methods/getBlockByHash.js deleted file mode 100644 index b54a923d..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBlockByHash.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getBlockByHash(hash) { - if (!is.string(hash)) throw new Error('Received an invalid hash.'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBlockByHeight.js b/src/transporters/types/BaseTransporter/methods/getBlockByHeight.js deleted file mode 100644 index 738b043b..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBlockByHeight.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getBlockByHeight(height) { - if (!is.num(height)) throw new Error('Received an invalid height.'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHash.js b/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHash.js deleted file mode 100644 index b9e86f8e..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHash.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getBlockHeaderByHash(hash) { - if (!is.string(hash)) throw new Error('Received an invalid hash.'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHeight.js b/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHeight.js deleted file mode 100644 index a795a3d3..00000000 --- a/src/transporters/types/BaseTransporter/methods/getBlockHeaderByHeight.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getBlockHeaderByHeight(height) { - if (!is.num(height)) throw new Error('Received an invalid height.'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getIdentityIdByFirstPublicKey.js b/src/transporters/types/BaseTransporter/methods/getIdentityIdByFirstPublicKey.js deleted file mode 100644 index e7235398..00000000 --- a/src/transporters/types/BaseTransporter/methods/getIdentityIdByFirstPublicKey.js +++ /dev/null @@ -1,4 +0,0 @@ -// eslint-disable-next-line no-unused-vars -module.exports = async function getIdentityIdByFirstPublicKey(publicKeyHash) { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getStatus.js b/src/transporters/types/BaseTransporter/methods/getStatus.js deleted file mode 100644 index 041d294e..00000000 --- a/src/transporters/types/BaseTransporter/methods/getStatus.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function getStatus() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getTransaction.js b/src/transporters/types/BaseTransporter/methods/getTransaction.js deleted file mode 100644 index 5de547cf..00000000 --- a/src/transporters/types/BaseTransporter/methods/getTransaction.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getTransaction(txid) { - if (!is.txid(txid)) throw new Error(`Received an invalid txid to fetch : ${txid}`); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/getUTXO.js b/src/transporters/types/BaseTransporter/methods/getUTXO.js deleted file mode 100644 index c5ad4e0d..00000000 --- a/src/transporters/types/BaseTransporter/methods/getUTXO.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function getUTXO(address) { - if (!is.address(address)) throw new Error('Received an invalid address to fetch'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/sendTransaction.js b/src/transporters/types/BaseTransporter/methods/sendTransaction.js deleted file mode 100644 index 77b80f09..00000000 --- a/src/transporters/types/BaseTransporter/methods/sendTransaction.js +++ /dev/null @@ -1,6 +0,0 @@ -const { is } = require('../../../../utils'); - -module.exports = async function sendTransaction(serializedTransaction) { - if (!is.string(serializedTransaction)) throw new Error('Received an invalid rawtx'); - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/subscribeToAddressesTransactions.js b/src/transporters/types/BaseTransporter/methods/subscribeToAddressesTransactions.js deleted file mode 100644 index dfc9809a..00000000 --- a/src/transporters/types/BaseTransporter/methods/subscribeToAddressesTransactions.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function subscribeToAddressesTransactions() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/subscribeToBlockHeaders.js b/src/transporters/types/BaseTransporter/methods/subscribeToBlockHeaders.js deleted file mode 100644 index fd6a4d5e..00000000 --- a/src/transporters/types/BaseTransporter/methods/subscribeToBlockHeaders.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function subscribeToBlockHeaders() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/BaseTransporter/methods/subscribeToBlocks.js b/src/transporters/types/BaseTransporter/methods/subscribeToBlocks.js deleted file mode 100644 index 82015d16..00000000 --- a/src/transporters/types/BaseTransporter/methods/subscribeToBlocks.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = async function subscribeToBlocks() { - throw new Error('Not implemented'); -}; diff --git a/src/transporters/types/DAPIClientWrapper/DAPIClientWrapper.js b/src/transporters/types/DAPIClientWrapper/DAPIClientWrapper.js deleted file mode 100644 index 6a9fbfa6..00000000 --- a/src/transporters/types/DAPIClientWrapper/DAPIClientWrapper.js +++ /dev/null @@ -1,64 +0,0 @@ -const BaseTransporter = require('../BaseTransporter/BaseTransporter'); -const logger = require('../../../logger'); - -const defaultDAPIOpts = { - seeds: [ - { service: 'seed-1.evonet.networks.dash.org' }, - { service: 'seed-2.evonet.networks.dash.org' }, - { service: 'seed-3.evonet.networks.dash.org' }, - { service: 'seed-4.evonet.networks.dash.org' }, - { service: 'seed-5.evonet.networks.dash.org' }, - ], - timeout: 20000, - retries: 5, -}; - -/** - * Creates a new DAPIClientWrapper; holds a DAPIClient instance initialized with passed params - * @param [props=defaultDAPIOpts] - * @param {Array<Object>} [options.seeds] - If no seeds provided default seeds will be used. - * @param {number} [options.port] - default port for connection to the DAPI - * @param {number} [options.nativeGrpcPort] - Native GRPC port for connection to the DAPI - * @param {number} [options.timeout] - timeout for connection to the DAPI - * @param {number} [options.retries] - num of retries if there is no response from DAPI node - * @constructor - */ -class DAPIClientWrapper extends BaseTransporter { - constructor(props) { - super({ ...props, type: 'DAPIClientWrapper' }); - try { - // This allows to not have dapi-client shipped by default. - // eslint-disable-next-line global-require,import/no-extraneous-dependencies - const Client = require('@dashevo/dapi-client'); - this.client = new Client({ ...defaultDAPIOpts, ...props }); - } catch (err) { - if (!err.message || !err.message.includes("Cannot find module '@dashevo/dapi-client'")) { - throw err; - } - - logger.error("The '@dashevo/dapi-client' package is missing! Please install it with 'npm install @dashevo/dapi-client --save' command."); - } - } -} - -DAPIClientWrapper.prototype.disconnect = require('./methods/disconnect'); -DAPIClientWrapper.prototype.getAddressSummary = require('./methods/getAddressSummary'); -DAPIClientWrapper.prototype.getBestBlock = require('./methods/getBestBlock'); -DAPIClientWrapper.prototype.getBestBlockHeader = require('./methods/getBestBlockHeader'); -DAPIClientWrapper.prototype.getBestBlockHash = require('./methods/getBestBlockHash'); -DAPIClientWrapper.prototype.getBestBlockHeight = require('./methods/getBestBlockHeight'); -DAPIClientWrapper.prototype.getBlockHash = require('./methods/getBlockHash'); -DAPIClientWrapper.prototype.getBlockByHash = require('./methods/getBlockByHash'); -DAPIClientWrapper.prototype.getBlockByHeight = require('./methods/getBlockByHeight'); -DAPIClientWrapper.prototype.getBlockHeaderByHash = require('./methods/getBlockHeaderByHash'); -DAPIClientWrapper.prototype.getBlockHeaderByHeight = require('./methods/getBlockHeaderByHeight'); -DAPIClientWrapper.prototype.getStatus = require('./methods/getStatus'); -DAPIClientWrapper.prototype.getTransaction = require('./methods/getTransaction'); -DAPIClientWrapper.prototype.getUTXO = require('./methods/getUTXO'); -DAPIClientWrapper.prototype.sendTransaction = require('./methods/sendTransaction'); -DAPIClientWrapper.prototype.subscribeToAddressesTransactions = require('./methods/subscribeToAddressesTransactions'); -DAPIClientWrapper.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders'); -DAPIClientWrapper.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks'); -DAPIClientWrapper.prototype.getIdentityIdByFirstPublicKey = require('./methods/getIdentityIdByFirstPublicKey'); - -module.exports = DAPIClientWrapper; diff --git a/src/transporters/types/DAPIClientWrapper/methods/disconnect.js b/src/transporters/types/DAPIClientWrapper/methods/disconnect.js deleted file mode 100644 index cd7948f1..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/disconnect.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = async function disconnect() { - const { executors } = this.state; - clearInterval(executors.blocks); - clearInterval(executors.blockHeaders); - clearInterval(executors.addresses); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.spec.js deleted file mode 100644 index 886dd78a..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getAddressSummary.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = { - addrStr: 'yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN', - balance: 10, - balanceSat: 1000000000, - totalReceived: 10, - totalReceivedSat: 1000000000, - totalSent: 0, - totalSentSat: 0, - unconfirmedBalance: 0, - unconfirmedBalanceSat: 0, - unconfirmedTxApperances: 0, - unconfirmedAppearances: 0, - txApperances: 1, - txAppearances: 1, - transactions: [ - '3ab6ebc86b9cdea1580d376510e54a904f74fcaf38dfe9363fb44bcf33f83703', - ], -}; -describe('transporters - DAPIClientWrapper - .getAddressSummary', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getAddressSummary = () => fixture; - const res = await transporter.getAddressSummary('yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN'); - expect(res).to.deep.equal(fixture); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlock.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBestBlock.spec.js deleted file mode 100644 index 5497a7d9..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlock.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -const { expect } = require('chai'); -const { Block } = require('@dashevo/dashcore-lib'); -const transporters = require('../../../index'); - -const bestBlockHash = '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad'; -const block = { - header: { - hash: '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad', version: 536870912, prevHash: '000002243e872509388a6bd9c1c69c719bdcee2a780262f00c3cf75060f7adae', merkleRoot: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', time: 1585673611, bits: 503479478, nonce: 24664, - }, - transactions: [], -}; -describe('transporters - DAPIClientWrapper - .getBestBlock', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getBestBlockHash = () => bestBlockHash; - transporter.client.getBlockByHash = (hash) => { - if (hash === bestBlockHash) return block; - return null; - }; - const res = await transporter.getBestBlock(); - expect(res).to.deep.equal(new Block(block)); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.js b/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.js deleted file mode 100644 index 549b8415..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.js +++ /dev/null @@ -1,6 +0,0 @@ -const logger = require('../../../../logger'); - -module.exports = async function getBestBlockHash() { - logger.silly('DAPIClientWrapper.getBestBlockHash'); - return this.client.getBestBlockHash(); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.spec.js deleted file mode 100644 index 8b5da8e0..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHash.spec.js +++ /dev/null @@ -1,14 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'; -describe('transporters - DAPIClientWrapper - .getBestBlockHash', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getBestBlockHash = () => fixture; - const res = await transporter.getBestBlockHash(); - expect(res).to.deep.equal(fixture); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.spec.js deleted file mode 100644 index ee935883..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeader.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -const { expect } = require('chai'); -const { Block } = require('@dashevo/dashcore-lib'); -const transporters = require('../../../index'); - -const bestBlockHash = '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad'; -const block = { - header: { - hash: '0000004bb65f29621dddcb85eb0d4aa3921e856097813b00d7784514809968ad', version: 536870912, prevHash: '000002243e872509388a6bd9c1c69c719bdcee2a780262f00c3cf75060f7adae', merkleRoot: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', time: 1585673611, bits: 503479478, nonce: 24664, - }, - transactions: [{ - hash: '89724abcb2132645cffa8fdce002d9ced6d59e35231eaa0b3ddaf69f6c4e5c84', - version: 3, - inputs: [{ - prevTxId: '0000000000000000000000000000000000000000000000000000000000000000', outputIndex: 4294967295, sequenceNumber: 4294967295, script: '028c300109', - }], - outputs: [{ satoshis: 6885000000, script: '76a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac' }, { satoshis: 6885000000, script: '76a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac' }], - nLockTime: 0, - type: 5, - extraPayload: '02008c300000cead425668f38cfbb8dc028ad53d163fcee7282ede84d9a577ac6851a847ebc80000000000000000000000000000000000000000000000000000000000000000', - }], -}; -describe('transporters - DAPIClientWrapper - .getBestBlock', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getBestBlockHash = () => bestBlockHash; - transporter.client.getBlockByHash = (hash) => { - if (hash === bestBlockHash) return block; - return null; - }; - const res = await transporter.getBestBlockHeader(); - expect(res).to.deep.equal(new Block(block).header); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.spec.js deleted file mode 100644 index a910a8b0..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBestBlockHeight.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = { - coreVersion: 150000, protocolVersion: 70216, blocks: 9495, timeOffset: 0, connections: 16, proxy: '', difficulty: 0.001447319555790497, testnet: false, relayFee: 0.00001, errors: '', network: 'testnet', -}; -describe('transporters - DAPIClientWrapper - .getBestBlockHeight', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getStatus = () => fixture; - const res = await transporter.getBestBlockHeight(); - expect(res).to.deep.equal(9495); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.spec.js deleted file mode 100644 index f78bd9c3..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHash.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - - -const fixture = '00000020e2bddfb998d7be4cc4c6b126f04d6e4bd201687523ded527987431707e0200005520320b4e263bec33e08944656f7ce17efbc2c60caab7c8ed8a73d413d02d3a169d555ecdd6021e56d000000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050219250102ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020019250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010019250000010001d02e9ee1b14c022ad6895450f3375a8e9a87f214912d4332fa997996d2000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; -describe('transporters - DAPIClientWrapper - .getBlockByHash', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getBlockByHash = () => new Buffer.from(fixture, 'hex'); - const res = await transporter.getBlockByHash('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); - expect(res.hash).to.equal('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.spec.js deleted file mode 100644 index f9b37490..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockByHeight.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - - -const fixture = '0000002008f7ac5b0e2df33ac233fef59549075ed24aa893ffc1d7b7067256da420000006670782820f19b64f011c55815c9315946573ac92bd5cce6deda684edcba1472c1904e5eae0d021e953d00000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050238180101ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020038180000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; -describe('transporters - DAPIClientWrapper - .getBlockByHeight', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getBlockByHeight = () => new Buffer.from(fixture, 'hex'); - const res = await transporter.getBlockByHeight(6200); - expect(res.hash).to.equal('000000c33ad38337e9bf648842f3cc08b146739d561ce468bd373ee815595436'); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockHash.js b/src/transporters/types/DAPIClientWrapper/methods/getBlockHash.js deleted file mode 100644 index 885b50e8..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockHash.js +++ /dev/null @@ -1,6 +0,0 @@ -const logger = require('../../../../logger'); - -module.exports = async function getBlockHash(hash) { - logger.silly(`DAPIClient.getBlockHash[${hash}]`); - return this.client.getBlockHash(hash); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.spec.js deleted file mode 100644 index 91277285..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHash.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = '00000020e2bddfb998d7be4cc4c6b126f04d6e4bd201687523ded527987431707e0200005520320b4e263bec33e08944656f7ce17efbc2c60caab7c8ed8a73d413d02d3a169d555ecdd6021e56d000000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050219250102ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020019250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010019250000010001d02e9ee1b14c022ad6895450f3375a8e9a87f214912d4332fa997996d2000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; - -describe('transporters - DAPIClientWrapper .getBlockHeaderByHash', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('dapi'); - it('should works', async () => { - transporter.client.getBlockByHash = () => new Buffer.from(fixture, 'hex'); - const res = await transporter.getBlockHeaderByHash('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); - expect(res.hash).to.equal('0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9'); - expect(res.nonce).to.equal(53334); - expect(res.timestamp).to.equal(1582669078); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.spec.js deleted file mode 100644 index 2be53f5e..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getBlockHeaderByHeight.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = '0000002008f7ac5b0e2df33ac233fef59549075ed24aa893ffc1d7b7067256da420000006670782820f19b64f011c55815c9315946573ac92bd5cce6deda684edcba1472c1904e5eae0d021e953d00000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff050238180101ffffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020038180000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; - -describe('transporters - DAPIClientWrapper .getBlockHeaderByHash', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('dapi'); - it('should works', async () => { - transporter.client.getBlockByHeight = () => new Buffer.from(fixture, 'hex'); - const res = await transporter.getBlockHeaderByHeight(6200); - expect(res.hash).to.equal('000000c33ad38337e9bf648842f3cc08b146739d561ce468bd373ee815595436'); - expect(res.nonce).to.equal(15765); - expect(res.timestamp).to.equal(1582207169); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getIdentityIdByFirstPublicKey.js b/src/transporters/types/DAPIClientWrapper/methods/getIdentityIdByFirstPublicKey.js deleted file mode 100644 index 92ffd787..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getIdentityIdByFirstPublicKey.js +++ /dev/null @@ -1,7 +0,0 @@ -const logger = require('../../../../logger'); - -module.exports = async function getIdentityIdByFirstPublicKey(publicKeyHash) { - logger.silly('DAPIClientWrapper.getIdentityIdByFirstPublicKey'); - - return this.client.getIdentityIdByFirstPublicKey(publicKeyHash); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getStatus.js b/src/transporters/types/DAPIClientWrapper/methods/getStatus.js deleted file mode 100644 index e995a36d..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getStatus.js +++ /dev/null @@ -1,6 +0,0 @@ -const logger = require('../../../../logger'); - -module.exports = async function getStatus() { - logger.silly('DAPIClientWrapper.getStatus'); - return this.client.getStatus(); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/getStatus.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getStatus.spec.js deleted file mode 100644 index 773fe81e..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getStatus.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = { - coreVersion: 150000, protocolVersion: 70216, blocks: 9495, timeOffset: 0, connections: 16, proxy: '', difficulty: 0.001447319555790497, testnet: false, relayFee: 0.00001, errors: '', network: 'testnet', -}; - -describe('transporters - DAPIClientWrapper - .getStatus', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getStatus = () => fixture; - const res = await transporter.getStatus(); - expect(res).to.deep.equal(fixture); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getTransaction.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getTransaction.spec.js deleted file mode 100644 index fdfe5764..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getTransaction.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = '03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff0502b924010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac00000000460200b9240000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f80000000000000000000000000000000000000000000000000000000000000000'; - -describe('transporters - DAPIClientWrapper .getTransaction', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - - it('should works', async () => { - transporter.client.getTransaction = () => new Buffer.from(fixture, 'hex'); - const res = await transporter.getTransaction('2c0ee853b91b23d881f96f0128bbb5ebb90c9ef7e7bdb4eda360b0e5abf97239'); - expect(res.hash).to.equal('2c0ee853b91b23d881f96f0128bbb5ebb90c9ef7e7bdb4eda360b0e5abf97239'); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/getUTXO.spec.js b/src/transporters/types/DAPIClientWrapper/methods/getUTXO.spec.js deleted file mode 100644 index b652c029..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/getUTXO.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); - -const fixture = { - totalItems: 1, - from: 0, - to: 1, - items: [ - { - address: 'yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN', - txid: '3ab6ebc86b9cdea1580d376510e54a904f74fcaf38dfe9363fb44bcf33f83703', - outputIndex: 0, - script: '76a914891da44c4bb40cbc32a186a99bb5f935ae92750288ac', - satoshis: 1000000000, - height: 9484, - }, - ], -}; -describe('transporters - DAPIClientWrapper - .getUTXO', function suite() { - this.timeout(10000); - const transporter = transporters.resolve('DAPIClient'); - it('should works', async () => { - transporter.client.getUTXO = () => fixture; - const res = await transporter.getUTXO('yYpSw2n2TRzoQaUShNsPo541z4bz4EJkGN'); - expect(res).to.deep.equal(fixture.items); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/sendTransaction.js b/src/transporters/types/DAPIClientWrapper/methods/sendTransaction.js deleted file mode 100644 index e2d60d43..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/sendTransaction.js +++ /dev/null @@ -1,8 +0,0 @@ -const { is } = require('../../../../utils'); -const logger = require('../../../../logger'); - -module.exports = async function sendTransaction(serializedTransaction) { - logger.silly('DAPIClientWrapper.sendTransaction'); - if (!is.string(serializedTransaction)) throw new Error('Received an invalid rawtx'); - return this.client.sendTransaction(Buffer.from(serializedTransaction, 'hex')); -}; diff --git a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.spec.js b/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.spec.js deleted file mode 100644 index e726391f..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlockHeaders.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); -const EVENTS = require('../../../../EVENTS'); - - -const fixtures = [ - ['00000120f4203130375fe8684b6b85415594c7a9374074026e59dbb46da42489', '00000020a586b835e3d642fb81f6624163e50ec381c7dcd11832e8cdbd670510a200000082bd70bf47542dbed1dacf9e5dc67f44c553a0bd5a1abdd5fc7198e8361b8f7cbdb2555ecaaf011ebcfe00000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024525010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020045250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010045250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], - ['000000b2832efed61899f1800542722bc9acb688937027824ff012ab0d3aca06', '000000208924a46db4db596e02744037a9c7945541856b4b68e85f37303120f42001000079500e16a28a2c049657174c5df6e409246abbae40d5ebe73b5e652a3f8128862bb4555ef0af011ec98200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024625010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020046250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010046250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], - ['000000cd464d3f00fea2c3e92a24d0edec1cc2a2579397bfcb9a7f6d994e7508', '0000002006ca3a0dab12f04f8227709388b6acc92b72420580f19918d6fe2e83b2000000ee66f18278bf8c4cc2ff47a8404e30ccd3372424fe1a63f3d236f602adb730eb92b4555e01b6011e032200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024725010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020047250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010047250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], -]; - -describe('transporters - DAPIClientWrapper - .subscribeToBlockHeaders', function suite() { - this.timeout(21000); - const transporter = transporters.resolve({ type: 'DAPIClient' }); - it('should works', async () => new Promise(async (resolve, reject) => { - let getBestBlockHashCalled = 0; - const blockHeaderAnnounced = []; - transporter.client.getBestBlockHash = () => { - const blockHash = fixtures[getBestBlockHashCalled][0]; - getBestBlockHashCalled += 1; - return blockHash; - }; - transporter.client.getBlockByHash = (hash) => new Buffer.from(fixtures.find((el) => el[0] === hash)[1], 'hex'); - transporter.on(EVENTS.BLOCKHEADER, (ev) => { - expect(ev.type).to.equal(EVENTS.BLOCKHEADER); - blockHeaderAnnounced.push(ev.payload); - - if (getBestBlockHashCalled === 2) { - blockHeaderAnnounced.forEach((blockHeader, index) => { - expect(fixtures[index][1].startsWith(blockHeader.toString('hex'))).to.equal(true); - }); - resolve(); - } - }); - await transporter.subscribeToBlockHeaders(); - })); - after(() => { - transporter.disconnect(); - }); -}); diff --git a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.spec.js b/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.spec.js deleted file mode 100644 index 3d0c2d6c..00000000 --- a/src/transporters/types/DAPIClientWrapper/methods/subscribeToBlocks.spec.js +++ /dev/null @@ -1,43 +0,0 @@ -const { expect } = require('chai'); -const transporters = require('../../../index'); -const EVENTS = require('../../../../EVENTS'); - - -const fixtures = [ - ['00000120f4203130375fe8684b6b85415594c7a9374074026e59dbb46da42489', '00000020a586b835e3d642fb81f6624163e50ec381c7dcd11832e8cdbd670510a200000082bd70bf47542dbed1dacf9e5dc67f44c553a0bd5a1abdd5fc7198e8361b8f7cbdb2555ecaaf011ebcfe00000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024525010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020045250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010045250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], - ['000000b2832efed61899f1800542722bc9acb688937027824ff012ab0d3aca06', '000000208924a46db4db596e02744037a9c7945541856b4b68e85f37303120f42001000079500e16a28a2c049657174c5df6e409246abbae40d5ebe73b5e652a3f8128862bb4555ef0af011ec98200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024625010effffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020046250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010046250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], - ['000000cd464d3f00fea2c3e92a24d0edec1cc2a2579397bfcb9a7f6d994e7508', '0000002006ca3a0dab12f04f8227709388b6acc92b72420580f19918d6fe2e83b2000000ee66f18278bf8c4cc2ff47a8404e30ccd3372424fe1a63f3d236f602adb730eb92b4555e01b6011e032200000203000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024725010affffffff0240c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac40c3609a010000001976a914ecfd5aaebcbb8f4791e716e188b20d4f0183265c88ac0000000046020047250000476416132511031b71167f4bb7658eab5c3957d79636767f83e0e18e2b9ed7f8000000000000000000000000000000000000000000000000000000000000000003000600000000000000fd4901010047250000010001f7c884225958d983e935a77322a10a8f0acb2fde388762f0c5dabba19f000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'], -]; - -describe('transporters - DAPIClientWrapper - .subscribeToBlocks', function suite() { - this.timeout(21000); - let transporter; - before(() => { - transporter = transporters.resolve({ type: 'DAPIClient' }); - }); - it('should works', async () => new Promise(async (resolve, reject) => { - let getBestBlockHashCalled = 0; - const blockAnnounced = []; - transporter.client.getBestBlockHash = () => { - const blockHash = fixtures[getBestBlockHashCalled][0]; - getBestBlockHashCalled += 1; - return blockHash; - }; - transporter.client.getBlockByHash = (hash) => new Buffer.from(fixtures.find((el) => el[0] === hash)[1], 'hex'); - transporter.on(EVENTS.BLOCK, (ev) => { - expect(ev.type).to.equal(EVENTS.BLOCK); - blockAnnounced.push(ev.payload); - - if (getBestBlockHashCalled === 2) { - blockAnnounced.forEach((block, index) => { - expect(fixtures[index + 1][1]).to.equal(block.toString('hex')); - }); - resolve(); - } - }); - await transporter.subscribeToBlocks(); - })); - after(() => { - transporter.disconnect(); - }); -}); diff --git a/src/transporters/types/ProtocolClient/ProtocolClient.js b/src/transporters/types/ProtocolClient/ProtocolClient.js deleted file mode 100644 index db6f9aa0..00000000 --- a/src/transporters/types/ProtocolClient/ProtocolClient.js +++ /dev/null @@ -1,8 +0,0 @@ -const BaseTransporter = require('../BaseTransporter/BaseTransporter'); - -class ProtocolClient extends BaseTransporter { - constructor(props) { - super({ ...props, type: 'ProtocolClient' }); - } -} -module.exports = ProtocolClient; diff --git a/src/transporters/types/RPCClient/RPCClient.js b/src/transporters/types/RPCClient/RPCClient.js deleted file mode 100644 index 5b1b20d7..00000000 --- a/src/transporters/types/RPCClient/RPCClient.js +++ /dev/null @@ -1,9 +0,0 @@ -const BaseTransporter = require('../BaseTransporter/BaseTransporter'); - -class RPCClient extends BaseTransporter { - constructor(props) { - super({ ...props, type: 'RPCClient' }); - this.ip = (props && props.ip) || '127.0.0.1'; - } -} -module.exports = RPCClient; diff --git a/src/types/Account/Account.js b/src/types/Account/Account.js index 5a2cfe47..a407fbee 100644 --- a/src/types/Account/Account.js +++ b/src/types/Account/Account.js @@ -77,8 +77,8 @@ class Account extends EventEmitter { this.label = (opts && opts.label && is.string(opts.label)) ? opts.label : null; - // If transporter is null or invalid, we won't try to fetch anything - this.transporter = wallet.transporter; + // If transport is null or invalid, we won't try to fetch anything + this.transport = wallet.transport; this.store = wallet.storage.store; this.storage = wallet.storage; diff --git a/src/types/Account/methods/broadcastTransaction.js b/src/types/Account/methods/broadcastTransaction.js index fec73db1..fb312f65 100644 --- a/src/types/Account/methods/broadcastTransaction.js +++ b/src/types/Account/methods/broadcastTransaction.js @@ -39,7 +39,7 @@ function impactAffectedInputs({ inputs }) { * @return {Promise<*>} */ async function broadcastTransaction(transaction) { - if (!this.transporter.isValid) throw new ValidTransportLayerRequired('broadcast'); + if (!this.transport) throw new ValidTransportLayerRequired('broadcast'); // We still support having in rawtransaction, if this is the case // we first need to reform our object @@ -56,7 +56,7 @@ async function broadcastTransaction(transaction) { if (!transaction.isFullySigned()) { throw new Error('Transaction not signed.'); } - const txid = await this.transporter.sendTransaction(transaction.toString()); + const txid = await this.transport.sendTransaction(transaction.toString()); // We now need to impact/update our affected inputs // so we clear them out from UTXOset. const { inputs } = new Dashcore.Transaction(transaction).toObject(); diff --git a/src/types/Account/methods/broadcastTransaction.spec.js b/src/types/Account/methods/broadcastTransaction.spec.js index a6c29832..65fcf281 100644 --- a/src/types/Account/methods/broadcastTransaction.spec.js +++ b/src/types/Account/methods/broadcastTransaction.spec.js @@ -40,9 +40,7 @@ describe('Account - broadcastTransaction', function suite() { it('should throw error on missing transport', async () => { const expectedException1 = 'A transport layer is needed to perform a broadcast'; const self = { - transporter: { - isValid: false, - }, + transport: null, }; expectThrowsAsync(async () => await broadcastTransaction.call(self, validRawTxs.tx2to2Testnet), expectedException1); @@ -56,9 +54,7 @@ describe('Account - broadcastTransaction', function suite() { it('should throw error on invalid rawtx (string)', async () => { const expectedException1 = 'A valid transaction object or it\'s hex representation is required'; const self = { - transporter: { - isValid: true, - }, + transport: { }, }; expectThrowsAsync(async () => await broadcastTransaction.call(self, invalidRawTxs.notRelatedString), expectedException1); @@ -66,9 +62,7 @@ describe('Account - broadcastTransaction', function suite() { it('should throw error on invalid rawtx (hex)', async () => { const expectedException1 = 'A valid transaction object or it\'s hex representation is required'; const self = { - transporter: { - isValid: true, - }, + transport: { }, }; expectThrowsAsync(async () => await broadcastTransaction.call(self, invalidRawTxs.truncatedRawTx), expectedException1); @@ -77,8 +71,7 @@ describe('Account - broadcastTransaction', function suite() { let sendCalled = +1; let searchCalled = +1; const self = { - transporter: { - isValid: true, + transport: { sendTransaction: () => sendCalled = +1, }, storage: { @@ -98,8 +91,7 @@ describe('Account - broadcastTransaction', function suite() { let sendCalled = +1; let searchCalled = +1; const self = { - transporter: { - isValid: true, + transport: { sendTransaction: () => sendCalled = +1, }, storage: { diff --git a/src/types/Account/methods/connect.js b/src/types/Account/methods/connect.js index e41c5667..725a98d5 100644 --- a/src/types/Account/methods/connect.js +++ b/src/types/Account/methods/connect.js @@ -3,9 +3,10 @@ * @return {Boolean} */ module.exports = function connect() { - if (this.transporter.isValid) { - this.transporter.connect(); + if (this.transport && this.transport.connect) { + this.transport.connect(); } + if (this.plugins.workers) { const workersKey = Object.keys(this.plugins.workers); workersKey.forEach((key) => { diff --git a/src/types/Account/methods/connect.spec.js b/src/types/Account/methods/connect.spec.js index 9c822fd0..e9b1399f 100644 --- a/src/types/Account/methods/connect.spec.js +++ b/src/types/Account/methods/connect.spec.js @@ -10,8 +10,7 @@ describe('Account - connect', function suite() { it('should connect to transport and worker', () => { const self = { emit: (eventName) => emitted.push(eventName), - transporter: { - isValid: true, + transport: { connect: () => { transportConnected = true; }, }, plugins: { diff --git a/src/types/Account/methods/createTransaction.spec.js b/src/types/Account/methods/createTransaction.spec.js index e33b2632..a29b3094 100644 --- a/src/types/Account/methods/createTransaction.spec.js +++ b/src/types/Account/methods/createTransaction.spec.js @@ -4,7 +4,7 @@ const { HDPrivateKey } = require('@dashevo/dashcore-lib'); const createTransaction = require('./createTransaction'); const { mnemonic } = require('../../../../fixtures/wallets/mnemonics/during-develop-before'); -const FakeNet = require('../../../../fixtures/FakeNet/FakeNet'); +const FixtureTransport = require('../../../transport/FixtureTransport/FixtureTransport'); const getUTXOS = require('./getUTXOS'); const { simpleDescendingAccumulator } = require('../../../utils/coinSelections/strategies'); @@ -43,13 +43,15 @@ describe('Account - createTransaction', function suite() { it('should create valid and deterministic transactions', async function () { if(process.browser){ - // FakeNet relies heavily on fs.existSync and fs.readFile which are not available on browser - this.skip('FakeNet do not support browser environment due to FS intensive usage'); + // FixtureTransport relies heavily on fs.existSync and fs.readFile which are not available on browser + this.skip('FixtureTransport do not support browser environment due to FS intensive usage'); return; } - const transporter = new FakeNet(); - transporter.setHeight(21546); - const utxos = await transporter.getUTXO.call(transporter, ['yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22']); + const transport = new FixtureTransport(); + transport.setHeight(21546); + + const utxos = await transport.getUTXO.call(transport, ['yQ1fb64aeLfgqFKyeV9Hg9KTaTq5ehHm22']); + mockWallet = { getUTXOS: () => utxos, getUnusedAddress: () => { @@ -65,7 +67,7 @@ describe('Account - createTransaction', function suite() { }, storage: { searchTransaction: (txId) => { - const tx = transporter.getTransaction(txId); + const tx = transport.getTransaction(txId); if (tx) { return {found: true, result: tx, hash: txId} } else { @@ -122,8 +124,8 @@ describe('Account - createTransaction', function suite() { }); it('should be able to create transaction with specific strategy', async function () { if(process.browser){ - // FakeNet relies heavily on fs.existSync and fs.readFile which are not available on browser - this.skip('FakeNet do not support browser environment due to FS intensive usage'); + // FixtureTransport relies heavily on fs.existSync and fs.readFile which are not available on browser + this.skip('FixtureTransport do not support browser environment due to FS intensive usage'); return; } const expectedTxStd = '0300000001b64e23b6bd8c1016c8595ab6256e97ac5a33a95b5c68cc99410bf88867023910000000006a47304402200f8851bfcba02f1375c9d14cc1e4a1f442a6ba04dade5060124b6d245738eb1502206f2655f5e3714e9a1aa46de58124ec44d4da36884db0f1a39e6cad912ce009fc012103987110fc08c848657176385b37a77fb7f6d89bc873bb4334146ffe44ac126566ffffffff0250c30000000000001976a9140a6a961f1c664a9cd004c593381dd4d9f1f5463588acb9059a3b000000001976a9140a6a961f1c664a9cd004c593381dd4d9f1f5463588ac00000000'; diff --git a/src/types/Account/methods/disconnect.js b/src/types/Account/methods/disconnect.js index b780d99b..19543ff5 100644 --- a/src/types/Account/methods/disconnect.js +++ b/src/types/Account/methods/disconnect.js @@ -6,8 +6,8 @@ */ module.exports = async function disconnect() { this.isDisconnecting = true; - if (this.transporter && this.transporter.isValid && this.transporter.disconnect) { - await this.transporter.disconnect(); + if (this.transport && this.transport.disconnect) { + await this.transport.disconnect(); } if (this.plugins.workers) { diff --git a/src/types/Account/methods/disconnect.spec.js b/src/types/Account/methods/disconnect.spec.js index eed0bb52..8dd18b4f 100644 --- a/src/types/Account/methods/disconnect.spec.js +++ b/src/types/Account/methods/disconnect.spec.js @@ -17,8 +17,7 @@ describe('Account - disconnect', function suite() { saveState: () => null, stopWorker: () => null, }, - transporter: { - isValid: true, + transport: { connect: () => { transportConnected = true; }, disconnect: () => { transportConnected = false; }, }, diff --git a/src/types/Account/methods/fetchAddressInfo.js b/src/types/Account/methods/fetchAddressInfo.js index 1c955382..581bcac3 100644 --- a/src/types/Account/methods/fetchAddressInfo.js +++ b/src/types/Account/methods/fetchAddressInfo.js @@ -8,12 +8,13 @@ const { is } = require('../../../utils'); * @return {Promise<addrInfo>} */ async function fetchAddressInfo(addressObj, fetchUtxo = true) { - if (!this.transporter.isValid) throw new ValidTransportLayerRequired('fetchAddressInfo'); + if (!this.transport) throw new ValidTransportLayerRequired('fetchAddressInfo'); + const self = this; const { address, path, index } = addressObj; try { - const addrSum = await this.transporter.getAddressSummary(address); + const addrSum = await this.transport.getAddressSummary(address); if (!addrSum) return false; const { balanceSat, unconfirmedBalanceSat, transactions, @@ -51,7 +52,7 @@ async function fetchAddressInfo(addressObj, fetchUtxo = true) { } } if (fetchUtxo) { - const fetchedUtxo = await self.transporter.getUTXO(address); + const fetchedUtxo = await self.transport.getUTXO(address); if (fetchedUtxo.length) { const utxos = []; if (balanceSat > 0) { diff --git a/src/types/Account/methods/fetchStatus.js b/src/types/Account/methods/fetchStatus.js index 4098a833..23702da8 100644 --- a/src/types/Account/methods/fetchStatus.js +++ b/src/types/Account/methods/fetchStatus.js @@ -1,13 +1,13 @@ const { ValidTransportLayerRequired } = require('../../../errors'); async function fetchStatus() { - if (!this.transporter.isValid) throw new ValidTransportLayerRequired('fetchStatus'); + if (!this.transport) throw new ValidTransportLayerRequired('fetchStatus'); const status = { blocks: -1 }; try { - return await this.transporter.getStatus(); + return await this.transport.getStatus(); } catch (e) { - status.blocks = await this.transporter.getBestBlockHeight(); + status.blocks = await this.transport.getBestBlockHeight(); } return status; } diff --git a/src/types/Account/methods/getBlockHeader.js b/src/types/Account/methods/getBlockHeader.js index 309ab216..514eb17d 100644 --- a/src/types/Account/methods/getBlockHeader.js +++ b/src/types/Account/methods/getBlockHeader.js @@ -12,8 +12,8 @@ async function getBlockHeader(identifier) { } const blockHeight = (is.num(identifier)) ? identifier : null; const blockHeader = (is.num(identifier)) - ? await this.transporter.getBlockByHeight(blockHeight) - : await this.transporter.getBlockHeaderByHash(identifier); + ? await this.transport.getBlockByHeight(blockHeight) + : await this.transport.getBlockHeaderByHash(identifier); if (this.cacheBlockHeaders) { await this.storage.importBlockHeader(blockHeader, blockHeight); diff --git a/src/types/Account/methods/getIdentityHDKeyById.spec.js b/src/types/Account/methods/getIdentityHDKeyById.spec.js index f9828967..5361e9af 100644 --- a/src/types/Account/methods/getIdentityHDKeyById.spec.js +++ b/src/types/Account/methods/getIdentityHDKeyById.spec.js @@ -22,7 +22,7 @@ describe('Account#getIdentityHDKeyById', function suite() { walletId, index: 0, storage: storageMock, - transporter: { + transport: { getTransaction: () => fetchTransactionInfoCalledNb += 1, }, getIdentityHDKeyByIndex: (identityIndex) => { diff --git a/src/types/Account/methods/getIdentityIds.spec.js b/src/types/Account/methods/getIdentityIds.spec.js index d4c65e02..3b1f7704 100644 --- a/src/types/Account/methods/getIdentityIds.spec.js +++ b/src/types/Account/methods/getIdentityIds.spec.js @@ -20,7 +20,7 @@ describe('Account#getIdentityIds', function suite() { walletId, index: 0, storage: storageHDW, - transporter: { + transport: { getTransaction: () => fetchTransactionInfoCalledNb += 1, }, }; diff --git a/src/types/Account/methods/getTransaction.js b/src/types/Account/methods/getTransaction.js index 38b533e1..71b4cd52 100644 --- a/src/types/Account/methods/getTransaction.js +++ b/src/types/Account/methods/getTransaction.js @@ -8,7 +8,7 @@ async function getTransaction(txid = null) { if (search.found) { return search.result; } - const tx = await this.transporter.getTransaction(txid); + const tx = await this.transport.getTransaction(txid); if (this.cacheTx) { await this.storage.importTransactions(tx); if (this.cacheBlockHeaders) { diff --git a/src/types/Account/methods/getTransaction.spec.js b/src/types/Account/methods/getTransaction.spec.js index 945e9474..a5b1f2c0 100644 --- a/src/types/Account/methods/getTransaction.spec.js +++ b/src/types/Account/methods/getTransaction.spec.js @@ -20,7 +20,7 @@ describe('Account - getTransaction', function suite() { walletId, index: 0, storage: storageHDW, - transporter: { + transport: { getTransaction: () => fetchTransactionInfoCalledNb += 1, }, }; diff --git a/src/types/Storage/methods/startWorker.spec.js b/src/types/Storage/methods/startWorker.spec.js index 58955c85..0711f409 100644 --- a/src/types/Storage/methods/startWorker.spec.js +++ b/src/types/Storage/methods/startWorker.spec.js @@ -26,7 +26,7 @@ describe('Storage - startWorker', function suite() { expect(self.interval._repeat).to.be.equal(defaultIntervalValue); // Timeout are null btw clearInterval(self.interval); }); - it('should works', async () => new Promise((res) => { + it('should work', async () => new Promise((res) => { let saved = 0; const self = { saveState: () => { diff --git a/src/types/Wallet/Wallet.d.ts b/src/types/Wallet/Wallet.d.ts index da7b6e6b..dbcf555f 100644 --- a/src/types/Wallet/Wallet.d.ts +++ b/src/types/Wallet/Wallet.d.ts @@ -1,47 +1,70 @@ -import {Mnemonic, PrivateKey, HDPublicKey, Strategy, Network, Plugins, AddressInfoMap, WalletType} from "../types"; -import {Account} from "../Account/Account"; -import {MappedAddress} from "../Storage/Storage"; +import {HDPublicKey, Mnemonic, Network, Plugins, PrivateKey} from "../types"; +import {Account} from '../Account/Account'; import {HDPrivateKey} from "@dashevo/dashcore-lib"; export declare class Wallet { offlineMode: boolean; allowSensitiveOperations: boolean; injectDefaultPlugins: boolean; - plugins:[Plugins]; - passphrase?:string; + plugins: [Plugins]; + passphrase?: string; + constructor(options?: Wallet.Options); + createAccount(accOptions: Account.Options): Promise<Account>; + disconnect(): void; - exportWallet():Mnemonic["toString"]; - fromMnemonic(mnemonic: Mnemonic):void; - fromPrivateKey(privateKey: PrivateKey):void; - fromHDPrivateKey(privateKey: HDPrivateKey):void; - fromHDPublicKey(HDPublicKey:HDPublicKey):void; - fromSeed(seed:string):void; - generateNewWalletId():void; + + exportWallet(): Mnemonic["toString"]; + + fromMnemonic(mnemonic: Mnemonic): void; + + fromPrivateKey(privateKey: PrivateKey): void; + + fromHDPrivateKey(privateKey: HDPrivateKey): void; + + fromHDPublicKey(HDPublicKey: HDPublicKey): void; + + fromSeed(seed: string): void; + + generateNewWalletId(): void; + getAccount(accOptions?: Wallet.getAccOptions): Promise<Account>; - updateNetwork(network:Network):boolean; + updateNetwork(network: Network): boolean; } +declare interface DAPIClientOptions { + dapiAddressProvider?: any; + addresses?: Array<any | string>; + seeds?: Array<any | string>; + network?: string; + networkType?: string; + timeout?: number; + retries?: number; + baseBanTime?: number; +} + + export declare namespace Wallet { interface Options { debug?: boolean; offlineMode?: boolean; - transporter?: string|object|any; + transport?: DAPIClientOptions | Transport; network?: Network; plugins?: [Plugins]; passphrase?: string; injectDefaultPlugins?: boolean; - mnemonic?: Mnemonic|string|null; - seed?: Mnemonic|string; - privateKey?: PrivateKey|string; - HDPrivateKey?: HDPrivateKey|string; - HDPublicKey?: HDPublicKey|string; + mnemonic?: Mnemonic | string | null; + seed?: Mnemonic | string; + privateKey?: PrivateKey | string; + HDPrivateKey?: HDPrivateKey | string; + HDPublicKey?: HDPublicKey | string; } - interface getAccOptions extends Account.Options{ - index?:number; + + interface getAccOptions extends Account.Options { + index?: number; } } diff --git a/src/types/Wallet/Wallet.js b/src/types/Wallet/Wallet.js index f46962ed..36aa8546 100644 --- a/src/types/Wallet/Wallet.js +++ b/src/types/Wallet/Wallet.js @@ -1,17 +1,15 @@ -const Dashcore = require('@dashevo/dashcore-lib'); +const { PrivateKey, Networks } = require('@dashevo/dashcore-lib'); + const _ = require('lodash'); const Storage = require('../Storage/Storage'); const { generateNewMnemonic, - is, } = require('../../utils'); -const transporters = require('../../transporters'); - const defaultOptions = { debug: false, offlineMode: false, - network: 'testnet', + network: 'evonet', plugins: [], passphrase: null, injectDefaultPlugins: true, @@ -25,6 +23,8 @@ const fromHDPublicKey = require('./methods/fromHDPublicKey'); const fromHDPrivateKey = require('./methods/fromHDPrivateKey'); const generateNewWalletId = require('./methods/generateNewWalletId'); +const createTransportFromOptions = require('../../transport/createTransportFromOptions'); + /** * Instantiate a basic Wallet object, * A wallet is able to spawn up all preliminary steps toward the creation of a Account with @@ -53,19 +53,22 @@ class Wallet { generateNewWalletId, }); - const network = _.has(opts, 'network') ? opts.network.toString() : defaultOptions.network; - const passphrase = _.has(opts, 'passphrase') ? opts.passphrase : defaultOptions.passphrase; - this.passphrase = passphrase; + this.passphrase = _.has(opts, 'passphrase') ? opts.passphrase : defaultOptions.passphrase; this.offlineMode = _.has(opts, 'offlineMode') ? opts.offlineMode : defaultOptions.offlineMode; this.debug = _.has(opts, 'debug') ? opts.debug : defaultOptions.debug; this.allowSensitiveOperations = _.has(opts, 'allowSensitiveOperations') ? opts.allowSensitiveOperations : defaultOptions.allowSensitiveOperations; this.injectDefaultPlugins = _.has(opts, 'injectDefaultPlugins') ? opts.injectDefaultPlugins : defaultOptions.injectDefaultPlugins; - if (!(is.network(network))) throw new Error('Expected a valid network (typeof String)'); - if (!Dashcore.Networks[network]) { - throw new Error(`Un-handled network: ${network}`); + // Validate network + const networkName = _.has(opts, 'network') ? opts.network.toString() : defaultOptions.network; + const network = Networks.get(networkName); + + if (!network) { + throw new Error(`Invalid network: ${network}`); } - this.network = Dashcore.Networks[network].toString(); + + this.network = network.toString(); + if ('mnemonic' in opts) { this.fromMnemonic((opts.mnemonic === null) ? generateNewMnemonic() : opts.mnemonic); } else if ('seed' in opts) { @@ -74,7 +77,7 @@ class Wallet { this.fromHDPrivateKey(opts.HDPrivateKey); } else if ('privateKey' in opts) { this.fromPrivateKey((opts.privateKey === null) - ? new Dashcore.PrivateKey(network).toString() + ? new PrivateKey(network).toString() : opts.privateKey); } else if ('HDPublicKey' in opts) { this.fromHDPublicKey(opts.HDPublicKey); @@ -110,11 +113,23 @@ class Wallet { this.storage.importAddresses(opts.cache.addresses, this.walletId); } } - if (this.offlineMode) { - this.transporter = { isValid: false }; - } else { - this.transporter = transporters.resolve(opts.transporter); + + if (!this.offlineMode) { + if (opts.transport && opts.transport.network) { + throw new Error('Please use Wallet\'s "network" option'); + } + + if (!opts.transport) { + // eslint-disable-next-line no-param-reassign + opts.transport = {}; + } + + // eslint-disable-next-line no-param-reassign + opts.transport.network = this.network; + + this.transport = createTransportFromOptions(opts.transport); } + this.accounts = []; this.interface = opts.interface; this.savedBackup = false; // TODO: When true, we delete mnemonic from internals diff --git a/src/types/Wallet/methods/exportWallet.spec.js b/src/types/Wallet/methods/exportWallet.spec.js index 19c3a731..5e8a2c84 100644 --- a/src/types/Wallet/methods/exportWallet.spec.js +++ b/src/types/Wallet/methods/exportWallet.spec.js @@ -45,7 +45,7 @@ describe('Wallet - exportWallet - integration', function suite() { offlineMode: true, mnemonic: knifeMnemonic.mnemonic, }); - it('should works as expected', () => { + it('should work as expected', () => { const exceptedException = 'Tried to export to invalid output : seed'; expect(wallet.exportWallet()).to.equal(knifeMnemonic.mnemonic); expect(wallet.exportWallet('mnemonic')).to.equal(knifeMnemonic.mnemonic); @@ -61,7 +61,7 @@ describe('Wallet - exportWallet - integration', function suite() { offlineMode: true, seed: knifeMnemonic.seed, }); - it('should works as expected', () => { + it('should work as expected', () => { const exceptedException = "Wallet was not initiated with a mnemonic, can't export it."; const exceptedException2 = 'Tried to export to invalid output : seed'; @@ -79,7 +79,7 @@ describe('Wallet - exportWallet - integration', function suite() { offlineMode: true, HDPrivateKey: knifeMnemonic.HDRootPrivateKeyTestnet, }); - it('should works as expected', () => { + it('should work as expected', () => { const exceptedException = "Wallet was not initiated with a mnemonic, can't export it."; const exceptedException2 = 'Tried to export to invalid output : seed'; @@ -97,7 +97,7 @@ describe('Wallet - exportWallet - integration', function suite() { offlineMode: true, HDPublicKey: knifeMnemonic.HDRootPublicKeyMainnet, }); - it('should works as expected', () => { + it('should work as expected', () => { const exceptedException = 'Tried to export to invalid output : mnemonic'; const exceptedException2 = 'Tried to export to invalid output : seed'; const exceptedException3 = 'Tried to export to invalid output : HDPrivateKey'; diff --git a/src/types/Wallet/methods/sweepWallet.js b/src/types/Wallet/methods/sweepWallet.js index d09d7f27..697c1101 100644 --- a/src/types/Wallet/methods/sweepWallet.js +++ b/src/types/Wallet/methods/sweepWallet.js @@ -29,7 +29,7 @@ async function sweepWallet(opts = {}) { try { const walletOpts = { network: self.network, - transporter: self.transporter, + transport: self.transport, ...opts, }; newWallet = new self.constructor(walletOpts); diff --git a/src/types/Wallet/methods/sweepWallet.spec.js b/src/types/Wallet/methods/sweepWallet.spec.js index 36296d79..482a1397 100644 --- a/src/types/Wallet/methods/sweepWallet.spec.js +++ b/src/types/Wallet/methods/sweepWallet.spec.js @@ -1,4 +1,3 @@ -const { expect } = require('chai'); const { Wallet } = require('../../../index'); const expectThrowsAsync = require('../../../utils/expectThrowsAsync'); const sweepWallet = require('./sweepWallet'); @@ -12,19 +11,25 @@ describe('Wallet - sweepWallet', function suite() { this.timeout(60000); let emptyWallet; let emptyAccount; + before(async () => { emptyWallet = new Wallet({ privateKey: paperWallet.privateKey, - network: 'testnet', - transporter: { + transport: { seeds: process.env.DAPI_SEED - .split(',') - .map((seed) => ({ service: seed })), + .split(','), }, }); emptyAccount = await emptyWallet.getAccount(); }); + + after(async () => { + if (emptyWallet) { + await emptyWallet.disconnect(); + } + }); + it('should warn on empty balance', async () => { await emptyAccount.isReady(); const exceptedException = 'Cannot sweep an empty private key (current balance: 0)'; @@ -39,7 +44,4 @@ describe('Wallet - sweepWallet', function suite() { }; expectThrowsAsync(async () => await sweepWallet.call(mockWallet), exceptedException); }); - after(async () => { - await emptyWallet.disconnect(); - }); }); diff --git a/src/utils/outputHandler.spec.js b/src/utils/outputHandler.spec.js index 06f49d7d..a7e715cc 100644 --- a/src/utils/outputHandler.spec.js +++ b/src/utils/outputHandler.spec.js @@ -3,7 +3,7 @@ const outputHandler = require('./outputHandler'); describe('Utils - outputHandler', function suite() { this.timeout(10000); - it('should works', () => { + it('should work', () => { const outputs = [{ amount: 9.9999, address: 'yeuLv2E9FGF4D9o8vphsaC2Vxoa8ZA7Efp', diff --git a/tests/functional/wallet.js b/tests/functional/wallet.js index 866edf09..215bb128 100644 --- a/tests/functional/wallet.js +++ b/tests/functional/wallet.js @@ -21,7 +21,7 @@ function wait(ms) { * @return {Promise<string>} */ async function fundAddress(dapiClient, faucetAddress, faucetPrivateKey, address, amount) { - const { items: inputs } = await dapiClient.getUTXO(faucetAddress); + const { items: inputs } = await dapiClient.core.getUTXO(faucetAddress); const transaction = new Transaction(); @@ -38,15 +38,15 @@ async function fundAddress(dapiClient, faucetAddress, faucetPrivateKey, address, .fee(668) .sign(faucetPrivateKey); - let { blocks: currentBlockHeight } = await dapiClient.getStatus(); + let { blocks: currentBlockHeight } = await dapiClient.core.getStatus(); - const transactionId = await dapiClient.sendTransaction(transaction.toBuffer()); + const transactionId = await dapiClient.core.broadcastTransaction(transaction.toBuffer()); const desiredBlockHeight = currentBlockHeight + 1; do { // eslint-disable-next-line no-await-in-loop - ({ blocks: currentBlockHeight } = await dapiClient.getStatus()); + ({ blocks: currentBlockHeight } = await dapiClient.core.getStatus()); // eslint-disable-next-line no-await-in-loop await wait(30000); } while (currentBlockHeight < desiredBlockHeight); @@ -55,8 +55,7 @@ async function fundAddress(dapiClient, faucetAddress, faucetPrivateKey, address, } const seeds = process.env.DAPI_SEED - .split(',') - .map((seed) => ({ service: seed })); + .split(','); let newWallet; let wallet; @@ -68,7 +67,7 @@ describe('Wallet-lib - functional ', function suite() { describe('Create a new Wallet', () => { it('should create a new wallet with default params', () => { newWallet = new Wallet({ - transporter: { + transport: { seeds, }, network: process.env.NETWORK, @@ -92,7 +91,7 @@ describe('Wallet-lib - functional ', function suite() { it('should load a wallet from mnemonic', () => { wallet = new Wallet({ mnemonic: newWallet.mnemonic, - transporter: { + transport: { seeds, }, network: process.env.NETWORK, @@ -127,7 +126,7 @@ describe('Wallet-lib - functional ', function suite() { .toString(); await fundAddress( - wallet.transporter.client, + wallet.transport.client, faucetAddress, faucetPrivateKey, account.getAddress().address,