Skip to content

Commit

Permalink
Build 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Apr 3, 2020
1 parent 70f479b commit 6e7d6d8
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dist/api/lib/DataCollector/DataCollectorItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class DataCollectorItem {
}
/**
* Resolves item query parsing params
* @param {*} query
* @param {*} params
* @param {*} query
* @param {*} params
*/
async getItem(query, { fields, getPrevNext }) {
try {
Expand Down
2 changes: 1 addition & 1 deletion dist/api/modules/ExtendedStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var _hashrateCalculator = require("../lib/hashrateCalculator");
var _difficultyCalculator = require("../lib/difficultyCalculator");


// 1 hour bucket size
const DIFFICULTY_BUCKET_SIZE = 3600000;

const PERIODS = {
Expand Down
2 changes: 1 addition & 1 deletion dist/api/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var _Stats = require("./Stats");
var _Summary = require("./Summary");

var _ContractVerification = require("./ContractVerification");
var _apiTools = require("../lib/apiTools");
var _apiTools = require("../lib/apiTools"); // import { ExtendedStats } from './ExtendedStats'

const apiModules = { Block: _Block.Block, Tx: _Tx.Tx, Address: _Address.Address, Event: _Event.Event, Token: _Token.Token, TxPending: _TxPending.TxPending, Stats: _Stats.Stats, Summary: _Summary.Summary, ContractVerification: _ContractVerification.ContractVerification };

Expand Down
58 changes: 58 additions & 0 deletions dist/dbPatches/tokenAccountBalances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";
var _dataSource = _interopRequireDefault(require("../lib/dataSource.js"));
var _nod3Connect = _interopRequireDefault(require("../lib/nod3Connect"));
var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser"));
var _rskUtils = require("rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const parser = new _rskContractParser.default({ nod3: _nod3Connect.default });

patch().then(() => {
console.log('DONE!');
}).catch(err => {
console.log('ERROR');
console.log(err);
process.exit(9);
});

async function patch() {
try {
let { db } = await (0, _dataSource.default)({ skipCheck: true });
let collection = db.collection('tokensAddresses');
let cursor = collection.find();
await cursor.forEach(async account => {
try {
let { balance, contract, address, _id } = account;
let name = `${contract}--${address}`;
if (balance !== null) {
console.log(`Getting balance for ${name}`);
let newBalance = await getBalance(account);
newBalance = (0, _rskUtils.add0x)(newBalance.toString(16));
if (balance !== newBalance) {
console.log(`Updating balance for ${name}`);
await collection.updateOne({ _id }, { $set: { balance: newBalance } });
} else {
console.log(`${name} .... OK`);
}
} else {
console.log(`${name} has null balance, skipped`);
}
} catch (err) {
console.log(err, account);
return Promise.reject(err);
}
});
} catch (err) {
console.log(err);
process.exit(9);
}
}

async function getBalance({ address, contract }, { abi } = {}) {
try {
let Contract = parser.makeContract(contract, abi);
let balance = await Contract.call('balanceOf', [address]);
return balance;
} catch (err) {
return Promise.reject(err);
}
}
1 change: 0 additions & 1 deletion dist/lib/Db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.Db = void 0;var _mongodb = require("mongodb");


const connectionOptions = { useNewUrlParser: true, useUnifiedTopology: true };
class Db {
constructor(config) {
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/btcUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.rskAddressFromBtcPublicKey = exports.compressPublic = exports.decompressPublic = exports.parsePublic = exports.pubToAddress = exports.h160toAddress = exports.h160 = exports.sha256 = void 0;var _crypto = _interopRequireDefault(require("crypto"));
var bs58 = _interopRequireWildcard(require("bs58"));
var _utils = require("./utils");
var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};if (obj != null) {var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const PREFIXES = {
mainnet: {
Expand Down
6 changes: 3 additions & 3 deletions dist/lib/initialConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
var _fs = _interopRequireDefault(require("fs"));
var _utils = require("./utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}




/**
*
*/

const defaultConfig = {
nativeContracts: {
Expand Down
7 changes: 5 additions & 2 deletions dist/services/classes/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ class Block extends _BcThing.BcThing {
}

newContract(address, data) {
const { nod3, initConfig } = this;
let contract = new _Contract.default(address, data, { nod3, initConfig });
let { nod3, initConfig } = this;
let { block } = this.data;
let contract = new _Contract.default(address, data, { nod3, initConfig, block });
this.contracts[address] = contract;
return contract;
}
Expand Down Expand Up @@ -386,6 +387,8 @@ const getBlockFromDb = async (blockHashOrNumber, collection) => {

const deleteBlockDataFromDb = async (blockHash, blockNumber, db) => {
try {
blockNumber = parseInt(blockNumber);
if (blockNumber < 1) throw new Error(`The blockNumber is wrong`);
if (!blockHash) throw new Error(`Empty block hash`);
let hash = blockHash;
let result = {};
Expand Down
3 changes: 2 additions & 1 deletion dist/services/classes/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ var _TokenAddress = _interopRequireDefault(require("./TokenAddress"));
var _utils = require("../../lib/utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

class Contract extends _BcThing.BcThing {
constructor(address, creationData, { nod3, initConfig }) {
constructor(address, creationData, { nod3, initConfig, block }) {
super({ nod3, initConfig });
if (!this.isAddress(address)) throw new Error(`Contract: invalid address ${address}`);
this.parser = new _rskContractParser.default({ initConfig, nod3 });
this.address = address;
this.creationData = creationData;
const createdByTx = creationData && creationData.tx ? creationData.tx : null;
this.block = block;
this.data = {
address,
createdByTx,
Expand Down
7 changes: 5 additions & 2 deletions dist/services/classes/RequestBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _BlocksBase = require("../../lib/BlocksBase");
var _types = require("../../lib/types");
var _Block = require("./Block");
var _utils = require("../../lib/utils");
var _UpdateTokenAccountBalances = require("./UpdateTokenAccountBalances");

class Emitter extends _events.EventEmitter {}

Expand Down Expand Up @@ -140,9 +141,11 @@ async function getBlock(hashOrNumber, { nod3, collections, log, initConfig }) {
}
try {
let newBlock = new _Block.Block(hashOrNumber, { nod3, collections, log, initConfig });
let block = await newBlock.save().then(res => {
let block = await newBlock.save().then(async res => {
if (!res || !res.data) return;
return res.data.block;
let block = res.data.block;
await (0, _UpdateTokenAccountBalances.updateTokenAccountBalances)(block, { nod3, collections, initConfig, log });
return block;
});
return { block, key: hashOrNumber };
} catch (error) {
Expand Down
11 changes: 9 additions & 2 deletions dist/services/classes/TokenAddress.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.TokenAddress = void 0;var _BcThing = require("./BcThing");
var _Contract = _interopRequireDefault(require("./Contract"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var _Contract = _interopRequireDefault(require("./Contract"));
var _utils = require("../../lib/utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

class TokenAddress extends _BcThing.BcThing {
constructor(address, contract) {
if (!(contract instanceof _Contract.default)) {
throw new Error('contract is not instance of Contract');
}
let { block } = contract;
if (!(0, _utils.isBlockObject)(block)) {
throw new Error(`Block must be a block object`);
}
const { initConfig } = contract;
super({ initConfig });
if (!this.isAddress(address)) {
throw new Error(`TokenAddress: invalid address: ${address}`);
}
this.Contract = contract;
this.address = address;
let { number, hash } = block;
this.data = {
address,
contract: this.Contract.address,
balance: null };
balance: null,
block: { number, hash } };

}
async fetch() {
Expand Down
1 change: 0 additions & 1 deletion dist/services/classes/Tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Tx extends _BcThing.BcThing {
} catch (err) {
return Promise.reject(err);
}

}

async getTx() {
Expand Down
42 changes: 42 additions & 0 deletions dist/services/classes/UpdateTokenAccountBalances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.updateTokenAccountBalances = updateTokenAccountBalances;
var _rskUtils = require("rsk-utils");
var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

async function updateTokenAccountBalances(block, { nod3, collections, log }) {
const parser = new _rskContractParser.default({ nod3 });
let { number } = block;
number = parseInt(number) - 1;
if (number < 1) return;
log.trace(`Checking token account balances for block ${number}`);
try {
let collection = collections.TokensAddrs;
let query = { 'block.number': number };
let cursor = collection.find(query);
await cursor.forEach(async account => {
try {
let { balance, _id, address, contract } = account;
let newBalance = await getBalance(account, { parser });
if (balance !== newBalance) {
log.info(`Updating token account balance ${contract}--${address}`);
await collection.updateOne({ _id }, { $set: { balance: newBalance } });
}
} catch (err) {
log.error(err);
return Promise.reject(err);
}
});
} catch (err) {
return Promise.reject(err);
}
}

async function getBalance({ address, contract }, { parser, abi } = {}) {
try {
let Contract = parser.makeContract(contract, abi);
let balance = await Contract.call('balanceOf', [address]);
if (balance) balance = (0, _rskUtils.add0x)(balance.toString(16));
return balance;
} catch (err) {
return Promise.reject(err);
}
}
2 changes: 1 addition & 1 deletion dist/services/userEvents/ContractVerifierModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var _StoredConfig = require("../../lib/StoredConfig");
var _mongodb = require("mongodb");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}


// id to store solc versions list on Config collection
const versionsId = '_contractVerifierVersions';exports.versionsId = versionsId;

function ContractVerifierModule(db, collections, { url } = {}, { log } = {}) {
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/wsChannel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";var _socket = _interopRequireDefault(require("socket.io-client"));
var c = _interopRequireWildcard(require("../lib/cli"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};if (obj != null) {var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var c = _interopRequireWildcard(require("../lib/cli"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const url = process.argv[2];
let channel = process.argv[3];
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/wsGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var c = _interopRequireWildcard(require("../lib/cli"));
var _fs = _interopRequireDefault(require("fs"));
var _crypto = _interopRequireDefault(require("crypto"));
var URL = _interopRequireWildcard(require("url"));
var _package = _interopRequireDefault(require("../../package.json"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};if (obj != null) {var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var _package = _interopRequireDefault(require("../../package.json"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const url = process.env.url || 'ws://localhost:3003';
if (process.argv[2] === '--help') help();
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.0.5",
"version": "1.0.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.0.5",
"version": "1.0.6",
"description": "explorer API Documentation"
},
"swagger": "2.0",
Expand Down

0 comments on commit 6e7d6d8

Please sign in to comment.