From 9919f811b0a742a3018ff2f51db36a7e3b7f53d1 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 24 Feb 2021 13:26:08 -0800 Subject: [PATCH] fix(origin): Testing idea around passing origin when bch-api calls bch-js --- package.json | 2 +- src/slp/utils.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index e67b66f..d37bb05 100644 --- a/package.json +++ b/package.json @@ -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: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: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/", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", diff --git a/src/slp/utils.js b/src/slp/utils.js index 71bf00a..3b9ae3e 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -436,10 +436,11 @@ class Utils { // will be like the examples above. If SLPDB has fallen behind real-time // processing, it will return this output: // [ null ] - async validateTxid (txid) { + async validateTxid (txid, origin = null) { const path = `${this.restURL}slp/validateTxid` // console.log(`txid: ${JSON.stringify(txid, null, 2)}`) + console.log('validateTxid origin: ', origin) // Handle a single TXID or an array of TXIDs. let txids @@ -649,11 +650,12 @@ class Utils { * '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476', * valid: true } ] */ - async validateTxid3 (txid) { + async validateTxid3 (txid, origin = null) { const path = `${this.restURL}slp/validateTxid3` // console.log(`txid: ${JSON.stringify(txid, null, 2)}`) // console.log(`path: ${JSON.stringify(path, null, 2)}`) + console.log('origin: ', origin) // Handle a single TXID or an array of TXIDs. let txids @@ -664,7 +666,8 @@ class Utils { const response = await _this.axios.post( path, { - txids: txids + txids: txids, + origin }, _this.axiosOptions ) @@ -1061,7 +1064,7 @@ class Utils { // https://github.com/Bitcoin-com/slp-sdk/issues/84 // CT 5/31/20: Refactored to use slp-parse library. - async tokenUtxoDetails (utxos) { + async tokenUtxoDetails (utxos, origin = null) { try { // Throw error if input is not an array. if (!Array.isArray(utxos)) throw new Error('Input must be an array.') @@ -1113,7 +1116,7 @@ class Utils { // information. // 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)}`) } } @@ -1450,8 +1453,7 @@ class Utils { * // returns * true */ - - async waterfallValidateTxid (txid) { + async waterfallValidateTxid (txid, origin = null) { try { // console.log('txid: ', txid) @@ -1483,7 +1485,7 @@ class Utils { // validateTxid2() uses slp-validate, which has a different output format. // Validate against the whitelist SLPDB first. - const whitelistResult = await this.validateTxid3(txid) + const whitelistResult = await this.validateTxid3(txid, origin) // console.log( // `whitelist-SLPDB for ${txid}: ${JSON.stringify( // whitelistResult, @@ -1504,7 +1506,7 @@ class Utils { } // Try the general SLPDB, if the whitelist returned null. - const generalResult = await this.validateTxid(txid) + const generalResult = await this.validateTxid(txid, origin) // console.log( // `validateTxid() isValid: ${JSON.stringify(generalResult, null, 2)}` // )