mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-23 01:22:01 -07:00
Compare commits
7
Commits
dh-dsproof
...
v4.20.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dc88c0af3 | ||
|
|
85caa9556b | ||
|
|
bbdc417eb2 | ||
|
|
cc3bc002e7 | ||
|
|
a75e1ab633 | ||
|
|
8c5f1e2274 | ||
|
|
c30e76c942 |
@@ -57,7 +57,7 @@ rate limits when interacting with the back end server. See [this article](https:
|
|||||||
```
|
```
|
||||||
const BCHJS = require("@psf/bch-js")
|
const BCHJS = require("@psf/bch-js")
|
||||||
let bchjs = new BCHJS({
|
let bchjs = new BCHJS({
|
||||||
restURL: 'https://bchn.fullstack.cash/v3/',
|
restURL: 'https://bchn.fullstack.cash/v5/',
|
||||||
apiToken: 'eyJhbGciO...' // Your JWT token here.
|
apiToken: 'eyJhbGciO...' // Your JWT token here.
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
+32
-2
@@ -2,7 +2,7 @@ const axios = require('axios')
|
|||||||
|
|
||||||
let _this
|
let _this
|
||||||
|
|
||||||
class Mining {
|
class DSProof {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
this.restURL = config.restURL
|
this.restURL = config.restURL
|
||||||
this.apiToken = config.apiToken
|
this.apiToken = config.apiToken
|
||||||
@@ -28,6 +28,36 @@ class Mining {
|
|||||||
_this = this
|
_this = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api DSProof.getDSProof() getDSProof()
|
||||||
|
* @apiName getDSProof
|
||||||
|
* @apiGroup DSProof
|
||||||
|
* @apiDescription Checks if a transaction generated a double-spend proof.
|
||||||
|
*
|
||||||
|
* If a double-spend is attempted, one of the transactions will generate a
|
||||||
|
* 'double spend proof'. This call can be used to check if a transaction
|
||||||
|
* generated such a proof.
|
||||||
|
*
|
||||||
|
* Merchants should wait 3-5 seconds after receiving notification of a
|
||||||
|
* transaction before calling this endpoint, to see if the TXID generated a
|
||||||
|
* proof. If this method returns no data, then the TX can be considered 'safe'
|
||||||
|
* and not a double spend. If proof data is returned by this method, then
|
||||||
|
* the transaction generated a proof and can be considered a 'double spend'.
|
||||||
|
*
|
||||||
|
* @apiExample Example usage:
|
||||||
|
* (async () => {
|
||||||
|
* try {
|
||||||
|
* const txid = 'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
* const result = await bchjs.DSProof.getDSProof(txid)
|
||||||
|
* console.log(result);
|
||||||
|
* } catch(error) {
|
||||||
|
* console.error(error)
|
||||||
|
* }
|
||||||
|
* })()
|
||||||
|
*
|
||||||
|
* // returns
|
||||||
|
* null
|
||||||
|
*/
|
||||||
async getDSProof (txid) {
|
async getDSProof (txid) {
|
||||||
try {
|
try {
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
@@ -48,4 +78,4 @@ class Mining {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Mining
|
module.exports = DSProof
|
||||||
|
|||||||
@@ -365,7 +365,9 @@ class RawTransactions {
|
|||||||
async getTxData (txid) {
|
async getTxData (txid) {
|
||||||
try {
|
try {
|
||||||
if (typeof txid !== 'string') {
|
if (typeof txid !== 'string') {
|
||||||
throw new Error('Input must be a string or array of strings.')
|
throw new Error(
|
||||||
|
'Input to raw-transaction.js/getTxData() must be a string containg a TXID.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the TX details for the transaction under consideration.
|
// Get the TX details for the transaction under consideration.
|
||||||
|
|||||||
+4
-2
@@ -37,7 +37,9 @@ class Transaction {
|
|||||||
async get (txid) {
|
async get (txid) {
|
||||||
try {
|
try {
|
||||||
if (typeof txid !== 'string') {
|
if (typeof txid !== 'string') {
|
||||||
throw new Error('Input must be a string or array of strings.')
|
throw new Error(
|
||||||
|
'Input to Transaction.get() must be a string containing a TXID.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const txDetails = await this.rawTransaction.getTxData(txid)
|
const txDetails = await this.rawTransaction.getTxData(txid)
|
||||||
@@ -136,7 +138,7 @@ class Transaction {
|
|||||||
|
|
||||||
return txDetails
|
return txDetails
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in transactions.js/get()')
|
// console.error('Error in transactions.js/get(): ', err)
|
||||||
|
|
||||||
if (err.error) throw new Error(err.error)
|
if (err.error) throw new Error(err.error)
|
||||||
throw err
|
throw err
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Integration tests for bchjs dsproof library.
|
Integration tests for bchjs dsproof library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const assert = require('chai').assert
|
||||||
|
|
||||||
const BCHJS = require('../../../../src/bch-js')
|
const BCHJS = require('../../../../src/bch-js')
|
||||||
const bchjs = new BCHJS()
|
const bchjs = new BCHJS()
|
||||||
|
|
||||||
@@ -15,7 +17,9 @@ describe('#DSProof', () => {
|
|||||||
const txid =
|
const txid =
|
||||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
const result = await bchjs.DSProof.getDSProof(txid)
|
const result = await bchjs.DSProof.getDSProof(txid)
|
||||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
|
|
||||||
|
assert.equal(result, null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -171,10 +171,15 @@ describe('#RawTransactions', () => {
|
|||||||
describe('#getTxData', () => {
|
describe('#getTxData', () => {
|
||||||
it('should return tx data with input addresses', async () => {
|
it('should return tx data with input addresses', async () => {
|
||||||
// Mock dependencies
|
// Mock dependencies
|
||||||
sandbox.stub(bchjs.RawTransactions, 'getRawTransaction').resolves(mockData.mockTx)
|
sandbox
|
||||||
sandbox.stub(bchjs.RawTransactions, '_getInputAddrs').resolves(mockData.mockGetInputAddrsOutput)
|
.stub(bchjs.RawTransactions, 'getRawTransaction')
|
||||||
|
.resolves(mockData.mockTx)
|
||||||
|
sandbox
|
||||||
|
.stub(bchjs.RawTransactions, '_getInputAddrs')
|
||||||
|
.resolves(mockData.mockGetInputAddrsOutput)
|
||||||
|
|
||||||
const txid = '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3'
|
const txid =
|
||||||
|
'05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3'
|
||||||
|
|
||||||
const result = await bchjs.RawTransactions.getTxData(txid)
|
const result = await bchjs.RawTransactions.getTxData(txid)
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
@@ -190,7 +195,10 @@ describe('#RawTransactions', () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// console.log(err)
|
// console.log(err)
|
||||||
|
|
||||||
assert2.include(err.message, 'Input must be a string or array of strings')
|
assert2.include(
|
||||||
|
err.message,
|
||||||
|
'Input to raw-transaction.js/getTxData() must be a string containg a TXID.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -201,7 +209,8 @@ describe('#RawTransactions', () => {
|
|||||||
.stub(bchjs.RawTransactions, 'getRawTransaction')
|
.stub(bchjs.RawTransactions, 'getRawTransaction')
|
||||||
.rejects(new Error('test error'))
|
.rejects(new Error('test error'))
|
||||||
|
|
||||||
const txid = '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3'
|
const txid =
|
||||||
|
'05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3'
|
||||||
|
|
||||||
await bchjs.RawTransactions.getTxData(txid)
|
await bchjs.RawTransactions.getTxData(txid)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe('#TransactionLib', () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert.include(
|
assert.include(
|
||||||
err.message,
|
err.message,
|
||||||
'Input must be a string or array of strings.'
|
'Input to Transaction.get() must be a string containing a TXID.'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user