Merge pull request #45 from christroutner/unstable

Added Gatsby instructions to README
This commit is contained in:
Chris Troutner
2020-06-12 07:23:35 -07:00
committed by GitHub
5 changed files with 72 additions and 43 deletions
+14
View File
@@ -61,6 +61,20 @@ let bchjs = new BCHJS({
})
```
### Gatsby
bch-js is included in this [gatsby-ipfs-template](https://github.com/Permissionless-Software-Foundation/gatsby-ipfs-template) for building uncensorable web apps that can interact with the blockchain. When building a Gatsby (or other front-end app that uses Webpack), you'll need to add these lines to your `gatsby-node.js` file, as per [this issue](https://github.com/gatsbyjs/gatsby/issues/564):
```
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
node: {
fs: 'empty'
}
})
}
```
This is because the new IPFS class in bch-js uses the fs library for uploading files, which is not supported by Gatsby.
## Features
This library sets itself apart from BITBOX with the following features:
+3 -2
View File
@@ -12,7 +12,8 @@ class Ninsight {
// this.restURL = config.restURL
// this.apiToken = config.apiToken
this.ninsightURL = `https://bch-explorer.api.bitcoin.com/v1/`
// this.ninsightURL = `https://bch-explorer.api.bitcoin.com/v1/`
this.ninsightURL = `https://rest.bitcoin.com/v2`
// Add JWT token to the authorization header.
this.axiosOptions = {
@@ -65,7 +66,7 @@ class Ninsight {
throw new Error(`address needs to be a string.`)
const response = await axios.get(
`${this.ninsightURL}addr/${address}/utxo`,
`${this.ninsightURL}/address/utxo/${address}`,
_this.axiosOptions
)
+22 -18
View File
@@ -11,23 +11,27 @@ describe(`#Ninsight`, () => {
afterEach(() => sandbox.restore())
describe(`#utxo`, () => {
// it(`should GET utxos for a single address`, async () => {
// const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
//
// const result = await bchjs.Ninsight.utxo(addr)
// // console.log(`result: ${JSON.stringify(result, null, 2)}`)
//
// assert.isArray(result)
//
// assert.property(result[0], "address")
// assert.property(result[0], "txid")
// assert.property(result[0], "vout")
// assert.property(result[0], "scriptPubKey")
// assert.property(result[0], "amount")
// assert.property(result[0], "satoshis")
// assert.isNumber(result[0].satoshis)
// assert.property(result[0], "height")
// assert.property(result[0], "confirmations")
// })
it(`should GET utxos for a single address`, async () => {
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
const result = await bchjs.Ninsight.utxo(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "utxos")
assert.property(result, "legacyAddress")
assert.property(result, "cashAddress")
assert.property(result, "slpAddress")
assert.property(result, "scriptPubKey")
assert.property(result, "asm")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "txid")
assert.property(result.utxos[0], "vout")
assert.property(result.utxos[0], "amount")
assert.property(result.utxos[0], "satoshis")
assert.property(result.utxos[0], "height")
assert.property(result.utxos[0], "confirmations")
})
})
})
+18 -12
View File
@@ -2,18 +2,24 @@
Mocking data for unit tests for the Ninsight library.
*/
const utxo = [
{
address: "15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF",
txid: "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7",
vout: 0,
scriptPubKey: "76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac",
amount: 0.00001,
satoshis: 1000,
height: 602405,
confirmations: 16720
}
]
const utxo = {
utxos: [
{
txid: "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7",
vout: 0,
amount: 0.00001,
satoshis: 1000,
height: 602405,
confirmations: 36459
}
],
legacyAddress: "15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF",
cashAddress: "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9",
slpAddress: "simpleledger:qqh793x9au6ehvh7r2zflzguanlme760wuwzunhjfm",
scriptPubKey: "76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac",
asm:
"OP_DUP OP_HASH160 2fe2c4c5ef359bb2fe1a849f891cecffbcfb4f77 OP_EQUALVERIFY OP_CHECKSIG"
}
module.exports = {
utxo
+15 -11
View File
@@ -33,19 +33,23 @@ describe(`#Ninsight`, () => {
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
const result = await bchjs.Ninsight.utxo(addr)
console.log(`result: ${JSON.stringify(result, null, 2)}`)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result, "utxos")
assert.property(result, "legacyAddress")
assert.property(result, "cashAddress")
assert.property(result, "slpAddress")
assert.property(result, "scriptPubKey")
assert.property(result, "asm")
assert.property(result[0], "address")
assert.property(result[0], "txid")
assert.property(result[0], "vout")
assert.property(result[0], "scriptPubKey")
assert.property(result[0], "amount")
assert.property(result[0], "satoshis")
assert.isNumber(result[0].satoshis)
assert.property(result[0], "height")
assert.property(result[0], "confirmations")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "txid")
assert.property(result.utxos[0], "vout")
assert.property(result.utxos[0], "amount")
assert.property(result.utxos[0], "satoshis")
assert.property(result.utxos[0], "height")
assert.property(result.utxos[0], "confirmations")
})
})
})