Skip to content

Commit

Permalink
feat: add method "getTokens" #14
Browse files Browse the repository at this point in the history
  • Loading branch information
bacher authored Sep 27, 2019
1 parent 6bc70cf commit 71b9842
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/controllers/BlockChainMongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,33 @@ class BlockChainMongo extends BasicController {
items,
};
}

async getTokens() {
const db = this._client.db('_CYBERWAY_cyber_token');
const collection = db.collection('stat');

const results = await collection
.find({})
.project({
_id: false,
issuer: true,
supply: true,
max_supply: true,
'_SERVICE_.scope': true,
})
.toArray();

const items = results.map(item => ({
symbol: item._SERVICE_.scope,
issuer: item.issuer,
supply: formatAsset(item.supply),
maxSupply: formatAsset(item.max_supply),
}));

return {
items,
};
}
}

module.exports = BlockChainMongo;
10 changes: 10 additions & 0 deletions src/services/Connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Connector extends BasicConnector {
inherits: ['pagination'],
handler: this._bcMongo.getDelegations,
scope: this._bcMongo,
validation: {},
},
getValidators: {
inherits: ['pagination'],
Expand All @@ -33,21 +34,30 @@ class Connector extends BasicConnector {
getLeaders: {
handler: this._bcMongo.getLeaders,
scope: this._bcMongo,
validation: {},
},
getNameBids: {
inherits: ['pagination'],
handler: this._bcMongo.getNameBids,
scope: this._bcMongo,
validation: {},
},
getLastClosedBid: {
inherits: ['pagination'],
handler: this._bcMongo.getLastClosedBid,
scope: this._bcMongo,
validation: {},
},
getReceivedGrants: {
inherits: ['pagination'],
handler: this._bcMongo.getReceivedGrants,
scope: this._bcMongo,
validation: {},
},
getTokens: {
handler: this._bcMongo.getTokens,
scope: this._bcMongo,
validation: {},
},
},
serverDefaults: {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ function formatAsset(value) {

const bigNum = new BigNum(value._amount);

return `${bigNum.shiftedBy(-Number(value._decs.toString()))} ${value._sym}`;
const decs = Number(value._decs.toString());

return `${bigNum.shiftedBy(-decs).toFixed(decs)} ${value._sym}`;
}

function extractNumber(value) {
Expand Down

0 comments on commit 71b9842

Please sign in to comment.