Merge pull request #110 from Permissionless-Software-Foundation/ct-unstable

fix(origin): Testing idea around passing origin when bch-api calls bc…
This commit is contained in:
Chris Troutner
2021-02-24 13:29:05 -08:00
committed by GitHub
2 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
"test:integration:local:abc": "export RESTURL=http://localhost:3000/v4/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/", "test:integration:local:abc": "export RESTURL=http://localhost:3000/v4/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
"test:integration:local:bchn": "export RESTURL=http://localhost:3000/v4/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/", "test:integration:local:bchn": "export RESTURL=http://localhost:3000/v4/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v4/ mocha --timeout 30000 test/integration/chains/testnet", "test:integration:local:testnet": "RESTURL=http://localhost:4000/v4/ mocha --timeout 30000 test/integration/chains/testnet",
"test:temp": "export RESTURL=https://bchn.fullstack.cash/v4/ && mocha --timeout 30000 -g '#Encryption' test/integration/", "test:temp": "export RESTURL=http://localhost:3000/v4/ && mocha --timeout 30000 -g '#hydrateUtxos' test/integration/",
"test:temp2": "mocha --timeout=30000 -g '#Util' test/unit/", "test:temp2": "mocha --timeout=30000 -g '#Util' test/unit/",
"coverage": "nyc report --reporter=text-lcov | coveralls", "coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/",
+11 -9
View File
@@ -436,10 +436,11 @@ class Utils {
// will be like the examples above. If SLPDB has fallen behind real-time // will be like the examples above. If SLPDB has fallen behind real-time
// processing, it will return this output: // processing, it will return this output:
// [ null ] // [ null ]
async validateTxid (txid) { async validateTxid (txid, origin = null) {
const path = `${this.restURL}slp/validateTxid` const path = `${this.restURL}slp/validateTxid`
// console.log(`txid: ${JSON.stringify(txid, null, 2)}`) // console.log(`txid: ${JSON.stringify(txid, null, 2)}`)
console.log('validateTxid origin: ', origin)
// Handle a single TXID or an array of TXIDs. // Handle a single TXID or an array of TXIDs.
let txids let txids
@@ -649,11 +650,12 @@ class Utils {
* '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476', * '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476',
* valid: true } ] * valid: true } ]
*/ */
async validateTxid3 (txid) { async validateTxid3 (txid, origin = null) {
const path = `${this.restURL}slp/validateTxid3` const path = `${this.restURL}slp/validateTxid3`
// console.log(`txid: ${JSON.stringify(txid, null, 2)}`) // console.log(`txid: ${JSON.stringify(txid, null, 2)}`)
// console.log(`path: ${JSON.stringify(path, null, 2)}`) // console.log(`path: ${JSON.stringify(path, null, 2)}`)
console.log('origin: ', origin)
// Handle a single TXID or an array of TXIDs. // Handle a single TXID or an array of TXIDs.
let txids let txids
@@ -664,7 +666,8 @@ class Utils {
const response = await _this.axios.post( const response = await _this.axios.post(
path, path,
{ {
txids: txids txids: txids,
origin
}, },
_this.axiosOptions _this.axiosOptions
) )
@@ -1061,7 +1064,7 @@ class Utils {
// https://github.com/Bitcoin-com/slp-sdk/issues/84 // https://github.com/Bitcoin-com/slp-sdk/issues/84
// CT 5/31/20: Refactored to use slp-parse library. // CT 5/31/20: Refactored to use slp-parse library.
async tokenUtxoDetails (utxos) { async tokenUtxoDetails (utxos, origin = null) {
try { try {
// Throw error if input is not an array. // Throw error if input is not an array.
if (!Array.isArray(utxos)) throw new Error('Input must be an array.') if (!Array.isArray(utxos)) throw new Error('Input must be an array.')
@@ -1113,7 +1116,7 @@ class Utils {
// information. // information.
// Validate using a 'waterfall' of validators. // Validate using a 'waterfall' of validators.
utxo.isValid = await this.waterfallValidateTxid(utxo.txid) utxo.isValid = await this.waterfallValidateTxid(utxo.txid, origin)
// console.log(`isValid: ${JSON.stringify(utxo.isValid, null, 2)}`) // console.log(`isValid: ${JSON.stringify(utxo.isValid, null, 2)}`)
} }
} }
@@ -1450,8 +1453,7 @@ class Utils {
* // returns * // returns
* true * true
*/ */
async waterfallValidateTxid (txid, origin = null) {
async waterfallValidateTxid (txid) {
try { try {
// console.log('txid: ', txid) // console.log('txid: ', txid)
@@ -1483,7 +1485,7 @@ class Utils {
// validateTxid2() uses slp-validate, which has a different output format. // validateTxid2() uses slp-validate, which has a different output format.
// Validate against the whitelist SLPDB first. // Validate against the whitelist SLPDB first.
const whitelistResult = await this.validateTxid3(txid) const whitelistResult = await this.validateTxid3(txid, origin)
// console.log( // console.log(
// `whitelist-SLPDB for ${txid}: ${JSON.stringify( // `whitelist-SLPDB for ${txid}: ${JSON.stringify(
// whitelistResult, // whitelistResult,
@@ -1504,7 +1506,7 @@ class Utils {
} }
// Try the general SLPDB, if the whitelist returned null. // Try the general SLPDB, if the whitelist returned null.
const generalResult = await this.validateTxid(txid) const generalResult = await this.validateTxid(txid, origin)
// console.log( // console.log(
// `validateTxid() isValid: ${JSON.stringify(generalResult, null, 2)}` // `validateTxid() isValid: ${JSON.stringify(generalResult, null, 2)}`
// ) // )