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

Commit

Permalink
Merge pull request #623 from nemtech/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
rg911 authored May 24, 2021
2 parents fcd14dc + 542600e commit bb0369e
Show file tree
Hide file tree
Showing 30 changed files with 1,074 additions and 123 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v2.3.6] - 24-May-2021

### Added

- Tokenomics endpoints.
- Symbol-bootstrap version in server version endpoints. This requires node operator to update rest.json configuration file with the correct bootstrap version details.

### Fixed

- Fixed zero median network transaction fee issue

## [v2.3.5] - 13-Mar-2021

### Updated
Expand Down
8 changes: 7 additions & 1 deletion catapult-sdk/src/model/ModelSchemaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ class ModelSchemaBuilder {
},
serverInfoData: {
restVersion: ModelType.string,
sdkVersion: ModelType.string
sdkVersion: ModelType.string,
deployment: { type: ModelType.object, schemaName: 'deploymentData' }
},
deploymentData: {
deploymentTool: ModelType.string,
deploymentToolVersion: ModelType.string,
lastUpdatedDate: ModelType.string
},
stateTree: {
tree: { type: ModelType.array, schemaName: ModelType.binary }
Expand Down
4 changes: 3 additions & 1 deletion catapult-sdk/src/plugins/catapultModelSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/** @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 @@ -46,7 +47,8 @@ const plugins = {
namespace,
receipts,
restrictions,
transfer
transfer,
cmc
};

/**
Expand Down
38 changes: 38 additions & 0 deletions catapult-sdk/src/plugins/cmc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
* Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
* All rights reserved.
*
* This file is part of Catapult.
*
* Catapult is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Catapult is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

/** @module plugins/cmc */

// To ensure cmc able to load from the config, created empty plugins

/* eslint-disable no-unused-vars */

/**
* Creates a cmc plugin use for CoinMarketCap.
* @type {module:plugins/CatapultPlugin}
*/
const cmcPlugin = {
registerSchema: builder => {},

registerCodecs: codecBuilder => {}
};

module.exports = cmcPlugin;
10 changes: 8 additions & 2 deletions catapult-sdk/test/model/ModelSchemaBuilder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('model schema builder', () => {
'nodeTime',
'serverInfo',
'serverInfoData',
'deploymentData',
'stateTree',
'storageInfo'
]);
Expand Down Expand Up @@ -179,7 +180,8 @@ describe('model schema builder', () => {

'nodeHealth.status',
'nodeTime.communicationTimestamps',
'serverInfo.serverInfo'
'serverInfo.serverInfo',
'serverInfoData.deployment'
]);
});

Expand Down Expand Up @@ -333,7 +335,11 @@ describe('model schema builder', () => {
'nodeInfo.friendlyName',
'nodeInfo.host',
'serverInfoData.restVersion',
'serverInfoData.sdkVersion'
'serverInfoData.sdkVersion',
'deploymentData.deploymentTool',
'deploymentData.deploymentToolVersion',
'deploymentData.lastUpdatedDate'

]);
});

Expand Down
3 changes: 2 additions & 1 deletion catapult-sdk/test/plugins/catapultModelSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('catapult model system', () => {
'namespace',
'receipts',
'restrictions',
'transfer'
'transfer',
'cmc'
]);
});
});
Expand Down
18 changes: 9 additions & 9 deletions catapult-sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2148,9 +2148,9 @@ home-or-tmp@^2.0.0:
os-tmpdir "^1.0.1"

hosted-git-info@^2.1.4:
version "2.8.8"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==
version "2.8.9"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==

html-escaper@^2.0.0:
version "2.0.2"
Expand Down Expand Up @@ -2731,9 +2731,9 @@ lodash.flattendeep@^4.4.0:
integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=

lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4:
version "4.17.20"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

log-driver@^1.2.7:
version "1.2.7"
Expand Down Expand Up @@ -4334,9 +4334,9 @@ xml@^1.0.1:
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=

y18n@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==
version "4.0.1"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4"
integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==

yallist@^2.1.2:
version "2.1.2"
Expand Down
2 changes: 1 addition & 1 deletion rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"nodemon": "^2.0.6",
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"symbol-bootstrap": "0.4.1"
"symbol-bootstrap": "1.0.4"
},
"dependencies": {
"catapult-sdk": "link:../catapult-sdk",
Expand Down
8 changes: 7 additions & 1 deletion rest/resources/rest.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,11 @@
}
},

"numBlocksTransactionFeeStats": 300
"numBlocksTransactionFeeStats": 300,

