From 8dbc5c3e40f811948f89a97984904818baae7114 Mon Sep 17 00:00:00 2001 From: ethan Date: Thu, 28 Oct 2021 18:25:14 +1100 Subject: [PATCH 1/2] Added a getCurrencyInfo endpoint to v4 and v5 routes --- src/routes/v4/util.js | 50 +++++++++++++++++++++++++++++++++++++++++++ src/routes/v5/util.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/routes/v4/util.js b/src/routes/v4/util.js index e3d20a7..aa824e2 100644 --- a/src/routes/v4/util.js +++ b/src/routes/v4/util.js @@ -59,6 +59,7 @@ class UtilRoute { this.router.get('/validateAddress/:address', this.validateAddressSingle) this.router.post('/validateAddress', this.validateAddressBulk) this.router.post('/sweep', this.sweepWif) + this.router.get('/getCurrencyInfo', this.getCurrencyInfo) _this = this } @@ -67,6 +68,55 @@ class UtilRoute { return res.json({ status: 'util' }) } + /** + * @api {get} /util/getCurrencyInfo Get information about the currency. + * @apiName getCurrencyInfo + * @apiGroup Util + * @apiDescription Returns an object containing information about the currency. + * + * + * @apiExample Example usage: + * curl -X GET "https://api.fullstack.cash/v4/util/getCurrencyInfo" -H "accept: application/json" + * + * + */ + async getCurrencyInfo (req, res, next) { + try { + + const { + BitboxHTTP, + // username, + // password, + requestConfig + } = routeUtils.setEnvVars() + + requestConfig.data.id = 'getcurrencyinfo' + requestConfig.data.method = 'getcurrencyinfo' + + const response = await BitboxHTTP(requestConfig) + + if (response.data.result.satoshisperunit === 100) { + response.data.result.ecash = 1; + } else { + response.data.result.ecash = 0; + } + + return res.json(response.data.result) + } catch (err) { + // Attempt to decode the error message. + const { msg, status } = routeUtils.decodeError(err) + if (msg) { + res.status(status) + return res.json({ error: msg }) + } + + wlogger.error('Error in util.ts/getCurrencyInfo().', err) + + res.status(500) + return res.json({ error: util.inspect(err) }) + } + } + /** * @api {get} /util/validateAddress/{address} Get information about single bitcoin cash address. * @apiName Information about single bitcoin cash address diff --git a/src/routes/v5/util.js b/src/routes/v5/util.js index 82b1535..039e781 100644 --- a/src/routes/v5/util.js +++ b/src/routes/v5/util.js @@ -39,6 +39,7 @@ class UtilRoute { this.router.get('/', this.root) this.router.get('/validateAddress/:address', this.validateAddressSingle) this.router.post('/validateAddress', this.validateAddressBulk) + this.router.get('/getCurrencyInfo', this.getCurrencyInfo) // this.router.post('/sweep', this.sweepWif) // _this = this @@ -48,6 +49,55 @@ class UtilRoute { return res.json({ status: 'util' }) } + /** + * @api {get} /util/getCurrencyInfo Get information about the currency. + * @apiName getCurrencyInfo + * @apiGroup Util + * @apiDescription Returns an object containing information about the currency. + * + * + * @apiExample Example usage: + * curl -X GET "https://api.fullstack.cash/v5/util/getCurrencyInfo" -H "accept: application/json" + * + * + */ + async getCurrencyInfo (req, res, next) { + try { + + const { + BitboxHTTP, + // username, + // password, + requestConfig + } = routeUtils.setEnvVars() + + requestConfig.data.id = 'getcurrencyinfo' + requestConfig.data.method = 'getcurrencyinfo' + + const response = await BitboxHTTP(requestConfig) + + if (response.data.result.satoshisperunit === 100) { + response.data.result.ecash = 1; + } else { + response.data.result.ecash = 0; + } + + return res.json(response.data.result) + } catch (err) { + // Attempt to decode the error message. + const { msg, status } = routeUtils.decodeError(err) + if (msg) { + res.status(status) + return res.json({ error: msg }) + } + + wlogger.error('Error in util.ts/getCurrencyInfo().', err) + + res.status(500) + return res.json({ error: util.inspect(err) }) + } + } + /** * @api {get} /util/validateAddress/{address} Get information about single bitcoin cash address. * @apiName Information about single bitcoin cash address From 45887fb24b218bfebfc983f0f55e15d7688d441b Mon Sep 17 00:00:00 2001 From: ethan Date: Thu, 28 Oct 2021 18:25:14 +1100 Subject: [PATCH 2/2] Added a getCurrencyInfo endpoint to v4 and v5 routes --- src/routes/v4/util.js | 44 +++++++++++++++++++++++++++++++++++++++++++ src/routes/v5/util.js | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/routes/v4/util.js b/src/routes/v4/util.js index e3d20a7..bd26637 100644 --- a/src/routes/v4/util.js +++ b/src/routes/v4/util.js @@ -59,6 +59,7 @@ class UtilRoute { this.router.get('/validateAddress/:address', this.validateAddressSingle) this.router.post('/validateAddress', this.validateAddressBulk) this.router.post('/sweep', this.sweepWif) + this.router.get('/getCurrencyInfo', this.getCurrencyInfo) _this = this } @@ -67,6 +68,49 @@ class UtilRoute { return res.json({ status: 'util' }) } + /** + * @api {get} /util/getCurrencyInfo Get information about the currency. + * @apiName getCurrencyInfo + * @apiGroup Util + * @apiDescription Returns an object containing information about the currency. + * + * + * @apiExample Example usage: + * curl -X GET "https://api.fullstack.cash/v4/util/getCurrencyInfo" -H "accept: application/json" + * + * + */ + async getCurrencyInfo (req, res, next) { + try { + + const { + BitboxHTTP, + // username, + // password, + requestConfig + } = routeUtils.setEnvVars() + + requestConfig.data.id = 'getcurrencyinfo' + requestConfig.data.method = 'getcurrencyinfo' + + const response = await BitboxHTTP(requestConfig) + + return res.json(response.data.result) + } catch (err) { + // Attempt to decode the error message. + const { msg, status } = routeUtils.decodeError(err) + if (msg) { + res.status(status) + return res.json({ error: msg }) + } + + wlogger.error('Error in util.ts/getCurrencyInfo().', err) + + res.status(500) + return res.json({ error: util.inspect(err) }) + } + } + /** * @api {get} /util/validateAddress/{address} Get information about single bitcoin cash address. * @apiName Information about single bitcoin cash address diff --git a/src/routes/v5/util.js b/src/routes/v5/util.js index 82b1535..48c5897 100644 --- a/src/routes/v5/util.js +++ b/src/routes/v5/util.js @@ -39,6 +39,7 @@ class UtilRoute { this.router.get('/', this.root) this.router.get('/validateAddress/:address', this.validateAddressSingle) this.router.post('/validateAddress', this.validateAddressBulk) + this.router.get('/getCurrencyInfo', this.getCurrencyInfo) // this.router.post('/sweep', this.sweepWif) // _this = this @@ -48,6 +49,49 @@ class UtilRoute { return res.json({ status: 'util' }) } + /** + * @api {get} /util/getCurrencyInfo Get information about the currency. + * @apiName getCurrencyInfo + * @apiGroup Util + * @apiDescription Returns an object containing information about the currency. + * + * + * @apiExample Example usage: + * curl -X GET "https://api.fullstack.cash/v5/util/getCurrencyInfo" -H "accept: application/json" + * + * + */ + async getCurrencyInfo (req, res, next) { + try { + + const { + BitboxHTTP, + // username, + // password, + requestConfig + } = routeUtils.setEnvVars() + + requestConfig.data.id = 'getcurrencyinfo' + requestConfig.data.method = 'getcurrencyinfo' + + const response = await BitboxHTTP(requestConfig) + + return res.json(response.data.result) + } catch (err) { + // Attempt to decode the error message. + const { msg, status } = routeUtils.decodeError(err) + if (msg) { + res.status(status) + return res.json({ error: msg }) + } + + wlogger.error('Error in util.ts/getCurrencyInfo().', err) + + res.status(500) + return res.json({ error: util.inspect(err) }) + } + } + /** * @api {get} /util/validateAddress/{address} Get information about single bitcoin cash address. * @apiName Information about single bitcoin cash address