diff --git a/README.md b/README.md index 8b39236..2b6574f 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,6 @@ Here are two YouTube walk-through videos to help you get started: ``` const BCHJS = require("@psf/bch-js") let bchjs = new BCHJS() // Defaults to BCHN network. - -// testnet -bchjs = new BCHJS({ restURL: 'https://testnet3.fullstack.cash/v5/' }) ``` This library is intended to be paired with @@ -43,7 +40,6 @@ the [bch-api](https://github.com/Permissionless-Software-Foundation/bch-api) RES - 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 diff --git a/src/price.js b/src/price.js index 7926f06..dcf094d 100644 --- a/src/price.js +++ b/src/price.js @@ -127,8 +127,9 @@ class Price { * @apiName Price getBchaUsd() * @apiGroup Price * @apiDescription Return current price of BCHA in USD. - * This endpoint gets the USD price of BCHA from the Coinex API. The price - * comes from bch-api, so it has a better chance of working in Tor. + * This endpoint gets the USD price of XEC from the Coinex API. The price + * denominated in BCHA comes from bch-api, so it has a better chance of + * working in Tor. * * @apiExample Example usage: *(async () => { @@ -140,9 +141,47 @@ class Price { * } *})() * - * // 18.81 + * // 212.34 */ async getBchaUsd () { + try { + const response = await this.axios.get( + `${this.restURL}price/bchausd`, + this.axiosOptions + ) + // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) + + const bchaPrice = response.data.usd * 1000000 + // Convert XEC denomination to BCHA denomination + + return bchaPrice + } catch (err) { + if (err.response && err.response.data) throw err.response.data + else throw err + } + } + + /** + * @api price.getXecUsd() getXecUsd() + * @apiName Price getXecUsd() + * @apiGroup Price + * @apiDescription Return current price of XEC in USD. + * This endpoint gets the USD price of XEC from the Coinex API. The price + * comes from bch-api, so it has a better chance of working in Tor. + * + * @apiExample Example usage: + *(async () => { + * try { + * let current = await bchjs.Price.getXecUsd(); + * console.log(current); + * } catch(err) { + * console.err(err) + * } + *})() + * + * // 0.00021234 + */ + async getXecUsd () { try { const response = await this.axios.get( `${this.restURL}price/bchausd`, diff --git a/test/integration/chains/testnet/ninsight.js b/test/integration/chains/testnet/ninsight.js deleted file mode 100644 index b65b29a..0000000 --- a/test/integration/chains/testnet/ninsight.js +++ /dev/null @@ -1,149 +0,0 @@ -// const chai = require('chai') -// const assert = chai.assert -const sinon = require('sinon') - -// const BCHJS = require('../../../../src/bch-js') -// const bchjs = new BCHJS({ ninsightURL: 'https://trest.bitcoin.com/v2' }) - -describe('#Ninsight', () => { - let sandbox - - beforeEach(async () => { - if (process.env.IS_USING_FREE_TIER) await sleep(1500) - - sandbox = sinon.createSandbox() - }) - - afterEach(() => sandbox.restore()) - - // describe('#utxo', () => { - // it('should GET utxos for a single address', async () => { - // const addr = 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr' - // - // const result = await bchjs.Ninsight.utxo(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.property(result[0], 'utxos') - // assert.property(result[0], 'legacyAddress') - // assert.property(result[0], 'cashAddress') - // assert.property(result[0], 'slpAddress') - // assert.property(result[0], 'scriptPubKey') - // assert.property(result[0], 'asm') - // - // assert.isArray(result[0].utxos) - // - // assert.property(result[0].utxos[0], 'txid') - // assert.property(result[0].utxos[0], 'vout') - // assert.property(result[0].utxos[0], 'amount') - // assert.property(result[0].utxos[0], 'satoshis') - // assert.property(result[0].utxos[0], 'height') - // assert.property(result[0].utxos[0], 'confirmations') - // }) - // - // it('should POST utxo details for an array of addresses', async () => { - // const addr = [ - // 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr', - // 'bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul' - // ] - // - // const result = await bchjs.Ninsight.utxo(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.isArray(result[0].utxos) - // - // assert.property(result[0], 'utxos') - // assert.property(result[0], 'legacyAddress') - // assert.property(result[0], 'cashAddress') - // assert.property(result[0], 'slpAddress') - // assert.property(result[0], 'scriptPubKey') - // assert.property(result[0], 'asm') - // - // // assert.hasAnyKeys(result[0][0], [ - // // "txid", - // // "vout", - // // "value", - // // "height", - // // "confirmations" - // // ]) - // }) - // }) - // - // describe('#transactions', () => { - // it('should POST transactions history for a single address', async () => { - // const addr = 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr' - // - // const result = await bchjs.Ninsight.transactions(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.property(result[0], 'cashAddress') - // assert.property(result[0], 'legacyAddress') - // assert.property(result[0], 'txs') - // assert.isArray(result[0].txs) - // assert.property(result[0].txs[0], 'txid') - // assert.property(result[0].txs[0], 'vin') - // assert.property(result[0].txs[0], 'vout') - // }) - // it('should POST transactions history for an array of addresses', async () => { - // const addr = [ - // 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr', - // 'bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul' - // ] - // - // const result = await bchjs.Ninsight.transactions(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.property(result[0], 'cashAddress') - // assert.property(result[0], 'legacyAddress') - // assert.property(result[0], 'txs') - // assert.isArray(result[0].txs) - // assert.property(result[0].txs[0], 'txid') - // assert.property(result[0].txs[0], 'vin') - // assert.property(result[0].txs[0], 'vout') - // }) - // }) - // - // describe('#txDetails', () => { - // it('should POST transactions details for a single address', async () => { - // const txid = - // '76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea' - // - // const result = await bchjs.Ninsight.txDetails(txid) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.property(result[0], 'txid') - // assert.property(result[0], 'version') - // assert.property(result[0], 'locktime') - // assert.property(result[0], 'vin') - // assert.property(result[0], 'vout') - // assert.property(result[0], 'blockhash') - // assert.property(result[0], 'blockheight') - // assert.property(result[0], 'confirmations') - // assert.property(result[0], 'time') - // assert.property(result[0], 'blocktime') - // assert.property(result[0], 'valueOut') - // assert.property(result[0], 'size') - // }) - // it('should POST transactions details for an array of addresses', async () => { - // const txid = [ - // 'f191d1062789d7071da6f2168ba306869a829294f6b1c09d03492db4ca3a8e77', - // '76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea' - // ] - // - // const result = await bchjs.Ninsight.txDetails(txid) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.property(result[0], 'txid') - // assert.property(result[0], 'vin') - // assert.property(result[0], 'vout') - // }) - // }) -}) - -function sleep (ms) { - return new Promise(resolve => setTimeout(resolve, ms)) -} diff --git a/test/integration/ninsight.js b/test/integration/ninsight.js deleted file mode 100644 index 83f9dac..0000000 --- a/test/integration/ninsight.js +++ /dev/null @@ -1,138 +0,0 @@ -const chai = require('chai') -const assert = chai.assert -const sinon = require('sinon') - -const BCHJS = require('../../src/bch-js') -const bchjs = new BCHJS({ ninsightURL: 'https://rest.bitcoin.com/v2' }) - -describe('#Ninsight', () => { - let sandbox - - beforeEach(async () => { - sandbox = sinon.createSandbox() - - if (process.env.IS_USING_FREE_TIER) await sleep(1500) - }) - - 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.property(result[0], 'utxos') - assert.property(result[0], 'legacyAddress') - assert.property(result[0], 'cashAddress') - assert.property(result[0], 'slpAddress') - assert.property(result[0], 'scriptPubKey') - assert.property(result[0], 'asm') - - assert.isArray(result[0].utxos) - - assert.property(result[0].utxos[0], 'txid') - assert.property(result[0].utxos[0], 'vout') - assert.property(result[0].utxos[0], 'amount') - assert.property(result[0].utxos[0], 'satoshis') - assert.property(result[0].utxos[0], 'height') - assert.property(result[0].utxos[0], 'confirmations') - }) - - it('should POST utxo details for an array of addresses', async () => { - const addr = [ - 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', - 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' - ] - - const result = await bchjs.Ninsight.utxo(addr) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.isArray(result) - assert.isArray(result[0].utxos) - - assert.property(result[0], 'utxos') - assert.property(result[0], 'legacyAddress') - assert.property(result[0], 'cashAddress') - assert.property(result[0], 'slpAddress') - assert.property(result[0], 'scriptPubKey') - assert.property(result[0], 'asm') - }) - }) - describe('#transactions', () => { - it('should POST transactions history for a single address', async () => { - const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' - - const result = await bchjs.Ninsight.transactions(addr) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.isArray(result) - assert.property(result[0], 'cashAddress') - assert.property(result[0], 'legacyAddress') - assert.property(result[0], 'txs') - assert.isArray(result[0].txs) - assert.property(result[0].txs[0], 'txid') - assert.property(result[0].txs[0], 'vin') - assert.property(result[0].txs[0], 'vout') - }) - it('should POST transactions history for an array of addresses', async () => { - const addr = [ - 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', - 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' - ] - - const result = await bchjs.Ninsight.transactions(addr) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.isArray(result) - assert.property(result[0], 'cashAddress') - assert.property(result[0], 'legacyAddress') - assert.property(result[0], 'txs') - assert.isArray(result[0].txs) - assert.property(result[0].txs[0], 'txid') - assert.property(result[0].txs[0], 'vin') - assert.property(result[0].txs[0], 'vout') - }) - }) - describe('#txDetails', () => { - it('should POST transactions details for a single address', async () => { - const txid = 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33' - - const result = await bchjs.Ninsight.txDetails(txid) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.isArray(result) - assert.property(result[0], 'txid') - assert.property(result[0], 'version') - assert.property(result[0], 'locktime') - assert.property(result[0], 'vin') - assert.property(result[0], 'vout') - assert.property(result[0], 'blockhash') - assert.property(result[0], 'blockheight') - assert.property(result[0], 'confirmations') - assert.property(result[0], 'time') - assert.property(result[0], 'blocktime') - assert.property(result[0], 'valueOut') - assert.property(result[0], 'size') - }) - it('should POST transactions details for an array of addresses', async () => { - const txid = [ - 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33', - '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' - ] - - const result = await bchjs.Ninsight.txDetails(txid) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.isArray(result) - assert.property(result[0], 'txid') - assert.property(result[0], 'vin') - assert.property(result[0], 'vout') - }) - }) -}) - -function sleep (ms) { - return new Promise(resolve => setTimeout(resolve, ms)) -}