Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
task: remove cmc plugin and move cmcRoutes into mosaic:supplyRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaguar0625 authored and Fernando committed Nov 16, 2021
1 parent 8e126e8 commit ac8e00b
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 399 deletions.
4 changes: 1 addition & 3 deletions catapult-sdk/src/plugins/catapultModelSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/** @module plugins/catapultModelSystem */
const accountLink = require('./accountLink');
const aggregate = require('./aggregate');
const cmc = require('./cmc');
const lockHash = require('./lockHash');
const lockSecret = require('./lockSecret');
const metadata = require('./metadata');
Expand All @@ -47,8 +46,7 @@ const plugins = {
namespace,
receipts,
restrictions,
transfer,
cmc
transfer
};

/**
Expand Down
38 changes: 0 additions & 38 deletions catapult-sdk/src/plugins/cmc.js

This file was deleted.

3 changes: 1 addition & 2 deletions catapult-sdk/test/plugins/catapultModelSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ describe('catapult model system', () => {
'namespace',
'receipts',
'restrictions',
'transfer',
'cmc'
'transfer'
]);
});
});
Expand Down
51 changes: 0 additions & 51 deletions rest/src/plugins/cmc/CmcDb.js

This file was deleted.

40 changes: 0 additions & 40 deletions rest/src/plugins/cmc/cmc.js

This file was deleted.

26 changes: 0 additions & 26 deletions rest/src/plugins/cmc/cmcUtils.js

This file was deleted.

2 changes: 2 additions & 0 deletions rest/src/plugins/mosaic/mosaic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/** @module plugins/mosaic */
const MosaicDb = require('./MosaicDb');
const mosaicRoutes = require('./mosaicRoutes');
const supplyRoutes = require('./supplyRoutes');

/**
* Creates a mosaic plugin.
Expand All @@ -36,5 +37,6 @@ module.exports = {

registerRoutes: (...args) => {
mosaicRoutes.register(...args);
supplyRoutes.register(...args);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

const cmcUtils = require('./cmcUtils');
const { longToUint64 } = require('../../db/dbUtils');
const routeUtils = require('../../routes/routeUtils');
const AccountType = require('../AccountType');
Expand All @@ -32,7 +31,9 @@ const { convert, uint64 } = catapult.utils;

module.exports = {
register: (server, db, services) => {
const sender = routeUtils.createSender('cmc');
const sender = routeUtils.createSender('supply');

const convertToFractionalWholeUnits = (value, divisibility) => (Number(value) / (10 ** divisibility)).toFixed(divisibility);

const propertyValueToMosaicId = value => uint64.fromHex(value.replace(/'/g, '').replace('0x', ''));

Expand All @@ -42,6 +43,14 @@ module.exports = {
.then(fileData => ini.parse(fileData));
};

const getMosaicProperties = async currencyMosaicId => {
const mosaics = await db.mosaicsByIds([currencyMosaicId]);
return {
totalSupply: mosaics[0].mosaic.supply.toNumber(),
divisibility: mosaics[0].mosaic.divisibility
};
};

const getUncirculatingAccountIds = propertiesObject => {
const publicKeys = [propertiesObject.network.nemesisSignerPublicKey].concat(services.config.uncirculatingAccountPublicKeys);
return publicKeys.map(publicKey => ({ [AccountType.publicKey]: convert.hexToUint8(publicKey) }));
Expand All @@ -59,30 +68,37 @@ module.exports = {
server.get('/network/currency/supply/circulating', (req, res, next) => readAndParseNetworkPropertiesFile()
.then(async propertiesObject => {
const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId);
const mosaics = await db.mosaicsByIds([currencyMosaicId]);
const accounts = await db.catapultDb.accountsByIds(getUncirculatingAccountIds(propertiesObject));
const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId);

const totalSupply = mosaics[0].mosaic.supply.toNumber();
const accounts = await db.catapultDb.accountsByIds(getUncirculatingAccountIds(propertiesObject));
const burnedSupply = accounts.reduce(
(sum, account) => sum + lookupMosaicAmount(account.account.mosaics, currencyMosaicId),
0
);
sender.sendPlainText(res, next)(cmcUtils.convertToRelative(totalSupply - burnedSupply));

sender.sendPlainText(res, next)(convertToFractionalWholeUnits(
currencyMosaicProperties.totalSupply - burnedSupply,
currencyMosaicProperties.divisibility
));
}));

server.get('/network/currency/supply/total', (req, res, next) => readAndParseNetworkPropertiesFile()
.then(propertiesObject => {
.then(async propertiesObject => {
const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId);
return db.mosaicsByIds([currencyMosaicId]).then(response => {
const supply = response[0].mosaic.supply.toNumber();
sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply));
});
const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId);
sender.sendPlainText(res, next)(convertToFractionalWholeUnits(
currencyMosaicProperties.totalSupply,
currencyMosaicProperties.divisibility
));
}));

server.get('/network/currency/supply/max', (req, res, next) => readAndParseNetworkPropertiesFile()
.then(propertiesObject => {
const supply = parseInt(propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, ''), 10);
sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply));
.then(async propertiesObject => {
const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId);
const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId);

const maxSupply = parseInt(propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, ''), 10);
sender.sendPlainText(res, next)(convertToFractionalWholeUnits(maxSupply, currencyMosaicProperties.divisibility));
}));
}
};
4 changes: 1 addition & 3 deletions rest/src/plugins/routeSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

const aggregate = require('./aggregate/aggregate');
const cmc = require('./cmc/cmc');
const empty = require('./empty');
const lockHash = require('./lockHash/lockHash');
const lockSecret = require('./lockSecret/lockSecret');
Expand All @@ -44,8 +43,7 @@ const plugins = {
namespace,
receipts,
restrictions,
transfer: empty,
cmc
transfer: empty
};

module.exports = {
Expand Down
Loading

0 comments on commit ac8e00b

Please sign in to comment.