Skip to content

Commit

Permalink
Build 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Sep 1, 2020
1 parent d97f206 commit 45b8efa
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
43 changes: 43 additions & 0 deletions dist/dbPatches/tokenData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";
var _dataSource = _interopRequireDefault(require("../lib/dataSource.js"));
var _Block = require("../services/classes/Block");
var _BlocksBase = _interopRequireDefault(require("../lib/BlocksBase"));
var _BlockSummary = require("../services/classes/BlockSummary");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

update().then(addresses => {
if (addresses.length) {
console.log('Addresses:');
console.log(JSON.stringify(addresses, null, 2));
} else {
console.log('There are not invalid token data');
}
process.exit(0);
});

async function update() {
try {
const addresses = {};
const { collections, db, initConfig } = await (0, _dataSource.default)();
const collection = collections.Addrs;
const q = { $type: 'object' };
const cursor = collection.find({ $or: [{ decimals: q }, { totalSupply: q }] }).project({ address: 1, name: 1, blockNumber: 1 });
while (await cursor.hasNext()) {
let { address, name, blockNumber } = await cursor.next();
addresses[address] = { address, name };
console.log(`Address: ${address}, name:${name}`);
let summaries = await (0, _BlockSummary.getBlockSummariesByNumber)(blockNumber, collections);
summaries = summaries.map(({ hash }) => hash);
console.log(`Removing block summaries for block ${blockNumber}`);
await Promise.all([...summaries.map(hash => (0, _BlockSummary.deleteBlockSummaryFromDb)(hash, collections))]);
console.log(`Deleting block ${blockNumber} from db`);
await Promise.all([...summaries.map(hash => (0, _Block.deleteBlockDataFromDb)(hash, blockNumber, collections))]);
console.log(`Getting block ${blockNumber}`);
let block = new _Block.Block(blockNumber, new _BlocksBase.default(db, { initConfig }));
await block.save();
}
return Object.values(addresses);
} catch (err) {
console.error(err);
process.exit(9);
}
}
2 changes: 1 addition & 1 deletion dist/services/classes/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Address extends _BcThing.BcThing {

async getBalance(blockNumber = 'latest') {
try {
if (this.isZeroAddress) return '0x0';
let { nod3, address } = this;
let balance = await nod3.eth.getBalance(address, blockNumber);
return balance;
Expand All @@ -62,6 +61,7 @@ class Address extends _BcThing.BcThing {
}
let { nod3, address, blockNumber, blockCode } = this;
if (blockCode !== undefined) return blockCode;

blockCode = await nod3.eth.getCode(address, blockNumber);
blockCode = (0, _utils.isNullData)(blockCode) ? null : blockCode;
this.blockCode = blockCode;
Expand Down
2 changes: 1 addition & 1 deletion dist/services/classes/Addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Addresses {
for (let address of addresses) {
await address.fetch(forceFetch);
}
return addresses.map(a => a.getData());
return addresses.map(a => a.getData(true));
} catch (err) {
return Promise.reject(err);
}
Expand Down
22 changes: 20 additions & 2 deletions dist/services/classes/BlockSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var _Tx = _interopRequireDefault(require("./Tx"));
var _BlockTrace = _interopRequireDefault(require("./BlockTrace"));
var _BlockAddresses = require("./BlockAddresses");
var _ids = require("../../lib/ids");
var _utils = require("../../lib/utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var _utils = require("../../lib/utils");
var _addresses = require("@rsksmart/rsk-utils/dist/addresses");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const BlocksSummaryCollection = 'BlocksSummary';exports.BlocksSummaryCollection = BlocksSummaryCollection;

Expand Down Expand Up @@ -108,7 +109,12 @@ class BlockSummary extends _BcThing.BcThing {
let blockData = await this.getBlockData();
Addresses = new _BlockAddresses.BlockAddresses(blockData, { nod3, initConfig, collections });
let { miner } = blockData;
Addresses.add(miner, { block: blockData });
let options = { block: blockData };
Addresses.add(miner, options);
let summariesAddresses = await this.getSummariesAddresses();
for (let address of summariesAddresses) {
if ((0, _addresses.isAddress)(address)) Addresses.add(address, options);
}
this.Addresses = Addresses;
}
return Addresses;
Expand All @@ -117,6 +123,18 @@ class BlockSummary extends _BcThing.BcThing {
}
}

async getSummariesAddresses() {
try {
const { collections } = this;
const { number } = await this.getBlockData();
const summaries = await getBlockSummariesByNumber(number, collections);
const addresses = [...new Set([].concat(...summaries.map(({ addresses }) => addresses)))];
return addresses;
} catch (err) {
return Promise.reject(err);
}
}

async save() {
try {
let data = await this.fetch();
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rsk-explorer-api",
"version": "1.1.5",
"version": "1.1.6",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"title": "rsk-explorer-api",
"version": "1.1.5",
"version": "1.1.6",
"description": "explorer API Documentation"
},
"swagger": "2.0",
Expand Down

0 comments on commit 45b8efa

Please sign in to comment.