Skip to content

Commit

Permalink
Merge pull request #45 from christroutner/unstable
Browse files Browse the repository at this point in the history
Added Gatsby instructions to README
  • Loading branch information
christroutner authored Jun 12, 2020
2 parents 8f22746 + 479fd47 commit 95c0b71
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 45 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 3 additions & 2 deletions src/ninsight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
)

Expand Down
40 changes: 22 additions & 18 deletions test/integration/ninsight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
})
30 changes: 18 additions & 12 deletions test/unit/fixtures/ninsight-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions test/unit/ninsight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`)

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")
// 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")
})
})
})

0 comments on commit 95c0b71

Please sign in to comment.