Updating from changes to master

This commit is contained in:
Chris Troutner
2020-08-07 15:35:46 -07:00
12 changed files with 985 additions and 468 deletions
+2
View File
@@ -19,6 +19,8 @@ start-fullstack-test.sh
start-free-main.sh
free-bch-api-main.sh
free-bch-api-test.sh
start-local-mainnet.sh.save
start-local-testnet.sh.save
coverage
start-my-infra
+2 -3
View File
@@ -16,9 +16,8 @@ of [BITBOX SDK](https://github.com/Bitcoin-com/bitbox-sdk).
Both bch-api and bch-js are part of the
[full stack of BCH software](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer).
- [API Documentation](https://api.bchjs.cash/docs/)
- [BCH Example Applications](https://github.com/Permissionless-Software-Foundation/bch-js-examples)
- [slp-cli-wallet](https://github.com/christroutner/slp-cli-wallet): a hacker-friendly, command-line BCH and SLP token wallet using this REST API.
- [API Documentation](https://fullstack.cash/documentation)
- [Example Code](https://fullstack.cash/examples)
Have questions? Need help? Join our community support
[Telegram channel](https://t.me/bch_js_toolkit)
@@ -1,28 +0,0 @@
#!/bin/bash
# test
# Full node
export RPC_BASEURL=http://142.93.13.2:8332/
export RPC_USERNAME=bitcoin
export RPC_PASSWORD=password
export NETWORK=mainnet
# SLPDB
#export SLPDB_URL=https://slpdb.bitcoin.com/
#export SLPDB_URL=http://172.17.0.1:12300/
export SLPDB_URL=https://slpdb2.bchtest.net/
export SLPDB_PASS=owmvgnsksoapwhrnvu
# Blockbook Indexer
export BLOCKBOOK_URL=https://157.230.214.175:9131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
export JWT_AUTH_SERVER=http://172.17.0.1:5001/
# Redis DB
export REDIS_PORT=6379
export REDIS_HOST=172.17.0.1
npm start
+237 -242
View File
@@ -1,6 +1,6 @@
{
"name": "bch-api",
"version": "1.0.0",
"version": "1.16.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1131,6 +1131,11 @@
"graceful-fs": "^4.1.11"
}
},
"lodash": {
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
},
"markdown-it": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz",
@@ -2296,9 +2301,9 @@
}
},
"bitcore-lib": {
"version": "8.16.2",
"resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-8.16.2.tgz",
"integrity": "sha512-wyiys24QYbj8CjeQvV0D0oMXJAEeIBJYf+ubob0d2sIno1P4hLkTkj/Yu4RGnUeePLVVWXcjnSR2micHimvU8w==",
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-8.21.0.tgz",
"integrity": "sha512-Z1lDqSReD/Ah/n7qEsR564AlNImwYeB1MQ0fnOD6e2piNsTXQ3cSjgH93MxVARpX4LRkEev2XBnYCJ4NcYTQdQ==",
"requires": {
"bech32": "=1.1.3",
"bn.js": "=4.11.8",
@@ -2327,15 +2332,20 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
}
}
},
"bitcore-lib-cash": {
"version": "8.16.2",
"resolved": "https://registry.npmjs.org/bitcore-lib-cash/-/bitcore-lib-cash-8.16.2.tgz",
"integrity": "sha512-WmREw2XkoEFKmIbJjhSmRgQUCh9XNfmJz6fdoVMReuqpQuzNWJtTueXmxDYMBvYDOmS4RNZq8SbBfkUOEqLTUQ==",
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/bitcore-lib-cash/-/bitcore-lib-cash-8.21.0.tgz",
"integrity": "sha512-vQs+b8AbJDccgDk8q5woqG4bSOFA0Mz5SuAhM7rH3VclbYwKSsEM4u3G2QjUGOnF5X3Ts7Dc683qoDyccEz5Jw==",
"requires": {
"bitcore-lib": "^8.16.2",
"bitcore-lib": "^8.21.0",
"bn.js": "=4.11.8",
"bs58": "^4.0.1",
"buffer-compare": "=1.1.1",
@@ -2362,6 +2372,11 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
}
}
},
@@ -3243,24 +3258,13 @@
"integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs="
},
"compare-func": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.2.tgz",
"integrity": "sha1-md0LpFfh+bxyKxLAjsM+6rMfpkg=",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz",
"integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==",
"dev": true,
"requires": {
"array-ify": "^1.0.0",
"dot-prop": "^3.0.0"
},
"dependencies": {
"dot-prop": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz",
"integrity": "sha1-G3CK8JSknJoOfbyteQq6U52sEXc=",
"dev": true,
"requires": {
"is-obj": "^1.0.0"
}
}
"dot-prop": "^5.1.0"
}
},
"component-bind": {
@@ -3382,22 +3386,34 @@
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
},
"conventional-changelog-angular": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.6.tgz",
"integrity": "sha512-QDEmLa+7qdhVIv8sFZfVxU1VSyVvnXPsxq8Vam49mKUcO1Z8VTLEJk9uI21uiJUsnmm0I4Hrsdc9TgkOQo9WSA==",
"version": "5.0.11",
"resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.11.tgz",
"integrity": "sha512-nSLypht/1yEflhuTogC03i7DX7sOrXGsRn14g131Potqi6cbGbGEE9PSDEHKldabB6N76HiSyw9Ph+kLmC04Qw==",
"dev": true,
"requires": {
"compare-func": "^1.3.1",
"compare-func": "^2.0.0",
"q": "^1.5.1"
},
"dependencies": {
"compare-func": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz",
"integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==",
"dev": true,
"requires": {
"array-ify": "^1.0.0",
"dot-prop": "^5.1.0"
}
}
}
},
"conventional-changelog-writer": {
"version": "4.0.16",
"resolved": "https://registry.npmjs.org/conventional-changelog-writer/-/conventional-changelog-writer-4.0.16.tgz",
"integrity": "sha512-jmU1sDJDZpm/dkuFxBeRXvyNcJQeKhGtVcFFkwTphUAzyYWcwz2j36Wcv+Mv2hU3tpvLMkysOPXJTLO55AUrYQ==",
"version": "4.0.17",
"resolved": "https://registry.npmjs.org/conventional-changelog-writer/-/conventional-changelog-writer-4.0.17.tgz",
"integrity": "sha512-IKQuK3bib/n032KWaSb8YlBFds+aLmzENtnKtxJy3+HqDq5kohu3g/UdNbIHeJWygfnEbZjnCKFxAW0y7ArZAw==",
"dev": true,
"requires": {
"compare-func": "^1.3.1",
"compare-func": "^2.0.0",
"conventional-commits-filter": "^2.0.6",
"dateformat": "^3.0.0",
"handlebars": "^4.7.6",
@@ -3426,11 +3442,12 @@
"dev": true
},
"through2": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/through2/-/through2-3.0.1.tgz",
"integrity": "sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/through2/-/through2-3.0.2.tgz",
"integrity": "sha512-enaDQ4MUyP2W6ZyT6EsMzqBPZaM/avg8iuo+l2d3QCs0J+6RaqkHV/2/lOwDTueBHeJ/2LG9lrLW3d5rWPucuQ==",
"dev": true,
"requires": {
"inherits": "^2.0.4",
"readable-stream": "2 || 3"
}
}
@@ -4415,9 +4432,9 @@
}
},
"elliptic": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz",
"integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==",
"version": "6.5.3",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
"integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
"requires": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",
@@ -5051,6 +5068,12 @@
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true
},
"lodash": {
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
"dev": true
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
@@ -7310,12 +7333,6 @@
"resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.4.tgz",
"integrity": "sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw=="
},
"is-obj": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
"dev": true
},
"is-object": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz",
@@ -8035,9 +8052,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
},
"lodash._baseiteratee": {
"version": "4.7.0",
@@ -9122,9 +9139,9 @@
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
},
"npm": {
"version": "6.14.3",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.3.tgz",
"integrity": "sha512-3tQYVEEdSGQGYoXhZvNqW8faqCidfMMaL387RdDo4Uu5kQy4IgvJ13NIsWVMQ6e3QWlbicNMSpFiyzYfMUuPDw==",
"version": "6.14.7",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.7.tgz",
"integrity": "sha512-swhsdpNpyXg4GbM6LpOQ6qaloQuIKizZ+Zh6JPXJQc59ka49100Js0WvZx594iaKSoFgkFq2s8uXFHS3/Xy2WQ==",
"dev": true,
"requires": {
"JSONStream": "^1.3.5",
@@ -9133,7 +9150,7 @@
"ansistyles": "~0.1.3",
"aproba": "^2.0.0",
"archy": "~1.0.0",
"bin-links": "^1.1.7",
"bin-links": "^1.1.8",
"bluebird": "^3.5.5",
"byte-size": "^5.0.1",
"cacache": "^12.0.3",
@@ -9154,9 +9171,9 @@
"find-npm-prefix": "^1.0.2",
"fs-vacuum": "~1.2.10",
"fs-write-stream-atomic": "~1.0.10",
"gentle-fs": "^2.3.0",
"gentle-fs": "^2.3.1",
"glob": "^7.1.6",
"graceful-fs": "^4.2.3",
"graceful-fs": "^4.2.4",
"has-unicode": "~2.0.1",
"hosted-git-info": "^2.8.8",
"iferr": "^1.0.2",
@@ -9169,14 +9186,14 @@
"is-cidr": "^3.0.0",
"json-parse-better-errors": "^1.0.2",
"lazy-property": "~1.0.0",
"libcipm": "^4.0.7",
"libcipm": "^4.0.8",
"libnpm": "^3.0.1",
"libnpmaccess": "^3.0.2",
"libnpmhook": "^5.0.3",
"libnpmorg": "^1.0.1",
"libnpmsearch": "^2.0.2",
"libnpmteam": "^1.0.2",
"libnpx": "^10.2.2",
"libnpx": "^10.2.4",
"lock-verify": "^2.1.0",
"lockfile": "^1.0.4",
"lodash._baseindexof": "*",
@@ -9193,20 +9210,20 @@
"lru-cache": "^5.1.1",
"meant": "~1.0.1",
"mississippi": "^3.0.0",
"mkdirp": "^0.5.3",
"mkdirp": "^0.5.5",
"move-concurrently": "^1.0.1",
"node-gyp": "^5.1.0",
"nopt": "~4.0.1",
"nopt": "^4.0.3",
"normalize-package-data": "^2.5.0",
"npm-audit-report": "^1.3.2",
"npm-audit-report": "^1.3.3",
"npm-cache-filename": "~1.0.2",
"npm-install-checks": "^3.0.2",
"npm-lifecycle": "^3.1.4",
"npm-lifecycle": "^3.1.5",
"npm-package-arg": "^6.1.1",
"npm-packlist": "^1.4.8",
"npm-pick-manifest": "^3.0.2",
"npm-profile": "^4.0.4",
"npm-registry-fetch": "^4.0.3",
"npm-registry-fetch": "^4.0.5",
"npm-user-validate": "~1.0.0",
"npmlog": "~4.1.2",
"once": "~1.4.0",
@@ -9415,7 +9432,7 @@
}
},
"bin-links": {
"version": "1.1.7",
"version": "1.1.8",
"bundled": true,
"dev": true,
"requires": {
@@ -9570,26 +9587,41 @@
}
},
"cliui": {
"version": "4.1.0",
"version": "5.0.0",
"bundled": true,
"dev": true,
"requires": {
"string-width": "^2.1.1",
"strip-ansi": "^4.0.0",
"wrap-ansi": "^2.0.0"
"string-width": "^3.1.0",
"strip-ansi": "^5.2.0",
"wrap-ansi": "^5.1.0"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"version": "4.1.0",
"bundled": true,
"dev": true
},
"strip-ansi": {
"version": "4.0.0",
"is-fullwidth-code-point": {
"version": "2.0.0",
"bundled": true,
"dev": true
},
"string-width": {
"version": "3.1.0",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
"strip-ansi": {
"version": "5.2.0",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "^4.1.0"
}
}
}
@@ -9834,7 +9866,7 @@
"dev": true
},
"deep-extend": {
"version": "0.5.1",
"version": "0.6.0",
"bundled": true,
"dev": true
},
@@ -9951,6 +9983,11 @@
"bundled": true,
"dev": true
},
"emoji-regex": {
"version": "7.0.3",
"bundled": true,
"dev": true
},
"encoding": {
"version": "0.1.12",
"bundled": true,
@@ -10076,14 +10113,6 @@
"bundled": true,
"dev": true
},
"find-up": {
"version": "2.1.0",
"bundled": true,
"dev": true,
"requires": {
"locate-path": "^2.0.0"
}
},
"flush-write-stream": {
"version": "1.0.3",
"bundled": true,
@@ -10282,7 +10311,7 @@
"dev": true
},
"gentle-fs": {
"version": "2.3.0",
"version": "2.3.1",
"bundled": true,
"dev": true,
"requires": {
@@ -10312,7 +10341,7 @@
}
},
"get-caller-file": {
"version": "1.0.3",
"version": "2.0.5",
"bundled": true,
"dev": true
},
@@ -10379,7 +10408,7 @@
}
},
"graceful-fs": {
"version": "4.2.3",
"version": "4.2.4",
"bundled": true,
"dev": true
},
@@ -10536,11 +10565,6 @@
"validate-npm-package-name": "^3.0.0"
}
},
"invert-kv": {
"version": "2.0.0",
"bundled": true,
"dev": true
},
"ip": {
"version": "1.1.5",
"bundled": true,
@@ -10557,11 +10581,11 @@
"dev": true
},
"is-ci": {
"version": "1.1.0",
"version": "1.2.1",
"bundled": true,
"dev": true,
"requires": {
"ci-info": "^1.0.0"
"ci-info": "^1.5.0"
},
"dependencies": {
"ci-info": {
@@ -10633,7 +10657,7 @@
}
},
"is-retry-allowed": {
"version": "1.1.0",
"version": "1.2.0",
"bundled": true,
"dev": true
},
@@ -10725,16 +10749,8 @@
"bundled": true,
"dev": true
},
"lcid": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"requires": {
"invert-kv": "^2.0.0"
}
},
"libcipm": {
"version": "4.0.7",
"version": "4.0.8",
"bundled": true,
"dev": true,
"requires": {
@@ -10744,7 +10760,7 @@
"find-npm-prefix": "^1.0.2",
"graceful-fs": "^4.1.11",
"ini": "^1.3.5",
"lock-verify": "^2.0.2",
"lock-verify": "^2.1.0",
"mkdirp": "^0.5.1",
"npm-lifecycle": "^3.0.0",
"npm-logical-tree": "^1.2.1",
@@ -10903,7 +10919,7 @@
}
},
"libnpx": {
"version": "10.2.2",
"version": "10.2.4",
"bundled": true,
"dev": true,
"requires": {
@@ -10914,16 +10930,7 @@
"update-notifier": "^2.3.0",
"which": "^1.3.0",
"y18n": "^4.0.0",
"yargs": "^11.0.0"
}
},
"locate-path": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"requires": {
"p-locate": "^2.0.0",
"path-exists": "^3.0.0"
"yargs": "^14.2.3"
}
},
"lock-verify": {
@@ -11054,36 +11061,11 @@
"ssri": "^6.0.0"
}
},
"map-age-cleaner": {
"version": "0.1.3",
"bundled": true,
"dev": true,
"requires": {
"p-defer": "^1.0.0"
}
},
"meant": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"mem": {
"version": "4.3.0",
"bundled": true,
"dev": true,
"requires": {
"map-age-cleaner": "^0.1.1",
"mimic-fn": "^2.0.0",
"p-is-promise": "^2.0.0"
},
"dependencies": {
"mimic-fn": {
"version": "2.1.0",
"bundled": true,
"dev": true
}
}
},
"mime-db": {
"version": "1.35.0",
"bundled": true,
@@ -11142,7 +11124,7 @@
}
},
"mkdirp": {
"version": "0.5.3",
"version": "0.5.5",
"bundled": true,
"dev": true,
"requires": {
@@ -11186,11 +11168,6 @@
"bundled": true,
"dev": true
},
"nice-try": {
"version": "1.0.5",
"bundled": true,
"dev": true
},
"node-fetch-npm": {
"version": "2.0.2",
"bundled": true,
@@ -11220,7 +11197,7 @@
}
},
"nopt": {
"version": "4.0.1",
"version": "4.0.3",
"bundled": true,
"dev": true,
"requires": {
@@ -11250,7 +11227,7 @@
}
},
"npm-audit-report": {
"version": "1.3.2",
"version": "1.3.3",
"bundled": true,
"dev": true,
"requires": {
@@ -11280,7 +11257,7 @@
}
},
"npm-lifecycle": {
"version": "3.1.4",
"version": "3.1.5",
"bundled": true,
"dev": true,
"requires": {
@@ -11346,7 +11323,7 @@
}
},
"npm-registry-fetch": {
"version": "4.0.3",
"version": "4.0.5",
"bundled": true,
"dev": true,
"requires": {
@@ -11360,7 +11337,7 @@
},
"dependencies": {
"safe-buffer": {
"version": "5.2.0",
"version": "5.2.1",
"bundled": true,
"dev": true
}
@@ -11437,44 +11414,6 @@
"bundled": true,
"dev": true
},
"os-locale": {
"version": "3.1.0",
"bundled": true,
"dev": true,
"requires": {
"execa": "^1.0.0",
"lcid": "^2.0.0",
"mem": "^4.0.0"
},
"dependencies": {
"cross-spawn": {
"version": "6.0.5",
"bundled": true,
"dev": true,
"requires": {
"nice-try": "^1.0.4",
"path-key": "^2.0.1",
"semver": "^5.5.0",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
}
},
"execa": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"requires": {
"cross-spawn": "^6.0.0",
"get-stream": "^4.0.0",
"is-stream": "^1.1.0",
"npm-run-path": "^2.0.0",
"p-finally": "^1.0.0",
"signal-exit": "^3.0.0",
"strip-eof": "^1.0.0"
}
}
}
},
"os-tmpdir": {
"version": "1.0.2",
"bundled": true,
@@ -11489,42 +11428,11 @@
"os-tmpdir": "^1.0.0"
}
},
"p-defer": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"p-finally": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"p-is-promise": {
"version": "2.1.0",
"bundled": true,
"dev": true
},
"p-limit": {
"version": "1.2.0",
"bundled": true,
"dev": true,
"requires": {
"p-try": "^1.0.0"
}
},
"p-locate": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"requires": {
"p-limit": "^1.1.0"
}
},
"p-try": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"package-json": {
"version": "4.0.1",
"bundled": true,
@@ -11781,18 +11689,18 @@
"dev": true
},
"rc": {
"version": "1.2.7",
"version": "1.2.8",
"bundled": true,
"dev": true,
"requires": {
"deep-extend": "^0.5.1",
"deep-extend": "^0.6.0",
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"version": "1.2.5",
"bundled": true,
"dev": true
}
@@ -11872,7 +11780,7 @@
}
},
"registry-auth-token": {
"version": "3.3.2",
"version": "3.4.0",
"bundled": true,
"dev": true,
"requires": {
@@ -11921,7 +11829,7 @@
"dev": true
},
"require-main-filename": {
"version": "1.0.1",
"version": "2.0.0",
"bundled": true,
"dev": true
},
@@ -12120,7 +12028,7 @@
}
},
"spdx-license-ids": {
"version": "3.0.3",
"version": "3.0.5",
"bundled": true,
"dev": true
},
@@ -12555,7 +12463,7 @@
}
},
"widest-line": {
"version": "2.0.0",
"version": "2.0.1",
"bundled": true,
"dev": true,
"requires": {
@@ -12571,22 +12479,41 @@
}
},
"wrap-ansi": {
"version": "2.1.0",
"version": "5.1.0",
"bundled": true,
"dev": true,
"requires": {
"string-width": "^1.0.1",
"strip-ansi": "^3.0.1"
"ansi-styles": "^3.2.0",
"string-width": "^3.0.0",
"strip-ansi": "^5.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "4.1.0",
"bundled": true,
"dev": true
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"bundled": true,
"dev": true
},
"string-width": {
"version": "1.0.2",
"version": "3.1.0",
"bundled": true,
"dev": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
"strip-ansi": {
"version": "5.2.0",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "^4.1.0"
}
}
}
@@ -12627,37 +12554,105 @@
"dev": true
},
"yargs": {
"version": "11.1.1",
"version": "14.2.3",
"bundled": true,
"dev": true,
"requires": {
"cliui": "^4.0.0",
"decamelize": "^1.1.1",
"find-up": "^2.1.0",
"get-caller-file": "^1.0.1",
"os-locale": "^3.1.0",
"cliui": "^5.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^1.0.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^2.0.0",
"string-width": "^3.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1",
"yargs-parser": "^9.0.2"
"y18n": "^4.0.0",
"yargs-parser": "^15.0.1"
},
"dependencies": {
"y18n": {
"version": "3.2.1",
"ansi-regex": {
"version": "4.1.0",
"bundled": true,
"dev": true
},
"find-up": {
"version": "3.0.0",
"bundled": true,
"dev": true,
"requires": {
"locate-path": "^3.0.0"
}
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"bundled": true,
"dev": true
},
"locate-path": {
"version": "3.0.0",
"bundled": true,
"dev": true,
"requires": {
"p-locate": "^3.0.0",
"path-exists": "^3.0.0"
}
},
"p-limit": {
"version": "2.3.0",
"bundled": true,
"dev": true,
"requires": {
"p-try": "^2.0.0"
}
},
"p-locate": {
"version": "3.0.0",
"bundled": true,
"dev": true,
"requires": {
"p-limit": "^2.0.0"
}
},
"p-try": {
"version": "2.2.0",
"bundled": true,
"dev": true
},
"string-width": {
"version": "3.1.0",
"bundled": true,
"dev": true,
"requires": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
"strip-ansi": {
"version": "5.2.0",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "^4.1.0"
}
}
}
},
"yargs-parser": {
"version": "9.0.2",
"version": "15.0.1",
"bundled": true,
"dev": true,
"requires": {
"camelcase": "^4.1.0"
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
},
"dependencies": {
"camelcase": {
"version": "5.3.1",
"bundled": true,
"dev": true
}
}
}
}
+5 -5
View File
@@ -1,7 +1,7 @@
{
"name": "bch-api",
"version": "1.0.0",
"description": "REST API based on rest.bitcoin.com",
"version": "1.16.0",
"description": "The REST API powering FullStack.cash",
"author": "Chris Troutner <chris.troutner@gmail.com>",
"contributors": [
"Gabriel Cardona <gabriel@bitcoin.com>"
@@ -9,7 +9,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/christroutner/bch-api.git"
"url": "git+https://github.com/Permissionless-Software-Foundation/bch-api.git"
},
"scripts": {
"start": "node ./src/app.js",
@@ -17,7 +17,7 @@
"test": "npm run lint && npm run test-v3",
"lint": "standard --env mocha --fix",
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/slp.js",
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/a01-electrumx.js",
"test:integration": "mocha test/v3/integration",
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
@@ -31,7 +31,7 @@
"@chris.troutner/bch-js": "^3.0.1",
"apidoc": "^0.23.0",
"axios": "^0.19.0",
"bitcore-lib-cash": "^8.16.2",
"bitcore-lib-cash": "^8.20.3",
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.3",
"cors": "^2.8.3",
+14 -14
View File
@@ -23,24 +23,24 @@
target="_blank"
>REST API</a
>, allowing modern applications to interact with the Bitcoin Cash (BCH)
blockchain. New to the BCH blockchain? Start by reading more about
blockchain. New to the BCH blockchain? Check out these
<a
href="https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer"
href="https://fullstack.cash/documentation"
target="_blank"
>building full stack applications on BCH</a
>educational resources</a
>.
</p><br />
<p>
A REST API can work with any programming language, but bch-api is intended
to be paired with the
<a
href="https://www.npmjs.com/package/@chris.troutner/bch-js"
href="https://www.npmjs.com/package/@psf/bch-js"
target="_blank"
>npm bch-js</a
>
JavaScript library.
<a
href="https://github.com/Permissionless-Software-Foundation/bch-js-examples"
href="https://fullstack.cash/examples"
target="_blank"
>Here is example code</a
>
@@ -53,7 +53,7 @@
</p><br />
<p>
While you'll be able to run through the examples without one, you should
<a href="https://account.bchjs.cash/" target="_blank"
<a href="https://fullstack.cash/login" target="_blank"
>sign-up for a free API key</a
>
in order to unlock higher rate limits.
@@ -66,7 +66,7 @@
<h3>bch-api</h3>
<ul>
<li>
<a href="https://account.bchjs.cash" target="_blank">
<a href="https://fullstack.cash/login" target="_blank">
Get an API key to increase rate limits
</a>
</li>
@@ -80,14 +80,14 @@
<br />
<li>
<a href="https://tapi.bchjs.cash">
<a href="https://tapi.fullstack.cash">
testnet REST API
</a>
</li>
<br />
<li>
<a href="https://github.com/christroutner/bch-api" target="_blank">
<a href="https://github.com/Permissionless-Software-Foundation/bch-api" target="_blank">
bch-api GitHub repository
</a>
</li>
@@ -114,14 +114,14 @@
</li>
<br />
<li>
<a href="https://bchjs.cash/" target="_blank">
<a href="https://fullstack.cash/cashstrap" target="_blank">
Run your own infrastructure
</a>
</li>
<br />
<li>
<a href="https://github.com/bitcoinbook/bitcoinbook#chapters" target="_blank">
<a href="https://fullstack.cash/documentation" target="_blank">
Mastering Bitcoin (great free reference)
</a>
</li>
@@ -135,7 +135,7 @@
<br />
<li>
<a href="https://developer.bitcoin.com/faucets/bch/" target="_blank">
<a href="https://fullstack.cash/faucet/" target="_blank">
Testnet Faucet
</a>
</li>
@@ -148,7 +148,7 @@
<h3>bch-js</h3>
<ul>
<li>
<a href="https://www.npmjs.com/package/@chris.troutner/bch-js"
<a href="https://www.npmjs.com/package/@psf/bch-js"
target="_blank">
npm library
</a>
@@ -163,7 +163,7 @@
<br />
<li>
<a href="https://github.com/christroutner/bch-js" target="_blank">
<a href="https://github.com/Permissionless-Software-Foundation/bch-js" target="_blank">
GitHub code repository
</a>
</li>
+195
View File
@@ -54,6 +54,8 @@ class Electrum {
_this.router.post('/balance', _this.balanceBulk)
_this.router.get('/transactions/:address', _this.getTransactions)
_this.router.post('/transactions', _this.transactionsBulk)
_this.router.get('/unconfirmed/:address', _this.getMempool)
_this.router.post('/unconfirmed', _this.mempoolBulk)
}
// Initializes a connection to electrum servers.
@@ -708,6 +710,199 @@ class Electrum {
}
}
// Returns a promise that resolves to unconfirmed UTXO data (mempool) for an address.
// Expects input to be a cash address, and input validation to have
// already been done by parent, calling function.
async _mempoolFromElectrumx (address) {
try {
// Convert the address to a scripthash.
const scripthash = _this.addressToScripthash(address)
if (!_this.isReady) {
throw new Error(
'ElectrumX server connection is not ready. Call await connectToServer() first.'
)
}
// Query the unconfirmed utxos from the ElectrumX server.
const electrumResponse = await _this.electrumx.request(
'blockchain.scripthash.get_mempool',
scripthash
)
// console.log(
// `electrumResponse: ${JSON.stringify(electrumResponse, null, 2)}`
// )
return electrumResponse
} catch (err) {
// console.log('err: ', err)
// Write out error to error log.
wlogger.error('Error in elecrumx.js/_mempoolFromElectrumx(): ', err)
throw err
}
}
/**
* @api {get} /electrumx/unconfirmed/{addr} Get unconfirmed utxos for a single address.
* @apiName Unconfirmed UTXOs for a single address
* @apiGroup ElectrumX / Fulcrum
* @apiDescription Returns an object with unconfirmed UTXOs associated with an address.
*
*
* @apiExample Example usage:
* curl -X GET "https://api.fullstack.cash/v3/electrumx/unconfirmed/bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur3" -H "accept: application/json"
*
*/
// GET handler for single balance
async getMempool (req, res, next) {
try {
const address = req.params.address
// Reject if address is an array.
if (Array.isArray(address)) {
res.status(400)
return res.json({
success: false,
error: 'address can not be an array. Use POST for bulk upload.'
})
}
// Ensure the address is in cash address format.
const cashAddr = _this.bchjs.Address.toCashAddress(address)
// Prevent a common user error. Ensure they are using the correct network address.
const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
if (!networkIsValid) {
res.status(400)
return res.json({
success: false,
error:
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
})
}
wlogger.debug(
'Executing electrumx/getMempool with this address: ',
cashAddr
)
// Get data from ElectrumX server.
const electrumResponse = await _this._mempoolFromElectrumx(cashAddr)
// console.log(`_mempoolFromElectrumx(): ${JSON.stringify(electrumResponse, null, 2)}`)
// Pass the error message if ElectrumX reports an error.
if (Object.prototype.hasOwnProperty.call(electrumResponse, 'code')) {
res.status(400)
return res.json({
success: false,
message: electrumResponse.message
})
}
res.status(200)
return res.json({
success: true,
utxos: electrumResponse
})
} catch (err) {
// Write out error to error log.
wlogger.error('Error in elecrumx.js/getMempool().', err)
return _this.errorHandler(err, res)
}
}
/**
* @api {post} /electrumx/unconfirmed Get unconfirmed utxos for an array of addresses.
* @apiName Unconfirmed UTXOs for an array of addresses
* @apiGroup ElectrumX / Fulcrum
* @apiDescription Returns an array of objects with unconfirmed UTXOs associated with an address.
* Limited to 20 items per request.
*
* @apiExample Example usage:
* curl -X POST "https://api.fullstack.cash/v3/electrumx/unconfirmed" -H "accept: application/json" -H "Content-Type: application/json" -d '{"addresses":["bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf","bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"]}'
*
*
*/
// POST handler for bulk queries on address details
async mempoolBulk (req, res, next) {
try {
let addresses = req.body.addresses
// Reject if addresses is not an array.
if (!Array.isArray(addresses)) {
res.status(400)
return res.json({
error: 'addresses needs to be an array. Use GET for single address.'
})
}
// Enforce array size rate limits
if (!_this.routeUtils.validateArraySize(req, addresses)) {
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
return res.json({
error: 'Array too large.'
})
}
wlogger.debug(
'Executing electrumx.js/mempoolBulk with these addresses: ',
addresses
)
// Validate each element in the address array.
for (let i = 0; i < addresses.length; i++) {
const thisAddress = addresses[i]
// Ensure the input is a valid BCH address.
try {
_this.bchjs.Address.toLegacyAddress(thisAddress)
} catch (err) {
res.status(400)
return res.json({
error: `Invalid BCH address. Double check your address is valid: ${thisAddress}`
})
}
// Prevent a common user error. Ensure they are using the correct network address.
const networkIsValid = _this.routeUtils.validateNetwork(thisAddress)
if (!networkIsValid) {
res.status(400)
return res.json({
error: `Invalid network for address ${thisAddress}. Trying to use a testnet address on mainnet, or vice versa.`
})
}
}
// Loops through each address and creates an array of Promises, querying
// Insight API in parallel.
addresses = addresses.map(async (address, index) => {
// console.log(`address: ${address}`)
const utxos = await _this._mempoolFromElectrumx(address)
return {
utxos,
address
}
})
// Wait for all parallel Insight requests to return.
const result = await Promise.all(addresses)
// Return the array of retrieved address information.
res.status(200)
return res.json({
success: true,
utxos: result
})
} catch (err) {
wlogger.error('Error in electrumx.js/mempoolBulk().', err)
return _this.errorHandler(err, res)
}
}
// Convert a 'bitcoincash:...' address to a script hash used by ElectrumX.
addressToScripthash (addrStr) {
try {
+78 -168
View File
@@ -64,10 +64,6 @@ class Slp {
_this.router.get('/balancesForAddress/:address', _this.balancesForAddress)
_this.router.post('/balancesForAddress', _this.balancesForAddressBulk)
_this.router.get('/balancesForToken/:tokenId', _this.balancesForTokenSingle)
_this.router.get(
'/balance/:address/:tokenId',
_this.balancesForAddressByTokenID
)
_this.router.get('/convert/:address', _this.convertAddressSingle)
_this.router.post('/convert', _this.convertAddressBulk)
_this.router.post('/validateTxid', _this.validateBulk)
@@ -82,6 +78,7 @@ class Slp {
'/transactionHistoryAllTokens/:address',
_this.txsByAddressSingle
)
_this.router.post('/generateSendOpReturn', _this.generateSendOpReturn)
}
// DRY error handler.
@@ -829,170 +826,6 @@ class Slp {
}
}
/**
* @api {get} /slp/balance/{address}/{TokenId} List single slp token balance for address.
* @apiName List single slp token balance for address.
* @apiGroup SLP
* @apiDescription Returns List single slp token balance for address.
*
*
* @apiExample Example usage:
* curl -X GET "https://api.fullstack.cash/v3/slp/balance/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m/1cda254d0a995c713b7955298ed246822bee487458cd9747a91d9e81d9d28125" -H "accept:application/json"
*
*
*/
// Retrieve token balances for a single token class, for a single address.
async balancesForAddressByTokenID (req, res, next) {
try {
// Validate input data.
const address = req.params.address
if (!address || address === '') {
res.status(400)
return res.json({ error: 'address can not be empty' })
}
const tokenId = req.params.tokenId
if (!tokenId || tokenId === '') {
res.status(400)
return res.json({ error: 'tokenId can not be empty' })
}
// Ensure the input is a valid BCH address.
try {
_this.bchjs.SLP.Address.toCashAddress(address)
} catch (err) {
res.status(400)
return res.json({
error: `Invalid BCH address. Double check your address is valid: ${address}`
})
}
// Prevent a common user error. Ensure they are using the correct network address.
const cashAddr = _this.bchjs.SLP.Address.toCashAddress(address)
const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
if (!networkIsValid) {
res.status(400)
return res.json({
error:
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
})
}
// Convert input to an simpleledger: address.
const slpAddr = _this.bchjs.SLP.Address.toSlpAddress(req.params.address)
const query = {
v: 3,
q: {
db: ['g'],
aggregate: [
{
$match: {
'graphTxn.outputs': {
$elemMatch: {
address: slpAddr,
status: 'UNSPENT',
slpAmount: { $gte: 0 }
}
}
}
},
{
$unwind: '$graphTxn.outputs'
},
{
$match: {
'graphTxn.outputs.address': slpAddr,
'graphTxn.outputs.status': 'UNSPENT',
'graphTxn.outputs.slpAmount': { $gte: 0 }
}
},
{
$project: {
amount: '$graphTxn.outputs.slpAmount',
address: '$graphTxn.outputs.address',
txid: '$graphTxn.txid',
vout: '$graphTxn.outputs.vout',
tokenId: '$tokenDetails.tokenIdHex'
}
},
{
$group: {
_id: '$tokenId',
balanceString: {
$sum: '$amount'
},
slpAddress: {
$first: '$address'
}
}
}
],
limit: 10000
}
}
const options = _this.generateCredentials()
const s = JSON.stringify(query)
const b64 = Buffer.from(s).toString('base64')
const url = `${process.env.SLPDB_URL}q/${b64}`
// Get data from SLPDB.
const opt = {
method: 'get',
baseURL: url,
headers: options.headers,
timeout: options.timeout
}
const tokenRes = await _this.axios.request(opt)
console.log(`tokenRes.data: ${JSON.stringify(tokenRes.data, null, 2)}`)
let resVal = {
cashAddress: _this.bchjs.SLP.Address.toCashAddress(slpAddr),
legacyAddress: _this.bchjs.SLP.Address.toLegacyAddress(slpAddr),
slpAddress: slpAddr,
tokenId: tokenId,
balance: 0,
balanceString: '0'
}
if (tokenRes.data.g.length > 0) {
tokenRes.data.g.forEach(async (token) => {
if (token._id === tokenId) {
resVal = {
cashAddress: _this.bchjs.SLP.Address.toCashAddress(slpAddr),
legacyAddress: _this.bchjs.SLP.Address.toLegacyAddress(slpAddr),
slpAddress: slpAddr,
tokenId: token._id,
balance: parseFloat(token.balanceString),
balanceString: token.balanceString
}
}
})
} else {
resVal = {
cashAddress: _this.bchjs.SLP.Address.toCashAddress(slpAddr),
legacyAddress: _this.bchjs.SLP.Address.toLegacyAddress(slpAddr),
slpAddress: slpAddr,
tokenId: tokenId,
balance: 0,
balanceString: '0'
}
}
res.status(200)
return res.json(resVal)
} catch (err) {
wlogger.error('Error in slp.ts/balancesForAddressByTokenID().', err)
return _this.errorHandler(err, res)
// return res.json({
// error: `Error in /balance/:address/:tokenId: ${err.message}`
// })
}
}
/**
* @api {get} /slp/convert/{address} Convert address to slpAddr, cashAddr and legacy.
* @apiName Convert address to slpAddr, cashAddr and legacy.
@@ -1609,6 +1442,83 @@ class Slp {
})
}
}
/**
* @api {post} /slp/generateSendOpReturn/ generateSendOpReturn
* @apiName SLP generateSendOpReturn
* @apiGroup SLP
* @apiDescription Generate the hex required for a SLP Send OP_RETURN.
*
* This will return a hexidecimal representation of the OP_RETURN code that
* can be used to generate an SLP Send transaction. The number of outputs
* (1 or 2) will also be returned.
*
* @apiExample Example usage:
* curl -X POST "https://api.fullstack.cash/v3/slp/generateSendOpReturn" -H "accept:application/json" -H "Content-Type: application/json" -d '{"tokenUtxos":[{"tokenId": "0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1","decimals": 0, "tokenQty": 2}], "sendQty": 1.5}'
*
*
*/
// Get OP_RETURN script and outputs
async generateSendOpReturn (req, res, next) {
try {
const tokenUtxos = req.body.tokenUtxos
// console.log(`tokenUtxos: `, tokenUtxos)
const _sendQty = req.body.sendQty
const sendQty = Number(_sendQty)
// console.log(`sendQty: `, sendQty)
// Reject if tokenUtxos is not an array.
if (!Array.isArray(tokenUtxos)) {
res.status(400)
return res.json({
error: 'tokenUtxos needs to be an array.'
})
}
// Reject if tokenUtxos array is empty.
if (!tokenUtxos.length) {
res.status(400)
return res.json({
error: 'tokenUtxos array can not be empty.'
})
}
// Reject if sendQty is not an number.
if (!sendQty) {
res.status(400)
return res.json({
error: 'sendQty must be a number.'
})
}
const opReturn = await _this.bchjs.SLP.TokenType1.generateSendOpReturn(
tokenUtxos,
sendQty
)
const script = opReturn.script.toString('hex')
// console.log(`script: ${script}`)
res.status(200)
return res.json({ script, outputs: opReturn.outputs })
} catch (err) {
wlogger.error('Error in slp.js/generateSendOpReturn().', err)
// Decode the error message.
const { msg, status } = routeUtils.decodeError(err)
if (msg) {
res.status(status)
return res.json({ error: msg })
}
res.status(500)
return res.json({
error: 'Error in /generateSendOpReturn()'
})
}
}
}
module.exports = Slp
+315 -3
View File
@@ -753,9 +753,7 @@ describe('#ElectrumX Router', () => {
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox
.stub(electrumxRoute.electrumx, 'request')
.resolves([])
sandbox.stub(electrumxRoute.electrumx, 'request').resolves([])
}
// Call the details API.
@@ -999,4 +997,318 @@ describe('#ElectrumX Router', () => {
assert.equal(result.transactions.length, 2, '2 outputs for 2 inputs')
})
})
describe('#_mempoolFromElectrumx', () => {
it('should throw error for invalid address', async () => {
try {
// Address has invalid checksum.
const address = 'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
// Call the details API.
await electrumxRoute._mempoolFromElectrumx(address)
assert.equal(true, false, 'Unexpected code path')
} catch (err) {
assert.include(err.message, 'Invalid checksum')
}
})
it('should return empty array for address with no unconfirmed utxos', async () => {
// Address has invalid checksum.
const address = 'bchtest:qqtmlpspjakqlvywae226esrcdrj9auynuwadh55uf'
// Mock unit tests to prevent live network calls.
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox.stub(electrumxRoute.electrumx, 'request').resolves([])
}
// Call the details API.
const result = await electrumxRoute._mempoolFromElectrumx(address)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.equal(result.length, 0)
})
it('should get mempool for a single address', async () => {
const address = 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
// Mock unit tests to prevent live network calls.
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox
.stub(electrumxRoute.electrumx, 'request')
.resolves(mockData.mempool)
} else {
// Skip this test for integrations. Unconfirmed UTXOs are transient and
// not easy to test in real-time.
assert.equal(true, true)
return
}
// Call the details API.
const result = await electrumxRoute._mempoolFromElectrumx(address)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], 'height')
assert.property(result[0], 'tx_hash')
assert.property(result[0], 'fee')
})
})
describe('#getMempool', () => {
it('should throw 400 if address is empty', async () => {
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
assert.property(result, 'success')
assert.equal(result.success, false)
})
it('should throw 400 on array input', async () => {
req.params.address = ['qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.property(result, 'error')
assert.include(result.error, 'address can not be an array')
assert.property(result, 'success')
assert.equal(result.success, false)
})
it('should throw an error for an invalid address', async () => {
req.params.address = '02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
assert.property(result, 'success')
assert.equal(result.success, false)
})
it('should detect a network mismatch', async () => {
req.params.address = 'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.property(result, 'error')
assert.include(result.error, 'Invalid network', 'Proper error message')
assert.property(result, 'success')
assert.equal(result.success, false)
})
it('should pass errors from electrum-cash to user', async () => {
// Address has invalid checksum.
req.params.address =
'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
// Call the details API.
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, 'success')
assert.equal(result.success, false)
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
})
it('should get mempool for a single address', async () => {
req.params.address =
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
// Mock unit tests to prevent live network calls.
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox
.stub(electrumxRoute, '_mempoolFromElectrumx')
.resolves(mockData.mempool)
} else {
// Skip this test for integrations. Unconfirmed UTXOs are transient and
// not easy to test in real-time.
assert.equal(true, true)
return
}
// Call the details API.
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, 'success')
assert.equal(result.success, true)
assert.property(result, 'utxos')
assert.isArray(result.utxos)
assert.property(result.utxos[0], 'height')
assert.property(result.utxos[0], 'tx_hash')
assert.property(result.utxos[0], 'fee')
})
})
describe('#mempoolBulk', () => {
it('should throw an error for an empty body', async () => {
req.body = {}
const result = await electrumxRoute.mempoolBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
assert.include(
result.error,
'addresses needs to be an array',
'Proper error message'
)
})
it('should error on non-array single address', async () => {
req.body = {
address: 'qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
}
const result = await electrumxRoute.mempoolBulk(req, res)
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
assert.include(
result.error,
'addresses needs to be an array',
'Proper error message'
)
})
it('should throw 400 error if addresses array is too large', async () => {
const testArray = []
for (var i = 0; i < 25; i++) testArray.push('')
req.body.addresses = testArray
const result = await electrumxRoute.mempoolBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'Array too large')
})
it('should throw an error for an invalid address', async () => {
req.body = {
addresses: ['02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
}
const result = await electrumxRoute.mempoolBulk(req, res)
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
assert.include(
result.error,
'Invalid BCH address',
'Proper error message'
)
})
it('should detect a network mismatch', async () => {
req.body = {
addresses: ['bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4']
}
const result = await electrumxRoute.mempoolBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
assert.include(result.error, 'Invalid network', 'Proper error message')
})
it('should get mempool details for a single address', async () => {
req.body = {
addresses: ['bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7']
}
// Mock the Insight URL for unit tests.
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox
.stub(electrumxRoute, '_mempoolFromElectrumx')
.resolves(mockData.mempool)
} else {
// Skip this test for integrations. Unconfirmed UTXOs are transient and
// not easy to test in real-time.
assert.equal(true, true)
return
}
// Call the details API.
const result = await electrumxRoute.mempoolBulk(req, res)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, 'success')
assert.equal(result.success, true)
assert.property(result, 'utxos')
assert.isArray(result.utxos)
assert.property(result.utxos[0], 'address')
assert.property(result.utxos[0], 'utxos')
assert.isArray(result.utxos[0].utxos)
assert.property(result.utxos[0].utxos[0], 'height')
assert.property(result.utxos[0].utxos[0], 'tx_hash')
assert.property(result.utxos[0].utxos[0], 'fee')
})
it('should get mempool for multiple addresses', async () => {
req.body = {
addresses: [
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf',
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
]
}
// Mock the Insight URL for unit tests.
if (process.env.TEST === 'unit') {
electrumxRoute.isReady = true // Force flag.
sandbox
.stub(electrumxRoute, '_mempoolFromElectrumx')
.resolves(mockData.mempool)
} else {
// Skip this test for integrations. Unconfirmed UTXOs are transient and
// not easy to test in real-time.
assert.equal(true, true)
return
}
// Call the details API.
const result = await electrumxRoute.mempoolBulk(req, res)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, 'success')
assert.equal(result.success, true)
assert.isArray(result.utxos)
assert.isArray(result.utxos[0].utxos)
assert.equal(result.utxos.length, 2, '2 outputs for 2 inputs')
})
})
})
+24 -2
View File
@@ -14,7 +14,9 @@ util.inspect.defaultOptions = { depth: 1 }
// Exit if SLPDB URL is not defined.
if (!process.env.SLPDB_URL) {
throw new Error('SLPDB_URL and SLPDB_PASS must be defined in order to run these tests.')
throw new Error(
'SLPDB_URL and SLPDB_PASS must be defined in order to run these tests.'
)
}
const SLP = require('../../../src/routes/v3/slp')
@@ -35,7 +37,7 @@ describe('#slp', () => {
it('should get token stats for token with no mint baton', async () => {
req.params.tokenId =
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
// 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
// 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
const result = await slp.tokenStats(req, res)
// console.log(`result: ${util.inspect(result)}`)
@@ -99,4 +101,24 @@ describe('#slp', () => {
assert.equal(result.containsBaton, true)
})
})
describe('generateSendOpReturn', () => {
it('should return OP_RETURN script', async () => {
req.body.tokenUtxos = [
{
tokenId:
'0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1',
decimals: 0,
tokenQty: 2
}
]
req.body.sendQty = 1.5
const result = await slp.generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['script', 'outputs'])
assert.isNumber(result.outputs)
})
})
})
+10 -1
View File
@@ -31,8 +31,17 @@ const txHistory = [
}
]
const mempool = [
{
tx_hash: '45381031132c57b2ff1cbe8d8d3920cf9ed25efd9a0beb764bdb2f24c7d1c7e3',
height: 0,
fee: 24310
}
]
module.exports = {
utxos,
balance,
txHistory
txHistory,
mempool
}
+103 -2
View File
@@ -474,7 +474,9 @@ describe('#SLP', () => {
it('returns proper error when downstream service stalls', async () => {
// Mock the timeout error.
sandbox.stub(slpRoute.slpdb, 'getTokenStats').throws({ code: 'ECONNABORTED' })
sandbox
.stub(slpRoute.slpdb, 'getTokenStats')
.throws({ code: 'ECONNABORTED' })
req.params.tokenId =
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
@@ -492,7 +494,9 @@ describe('#SLP', () => {
it('returns proper error when downstream service is down', async () => {
// Mock the timeout error.
sandbox.stub(slpRoute.slpdb, 'getTokenStats').throws({ code: 'ECONNREFUSED' })
sandbox
.stub(slpRoute.slpdb, 'getTokenStats')
.throws({ code: 'ECONNREFUSED' })
req.params.tokenId =
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
@@ -787,6 +791,103 @@ describe('#SLP', () => {
assert.isArray(result)
})
})
describe('generateSendOpReturn()', () => {
const generateSendOpReturn = slpRoute.generateSendOpReturn
// Validate tokenUtxos input
it('should throw 400 if tokenUtxos is missing', async () => {
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'tokenUtxos needs to be an array.')
})
it('should throw 400 if tokenUtxos is empty', async () => {
req.body.tokenUtxos = ''
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'tokenUtxos needs to be an array.')
})
it('should throw 400 if tokenUtxos is not array', async () => {
req.body.tokenUtxos = 'tokenUtxos'
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'tokenUtxos needs to be an array.')
})
it('should throw 400 if tokenUtxos is empty array', async () => {
req.body.tokenUtxos = []
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'tokenUtxos array can not be empty.')
})
// Validate sendQty input
it('should throw 400 if sendQty is missing', async () => {
req.body.tokenUtxos = [{}, {}, {}]
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'sendQty must be a number')
})
it('should throw 400 if sendQty is empty', async () => {
req.body.tokenUtxos = [{}, {}, {}]
req.body.sendQty = ''
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'sendQty must be a number')
})
it('should throw 400 if sendQty is not a number', async () => {
req.body.tokenUtxos = [{}, {}, {}]
req.body.sendQty = 'sendQty'
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['error'])
assert.include(result.error, 'sendQty must be a number')
})
it('should return OP_RETURN script', async () => {
req.body.tokenUtxos = [
{
tokenId:
'0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1',
decimals: 0,
tokenQty: 2
}
]
req.body.sendQty = 1.5
if (process.env.TEST === 'unit') {
sandbox
.stub(slpRoute.bchjs.SLP.TokenType1, 'generateSendOpReturn')
.resolves({ script: '<Buffer ', outputs: 2 })
}
const result = await generateSendOpReturn(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.hasAllKeys(result, ['script', 'outputs'])
assert.isNumber(result.outputs)
})
})
})
/*