Skip to content

Commit

Permalink
Merge pull request #104 from Cerebellum-Network/release/0.23.0
Browse files Browse the repository at this point in the history
Release/0.23.0
  • Loading branch information
Andrei Navoichyk authored Sep 8, 2022
2 parents e95d8d6 + d0b5681 commit 464e028
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 200 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Cere Stats

## vNext
-
- ...

## v0.23.0
- [FE] Updated the main metrics grid: removed accounts, split validators into active and waiting

## v0.22.0
- [BE] Implemented all errors catch to avoid app crash
Expand Down
8 changes: 8 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ app.use('/', (req, res) => {
})
});

app.use((err, req, res, next) => {
err.message = `Failed to process ${req.path} request. ${err.message}`;
console.error(err);
res.status(500).json({
msg: 'Unexpected server error'
});
});

// Start app
app.listen(port, async () => {
console.log(`PolkaStats API is listening on port ${port}.`);
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.22.0",
"version": "0.23.0",
"description": "PolkaStats API",
"author": "Mario Pino Uceda",
"license": "Apache-2.0",
Expand Down
7 changes: 6 additions & 1 deletion api/src/services/cacheService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ module.exports = {
console.log('Cache service initialized');

setInterval(async () => {
cache.accounts = await accountsService.get();
try {
cache.accounts = await accountsService.get();
} catch (err) {
err.message = `Failed to get accounts balances. ${err.message}`;
console.error(err);
}
}, cacheIntervalMs);
},
getAccounts: ()=> cache.accounts,
Expand Down
48 changes: 28 additions & 20 deletions api/src/services/cereTokensService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,35 @@ function getTotalSupplyInternal(network) {
}

module.exports = {
getTotalSupply: async (req, res) => {
const totalSupply = await getTotalSupplyInternal(networkNames.MAINNET);
res.json(toFloat(totalSupply, decimals.CERE));
getTotalSupply: async (req, res, next) => {
try {
const totalSupply = await getTotalSupplyInternal(networkNames.MAINNET);
res.json(toFloat(totalSupply, decimals.CERE));
} catch (err) {
next(err);
}
},
getCirculatingSupply: async (req, res) => {
const totalSupply = await getTotalSupplyInternal(networkNames.MAINNET);
let circulatingSupply = totalSupply;
const ethereumCERELockedAddresses = JSON.parse(ETHEREUM_CERE_LOCKED_ADDRESSES);
const { cereTokenContractAddress } =
blockchains.find(blockchain => blockchain.name === blockchainNames.ETHEREUM)
.networks.find(network => network.name === networkNames.MAINNET);
getCirculatingSupply: async (req, res, next) => {
try {
const totalSupply = await getTotalSupplyInternal(networkNames.MAINNET);
let circulatingSupply = totalSupply;
const ethereumCERELockedAddresses = JSON.parse(ETHEREUM_CERE_LOCKED_ADDRESSES);
const { cereTokenContractAddress } =
blockchains.find(blockchain => blockchain.name === blockchainNames.ETHEREUM)
.networks.find(network => network.name === networkNames.MAINNET);

for (let i = 0; i < ethereumCERELockedAddresses.length; i++) {
const balance = await ethNetworkService.getErc20Balance({
blockchain: blockchainNames.ETHEREUM,
network: networkNames.MAINNET,
erc20TokenAddress: cereTokenContractAddress,
address: ethereumCERELockedAddresses[i]
});
circulatingSupply = circulatingSupply.sub(balance);
}
res.json(toFloat(circulatingSupply, decimals.CERE));
for (let i = 0; i < ethereumCERELockedAddresses.length; i++) {
const balance = await ethNetworkService.getErc20Balance({
blockchain: blockchainNames.ETHEREUM,
network: networkNames.MAINNET,
erc20TokenAddress: cereTokenContractAddress,
address: ethereumCERELockedAddresses[i]
});
circulatingSupply = circulatingSupply.sub(balance);
}
res.json(toFloat(circulatingSupply, decimals.CERE));
} catch(err) {
next(err);
};
},
};
Loading

0 comments on commit 464e028

Please sign in to comment.