Skip to content

Commit

Permalink
Build 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Aug 11, 2020
1 parent 83bf692 commit 807d52b
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 82 deletions.
23 changes: 17 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
# Changelog

## [1.1.5] - 2020-08-11

## Added

- Self destructed contracts support.
- Tools: updateBalances, checks/updates the balances of all DB addresses.

## Fixed

- Contracts balances

## [1.1.4] - 2020-08-06

### Updated

- Db.createCollection to the new mongodb driver behavior
- Db.createCollection to the new mongodb driver behavior.
- blocks checker service, delay before start.
- config: disable services in config
- Config: disable services in config.

## [1.1.3] - 2020-08-04

This release requires the regeneration of the DB follow the instructions in [UPDATES.md](UPDATES.md) before starting.

### Fixed

- Event decoding
- Addresses balances
- Token Addresses balances and detection
- Event decoding.
- Addresses balances.
- Token Addresses balances and detection.
- Repetitive indexing of collections at each service start.
- Tokens total supply, see #30
- Tokens total supply, see #30.

## [1.1.2] - 2020-07-17

Expand Down
1 change: 0 additions & 1 deletion dist/api/api.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if (log && log.dir) {
conf.out_file = `${dir}/${name}-out.log`;
}


const apps = [conf];exports.apps = apps;

console.log(apps);
6 changes: 5 additions & 1 deletion dist/lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@

{
key: { 'action.to': 1 },
name: 'internalTxsToIndex' }] },
name: 'internalTxsToIndex' },

{
key: { type: 1 },
name: 'internalTxTypeIndex' }] },



Expand Down
3 changes: 2 additions & 1 deletion dist/lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ const TOTAL_SUPPLY = 21 * 10 ** 6;exports.TOTAL_SUPPLY = TOTAL_SUPPLY;
const fields = {
LAST_BLOCK_MINED: 'lastBlockMined',
DEPLOYED_CODE: 'deployedCode',
CREATED_BY_TX: 'createdByTx' };exports.fields = fields;
CREATED_BY_TX: 'createdByTx',
DESTROYED_BY: 'destroyedByTx' };exports.fields = fields;


