diff --git a/docker/mainnet/Dockerfile b/docker/mainnet/Dockerfile new file mode 100644 index 0000000..13f0b7e --- /dev/null +++ b/docker/mainnet/Dockerfile @@ -0,0 +1,24 @@ +FROM christroutner/ct-base-ubuntu +MAINTAINER Chris Troutner + +RUN apt-get update -y + +#Set the working directory to be the home directory +WORKDIR /home/safeuser + +# Switch to user account. +USER safeuser +# Prep 'sudo' commands. +#RUN echo 'abcd8765' | sudo -S pwd + +# Clone the Bitcore repository +WORKDIR /home/safeuser +RUN git clone https://github.com/christroutner/bch-api +WORKDIR /home/safeuser/bch-api +RUN npm install + + +EXPOSE 3000 + +COPY start-local-mainnet start-local-mainnet +CMD ["./start-local-mainnet"] diff --git a/docker/mainnet/docker-compose.yml b/docker/mainnet/docker-compose.yml new file mode 100644 index 0000000..c3dad5d --- /dev/null +++ b/docker/mainnet/docker-compose.yml @@ -0,0 +1,10 @@ +bch-api: + build: . + dockerfile: Dockerfile + #image: bitcore + container_name: bch-api-main + #links: + # - mongodb + ports: + - "12400:3000" + restart: always diff --git a/docker/mainnet/start-local-mainnet b/docker/mainnet/start-local-mainnet new file mode 100755 index 0000000..323e9ae --- /dev/null +++ b/docker/mainnet/start-local-mainnet @@ -0,0 +1,26 @@ +#!/bin/bash + +# Harddrive Mainnet full node +export RPC_BASEURL=http://172.17.0.1:8332/ +export RPC_USERNAME=bitcoin +export RPC_PASSWORD=password +export ZEROMQ_PORT=28332 +export ZEROMQ_URL=172.17.0.1 +export NETWORK=mainnet + +# Team DO QA Testnet Insight Server +export BITCOINCOM_BASEURL=http://172.17.0.1:12100/api/ + +# Testnet SLPDB +export SLPDB_URL=https://slpdb.bchdata.cash/ +#export SLPDB_URL=http://172.17.0.1:4000/ + +# Testnet Bitcore Node API +export BITCORE_URL=http://172.17.0.1:12200/ + +# Testnet Blockbook +export BLOCKBOOK_URL=https://172.17.0.1:9131/ +# Allow node.js to make network calls to https using self-signed certificate. +export NODE_TLS_REJECT_UNAUTHORIZED=0 + +npm start diff --git a/package-lock.json b/package-lock.json index 83d5865..68bd12a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -101,6 +101,164 @@ "to-fast-properties": "^2.0.0" } }, + "@chris.troutner/bch-js": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@chris.troutner/bch-js/-/bch-js-1.3.0.tgz", + "integrity": "sha512-Fv5d3JYLgH8DO45BYKEbyVu1WfTBSVAtYRHMLaH9hbFALewtl1TFvxY2EaNeNZU/0VUFSfRNUuVeRfv/s7FeVw==", + "requires": { + "assert": "^2.0.0", + "axios": "^0.19.0", + "bc-bip68": "^1.0.5", + "bch-wallet-bridge.js": "github:web3bch/bch-wallet-bridge.js#master", + "bigi": "^1.4.2", + "bip-schnorr": "^0.3.0", + "bip21": "github:Bitcoin-com/bip21", + "bip32-utils": "github:Bitcoin-com/bip32-utils#0.13.1", + "bip38": "^2.0.2", + "bip39": "^3.0.2", + "bip66": "^1.1.5", + "bitcoincash-ops": "github:christroutner/bitcoincash-ops", + "bitcoincashjs-lib": "github:christroutner/bitcoincashjs-lib", + "bitcoinjs-message": "^2.0.0", + "bs58": "^4.0.1", + "buffer": "^5.1.0", + "cashaddrjs": "^0.3.3", + "chalk": "^2.3.0", + "clear": "0.1.0", + "coininfo": "github:Bitcoin-com/coininfo", + "commander": "^2.13.0", + "cp-file": "^7.0.0", + "ecurve": "^1.0.6", + "figlet": "^1.2.0", + "git-clone": "^0.1.0", + "ini": "^1.3.5", + "mkdirp": "^0.5.1", + "node-cmd": "^3.0.0", + "node-emoji": "^1.8.1", + "qrcode": "^1.2.0", + "randombytes": "^2.0.6", + "repl.history": "^0.1.4", + "safe-buffer": "^5.1.2", + "satoshi-bitcoin": "^1.0.4", + "socket.io": "^2.1.1", + "socket.io-client": "^2.1.1", + "touch": "^3.1.0", + "wif": "^2.0.6" + }, + "dependencies": { + "@types/node": { + "version": "11.11.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", + "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==" + }, + "assert": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz", + "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==", + "requires": { + "es6-object-assign": "^1.1.0", + "is-nan": "^1.2.1", + "object-is": "^1.0.1", + "util": "^0.12.0" + } + }, + "big-integer": { + "version": "1.6.36", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.36.tgz", + "integrity": "sha512-t70bfa7HYEA1D9idDbmuv7YbsbVkQ+Hp+8KFSul4aE5e/i1bjCNIRYJZlA8Q8p0r9T8cF/RVvwUgRA//FydEyg==" + }, + "bip39": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/bip39/-/bip39-3.0.2.tgz", + "integrity": "sha512-J4E1r2N0tUylTKt07ibXvhpT2c5pyAFgvuA5q1H9uDy6dEGpjV8jmymh3MTYJDLCNbIVClSB9FbND49I6N24MQ==", + "requires": { + "@types/node": "11.11.6", + "create-hash": "^1.1.0", + "pbkdf2": "^3.0.9", + "randombytes": "^2.0.1" + } + }, + "bitcoincash-ops": { + "version": "github:christroutner/bitcoincash-ops#6ab82cc7326c67236f3b2d9d0457258ac2ef48e3", + "from": "github:christroutner/bitcoincash-ops" + }, + "bitcoincashjs-lib": { + "version": "github:christroutner/bitcoincashjs-lib#0a2291b5c5558241003aa9609f82846313604f15", + "from": "github:christroutner/bitcoincashjs-lib", + "requires": { + "bech32": "^1.1.2", + "bigi": "^1.4.0", + "bip66": "^1.1.0", + "bitcoincash-ops": "github:christroutner/bitcoincash-ops", + "bs58check": "^2.0.0", + "create-hash": "^1.1.0", + "create-hmac": "^1.1.3", + "ecurve": "^1.0.0", + "merkle-lib": "^2.0.10", + "pushdata-bitcoin": "github:Bitcoin-com/pushdata-bitcoin#1.2.1", + "randombytes": "^2.0.1", + "safe-buffer": "^5.0.1", + "typeforce": "^1.18.0", + "varuint-bitcoin": "^1.0.4", + "wif": "^2.0.1" + } + }, + "cashaddrjs": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/cashaddrjs/-/cashaddrjs-0.3.5.tgz", + "integrity": "sha512-bRLNkj+1UM7Lh2hQ1ffE4A+j9916WckhtDHP7ykxbNnHc6K8jJ4KfrIKZ+FLSia9QSZtm6cTW9B9ZGGpqbMkGA==", + "requires": { + "big-integer": "1.6.36" + } + }, + "clear": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/clear/-/clear-0.1.0.tgz", + "integrity": "sha512-qMjRnoL+JDPJHeLePZJuao6+8orzHMGP04A8CdwCNsKhRbOnKRjefxONR7bwILT3MHecxKBjHkKL/tkZ8r4Uzw==" + }, + "cp-file": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/cp-file/-/cp-file-7.0.0.tgz", + "integrity": "sha512-0Cbj7gyvFVApzpK/uhCtQ/9kE9UnYpxMzaq5nQQC/Dh4iaj5fxp7iEFIullrYwzj8nf0qnsI1Qsx34hAeAebvw==", + "requires": { + "graceful-fs": "^4.1.2", + "make-dir": "^3.0.0", + "nested-error-stacks": "^2.0.0", + "p-event": "^4.1.0" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "make-dir": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.0.tgz", + "integrity": "sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw==", + "requires": { + "semver": "^6.0.0" + } + }, + "semver": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.2.0.tgz", + "integrity": "sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A==" + }, + "util": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.1.tgz", + "integrity": "sha512-MREAtYOp+GTt9/+kwf00IYoHZyjM8VU4aVrkzUlejyqaIjd2GztVl5V9hGXKlvBKE3gENn/FMfHE5v6hElXGcQ==", + "requires": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "object.entries": "^1.1.0", + "safe-buffer": "^5.1.2" + } + } + } + }, "@chris.troutner/bitbox-js": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@chris.troutner/bitbox-js/-/bitbox-js-7.0.2.tgz", @@ -3783,6 +3941,11 @@ "event-emitter": "~0.3.5" } }, + "es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=" + }, "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", @@ -6586,6 +6749,11 @@ } } }, + "is-arguments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==" + }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -6693,6 +6861,11 @@ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" }, + "is-generator-function": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz", + "integrity": "sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw==" + }, "is-glob": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", @@ -6711,6 +6884,14 @@ "is-path-inside": "^1.0.0" } }, + "is-nan": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.2.1.tgz", + "integrity": "sha1-n69ltvttskt/XAYoR16nH5iEAeI=", + "requires": { + "define-properties": "^1.1.1" + } + }, "is-negated-glob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-negated-glob/-/is-negated-glob-1.0.0.tgz", @@ -12336,6 +12517,11 @@ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==" }, + "object-is": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.0.1.tgz", + "integrity": "sha1-CqYOyZiaCz7Xlc9NBvYs8a1lObY=" + }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -12361,6 +12547,17 @@ "object-keys": "^1.0.11" } }, + "object.entries": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.0.tgz", + "integrity": "sha512-l+H6EQ8qzGRxbkHOd5I/aHRhHDKoQXQ8g0BYt4uSweQU1/J6dZUOyWh9a2Vky35YCKjzmgxOzta2hH6kf9HuXA==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.12.0", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, "object.getownpropertydescriptors": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", @@ -12508,6 +12705,14 @@ "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" }, + "p-event": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-event/-/p-event-4.1.0.tgz", + "integrity": "sha512-4vAd06GCsgflX4wHN1JqrMzBh/8QZ4j+rzp0cd2scXRwuBEv+QR3wrVA5aLhWDLw4y2WgDKvzWF3CCLmVM1UgA==", + "requires": { + "p-timeout": "^2.0.1" + } + }, "p-filter": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-filter/-/p-filter-2.1.0.tgz", @@ -12565,6 +12770,14 @@ "retry": "^0.12.0" } }, + "p-timeout": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz", + "integrity": "sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==", + "requires": { + "p-finally": "^1.0.0" + } + }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", diff --git a/package.json b/package.json index 0eec961..8a4596f 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "node": ">=10.15.1" }, "dependencies": { + "@chris.troutner/bch-js": "^1.3.0", "@chris.troutner/bitbox-js": "^7.0.2", "apidoc": "^0.17.7", "axios": "^0.19.0", diff --git a/src/routes/v3/bitcore.js b/src/routes/v3/bitcore.js index 49eaa6c..79475ff 100644 --- a/src/routes/v3/bitcore.js +++ b/src/routes/v3/bitcore.js @@ -16,8 +16,8 @@ const router = express.Router() const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() //const BITCORE_URL = process.env.BITCORE_URL @@ -40,7 +40,7 @@ async function balanceFromBitcore(thisAddress) { //console.log(`BITCORE_URL: ${BITCORE_URL}`) // Convert the address to a cashaddr without a prefix. - const addr = BITBOX.Address.toCashAddress(thisAddress, false) + const addr = bchjs.Address.toCashAddress(thisAddress, false) // Determine if we are working with the testnet or mainnet networks. let network = "mainnet" @@ -48,7 +48,7 @@ async function balanceFromBitcore(thisAddress) { const path = `${process.env.BITCORE_URL}api/BCH/${network}/address/${addr}/balance` - console.log(`path: ${path}`) + //console.log(`path: ${path}`) // Query the Bitcore Node API. const axiosResponse = await axios.get(path) @@ -98,7 +98,7 @@ async function balanceSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - const legacyAddr = BITBOX.Address.toLegacyAddress(address) + const legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -172,7 +172,7 @@ async function balanceBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ @@ -224,7 +224,7 @@ async function utxosFromBitcore(thisAddress) { //console.log(`BITCORE_URL: ${BITCORE_URL}`) // Convert the address to a cashaddr without a prefix. - const addr = BITBOX.Address.toCashAddress(thisAddress, false) + const addr = bchjs.Address.toCashAddress(thisAddress, false) // Determine if we are working with the testnet or mainnet networks. let network = "mainnet" @@ -267,7 +267,7 @@ async function utxosSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - const legacyAddr = BITBOX.Address.toLegacyAddress(address) + const legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -339,7 +339,7 @@ async function utxosBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ diff --git a/src/routes/v3/blockbook.js b/src/routes/v3/blockbook.js index 1858f96..4369cfa 100644 --- a/src/routes/v3/blockbook.js +++ b/src/routes/v3/blockbook.js @@ -16,8 +16,8 @@ const router = express.Router() const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() //const BLOCKBOOK_URL = process.env.BLOCKBOOK_URL @@ -40,7 +40,7 @@ async function balanceFromBlockbook(thisAddress) { //console.log(`BLOCKBOOK_URL: ${BLOCKBOOK_URL}`) // Convert the address to a cashaddr without a prefix. - const addr = BITBOX.Address.toCashAddress(thisAddress) + const addr = bchjs.Address.toCashAddress(thisAddress) const path = `${process.env.BLOCKBOOK_URL}api/v2/address/${addr}` @@ -82,7 +82,7 @@ async function balanceSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - const legacyAddr = BITBOX.Address.toLegacyAddress(address) + const legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -154,7 +154,7 @@ async function balanceBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ @@ -207,7 +207,7 @@ async function utxosFromBlockbook(thisAddress) { //console.log(`BLOCKBOOK_URL: ${BLOCKBOOK_URL}`) // Convert the address to a cashaddr without a prefix. - const addr = BITBOX.Address.toCashAddress(thisAddress) + const addr = bchjs.Address.toCashAddress(thisAddress) const path = `${process.env.BLOCKBOOK_URL}api/v2/utxo/${addr}` @@ -249,7 +249,7 @@ async function utxosSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - const legacyAddr = BITBOX.Address.toLegacyAddress(address) + const legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -321,7 +321,7 @@ async function utxosBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ diff --git a/src/routes/v3/insight/address.js b/src/routes/v3/insight/address.js index 1fd655b..5b2088b 100644 --- a/src/routes/v3/insight/address.js +++ b/src/routes/v3/insight/address.js @@ -17,8 +17,8 @@ const router = express.Router() const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() // Use the default (and max) page size of 1000 // https://github.com/bitpay/insight-api#notes-on-upgrading-from-v03 @@ -45,16 +45,8 @@ function root(req, res, next) { // Returns a Promise. async function detailsFromInsight(thisAddress, currentPage = 0) { try { - /* - let addr - - if ( - process.env.BITCOINCOM_BASEURL === "https://bch-insight.bitpay.com/api/" - ) - addr = BITBOX.Address.toCashAddress(thisAddress) - else addr = BITBOX.Address.toLegacyAddress(thisAddress) - */ - const addr = BITBOX.Address.toLegacyAddress(thisAddress) + //const addr = bchjs.Address.toLegacyAddress(thisAddress) + const addr = bchjs.Address.toCashAddress(thisAddress) let path = `${process.env.BITCOINCOM_BASEURL}addr/${addr}` @@ -64,7 +56,7 @@ async function detailsFromInsight(thisAddress, currentPage = 0) { const to = from + PAGE_SIZE path = `${path}?from=${from}&to=${to}` - //console.log(`path: ${path}`) + //console.log(`insight path: ${path}`) // Query the Insight server. const axiosResponse = await axios.get(path) @@ -75,8 +67,8 @@ async function detailsFromInsight(thisAddress, currentPage = 0) { const pagesTotal = Math.ceil(retData.txApperances / PAGE_SIZE) // Append different address formats to the return data. - retData.legacyAddress = BITBOX.Address.toLegacyAddress(retData.addrStr) - retData.cashAddress = BITBOX.Address.toCashAddress(retData.addrStr) + retData.legacyAddress = bchjs.Address.toLegacyAddress(retData.addrStr) + retData.cashAddress = bchjs.Address.toCashAddress(retData.addrStr) delete retData.addrStr // Append pagination information to the return data. @@ -123,7 +115,7 @@ async function detailsBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ @@ -195,7 +187,7 @@ async function detailsSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - var legacyAddr = BITBOX.Address.toLegacyAddress(address) + var legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -238,12 +230,7 @@ async function detailsSingle(req, res, next) { // Retrieve UTXO data from the Insight API async function utxoFromInsight(thisAddress) { try { - let addr - if ( - process.env.BITCOINCOM_BASEURL === "https://bch-insight.bitpay.com/api/" - ) - addr = BITBOX.Address.toCashAddress(thisAddress) - else addr = BITBOX.Address.toLegacyAddress(thisAddress) + const addr = bchjs.Address.toCashAddress(thisAddress) const path = `${process.env.BITCOINCOM_BASEURL}addr/${addr}/utxo` @@ -261,8 +248,8 @@ async function utxoFromInsight(thisAddress) { const spk = response.data[0].scriptPubKey retData.scriptPubKey = spk } - retData.legacyAddress = BITBOX.Address.toLegacyAddress(thisAddress) - retData.cashAddress = BITBOX.Address.toCashAddress(thisAddress) + retData.legacyAddress = bchjs.Address.toLegacyAddress(thisAddress) + retData.cashAddress = bchjs.Address.toCashAddress(thisAddress) retData.utxos = response.data.map(utxo => { delete utxo.address delete utxo.scriptPubKey @@ -303,7 +290,7 @@ async function utxoBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (er) { //if (er.message.includes("Unsupported address format")) res.status(400) @@ -376,7 +363,7 @@ async function utxoSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - var legacyAddr = BITBOX.Address.toLegacyAddress(address) + var legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -443,7 +430,7 @@ async function unconfirmedBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ @@ -522,7 +509,7 @@ async function unconfirmedSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - var legacyAddr = BITBOX.Address.toLegacyAddress(address) + var legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -584,8 +571,8 @@ async function transactionsFromInsight(thisAddress, currentPage = 0) { // Append different address formats to the return data. const retData = response.data - retData.legacyAddress = BITBOX.Address.toLegacyAddress(thisAddress) - retData.cashAddress = BITBOX.Address.toCashAddress(thisAddress) + retData.legacyAddress = bchjs.Address.toLegacyAddress(thisAddress) + retData.cashAddress = bchjs.Address.toCashAddress(thisAddress) retData.currentPage = currentPage return retData @@ -624,7 +611,7 @@ async function transactionsBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - BITBOX.Address.toLegacyAddress(thisAddress) + bchjs.Address.toLegacyAddress(thisAddress) } catch (err) { res.status(400) return res.json({ @@ -696,7 +683,7 @@ async function transactionsSingle(req, res, next) { // Ensure the input is a valid BCH address. try { - var legacyAddr = BITBOX.Address.toLegacyAddress(address) + var legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ @@ -757,8 +744,8 @@ async function fromXPubSingle(req, res, next) { wlogger.debug(`Executing address/fromXPub with this xpub: `, xpub) - const cashAddr = BITBOX.Address.fromXPub(xpub, hdPath) - const legacyAddr = BITBOX.Address.toLegacyAddress(cashAddr) + const cashAddr = bchjs.Address.fromXPub(xpub, hdPath) + const legacyAddr = bchjs.Address.toLegacyAddress(cashAddr) res.status(200) return res.json({ cashAddress: cashAddr, diff --git a/src/routes/v3/insight/index.js b/src/routes/v3/insight/index.js index ad5037d..8f3c11f 100644 --- a/src/routes/v3/insight/index.js +++ b/src/routes/v3/insight/index.js @@ -17,8 +17,8 @@ const router = express.Router() const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +//const BCHJS = require("@chris.troutner/bch-js") +//const bchjs = new BCHJS() //const BITCORE_URL = process.env.BITCORE_URL diff --git a/src/routes/v3/insight/transaction.js b/src/routes/v3/insight/transaction.js index ccb16e9..e2978dc 100644 --- a/src/routes/v3/insight/transaction.js +++ b/src/routes/v3/insight/transaction.js @@ -7,8 +7,8 @@ const axios = require("axios") const routeUtils = require("../route-utils") const wlogger = require("../../../util/winston-logging") -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() // Used to convert error messages to strings, to safely pass to users. const util = require("util") @@ -23,8 +23,8 @@ const processInputs = tx => { vin.value = vin.valueSat const address = vin.addr if (address) { - vin.legacyAddress = BITBOX.Address.toLegacyAddress(address) - vin.cashAddress = BITBOX.Address.toCashAddress(address) + vin.legacyAddress = bchjs.Address.toLegacyAddress(address) + vin.cashAddress = bchjs.Address.toCashAddress(address) delete vin.addr } delete vin.valueSat @@ -43,7 +43,7 @@ const processInputs = tx => { if (vout.scriptPubKey.addresses) { const cashAddrs = [] vout.scriptPubKey.addresses.forEach(addr => { - const cashAddr = BITBOX.Address.toCashAddress(addr) + const cashAddr = bchjs.Address.toCashAddress(addr) cashAddrs.push(cashAddr) }) vout.scriptPubKey.cashAddrs = cashAddrs diff --git a/src/routes/v3/route-utils.js b/src/routes/v3/route-utils.js index 93e6e9b..be11a4e 100644 --- a/src/routes/v3/route-utils.js +++ b/src/routes/v3/route-utils.js @@ -10,8 +10,8 @@ const wlogger = require("../../util/winston-logging") const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() module.exports = { validateNetwork, // Prevents a common user error @@ -54,14 +54,14 @@ function validateNetwork(addr) { // Convert the user-provided address to a cashaddress, for easy detection // of the intended network. - const cashAddr = BITBOX.Address.toCashAddress(addr) + const cashAddr = bchjs.Address.toCashAddress(addr) // Return true if the network and address both match testnet - const addrIsTest = BITBOX.Address.isTestnetAddress(cashAddr) + const addrIsTest = bchjs.Address.isTestnetAddress(cashAddr) if (network === "testnet" && addrIsTest) return true // Return true if the network and address both match mainnet - const addrIsMain = BITBOX.Address.isMainnetAddress(cashAddr) + const addrIsMain = bchjs.Address.isMainnetAddress(cashAddr) if (network === "mainnet" && addrIsMain) return true return false diff --git a/src/routes/v3/util.js b/src/routes/v3/util.js index 892e538..31931e4 100644 --- a/src/routes/v3/util.js +++ b/src/routes/v3/util.js @@ -7,14 +7,14 @@ const axios = require("axios") const routeUtils = require("./route-utils") const wlogger = require("../../util/winston-logging") -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() // Used to convert error messages to strings, to safely pass to users. const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BitboxHTTP = axios.create({ +const bchjsHTTP = axios.create({ baseURL: process.env.RPC_BASEURL }) @@ -103,7 +103,7 @@ async function validateAddressBulk(req, res, next) { // Ensure the input is a valid BCH address. try { - var legacyAddr = BITBOX.Address.toLegacyAddress(address) + var legacyAddr = bchjs.Address.toLegacyAddress(address) } catch (err) { res.status(400) return res.json({ diff --git a/src/routes/v3/xpub.js b/src/routes/v3/xpub.js index 60d36e9..d7da89a 100644 --- a/src/routes/v3/xpub.js +++ b/src/routes/v3/xpub.js @@ -17,8 +17,8 @@ const router = express.Router() const util = require("util") util.inspect.defaultOptions = { depth: 1 } -const BITBOXJS = require("@chris.troutner/bitbox-js") -const BITBOX = new BITBOXJS() +const BCHJS = require("@chris.troutner/bch-js") +const bchjs = new BCHJS() // Connect the route endpoints to their handler functions. router.get("/", root) @@ -49,8 +49,8 @@ async function fromXPubSingle(req, res, next) { wlogger.debug(`Executing address/fromXPub with this xpub: `, xpub) - const cashAddr = BITBOX.Address.fromXPub(xpub, hdPath) - const legacyAddr = BITBOX.Address.toLegacyAddress(cashAddr) + const cashAddr = bchjs.Address.fromXPub(xpub, hdPath) + const legacyAddr = bchjs.Address.toLegacyAddress(cashAddr) res.status(200) return res.json({ cashAddress: cashAddr, diff --git a/test/v3/address.js b/test/v3/insight-address.js similarity index 94% rename from test/v3/address.js rename to test/v3/insight-address.js index c1cafdc..72b6fb0 100644 --- a/test/v3/address.js +++ b/test/v3/insight-address.js @@ -30,7 +30,7 @@ const mockData = require("./mocks/address-mock") const util = require("util") util.inspect.defaultOptions = { depth: 1 } -describe("#AddressRouter", () => { +describe("#Insight Address", () => { let req, res before(() => { @@ -191,7 +191,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -212,7 +212,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=5000&to=6000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -232,7 +232,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -251,7 +251,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -291,12 +291,13 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) + .times(2) .reply(200, mockData.mockAddressDetails) - nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8?from=0&to=1000`) - .reply(200, mockData.mockAddressDetails) + //nock(`${process.env.BITCOINCOM_BASEURL}`) + // .get(uri => uri.includes("/")) + // .reply(200, mockData.mockAddressDetails) } // Call the details API. @@ -383,7 +384,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -402,7 +403,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=5000&to=6000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -419,7 +420,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -435,7 +436,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockAddressDetails) } @@ -554,7 +555,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) } @@ -594,12 +595,13 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) + .times(2) .reply(200, mockData.mockUtxoDetails) - nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8/utxo`) - .reply(200, mockData.mockUtxoDetails) + //nock(`${process.env.BITCOINCOM_BASEURL}`) + // .get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8/utxo`) + // .reply(200, mockData.mockUtxoDetails) } // Call the details API. @@ -699,7 +701,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) } @@ -830,7 +832,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) } @@ -857,11 +859,11 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) } @@ -947,7 +949,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`) + .get(uri => uri.includes("/")) .reply(200, mockData.mockUtxoDetails) } @@ -1070,9 +1072,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=0` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) } @@ -1092,9 +1092,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=5` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) } @@ -1113,9 +1111,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=0` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) } @@ -1143,16 +1139,15 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=0` - ) + .get(uri => uri.includes("/")) + .times(2) .reply(200, mockData.mockTransactions) - nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr&pageNum=0` - ) - .reply(200, mockData.mockTransactions) + //nock(`${process.env.BITCOINCOM_BASEURL}`) + // .get( + // `/txs/?address=bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr&pageNum=0` + // ) + // .reply(200, mockData.mockTransactions) } // Call the details API. @@ -1240,9 +1235,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=0` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) } @@ -1260,9 +1253,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=5` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) } @@ -1279,9 +1270,7 @@ describe("#AddressRouter", () => { // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BITCOINCOM_BASEURL}`) - .get( - `/txs/?address=bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4&pageNum=0` - ) + .get(uri => uri.includes("/")) .reply(200, mockData.mockTransactions) }