Skip to content

Commit ab91a30

Browse files
committed
Build 0.7.2
1 parent 9dc45ae commit ab91a30

File tree

12 files changed

+183
-31
lines changed

12 files changed

+183
-31
lines changed

dist/api/Address.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.Address = undefined;var _DataCollector = require('../lib/DataCollector');
22
var _types = require('../lib/types');
33
var _config = require('../lib/config');var _config2 = _interopRequireDefault(_config);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
4-
const bridgeAddress = _config2.default.bridgeAddress;
5-
const remascAddress = _config2.default.remascAddress;
4+
const { bridgeAddress, remascAddress } = _config2.default;
65
class Address extends _DataCollector.DataCollectorItem {
76
constructor(collection, key, parent) {
87
let sortable = { 'createdByTx.timestamp': -1 };

dist/api/Blocks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ class Blocks extends _DataCollector.DataCollector {
7171
this.events.emit('newBlocks', this.formatData({ blocks, transactions }));
7272
}
7373
}
74+
async getAddress(address) {
75+
return this.Address.run('getAddress', { address });
76+
}
7477

7578
async addAddressData(address, data, key = '_addressData') {
76-
const account = await this.Address.run('getAddress', { address });
79+
const account = await this.getAddress(address);
7780
if (data && data.data && account) data.data[key] = account.data;
7881
return data || account;
7982
}}exports.default =

