From 8c5f1e22745a30298467aa720ed9a8273a17c7b6 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jun 2021 15:47:22 -0700 Subject: [PATCH] fix(dsproof): Adding documentation --- src/dsproof.js | 34 +++++++++++++++++++++++-- test/integration/chains/bchn/dsproof.js | 6 ++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/dsproof.js b/src/dsproof.js index 5116622..bb116ec 100644 --- a/src/dsproof.js +++ b/src/dsproof.js @@ -2,7 +2,7 @@ const axios = require('axios') let _this -class Mining { +class DSProof { constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken @@ -28,6 +28,36 @@ class Mining { _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) { try { if (!txid) { @@ -48,4 +78,4 @@ class Mining { } } -module.exports = Mining +module.exports = DSProof diff --git a/test/integration/chains/bchn/dsproof.js b/test/integration/chains/bchn/dsproof.js index 3eda3d0..6ff9632 100644 --- a/test/integration/chains/bchn/dsproof.js +++ b/test/integration/chains/bchn/dsproof.js @@ -2,6 +2,8 @@ Integration tests for bchjs dsproof library. */ +const assert = require('chai').assert + const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS() @@ -15,7 +17,9 @@ describe('#DSProof', () => { const txid = 'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e' 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) }) }) })