"deployment": {
"deploymentTool": "",
"deploymentToolVersion": "",
"lastUpdatedDate": ""
}
}
3 changes: 2 additions & 1 deletion rest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ const registerRoutes = (server, db, services) => {
},
apiNode: services.config.apiNode,
websocket: services.config.websocket,
numBlocksTransactionFeeStats: services.config.numBlocksTransactionFeeStats
numBlocksTransactionFeeStats: services.config.numBlocksTransactionFeeStats,
deployment: services.config.deployment
},
connections: services.connectionService
};
Expand Down
51 changes: 51 additions & 0 deletions rest/src/plugins/cmc/CmcDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
* Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
* All rights reserved.
*
* This file is part of Catapult.
*
* Catapult is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Catapult is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

const { convertToLong } = require('../../db/dbUtils');

class CmcDb {
/**
* Creates NetworkCurrencyDb around CatapultDb.
* @param {module:db/CatapultDb} db Catapult db instance.
*/
constructor(db) {
this.catapultDb = db;
}

// region NetworkCurrency retrieval
/**
* Retrieves mosaics given their ids.
* @param {Array.<module:catapult.utils/uint64~uint64>} ids Mosaic ids.
* @returns {Promise.<array>} Mosaics.
*/
mosaicsByIds(ids) {
const mosaicIds = ids.map(id => convertToLong(id));
const conditions = { 'mosaic.id': { $in: mosaicIds } };
const collection = this.catapultDb.database.collection('mosaics');
return collection.find(conditions)
.sort({ _id: -1 })
.toArray()
.then(entities => Promise.resolve(this.catapultDb.sanitizer.renameIds(entities)));
}
// endregion
}

module.exports = CmcDb;
40 changes: 40 additions & 0 deletions rest/src/plugins/cmc/cmc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
* Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
* All rights reserved.
*
* This file is part of Catapult.
*
* Catapult is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Catapult is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

/** @module plugins/cmc */
const CmcDb = require('./CmcDb');
const cmcRoutes = require('./cmcRoutes');

/**
* Creates a cmc plugin.
* @type {module:plugins/CatapultRestPlugin}
*/
module.exports = {
createDb: db => new CmcDb(db),

registerTransactionStates: () => {},

registerMessageChannels: () => {},

registerRoutes: (...args) => {
cmcRoutes.register(...args);
}
};
85 changes: 85 additions & 0 deletions rest/src/plugins/cmc/cmcRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
* Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
* All rights reserved.
*
* This file is part of Catapult.
*
* Catapult is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Catapult is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

const cmcUtils = require('./cmcUtils');
const uncirculatedAddresses = require('./unCirculatedAccounts');
const routeUtils = require('../../routes/routeUtils');
const errors = require('../../server/errors');
const AccountType = require('../AccountType');
const ini = require('ini');
const fs = require('fs');
const util = require('util');

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

const readAndParseNetworkPropertiesFile = () => {
const readFile = util.promisify(fs.readFile);
return readFile(services.config.apiNode.networkPropertyFilePath, 'utf8')
.then(fileData => ini.parse(fileData));
};

server.get('/network/currency/supply/circulating', (req, res, next) => readAndParseNetworkPropertiesFile()
.then(async propertiesObject => {
/* eslint-disable global-require */
const accountIds = routeUtils.parseArgumentAsArray({ addresses: uncirculatedAddresses }, 'addresses', 'address');
const currencyId = propertiesObject.chain.currencyMosaicId.replace(/'/g, '').replace('0x', '');
const mosaicId = routeUtils.parseArgument({ mosaicId: currencyId }, 'mosaicId', 'uint64hex');

const mosaics = await db.mosaicsByIds([mosaicId]);
const accounts = await db.catapultDb.accountsByIds(accountIds.map(accountId => ({ [AccountType.address]: accountId })));

const totalSupply = parseInt(mosaics[0].mosaic.supply.toString(), 10);
const totalUncirculated = accounts.reduce((a, b) => a + parseInt(b.account.mosaics[0].amount.toString(), 10), 0);

const circulatingSupply = (totalSupply - totalUncirculated).toString();

sender.sendPlainText(res, next)(cmcUtils.convertToRelative(circulatingSupply));
}).catch(() => {
res.send(errors.createInvalidArgumentError('there was an error reading the network properties file'));
next();
}));

server.get('/network/currency/supply/total', (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 supply = response[0].mosaic.supply.toString();

sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply));
}).catch(() => {
res.send(errors.createInvalidArgumentError('there was an error reading the network properties file'));
next();
});
}));

server.get('/network/currency/supply/max', (req, res, next) => readAndParseNetworkPropertiesFile()
.then(propertiesObject => {
const supply = propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, '').replace('0x', '');
sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply));
}).catch(() => {
res.send(errors.createInvalidArgumentError('there was an error reading the network properties file'));
next();
}));
}
};
Loading

0 comments on commit bb0369e

Please sign in to comment.