diff --git a/rest/src/plugins/mosaic/mosaicRoutes.js b/rest/src/plugins/mosaic/mosaicRoutes.js index 43c4aaa39..b55cb97a8 100644 --- a/rest/src/plugins/mosaic/mosaicRoutes.js +++ b/rest/src/plugins/mosaic/mosaicRoutes.js @@ -22,6 +22,9 @@ const merkleUtils = require('../../routes/merkleUtils'); const routeUtils = require('../../routes/routeUtils'); const catapult = require('catapult-sdk'); +const ini = require('ini'); +const fs = require('fs'); +const util = require('util'); const { PacketType } = catapult.packet; @@ -60,5 +63,25 @@ module.exports = { next(); }); }); + + // CMC specific endpoint + const readAndParseNetworkPropertiesFile = () => { + const readFile = util.promisify(fs.readFile); + return readFile(services.config.apiNode.networkPropertyFilePath, 'utf8') + .then(fileData => ini.parse(fileData)); + }; + + server.get('/network/currency/circulating', (req, res, next) => readAndParseNetworkPropertiesFile() + .then(propertiesObject => { + const currencyId = propertiesObject.chain.currencyMosaicId.replace(/'/g, '').replace('0x', ''); + const mosaicId = routeUtils.parseArgument({ mosaicId: currencyId }, 'mosaicId', 'uint64hex'); + return db.mosaicsByIds([mosaicId]).then(response => { + const s = response[0].mosaic.supply.toString(); + const supply = `${s.substring(0, s.length - 6)}.${s.substring(s.length - 6, s.length)}`; + res.setHeader('content-type', 'text/plain'); + res.send(supply); + next(); + }); + })); } }; diff --git a/rest/src/routes/networkRoutes.js b/rest/src/routes/networkRoutes.js index fcf6a3013..fa552052c 100644 --- a/rest/src/routes/networkRoutes.js +++ b/rest/src/routes/networkRoutes.js @@ -129,5 +129,17 @@ module.exports = { next(); }); }); + + // CMC specific, only return the plain value of the max mosaic supply + server.get('/network/currency/total', (req, res, next) => readAndParseNetworkPropertiesFile() + .then(propertiesObject => { + const maxSupply = propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, '').slice(0, -6); + res.setHeader('content-type', 'text/plain'); + res.send(maxSupply); + next(); + }).catch(() => { + res.send(errors.createInvalidArgumentError('there was an error reading the network properties file')); + next(); + })); } }; diff --git a/rest/test/plugins/mosaic/mosaic_spec.js b/rest/test/plugins/mosaic/mosaic_spec.js index 5ed434b79..9524cc3d8 100644 --- a/rest/test/plugins/mosaic/mosaic_spec.js +++ b/rest/test/plugins/mosaic/mosaic_spec.js @@ -42,7 +42,8 @@ describe('mosaic plugin', () => { test.assert.assertRoutes(routes, [ '/mosaics', '/mosaics/:mosaicId', - '/mosaics/:mosaicId/merkle' + '/mosaics/:mosaicId/merkle', + '/network/currency/circulating' ]); }); diff --git a/rest/test/routes/allRoutes_spec.js b/rest/test/routes/allRoutes_spec.js index e48ecc6fc..02171e1e8 100644 --- a/rest/test/routes/allRoutes_spec.js +++ b/rest/test/routes/allRoutes_spec.js @@ -69,7 +69,9 @@ describe('all routes', () => { '/transactions/:group/:transactionId', '/transactions/:group', - '/transactionStatus/:hash' + '/transactionStatus/:hash', + + '/network/currency/total' ]); });