From 93904a632f1be6b76ca25d9e02c30a0b3f7ed7dc Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 8 Aug 2021 20:01:38 -0700 Subject: [PATCH] fix(apiToken): Changed _this.axiosOptions to this.axiosOptions --- src/blockchain.js | 52 ++++++++++++++++++++--------------------- src/control.js | 8 +++---- src/dsproof.js | 2 +- src/electrumx.js | 28 +++++++++++----------- src/encryption.js | 6 +++-- src/generating.js | 6 ++--- src/mining.js | 12 +++++----- src/ninsight.js | 20 ++++++++-------- src/price.js | 12 +++++----- src/raw-transactions.js | 8 +++---- src/slp/nft1.js | 8 +++---- src/slp/tokentype1.js | 18 +++++++------- src/slp/utils.js | 34 +++++++++++++-------------- src/util.js | 6 ++--- 14 files changed, 111 insertions(+), 109 deletions(-) diff --git a/src/blockchain.js b/src/blockchain.js index a953181..f758fbf 100644 --- a/src/blockchain.js +++ b/src/blockchain.js @@ -5,7 +5,7 @@ const axios = require('axios') -let _this +// let _this class Blockchain { constructor (config) { @@ -29,7 +29,7 @@ class Blockchain { } } - _this = this + // _this = this } /** @@ -54,7 +54,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getBestBlockHash`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -112,7 +112,7 @@ class Blockchain { blockhash, verbosity }, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -162,7 +162,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getBlockchainInfo`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -193,7 +193,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getBlockCount`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -226,7 +226,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getBlockHash/${height}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -273,7 +273,7 @@ class Blockchain { if (typeof hash === 'string') { const response = await axios.get( `${this.restURL}blockchain/getBlockHeader/${hash}?verbose=${verbose}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -287,7 +287,7 @@ class Blockchain { hashes: hash, verbose: verbose }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -334,7 +334,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getChainTips`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -366,7 +366,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getDifficulty`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -382,7 +382,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getMempoolAncestors/${txid}?verbose=${verbose}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -397,7 +397,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getMempoolDescendants/${txid}?verbose=${verbose}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -494,7 +494,7 @@ class Blockchain { if (typeof txid === 'string') { const response = await axios.get( `${this.restURL}blockchain/getMempoolEntry/${txid}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -505,7 +505,7 @@ class Blockchain { { txids: txid }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -545,7 +545,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getMempoolInfo`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -592,7 +592,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/getRawMempool?vebose=${verbose}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -636,7 +636,7 @@ class Blockchain { // Send the request to the REST API. // const response = await axios.get( // `${this.restURL}blockchain/getTxOut/${txid}/${n}?includeMempool=${includeMempool}`, - // _this.axiosOptions + // this.axiosOptions // ) const response = await axios.post( `${this.restURL}blockchain/getTxOut`, @@ -645,7 +645,7 @@ class Blockchain { vout: n, mempool: includeMempool }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -698,7 +698,7 @@ class Blockchain { const path = `${this.restURL}blockchain/getTxOutProof/${txids}` // if (blockhash) path = `${path}?blockhash=${blockhash}` - const response = await axios.get(path, _this.axiosOptions) + const response = await axios.get(path, this.axiosOptions) return response.data // Array of txids. @@ -709,7 +709,7 @@ class Blockchain { { txids: txids }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -726,7 +726,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/preciousBlock/${blockhash}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -739,7 +739,7 @@ class Blockchain { try { const response = await axios.post( `${this.restURL}blockchain/pruneBlockchain/${height}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -752,7 +752,7 @@ class Blockchain { try { const response = await axios.get( `${this.restURL}blockchain/verifyChain?checklevel=${checklevel}&nblocks=${nblocks}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -804,7 +804,7 @@ class Blockchain { if (typeof proof === 'string') { const response = await axios.get( `${this.restURL}blockchain/verifyTxOutProof/${proof}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -816,7 +816,7 @@ class Blockchain { { proofs: proof }, - _this.axiosOptions + this.axiosOptions ) return response.data diff --git a/src/control.js b/src/control.js index 8904270..903383c 100644 --- a/src/control.js +++ b/src/control.js @@ -4,7 +4,7 @@ const axios = require('axios') -let _this // Global reference to the instance of this class. +// let _this // Global reference to the instance of this class. class Control { constructor (config) { @@ -28,7 +28,7 @@ class Control { } } - _this = this + // _this = this } /** @@ -81,7 +81,7 @@ class Control { try { const response = await axios.get( `${this.restURL}control/getNetworkInfo`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -94,7 +94,7 @@ class Control { try { const response = await axios.get( `${this.restURL}control/getMemoryInfo`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { diff --git a/src/dsproof.js b/src/dsproof.js index bb116ec..1c04613 100644 --- a/src/dsproof.js +++ b/src/dsproof.js @@ -68,7 +68,7 @@ class DSProof { } const response = await _this.axios.get( `${this.restURL}dsproof/getdsproof/${txid}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { diff --git a/src/electrumx.js b/src/electrumx.js index 2e8456c..035e417 100644 --- a/src/electrumx.js +++ b/src/electrumx.js @@ -8,7 +8,7 @@ const axios = require('axios') // Local libraries. const Blockchain = require('./blockchain') -let _this +// let _this class ElectrumX { constructor (config) { @@ -34,7 +34,7 @@ class ElectrumX { this.blockchain = new Blockchain(config) - _this = this + // _this = this } /** @@ -108,7 +108,7 @@ class ElectrumX { if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/utxos/${address}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -119,7 +119,7 @@ class ElectrumX { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -192,7 +192,7 @@ class ElectrumX { if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/balance/${address}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -203,7 +203,7 @@ class ElectrumX { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -290,7 +290,7 @@ class ElectrumX { if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/transactions/${address}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -302,7 +302,7 @@ class ElectrumX { addresses: address, usrObj // pass user data when making an internal call. }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -383,7 +383,7 @@ class ElectrumX { if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/unconfirmed/${address}`, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -394,7 +394,7 @@ class ElectrumX { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -452,7 +452,7 @@ class ElectrumX { try { const response = await axios.get( `${this.restURL}electrumx/block/headers/${height}?count=${count}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -543,7 +543,7 @@ class ElectrumX { if (typeof txid === 'string') { const response = await axios.get( `${this.restURL}electrumx/tx/data/${txid}`, - _this.axiosOptions + this.axiosOptions ) return response.data } else if (Array.isArray(txid)) { @@ -552,7 +552,7 @@ class ElectrumX { { txids: txid }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -592,7 +592,7 @@ class ElectrumX { const response = await axios.post( `${this.restURL}electrumx/tx/broadcast`, { txHex }, - _this.axiosOptions + this.axiosOptions ) return response.data diff --git a/src/encryption.js b/src/encryption.js index ce0ae37..d80e026 100644 --- a/src/encryption.js +++ b/src/encryption.js @@ -35,11 +35,13 @@ class Encryption { // Search the blockchain for a public key associated with a BCH address. async getPubKey (addr) { try { - if (!addr || typeof addr !== 'string') { throw new Error('Input must be a valid Bitcoin Cash address.') } + if (!addr || typeof addr !== 'string') { + throw new Error('Input must be a valid Bitcoin Cash address.') + } const response = await _this.axios.get( `${this.restURL}encryption/publickey/${addr}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { diff --git a/src/generating.js b/src/generating.js index df0efb5..ee4c313 100644 --- a/src/generating.js +++ b/src/generating.js @@ -1,6 +1,6 @@ const axios = require('axios') -let _this +// let _this class Generating { constructor (config) { @@ -24,14 +24,14 @@ class Generating { } } - _this = this + // _this = this } async generateToAddress (blocks, address, maxtries = 1000000) { try { const response = await axios.post( `${this.restURL}generating/generateToAddress/${blocks}/${address}?maxtries=${maxtries}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { diff --git a/src/mining.js b/src/mining.js index 8c3e348..6d39a10 100644 --- a/src/mining.js +++ b/src/mining.js @@ -1,6 +1,6 @@ const axios = require('axios') -let _this +// let _this class Mining { constructor (config) { @@ -24,14 +24,14 @@ class Mining { } } - _this = this + // _this = this } async getBlockTemplate (templateRequest) { try { const response = await axios.get( `${this.restURL}mining/getBlockTemplate/${templateRequest}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -44,7 +44,7 @@ class Mining { try { const response = await axios.get( `${this.restURL}mining/getMiningInfo`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -57,7 +57,7 @@ class Mining { try { const response = await axios.get( `${this.restURL}mining/getNetworkHashps?nblocks=${nblocks}&height=${height}`, - _this.axiosOptions + this.axiosOptions ) return response.data } catch (error) { @@ -71,7 +71,7 @@ class Mining { if (parameters) path = `${path}?parameters=${parameters}` try { - const response = await axios.post(path, _this.axiosOptions) + const response = await axios.post(path, this.axiosOptions) return response.data } catch (error) { if (error.response && error.response.data) throw error.response.data diff --git a/src/ninsight.js b/src/ninsight.js index 4396db8..2839b91 100644 --- a/src/ninsight.js +++ b/src/ninsight.js @@ -5,7 +5,7 @@ const axios = require('axios') -let _this +// let _this class Ninsight { constructor (config) { @@ -27,7 +27,7 @@ class Ninsight { } } - _this = this + // _this = this } /** @@ -75,7 +75,7 @@ class Ninsight { { addresses: [address] }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -86,7 +86,7 @@ class Ninsight { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -143,7 +143,7 @@ class Ninsight { { addresses: [address] }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -153,7 +153,7 @@ class Ninsight { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -219,7 +219,7 @@ class Ninsight { { addresses: [address] }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -229,7 +229,7 @@ class Ninsight { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -292,7 +292,7 @@ class Ninsight { { txids: [txid] }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -302,7 +302,7 @@ class Ninsight { { txids: txid }, - _this.axiosOptions + this.axiosOptions ) return response.data diff --git a/src/price.js b/src/price.js index 052a080..7926f06 100644 --- a/src/price.js +++ b/src/price.js @@ -1,10 +1,10 @@ const axios = require('axios') -let _this +// let _this class Price { constructor (config) { - _this = this + // _this = this this.restURL = config.restURL this.apiToken = config.apiToken @@ -68,7 +68,7 @@ class Price { try { const response = await this.axios.get( `${this.restURL}price/usd`, - _this.axiosOptions + this.axiosOptions ) // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) @@ -111,7 +111,7 @@ class Price { try { const response = await this.axios.get( `${this.restURL}price/rates`, - _this.axiosOptions + this.axiosOptions ) // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) @@ -146,7 +146,7 @@ class Price { try { const response = await this.axios.get( `${this.restURL}price/bchausd`, - _this.axiosOptions + this.axiosOptions ) // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) @@ -181,7 +181,7 @@ class Price { try { const response = await this.axios.get( `${this.restURL}price/bchusd`, - _this.axiosOptions + this.axiosOptions ) // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) diff --git a/src/raw-transactions.js b/src/raw-transactions.js index 0fb9b47..80923ce 100644 --- a/src/raw-transactions.js +++ b/src/raw-transactions.js @@ -259,10 +259,10 @@ class RawTransactions { async getRawTransaction (txid, verbose = false, usrObj = null) { try { if (typeof txid === 'string') { - console.log( - 'getRawTransaction() this.axiosOptions: ', - this.axiosOptions - ) + // console.log( + // 'getRawTransaction() this.axiosOptions: ', + // this.axiosOptions + // ) const response = await axios.get( `${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=${verbose}`, this.axiosOptions diff --git a/src/slp/nft1.js b/src/slp/nft1.js index 9cf5f50..1f52f9f 100644 --- a/src/slp/nft1.js +++ b/src/slp/nft1.js @@ -17,7 +17,7 @@ const Address = require('./address') // const BigNumber = require('bignumber.js') const slpMdm = require('slp-mdm') -let _this +// let _this // const addy = new Address() let addy const TransactionBuilder = require('../transaction-builder') @@ -31,7 +31,7 @@ class Nft1 { // Instantiate the transaction builder. TransactionBuilder.setAddress(addy) - _this = this + // _this = this } /** @@ -446,7 +446,7 @@ class Nft1 { if (typeof groupId === 'string') { const response = await axios.get( `${this.restURL}slp/nftChildren/${groupId}`, - _this.axiosOptions + this.axiosOptions ) return response.data } @@ -498,7 +498,7 @@ class Nft1 { if (typeof tokenId === 'string') { const response = await axios.get( `${this.restURL}slp/nftGroup/${tokenId}`, - _this.axiosOptions + this.axiosOptions ) return response.data } diff --git a/src/slp/tokentype1.js b/src/slp/tokentype1.js index 307d18e..f828f75 100644 --- a/src/slp/tokentype1.js +++ b/src/slp/tokentype1.js @@ -125,13 +125,13 @@ class TokenType1 { // console.log('baseChange: ', baseChange) // Check for potential burns - const outputQty = new BigNumber(baseChange).plus( - new BigNumber(baseQty) - ) + const outputQty = new BigNumber(baseChange).plus(new BigNumber(baseQty)) const inputQty = new BigNumber(totalTokens) const tokenOutputDelta = outputQty.minus(inputQty).toString() !== '0' if (tokenOutputDelta) { - throw new Error('Token transaction inputs do not match outputs, cannot send transaction') + throw new Error( + 'Token transaction inputs do not match outputs, cannot send transaction' + ) } // Generate the OP_RETURN as a Buffer. @@ -152,7 +152,9 @@ class TokenType1 { const tokenSingleOutputError = noChangeOutputQty.minus(noChangeInputQty).toString() !== '0' if (tokenSingleOutputError) { - throw new Error('Token transaction inputs do not match outputs, cannot send transaction') + throw new Error( + 'Token transaction inputs do not match outputs, cannot send transaction' + ) } // Generate the OP_RETURN as a Buffer. @@ -378,9 +380,7 @@ class TokenType1 { // Throw an error if the minting baton could not be found. if (!mintBatonUtxo) { - throw new Error( - 'Minting baton could not be found in tokenUtxos array.' - ) + throw new Error('Minting baton could not be found in tokenUtxos array.') } const tokenId = mintBatonUtxo.tokenId @@ -454,7 +454,7 @@ class TokenType1 { const result = await _this.axios.post( `${this.restURL}slp/generatesendopreturn`, data, - _this.axiosOptions + this.axiosOptions ) const slpSendObj = result.data diff --git a/src/slp/utils.js b/src/slp/utils.js index 3147f8f..f6c6602 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -217,14 +217,14 @@ class Utils { try { let response if (method === 'get') { - response = await _this.axios.get(path, _this.axiosOptions) + response = await _this.axios.get(path, this.axiosOptions) } else { response = await _this.axios.post( path, { tokenIds: id }, - _this.axiosOptions + this.axiosOptions ) } return response.data @@ -315,7 +315,7 @@ class Utils { if (typeof address === 'string') { const path = `${this.restURL}slp/balancesForAddress/${address}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data // Array of addresses. @@ -328,7 +328,7 @@ class Utils { { addresses: address }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -380,7 +380,7 @@ class Utils { try { const path = `${this.restURL}slp/balancesForToken/${tokenId}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { if (error.response && error.response.data) throw error.response.data @@ -450,7 +450,7 @@ class Utils { else txids = txid try { - console.log('validateTxid() this.axiosOptions: ', this.axiosOptions) + // console.log('validateTxid() this.axiosOptions: ', this.axiosOptions) const response = await _this.axios.post( path, { @@ -521,7 +521,7 @@ class Utils { const path = `${this.restURL}slp/validateTxid2/${txid}` - console.log('validateTxid2() this.axiosOptions: ', this.axiosOptions) + // console.log('validateTxid2() this.axiosOptions: ', this.axiosOptions) const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { @@ -591,7 +591,7 @@ class Utils { // Retrieve the whitelist from the REST API if we haven't gotten it yet. if (this.whitelist.length === 0) { - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) this.whitelist = response.data @@ -668,7 +668,7 @@ class Utils { else txids = txid try { - console.log('validateTxid3() this.axiosOptions: ', this.axiosOptions) + // console.log('validateTxid3() this.axiosOptions: ', this.axiosOptions) const response = await _this.axios.post( path, { @@ -735,7 +735,7 @@ class Utils { try { const path = `${this.restURL}slp/tokenStats/${tokenId}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { @@ -806,7 +806,7 @@ class Utils { try { const path = `${this.restURL}slp/transactions/${tokenId}/${address}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { @@ -846,7 +846,7 @@ class Utils { try { const path = `${this.restURL}slp/burnTotal/${transactionId}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { @@ -890,7 +890,7 @@ class Utils { // console.log(`this.restURL: ${this.restURL}`) const path = `${this.restURL}slp/txDetails/${txid}` - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) return response.data } catch (error) { if (error.response && error.response.data) throw error.response.data @@ -970,7 +970,7 @@ class Utils { // CT: 2/24/21 Deprected GET in favor of POST, to pass IP address. // Retrieve the transaction object from the full node. const path = `${this.restURL}rawtransactions/getRawTransaction` - console.log('decodeOpReturn() this.axiosOptions: ', this.axiosOptions) + // console.log('decodeOpReturn() this.axiosOptions: ', this.axiosOptions) const response = await this.axios.post( path, { @@ -1853,7 +1853,7 @@ class Utils { utxos: utxos, usrObj }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -1891,7 +1891,7 @@ class Utils { { utxos: utxos }, - _this.axiosOptions + this.axiosOptions ) return response.data @@ -1931,7 +1931,7 @@ class Utils { const path = `${this.restURL}slp/status` try { - const response = await _this.axios.get(path, _this.axiosOptions) + const response = await _this.axios.get(path, this.axiosOptions) // console.log( // `getStatus response.data: ${JSON.stringify(response.data, null, 2)}` // ) diff --git a/src/util.js b/src/util.js index 27d817c..724d51a 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,6 @@ const axios = require('axios') -let _this +// let _this class Util { constructor (config) { @@ -24,7 +24,7 @@ class Util { } } - _this = this + // _this = this } /** @@ -225,7 +225,7 @@ class Util { if (typeof address === 'string') { const response = await axios.get( `${this.restURL}util/validateAddress/${address}`, - _this.axiosOptions + this.axiosOptions ) return response.data