Compare commits

..
11 Commits
Author SHA1 Message Date
Chris Troutner 955a5e428e Merge pull request #168 from Permissionless-Software-Foundation/ct-unstable
fix(getRawTransaction): Fixing integration test
2021-08-09 14:56:52 -07:00
Chris Troutner 44c3bf44f9 fix(getRawTransaction): Fixing integration test 2021-08-09 14:54:49 -07:00
Chris Troutner 31ce84abb0 Merge pull request #167 from Permissionless-Software-Foundation/ct-unstable
fix(waterfallValidateTxid): Skipping validateTxid3() if it throws an error
2021-08-09 10:39:18 -07:00
Chris Troutner 40fa4b6bc1 linting 2021-08-09 10:36:07 -07:00
Chris Troutner 8c5e111d60 fix(waterfallValidateTxid): Skipping validateTxid3() if it throws an error 2021-08-09 10:35:51 -07:00
Chris Troutner 8965dfc57f Merge pull request #166 from Permissionless-Software-Foundation/ct-unstable
fix(apiToken): Changed _this.axiosOptions to this.axiosOptions
2021-08-08 20:06:05 -07:00
Chris Troutner 93904a632f fix(apiToken): Changed _this.axiosOptions to this.axiosOptions 2021-08-08 20:01:38 -07:00
Chris Troutner 851d4c404c fix(rate limits): Fixing more bugs with rate limit handling axios.options 2021-08-08 19:51:01 -07:00
Chris Troutner 44bac45c32 Updating README 2021-08-08 18:42:04 -07:00
Chris Troutner 95ee8054be Merge pull request #165 from Permissionless-Software-Foundation/ct-unstable
fix(Transactions.get()): Adding extra error handling for rate limits
2021-08-08 18:40:43 -07:00
Chris Troutner 547b28cac8 fix(Transactions.get()): Adding extra error handling for rate limits 2021-08-08 18:38:46 -07:00
35 changed files with 218 additions and 169 deletions
+4 -4
View File
@@ -35,15 +35,15 @@ const BCHJS = require("@psf/bch-js")
let bchjs = new BCHJS() // Defaults to BCHN network.
// testnet
bchjs = new BCHJS({ restURL: 'https://testnet3.fullstack.cash/v4/' })
bchjs = new BCHJS({ restURL: 'https://testnet3.fullstack.cash/v5/' })
```
This library is intended to be paired with
the [bch-api](https://github.com/Permissionless-Software-Foundation/bch-api) REST API, and the infrastructure provided by [FullStack.cash](https://fullstack.cash). The `restURL` property can be changed to work with different Bitcoin Cash networks:
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v4/
- ABC Mainnet REST API server: https://abc.fullstack.cash/v4/
- Testnet3 REST API server: https://testnet3.fullstack.cash/v4/
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v5/
- ABC Mainnet REST API server: https://abc.fullstack.cash/v5/
- Testnet3 REST API server: https://testnet3.fullstack.cash/v5/
- Check server status: https://metrics.fullstack.cash
### API Key
+26 -26
View File
@@ -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
+4 -4
View File
@@ -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) {
+1 -1
View File
@@ -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) {
+14 -14
View File
@@ -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
+4 -2
View File
@@ -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) {
+3 -3
View File
@@ -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) {
+6 -6
View File
@@ -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
+10 -10
View File
@@ -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
+6 -6
View File
@@ -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)}`)
+25 -6
View File
@@ -259,6 +259,10 @@ class RawTransactions {
async getRawTransaction (txid, verbose = false, usrObj = null) {
try {
if (typeof txid === 'string') {
// console.log(
// 'getRawTransaction() this.axiosOptions: ',
// this.axiosOptions
// )
const response = await axios.get(
`${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=${verbose}`,
this.axiosOptions
@@ -284,8 +288,13 @@ class RawTransactions {
throw new Error('Input must be a string or array of strings.')
} catch (error) {
if (error.error) throw new Error(error.error)
else if (error.response && error.response.data) throw error.response.data
else throw error
// This case handles rate limit errors.
if (error.response && error.response.data && error.response.data.error) {
throw new Error(error.response.data.error)
} else if (error.response && error.response.data) {
throw error.response.data
} else throw error
}
}
@@ -330,8 +339,13 @@ class RawTransactions {
return retArray
} catch (error) {
if (error.error) throw new Error(error.error)
else if (error.response && error.response.data) throw error.response.data
else throw error
// This case handles rate limit errors.
if (error.response && error.response.data && error.response.data.error) {
throw new Error(error.response.data.error)
} else if (error.response && error.response.data) {
throw error.response.data
} else throw error
}
}
@@ -386,8 +400,13 @@ class RawTransactions {
return txDetails
} catch (error) {
if (error.error) throw new Error(error.error)
else if (error.response && error.response.data) throw error.response.data
else throw error
// This case handles rate limit errors.
if (error.response && error.response.data && error.response.data.error) {
throw new Error(error.response.data.error)
} else if (error.response && error.response.data) {
throw error.response.data
} else throw error
}
}
+4 -4
View File
@@ -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
}
+9 -9
View File
@@ -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
+51 -34
View File
@@ -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,13 +450,14 @@ class Utils {
else txids = txid
try {
// console.log('validateTxid() this.axiosOptions: ', this.axiosOptions)
const response = await _this.axios.post(
path,
{
txids: txids,
usrObj // pass user data when making an internal call.
},
_this.axiosOptions
this.axiosOptions
)
// console.log(
// `validateTxid response.data: ${JSON.stringify(response.data, null, 2)}`
@@ -520,7 +521,8 @@ class Utils {
const path = `${this.restURL}slp/validateTxid2/${txid}`
const response = await _this.axios.get(path, _this.axiosOptions)
// console.log('validateTxid2() this.axiosOptions: ', 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
@@ -589,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
@@ -666,13 +668,14 @@ class Utils {
else txids = txid
try {
// console.log('validateTxid3() this.axiosOptions: ', this.axiosOptions)
const response = await _this.axios.post(
path,
{
txids: txids,
usrObj // pass user data when making an internal call.
},
_this.axiosOptions
this.axiosOptions
)
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
@@ -732,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) {
@@ -803,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) {
@@ -843,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) {
@@ -887,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
@@ -967,14 +970,15 @@ 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`
const response = await _this.axios.post(
// console.log('decodeOpReturn() this.axiosOptions: ', this.axiosOptions)
const response = await this.axios.post(
path,
{
verbose: true,
txids: [txid],
usrObj // pass user data when making an internal call.
},
_this.axiosOptions
this.axiosOptions
)
const txDetails = response.data[0]
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
@@ -1584,25 +1588,31 @@ class Utils {
// Note: validateTxid3() has the same output as validateTxid().
// validateTxid2() uses slp-validate, which has a different output format.
// Validate against the whitelist SLPDB first.
const whitelistResult = await this.validateTxid3(txid, usrObj)
// console.log(
// `whitelist-SLPDB for ${txid}: ${JSON.stringify(
// whitelistResult,
// null,
// 2
// )}`
// )
// If the whitelist SLPDB is having issues, the try/catch will skip it
// and continue execution.
try {
// Validate against the whitelist SLPDB first.
const whitelistResult = await this.validateTxid3(txid, usrObj)
// console.log(
// `whitelist-SLPDB for ${txid}: ${JSON.stringify(
// whitelistResult,
// null,
// 2
// )}`
// )
// Safely retrieve the returned value.
if (whitelistResult[0] !== null) isValid = whitelistResult[0].valid
// Safely retrieve the returned value.
if (whitelistResult[0] !== null) isValid = whitelistResult[0].valid
// Exit if isValid is not null.
if (isValid !== null) {
// Save to the cache.
cachedTxValidation[txid] = isValid
// Exit if isValid is not null.
if (isValid !== null) {
// Save to the cache.
cachedTxValidation[txid] = isValid
return isValid
return isValid
}
} catch {
/* exit quietly */
}
// Try the general SLPDB, if the whitelist returned null.
@@ -1647,6 +1657,11 @@ class Utils {
// could not be validated.
return isValid
} catch (error) {
// This case handles rate limit errors.
if (error.response && error.response.data && error.response.data.error) {
throw new Error(error.response.data.error)
}
// console.log('Error in waterfallValidateTxid()')
if (error.response && error.response.data) throw error.response.data
throw error
@@ -1844,11 +1859,13 @@ class Utils {
utxos: utxos,
usrObj
},
_this.axiosOptions
this.axiosOptions
)
return response.data
} catch (error) {
console.log('Error in hydrateUtxos(): ', error)
if (error.response && error.response.data) {
throw new Error(JSON.stringify(error.response.data, null, 2))
}
@@ -1882,7 +1899,7 @@ class Utils {
{
utxos: utxos
},
_this.axiosOptions
this.axiosOptions
)
return response.data
@@ -1922,7 +1939,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)}`
// )
+10
View File
@@ -131,6 +131,11 @@ class Transaction {
} catch (err) {
// console.log('Error: ', err)
// This case handles rate limit errors.
if (err.response && err.response.data && err.response.data.error) {
throw new Error(err.response.data.error)
}
// If decoding the op_return fails, then it's not an SLP transaction,
// and the non-hyrated TX details can be returned.
return txDetails
@@ -140,6 +145,11 @@ class Transaction {
} catch (err) {
// console.error('Error in transactions.js/get(): ', err)
// This case handles rate limit errors.
if (err.response && err.response.data && err.response.data.error) {
throw new Error(err.response.data.error)
}
if (err.error) throw new Error(err.error)
throw err
}
+3 -3
View File
@@ -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
+1 -1
View File
@@ -22,7 +22,7 @@ util.inspect.defaultOptions = {
describe('#blockchain', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#getBestBlockHash', () => {
@@ -20,7 +20,7 @@ util.inspect.defaultOptions = {
describe('#rawtransaction', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
/*
+1 -1
View File
@@ -25,7 +25,7 @@ describe('#SLP', () => {
beforeEach(async () => {
// Introduce a delay so that the BVT doesn't trip the rate limits.
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
bchjs = new BCHJS({ restURL: process.env.RESTURL })
})
@@ -11,7 +11,7 @@ describe('#UTXO', () => {
beforeEach(async () => {
// sandbox = sinon.createSandbox()
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#get', () => {
@@ -29,7 +29,7 @@ util.inspect.defaultOptions = {
describe('#blockchain', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#getBestBlockHash', () => {
+1 -1
View File
@@ -14,7 +14,7 @@ const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
describe('#control', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#getNetworkInfo', () => {
+1 -1
View File
@@ -16,7 +16,7 @@ describe('#ElectrumX', () => {
beforeEach(async () => {
sandbox = sinon.createSandbox()
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
afterEach(() => sandbox.restore())
+1 -1
View File
@@ -9,7 +9,7 @@ describe('#Ninsight', () => {
let sandbox
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
sandbox = sinon.createSandbox()
})
@@ -27,7 +27,7 @@ util.inspect.defaultOptions = {
describe('#rawtransaction', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#decodeRawTransaction', () => {
+1 -1
View File
@@ -25,7 +25,7 @@ util.inspect.defaultOptions = {
describe('#SLP', () => {
beforeEach(async () => {
// Introduce a delay so that the BVT doesn't trip the rate limits.
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#util', () => {
+1 -1
View File
@@ -25,7 +25,7 @@ util.inspect.defaultOptions = {
describe('#util', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#validateAddress', () => {
+1 -1
View File
@@ -9,7 +9,7 @@ const bchjs = new BCHJS()
describe('#control', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#getNetworkInfo', () => {
+1 -1
View File
@@ -11,7 +11,7 @@ describe('#ElectrumX', () => {
beforeEach(async () => {
sandbox = sinon.createSandbox()
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
afterEach(() => sandbox.restore())
+1 -1
View File
@@ -5,7 +5,7 @@ const bchjs = new BCHJS()
describe('#Encryption', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#getPubKey', () => {
+1 -1
View File
@@ -11,7 +11,7 @@ describe('#Ninsight', () => {
beforeEach(async () => {
sandbox = sinon.createSandbox()
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
afterEach(() => sandbox.restore())
+1 -1
View File
@@ -4,7 +4,7 @@ const bchjs = new BCHJS()
describe('#price', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#current', () => {
+2 -3
View File
@@ -19,7 +19,7 @@ util.inspect.defaultOptions = {
describe('#rawtransaction', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#decodeRawTransaction', () => {
@@ -191,8 +191,7 @@ describe('#rawtransaction', () => {
console.log(`result: ${util.inspect(result)}`)
assert.equal(true, false, 'Unexpected result!')
} catch (err) {
assert.hasAnyKeys(err, ['error'])
assert.include(err.error, 'Array too large')
assert.include(err.message, 'Array too large')
}
})
})
+1 -1
View File
@@ -18,7 +18,7 @@ util.inspect.defaultOptions = {
describe('#util', () => {
beforeEach(async () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1000)
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
describe('#validateAddress', () => {
+19 -17
View File
@@ -2281,23 +2281,25 @@ describe('#SLP Utils', () => {
assert.equal(result, true)
})
it('catches and throws an error', async () => {
try {
const txid = 'fakeTxid'
// Force an error
sandbox
.stub(uut.Utils, 'validateTxid3')
.rejects(new Error('fake error'))
await await uut.Utils.waterfallValidateTxid(txid)
assert.fail('Unexpected result')
} catch (err) {
// console.log(`err.message: ${err.message}`)
assert.include(err.message, 'fake error')
}
})
// CT 08-09-21 Changed behavior. validateTxid3() is now wrapped in a
// try/catch statement that exits quietly if there is an error.
// it('catches and throws an error', async () => {
// try {
// const txid = 'fakeTxid'
//
// // Force an error
// sandbox
// .stub(uut.Utils, 'validateTxid3')
// .rejects(new Error('fake error'))
//
// await await uut.Utils.waterfallValidateTxid(txid)
//
// assert.fail('Unexpected result')
// } catch (err) {
// // console.log(`err.message: ${err.message}`)
// assert.include(err.message, 'fake error')
// }
// })
})
describe('#getWhitelist', () => {