dist/api/Event.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.Event = undefined;var _DataCollector = require('../lib/DataCollector');
2+
var _config = require('../lib/config');var _config2 = _interopRequireDefault(_config);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
3+
const { remascAddress, bridgeAddress } = _config2.default;
24
class Event extends _DataCollector.DataCollectorItem {
35
constructor(collection, key, parent) {
4-
const sortable = { timestamp: -1 };
5-
super(collection, key, parent, { sortable });
6+
// const sortable = { timestamp: -1 }
7+
super(collection, key, parent);
68
this.publicActions = {
79

810
getEvent: async params => {
911
try {
10-
const _id = params._id;
12+
const { _id } = params;
1113
let data = await this.getOne({ _id });
1214
if (!data) throw new Error(`Event ${_id} does not exist`);
1315
const address = data.data.address;
@@ -19,8 +21,42 @@ class Event extends _DataCollector.DataCollectorItem {
1921
},
2022

2123
getEventsByAddress: async params => {
22-
const address = params.address;
23-
if (address) return this.getPageData({ address }, params);
24+
const { address, signatures, contract } = params;
25+
if (address) {
26+
let query = { args: address
27+
28+
// search by events signatures
29+
};if (Array.isArray(signatures)) {
30+
// skip remasc & bridge events
31+
if (address !== remascAddress && address !== bridgeAddress) {
32+
query.signature = { $in: signatures };
33+
}
34+
}
35+
36+
if (contract) query.address = contract;
37+
38+
let res = await this.getPageData(query, params);
39+
if (res.data) {
40+
let addresses = new Set(res.data.map(d => d.address));
41+
addresses = [...addresses.values()];
42+
let addrData = await this.parent.Address.find({ address: { $in: addresses } });
43+
let { data } = addrData;
44+
if (data) {
45+
res.data = res.data.map(d => {
46+
d._addressData = data.find(a => a.address === d.address);
47+
return d;
48+
});
49+
}
50+
}
51+
return res;
52+
}
53+
},
54+
55+
getAllEventsByAddress: async params => {
56+
const { address } = params;
57+
if (address) {
58+
return this.getPageData({ $or: [{ address }, { args: address }] }, params);
59+
}
2460
} };
2561

2662
}}exports.Event = Event;exports.default =

dist/api/TokenAccount.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.TokenAccount = undefined;var _DataCollector = require('../lib/DataCollector');
2+
var _utils = require('../lib/utils');
3+
var _bignumber = require('bignumber.js');
24

35
class TokenAccount extends _DataCollector.DataCollectorItem {
46
constructor(collection, key, parent) {
@@ -36,6 +38,25 @@ class TokenAccount extends _DataCollector.DataCollectorItem {
3638
const { address, contract } = params;
3739
const account = await this.getOne({ address, contract });
3840
return this.parent.addAddressData(contract, account, '_contractData');
41+
},
42+
43+
getTokenBalance: async params => {
44+
const { contract } = params;
45+
let contractData = await this.parent.getAddress(contract);
46+
contractData = contractData.data;
47+
if (!contractData) return;
48+
let { totalSupply } = contractData;
49+
if (!totalSupply) return;
50+
let accounts = await this.find({ contract });
51+
if (accounts) accounts = accounts.data;
52+
if (!accounts) return;
53+
54+
let accountsBalance = (0, _utils.bigNumberSum)(accounts.map(account => account.balance));
55+
totalSupply = new _bignumber.BigNumber(totalSupply);
56+
let balance = accountsBalance ? totalSupply.minus(accountsBalance) : totalSupply;
57+
58+
const data = this.serialize({ balance, accountsBalance, totalSupply });
59+
return { data };
3960
} };
4061

4162
}}exports.TokenAccount = TokenAccount;exports.default =

dist/lib/ContractParser/ContractParser.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var _web3Connect = require('../web3Connect');
44
var _types = require('../types');
55
var _interfacesIds = require('./interfacesIds');var _interfacesIds2 = _interopRequireDefault(_interfacesIds);
66
var _utils = require('../../lib/utils');
7-
7+
var _config = require('../config');var _config2 = _interopRequireDefault(_config);
8+
var _RemascEvents = require('./RemascEvents');var _RemascEvents2 = _interopRequireDefault(_RemascEvents);
89
var _lib = require('./lib');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
910

1011

@@ -14,6 +15,8 @@ var _lib = require('./lib');function _interopRequireDefault(obj) {return obj &&
1415

1516

1617

18+
19+
const { remascAddress } = _config2.default;
1720
class ContractParser {
1821
constructor(abi, options = {}) {
1922
this.abi = null;
@@ -55,6 +58,9 @@ class ContractParser {
5558

5659
parseTxLogs(logs) {
5760
return logs.map(log => {
61+
// non-standard remasc events
62+
if (log.address === remascAddress) return _RemascEvents2.default.decode(log);
63+
5864
let back = Object.assign({}, log);
5965
let decoder = this.getLogDecoder(log.topics || []);
6066
let decoded = decoder ? decoder.event.decode(log) : log;
@@ -152,7 +158,7 @@ class ContractParser {
152158
let methods = this.getMethodsBySelectors(txInputData);
153159
let isErc165 = false;
154160
// skip non-erc165 conrtacts
155-
if ((0, _utils.hasValues)(methods, ['supportsInterface(bytes4)'])) {
161+
if ((0, _utils.includesAll)(methods, ['supportsInterface(bytes4)'])) {
156162
isErc165 = await this.implementsErc165(contract);
157163
}
158164
let interfaces;
@@ -176,7 +182,7 @@ class ContractParser {
176182
getInterfacesByMethods(methods, isErc165) {
177183
return Object.keys(_interfacesIds2.default).
178184
map(i => {
179-
return [i, (0, _utils.hasValues)(methods, _interfacesIds2.default[i].methods)];
185+
return [i, (0, _utils.includesAll)(methods, _interfacesIds2.default[i].methods)];
180186
}).
181187
reduce((obj, value) => {
182188
obj[value[0]] = value[1];
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.RemascEvents = undefined;var _rlp = require('rlp');var rlp = _interopRequireWildcard(_rlp);function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}
2+
3+
class RemascEvents {
4+
decode(log) {
5+
let event = this.decodeEventName(log.topics[0]);
6+
// at the moment remasc emits only one event
7+
if (event === 'mining_fee_topic') {
8+
let [blockHash, value] = this.decodeData(log.data);
9+
let to = this.decodeAddress(log.topics[1]);
10+
log.event = event;
11+
log.args = [to, blockHash, value];
12+
log.abi = this.fakeAbi();
13+
}
14+
return log;
15+
}
16+
17+
decodeEventName(name) {
18+
name = name.slice(0, 2) === '0x' ? name.slice(2, name.length) : name;
19+
return Buffer.from(name, 'hex').toString('ascii').replace(/\0/g, '');
20+
}
21+
22+
decodeData(data) {
23+
return rlp.decode(data).map(d => '0x' + d.toString('hex').replace(/^0+/, ''));
24+
}
25+
26+
decodeAddress(address) {
27+
return '0x' + address.slice(-40);
28+
}
29+
fakeAbi() {
30+
return {
31+
anonymous: false,
32+
inputs: [
33+
{
34+
indexed: true,
35+
name: 'to',
36+
type: 'address' },
37+
38+
{
39+
indexed: false,
40+
name: 'blockHash',
41+
type: 'address' },
42+
43+
{
44+
indexed: false,
45+
name: 'value',
46+
type: 'uint256' }],
47+
48+
49+
name: 'mining_fee_topic',
50+
type: 'event' };
51+
52+
}}exports.RemascEvents = RemascEvents;
53+
54+
55+
const remascEvents = new RemascEvents();exports.default =
56+
remascEvents;

dist/lib/collections.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,15 @@
105105

106106
{
107107
key: { blockNumber: 1 },
108-
name: 'eventBlockNumberIndex' }],
108+
name: 'eventBlockNumberIndex' },
109+
110+
{
111+
key: { args: 1 },
112+
name: 'eventsArgsIndex' },
113+
114+
{
115+
key: { signature: 1 },
116+
name: 'eventSignatureIndex' }],
109117

110118

111119
TokensAddrs: [

dist/lib/utils.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.jsonDecode = exports.jsonEncode = exports.keccak256 = exports.base64toHex = exports.btoa = exports.atob = exports.hasValues = exports.hasValue = exports.arraySymmetricDifference = exports.arrayDifference = exports.arrayIntersection = exports.getBestBlock = exports.blockQuery = exports.isBlockHash = exports.checkBlockHash = exports.serialize = exports.bigNumberToSring = exports.unSerializeBigNumber = exports.isSerializedBigNumber = exports.serializeBigNumber = exports.isBigNumber = exports.bigNumberDoc = exports.isValidAddress = exports.isAddress = exports.remove0x = exports.add0x = exports.isHexString = undefined;var _bignumber = require('bignumber.js');
1+
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.jsonDecode = exports.jsonEncode = exports.keccak256 = exports.base64toHex = exports.btoa = exports.atob = exports.includesAll = exports.hasValue = exports.arraySymmetricDifference = exports.arrayDifference = exports.arrayIntersection = exports.getBestBlock = exports.blockQuery = exports.isBlockHash = exports.checkBlockHash = exports.serialize = exports.bigNumberSum = exports.bigNumberToSring = exports.unSerializeBigNumber = exports.isSerializedBigNumber = exports.serializeBigNumber = exports.isBigNumber = exports.bigNumberDoc = exports.isValidAddress = exports.isAddress = exports.remove0x = exports.add0x = exports.isHexString = undefined;var _bignumber = require('bignumber.js');
22
var _types = require('./types');
33
var _mongodb = require('mongodb');
44
var _keccak = require('keccak');var _keccak2 = _interopRequireDefault(_keccak);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
@@ -8,9 +8,25 @@ const isHexString = exports.isHexString = str => {
88
return (/^[0-9a-f]+$/i.test(str));
99
};
1010

11-
const add0x = exports.add0x = str => isHexString(str) && str.substring(0, 2) !== '0x' ? `0x${str}` : str;
11+
const add0x = exports.add0x = str => {
12+
let s = str;
13+
let prefix = s[0] === '-' ? '-' : '';
14+
if (prefix) s = s.substring(prefix.length);
15+
if (isHexString(s) && s.substring(0, 2) !== '0x') {
16+
return `${prefix}0x${s}`;
17+
}
18+
return str;
19+
};
1220

13-
const remove0x = exports.remove0x = str => isHexString(str) && str.substring(0, 2) === '0x' ? str.substr(2, str.length) : str;
21+
const remove0x = exports.remove0x = str => {
22+
let s = str;
23+
let prefix = s[0] === '-' ? '-' : '';
24+
if (prefix) s = s.substring(prefix.length);
25+
if (isHexString(s)) {
26+
if (s.substring(0, 2) === '0x') return prefix + s.substr(2);
27+
}
28+
return str;
29+
};
1430

1531
const isAddress = exports.isAddress = address => {
1632
return (/^(0x)?[0-9a-f]{40}$/i.test(address));
@@ -50,6 +66,16 @@ const bigNumberToSring = exports.bigNumberToSring = bn => {
5066
return bn;
5167
};
5268

69+
const bigNumberSum = exports.bigNumberSum = values => {
70+
let total = new _bignumber.BigNumber(0);
71+
values.
72+
forEach(value => {
73+
value = isBigNumber(value) ? value : new _bignumber.BigNumber(value);
74+
total = total.plus(value);
75+
});
76+
return total;
77+
};
78+
5379
const isObj = value => {
5480
if (undefined === value || value === null) return false;
5581
let is = typeof value === 'object';
@@ -117,7 +143,7 @@ const arraySymmetricDifference = exports.arraySymmetricDifference = (a, b) => ar
117143

118144
const hasValue = exports.hasValue = (arr, search) => arrayIntersection(arr, search).length > 0;
119145

120-
const hasValues = exports.hasValues = (arr, search) => !search.map(t => arr.indexOf(t)).filter(i => i < 0).length;
146+
const includesAll = exports.includesAll = (arr, search) => !search.map(t => arr.indexOf(t)).filter(i => i < 0).length;
121147

122148
const atob = exports.atob = str => Buffer.from(str, 'base64').toString('binary');
123149

dist/services/classes/GetTxBalance.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.GetTxBalance = undefined;var _bignumber = require('bignumber.js');
1+
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.GetTxBalance = undefined;var _utils = require('../../lib/utils');
22
class GetTxBalance {
33
constructor(txCollection) {
44
this.txCollection = txCollection;
@@ -13,13 +13,7 @@ class GetTxBalance {
1313
}
1414

1515
sumValues(values) {
16-
let total = new _bignumber.BigNumber(0);
17-
values.
18-
map(v => v.value).
19-
forEach(value => {
20-
total = total.plus(new _bignumber.BigNumber(value));
21-
});
22-
return total;
16+
return (0, _utils.bigNumberSum)(values.map(v => v.value));
2317
}
2418

2519
async getBalanceFromTx(address) {

dist/tools/wsGet.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const writeFile = _util2.default.promisify(_fs2.default.writeFile);
77
const url = process.env.url || 'http://localhost:3003';
88
const outDir = process.env.outDir || '/tmp';
99

10-
let payload = process.env.payload;
10+
let payload = process.env.payload || process.argv[2];
1111

1212
if (!url || !payload) help();
1313
payload = JSON.parse(payload);
@@ -35,8 +35,10 @@ socket.on('disconnect', socket => {
3535
socket.on('data', async res => {
3636
try {
3737
let { data, error, req } = res;
38-
39-
if (error) throw new Error(error);
38+
if (error) {
39+
c.error(error);
40+
process.exit();
41+
}
4042
if (!error && req && key === req.key) {
4143
// multiple results
4244
if (res.pages) {
@@ -70,8 +72,9 @@ socket.on('data', async res => {
7072
});
7173

7274
socket.on('Error', err => {
73-
c.error('ERROR:');
74-
c.error(err);
75+
let error = err.error || '';
76+
c.error(`ERROR: ${error}`);
77+
c.warn(err);
7578
});
7679

7780
process.on('unhandledRejection', err => {

0 commit comments

Comments
 (0)