diff --git a/dist/dbPatches/tokenData.js b/dist/dbPatches/tokenData.js new file mode 100644 index 00000000..8e234dbd --- /dev/null +++ b/dist/dbPatches/tokenData.js @@ -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); + } +} \ No newline at end of file diff --git a/dist/services/classes/Address.js b/dist/services/classes/Address.js index e243bcf8..62bdeae9 100644 --- a/dist/services/classes/Address.js +++ b/dist/services/classes/Address.js @@ -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; @@ -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; diff --git a/dist/services/classes/Addresses.js b/dist/services/classes/Addresses.js index d4fabdd9..80655762 100644 --- a/dist/services/classes/Addresses.js +++ b/dist/services/classes/Addresses.js @@ -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); } diff --git a/dist/services/classes/BlockSummary.js b/dist/services/classes/BlockSummary.js index 76c78c37..f3f3e910 100644 --- a/dist/services/classes/BlockSummary.js +++ b/dist/services/classes/BlockSummary.js @@ -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; @@ -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; @@ -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(); diff --git a/package-lock.json b/package-lock.json index 02f3b815..4a3ed113 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.5", + "version": "1.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0ea7cc05..2f66b335 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.5", + "version": "1.1.6", "description": "", "main": "index.js", "scripts": { diff --git a/public/swagger.json b/public/swagger.json index 30e06bb5..4f9c9f5b 100644 --- a/public/swagger.json +++ b/public/swagger.json @@ -1,7 +1,7 @@ { "info": { "title": "rsk-explorer-api", - "version": "1.1.5", + "version": "1.1.6", "description": "explorer API Documentation" }, "swagger": "2.0",