const EVMversions = [
Expand Down
6 changes: 2 additions & 4 deletions dist/services/blocks.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.apps = exports.paths = void 0;
var _config = _interopRequireDefault(require("../lib/config"));
var _servicesConfig = require("./servicesConfig");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
const { services } = _config.default.blocks;
var _serviceFactory = require("./serviceFactory");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const scripts = Object.entries(_servicesConfig.servicesNames).
filter(([service]) => services[service]).
const scripts = Object.entries(_serviceFactory.enabledServices).
map(([service, name]) => name);

const scriptName = name => `${name}.js`;
Expand Down
63 changes: 45 additions & 18 deletions dist/services/classes/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Address extends _BcThing.BcThing {
this.name = nName;
this.isNative = !!nName;
this.dbData = undefined;
this.blockCode = undefined;
this.tx = tx;
this.data = createAddressData(this);
this.setBlock(block);
Expand Down Expand Up @@ -56,36 +57,46 @@ class Address extends _BcThing.BcThing {

async getCode() {
try {
if (this.isZeroAddress || this.isNative) return null;
let { code } = this.getData();
let { nod3, address, blockNumber } = this;
if (code !== undefined) return code;
code = await nod3.eth.getCode(address, blockNumber);
code = (0, _utils.isNullData)(code) ? null : code;
this.setData({ code });
return code;
if (this.isZeroAddress || this.isNative) {
this.blockCode = null;
}
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;
return blockCode;
} catch (err) {
return Promise.reject(err);
}
}

saveCode() {
let { code } = this.getData();
if (code) return;
let { blockCode } = this;
if (!blockCode) return;
code = blockCode;
let codeStoredAtBlock = this.blockNumber;
this.setData({ code, codeStoredAtBlock });
}

async fetch(forceFetch) {
try {
if (this.fetched && !forceFetch) return this.getData(true);
this.fetched = false;
let dbData = this.isZeroAddress ? {} : await this.getFromDb();
this.setData(dbData);

let { blockNumber } = this;

let storedBlock = this.data.blockNumber || 0;
if (blockNumber >= storedBlock) {
if (storedBlock <= blockNumber) {
let balance = await this.getBalance('latest');
this.setData({ balance, blockNumber });
}

let code = await this.getCode();
// TODO suicide
this.saveCode();
if (code) {
// get contract info
let deployedCode = dbData ? dbData[_types.fields.DEPLOYED_CODE] : undefined;
Expand All @@ -101,8 +112,11 @@ class Address extends _BcThing.BcThing {
data[_types.fields.DEPLOYED_CODE] = deployedCode;
this.setData(data);
}
this.makeContract(deployedCode, dbData);
this.makeContract(deployedCode);
let contractData = await this.contract.fetch();
// prevent update this fields from contractData
delete contractData.balance;
delete contractData.blockNumber;
this.setData(contractData);
}
if (this.isNative) this.makeContract();
Expand Down Expand Up @@ -187,15 +201,15 @@ class Address extends _BcThing.BcThing {
}

isContract() {
let { code, type } = this.getData();
let { isNative, address } = this;
if (undefined === code && !isNative && !(0, _rskUtils.isZeroAddress)(address)) {
let { address, blockCode } = this;
if (undefined === blockCode) {
throw new Error(`Run getCode first ${address}`);
}
return type === _types.addrTypes.CONTRACT;
return !!blockCode;
}

makeContract(deployedCode, dbData) {
makeContract(deployedCode) {
const dbData = Object.assign({}, this.getData(true));
if (this.contract) return this.contract;
let { address, nod3, initConfig, collections, block } = this;
this.contract = new _Contract.default(address, deployedCode, { dbData, nod3, initConfig, collections, block });
Expand All @@ -208,6 +222,12 @@ class Address extends _BcThing.BcThing {
} catch (err) {
return Promise.reject(err);
}
}

suicide(destroyedBy) {
let data = {};
data[_types.fields.DESTROYED_BY] = destroyedBy;
this.setData(data);
}}exports.Address = Address;


Expand Down Expand Up @@ -239,13 +259,20 @@ function createAddressData({ address, isNative, name }) {
switch (prop) {
case 'code':
if ((0, _utils.isNullData)(val)) val = null;
if (val) {
if (val && data[_types.fields.DESTROYED_BY] === undefined) {
data.type = _types.addrTypes.CONTRACT;
}
// Fix to support suicide
data.code = val;
break;

case _types.fields.DESTROYED_BY:
if (data[prop] !== undefined) return true;
val = (0, _InternalTx.checkInternalTransactionData)(Object.assign({}, val));
data[prop] = val;
data.type = _types.addrTypes.ADDRESS;
break;

case _types.fields.LAST_BLOCK_MINED:
const lastBlock = data[_types.fields.LAST_BLOCK_MINED] || {};
let number = lastBlock.number || -1;
Expand Down
13 changes: 8 additions & 5 deletions dist/services/classes/Addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class Addresses {
this.initConfig = initConfig;
this.addresses = {};
}
add(address, options = {}) {
createAddress(address, options = {}) {
if (!(0, _utils.isAddress)(address)) throw new Error(`Invalid address ${address}`);
options = options || {};
let { nod3, initConfig, collections } = this;
options = Object.assign(options, { nod3, initConfig, collections });
return new _Address.default(address, options);
}
add(address, options = {}) {
if (!this.addresses[address]) {
options = options || {};
let { nod3, initConfig, collections } = this;
options = Object.assign(options, { nod3, initConfig, collections });
this.addresses[address] = new _Address.default(address, options);
this.addresses[address] = this.createAddress(address, options);
}
return this.addresses[address];
}
Expand Down
1 change: 1 addition & 0 deletions dist/services/classes/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Block extends _BcThing.BcThing {
return result;
} catch (err) {
this.log.error('Error inserting events');
this.log.trace(`Events: ${JSON.stringify(events, null, 2)}`);
return Promise.reject(err);
}
}
Expand Down
3 changes: 2 additions & 1 deletion dist/services/classes/BlockSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class BlockSummary extends _BcThing.BcThing {
let events = [].concat(...txsData.map(d => d.events));
let internalTransactions = [].concat(...txsData.map(d => d.internalTransactions));
let tokenAddresses = [].concat(...txsData.map(d => d.tokenAddresses));
let suicides = [].concat(...txsData.map(d => d.suicides));
let addresses = await Addresses.fetch();
this.setData({ internalTransactions, events, addresses, tokenAddresses });
this.setData({ internalTransactions, events, addresses, tokenAddresses, suicides });
this.fetched = true;
return this.getData();
} catch (err) {
Expand Down
64 changes: 44 additions & 20 deletions dist/services/classes/InternalTx.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.getInternalTxId = getInternalTxId;exports.filterValueAddresses = filterValueAddresses;exports.default = exports.InternalTx = void 0;var _BcThing = require("./BcThing");
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.checkInternatTransactionType = checkInternatTransactionType;exports.getInternalTxId = getInternalTxId;exports.filterValueAddresses = filterValueAddresses;exports.checkInternalTransactionData = checkInternalTransactionData;exports.default = exports.InternalTx = void 0;var _BcThing = require("./BcThing");
var _ids = require("../../lib/ids");
var _utils = require("../../lib/utils");

const REQUIRED_FIELDS = [
'blockHash',
'blockNumber',
'transactionHash',
'transactionPosition',
'type',
'subtraces',
'traceAddress',
'result',
'action',
'timestamp'];
const ITX_FIELDS = {
blockNumber: null,
transactionHash: _utils.isBlockHash,
blockHash: _utils.isBlockHash,
transactionPosition: null,
type: checkInternatTransactionType,
subtraces: null,
traceAddress: Array.isArray,
result: null,
action: null,
timestamp: null,
_index: null };


class InternalTx extends _BcThing.BcThing {
Expand All @@ -21,11 +23,7 @@ class InternalTx extends _BcThing.BcThing {
}

checkData(data) {
if (typeof data !== 'object') throw new Error('Data is not an object');
for (let field of REQUIRED_FIELDS) {
if (!data.hasOwnProperty(field)) throw new Error(`Missing field: ${field}`);
}
return data;
return checkInternalTransactionData(data);
}

setData(data) {
Expand All @@ -40,14 +38,24 @@ class InternalTx extends _BcThing.BcThing {
let data = this.getData();
let { action } = data;
let { isAddress } = this;
return Object.entries(action).
filter(a => {
let [name, value] = a;
let addresses = Object.entries(action).
filter(([name, value]) => {
return name !== 'balance' && isAddress(value);
}).map(v => v[1]);
return [...new Set(addresses)];
}

isSuicide() {
let { type, action } = this.getData();
return checkInternatTransactionType(type) === 'suicide' && (0, _utils.isAddress)(action.address);
}}exports.InternalTx = InternalTx;


function checkInternatTransactionType(type) {
if (typeof type !== 'string') throw new Error(`Invalid itx type: ${type}`);
return type;
}

function getInternalTxId({ blockNumber, transactionPosition: transactionIndex, transactionHash: hash, _index: index }) {
return (0, _ids.generateId)({ blockNumber, transactionIndex, hash, index });
}
Expand All @@ -59,9 +67,25 @@ function filterValueAddresses(internalTransactions) {
if (!error && parseInt(value) > 0) {
addresses.add(from);
addresses.add(to);
// review suicide and refund address
}
});
return [...addresses];
}

function checkInternalTransactionData(data) {
if (typeof data !== 'object') throw new Error('Data is not an object');
for (let field of Object.keys(ITX_FIELDS)) {
if (!data.hasOwnProperty(field)) throw new Error(`Missing field: ${field}`);
let value = data[field];
let check = ITX_FIELDS[field];
if (typeof check === 'function') {
if (!check(data[field])) {
throw new Error(`Invalid value: ${value} for itx field: ${field}`);
}
}
}
return data;
}var _default =

InternalTx;exports.default = _default;
Loading

0 comments on commit 807d52b

Please sign in to comment.