mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 00:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5f7e6aa7f | ||
|
|
04e3346086 | ||
|
|
cb2a90fc93 |
+3
-2
@@ -15,10 +15,11 @@
|
||||
"test:integration": "npm run test:integration:local:noauth",
|
||||
"test:integration:fullstack:free": "export RESTURL=https://bch.fullstack.cash/v6 && mocha --timeout 60000 test/integration/",
|
||||
"test:integration:fullstack:x402": "export RESTURL=https://x402-bch.fullstack.cash/v6 && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 120000 test/integration/",
|
||||
"test:integration:local:noauth": "export RESTURL=http://localhost:5942/v6 && mocha --timeout 30000 test/integration/",
|
||||
"test:integration:fullstack:auth": "export RESTURL=http://dev.fullstack.cash/v6 && export BCHJSBEARERTOKEN=test01 && mocha --timeout 30000 test/integration/",
|
||||
"test:integration:local:noauth": "export RESTURL=http://192.168.1.65:5942/v6 && mocha --timeout 30000 test/integration/",
|
||||
"test:integration:local:auth": "export RESTURL=http://192.168.1.115:5942/v6 && export BCHJSBEARERTOKEN=temp01 && mocha --timeout 30000 test/integration/",
|
||||
"test:integration:local:x402": "export RESTURL=http://localhost:5942/v6 && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 1200000 test/integration/",
|
||||
"test:integration:decatur": "export RESTURL=http://192.168.2.127:5942/v6 && mocha --timeout 30000 test/integration/",
|
||||
"test:integration:decatur": "export RESTURL=http://192.168.1.65:5942/v6 && mocha --timeout 30000 test/integration/",
|
||||
"coverage": "nyc --reporter=html mocha --timeout 25000 test/unit/",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs && ./fix-docs-contrast.sh",
|
||||
"lint": "standard --env mocha --fix"
|
||||
|
||||
+97
-38
@@ -47,8 +47,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +108,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,8 +161,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,8 +198,11 @@ class Blockchain {
|
||||
console.log('Error in bch-js/blockchain.js/getBlockCount()')
|
||||
console.log('blockchain.js restURL: ', this.restURL)
|
||||
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +234,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,8 +302,13 @@ class Blockchain {
|
||||
|
||||
throw new Error('Input hash must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
// console.log('Error in bch-js/blockchain.js/getBlockHeader() error: ', error)
|
||||
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,8 +350,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,8 +385,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,8 +404,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,8 +422,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,8 +537,11 @@ class Blockchain {
|
||||
|
||||
throw new Error('Input must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,8 +576,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,8 +626,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,8 +683,11 @@ class Blockchain {
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,8 +753,11 @@ class Blockchain {
|
||||
|
||||
throw new Error('Input must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,8 +769,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,8 +785,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,8 +801,11 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,8 +872,11 @@ class Blockchain {
|
||||
|
||||
throw new Error('Input must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -62,8 +62,11 @@ class DSProof {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-15
@@ -120,8 +120,11 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,8 +207,11 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,8 +311,11 @@ class ElectrumX {
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
// console.log('Error in transactions(): ', error)
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,8 +406,11 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,9 +465,13 @@ class ElectrumX {
|
||||
} catch (error) {
|
||||
// console.log("error: ", error)
|
||||
if (error.response && error.response.data) {
|
||||
if (error.response && error.response.data) {
|
||||
throw new Error(error.response.data.error)
|
||||
} else throw error.response.data
|
||||
const errorData = error.response.data
|
||||
if (errorData.error) {
|
||||
throw new Error(errorData.error)
|
||||
} else {
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
@@ -555,8 +571,11 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input txId must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,8 +614,11 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input txHex must be a string.')
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
if (error.response && error.response.data) {
|
||||
const errorData = error.response.data
|
||||
const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
|
||||
throw new Error(errorMessage)
|
||||
} else throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ describe('#blockchain', () => {
|
||||
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.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -171,8 +171,8 @@ describe('#blockchain', () => {
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
// console.log(`err: ${util.inspect(err)}`)
|
||||
assert.hasAnyKeys(err, ['error'])
|
||||
assert.include(err.error, 'Transaction not in mempool')
|
||||
assert.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Transaction not in mempool')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -241,8 +241,8 @@ describe('#blockchain', () => {
|
||||
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.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -73,8 +73,8 @@ describe('#ElectrumX', () => {
|
||||
// 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.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -129,8 +129,8 @@ describe('#ElectrumX', () => {
|
||||
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.hasAnyKeys(err, ['error'])
|
||||
assert.include(err.error, 'Array too large')
|
||||
assert.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -187,8 +187,8 @@ describe('#ElectrumX', () => {
|
||||
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.hasAnyKeys(err, ['error'])
|
||||
assert.include(err.error, 'Array too large')
|
||||
assert.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -250,8 +250,8 @@ describe('#ElectrumX', () => {
|
||||
// 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.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -345,8 +345,8 @@ describe('#ElectrumX', () => {
|
||||
// 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.instanceOf(err, Error)
|
||||
assert.include(err.message, 'Array too large')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -359,8 +359,9 @@ describe('#ElectrumX', () => {
|
||||
try {
|
||||
await bchjs.Electrumx.broadcast(txHex)
|
||||
} catch (err) {
|
||||
// console.error('err: ', err)
|
||||
assert.include(
|
||||
err.error,
|
||||
err.message,
|
||||
'the transaction was rejected by network rules'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('#Blockchain', () => {
|
||||
await bchjs.Blockchain.getBlock(blockhash)
|
||||
assert2.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert2.include(err, 'Test Error')
|
||||
assert2.include(err.message, 'Test Error')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user