Skip to content

Commit

Permalink
Build 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Jul 13, 2020
1 parent fda78ca commit 62d7a37
Show file tree
Hide file tree
Showing 73 changed files with 5,887 additions and 1,951 deletions.
22 changes: 17 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog

## [1.0.8] - 2019-06-02
## [1.1.0] - 2020-07-13

### Added

- Internal Transactions
- Address Balances
- Decode events using ABI for verified contracts

## Changed

- Services

## [1.0.8] - 2020-06-02

### Added

Expand All @@ -10,7 +22,7 @@

- TxPool collection indexes

## [1.0.7] - 2019-04-08
## [1.0.7] - 2020-04-08

### Fixed

Expand All @@ -22,7 +34,7 @@

- Update the balances of the token accounts, recovered in the previous block, when a new block is saved.

## [1.0.5] - 2019-03-05
## [1.0.5] - 2020-03-05

### Fixed

Expand All @@ -33,7 +45,7 @@

- Docker: expose api documentation

## [1.0.4] - 2019-02-27
## [1.0.4] - 2020-02-27

### Added

Expand All @@ -50,7 +62,7 @@

- API/Address.getMiners

## [1.0.3] - 2019-01-03
## [1.0.3] - 2020-01-03

### Added

Expand Down
11 changes: 11 additions & 0 deletions dist/api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Api extends _DataCollector.DataCollector {
this.latest = undefined;
this.lastBlocks = { data: [] };
this.lastTransactions = { data: [] };
this.balancesStatus = { data: {} };
this.circulatingSupply = null;
this.stats = { timestamp: 0 };
this.loadModules((0, _modules.getEnabledApiModules)(modules));
Expand All @@ -28,6 +29,7 @@ class Api extends _DataCollector.DataCollector {
}
tick() {
this.setLastBlocks();
this.updateBalancesStatus();
}

loadModules(modules) {
Expand Down Expand Up @@ -105,6 +107,15 @@ class Api extends _DataCollector.DataCollector {
return data[0] || null;
}

getBalancesStatus() {
return this.balancesStatus;
}

async updateBalancesStatus() {
let data = await this.getModule('Balances').run('getStatus');
this.balancesStatus = data;
}

updateLastBlocks(blocks, transactions) {
let blockData = blocks.data;
this.lastBlocks = blocks;
Expand Down
3 changes: 2 additions & 1 deletion dist/api/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const CHANNELS = {
txsChannel: 'transactions',
statusChannel: 'status',
txPoolChannel: 'txpool',
statsChannel: 'stats' };exports.CHANNELS = CHANNELS;
statsChannel: 'stats',
balancesChannel: 'balances' };exports.CHANNELS = CHANNELS;


const createChannels = io => {
Expand Down
8 changes: 7 additions & 1 deletion dist/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const address = _config.default.api.address || 'localhost';

// create channels
const channels = (0, _channels.createChannels)(io);
const { blocksChannel, statusChannel, txPoolChannel, statsChannel, txsChannel } = channels.channels;
const { blocksChannel, statusChannel, txPoolChannel, statsChannel, txsChannel, balancesChannel } = channels.channels;

// send blocks on join
blocksChannel.on('join', socket => {
Expand All @@ -65,6 +65,7 @@ const address = _config.default.api.address || 'localhost';
api.events.on('newBlocks', result => {
blocksChannel.emit('newBlocks', result);
txsChannel.emit('newTransactions', api.getLastTransactions());
balancesChannel.emit('balancesStatus', api.getBalancesStatus());
});

// send stats on join
Expand Down Expand Up @@ -92,6 +93,11 @@ const address = _config.default.api.address || 'localhost';
statsChannel.emit('stats', result);
});

// send balances status on join
balancesChannel.on('join', socket => {
socket.emit('data', (0, _apiTools.formatRes)({ action: 'balancesStatus', result: api.getBalancesStatus() }));
});

io.on('connection', socket => {
socket.emit('open', { time: Date.now(), settings: api.info() });
socket.on('message', () => {});
Expand Down
8 changes: 6 additions & 2 deletions dist/api/lib/DataCollector/DataCollectorItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ class DataCollectorItem {
return { data };
}

async getOne(query, projection) {
async getOne(query, projection, sort) {
projection = projection || this.getDefaultsFields();
const data = await this.db.findOne(query, { projection });
sort = sort || this.sort;
const data = await this.db.findOne(query, { projection, sort });
return { data };
}

Expand All @@ -80,7 +81,10 @@ class DataCollectorItem {
let sortDir = this.sortDir;

let { limit, next, prev, fields, count, countOnly, page, getPages } = params;

// fields = parseFields(fields)
if (!fields) fields = this.getDefaultsFields();

sort = filterSort(sort, sortable, defaultSort);
return { sort, sortable, defaultSort, sortDir, limit, next, prev, fields, count, countOnly, page, getPages };
}
Expand Down
7 changes: 6 additions & 1 deletion dist/api/modules/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ class Address extends _DataCollector.DataCollectorItem {
const { createdByTx, code } = data;
if (!code) throw new Error('The address does not have code');
if (createdByTx) {
data.creationCode = createdByTx.input;
// is a transaction
if (createdByTx.hasOwnProperty('receipt')) {
data.creationCode = createdByTx.input;
} else {// is an internal transactions
data.creationCode = createdByTx.action.init;
}
data.created = createdByTx.timestamp;
delete data.createdByTx;
}
Expand Down
114 changes: 114 additions & 0 deletions dist/api/modules/Balances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.Balances = void 0;var _DataCollector = require("../lib/DataCollector");
var _utils = require("../../lib/utils");

class Balances extends _DataCollector.DataCollectorItem {
constructor({ Balances }, name) {
let sortable = { timestamp: -1, blockNumber: -1 };
super(Balances, name, { sortDir: -1, sortable });
this.fields = {};
this.publicActions = {
/**
* @swagger
* /api?module=balances&action=getBalance:
* get:
* description: get address balance at blockNumber (if exists)
* tags:
* - balances
* parameters:
* - name: module
* in: query
* required: true
* enum: [balances]
* - name: action
* in: query
* required: true
* enum: [getBalance]
* - $ref: '#/parameters/address'
* - name: block
* in: query
* required: true
* schema:
* type: string
* description: block hash or block number
* example: 30000
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getBalance: async params => {
const { address, block } = params;
const query = { address };

if ((0, _utils.isBlockHash)(block)) query.blockHash = block;else
query.blockNumber = parseInt(block);

return this.getItem(query, params);
},
/**
* @swagger
* /api?module=balances&action=getBalances:
* get:
* description: get address balances
* tags:
* - balances
* parameters:
* - name: module
* in: query
* required: true
* enum: [balances]
* - name: action
* in: query
* required: true
* enum: [getBalances]
* - $ref: '#/parameters/address'
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getBalances: async params => {
const { address } = params;
return this.getPageData({ address }, params);
},
/**
* @swagger
* /api?module=balances&action=getStatus:
* get:
* description: get status of balances
* tags:
* - balances
* parameters:
* - name: module
* in: query
* required: true
* enum: [balances]
* - name: action
* in: query
* required: true
* enum: [getStatus]
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getStatus: async params => {
const projection = { blockHash: 1, blockNumber: 1, _id: 0 };
const fromBlock = await this.getOne({}, projection, { blockNumber: 1 });
const toBlock = await this.getOne({}, projection, { blockNumber: -1 });
return { data: { fromBlock: fromBlock.data, toBlock: toBlock.data } };
} };

}}exports.Balances = Balances;var _default =


Balances;exports.default = _default;
56 changes: 38 additions & 18 deletions dist/api/modules/ContractVerification.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,44 @@ class ContractVerification extends _DataCollector.DataCollectorItem {
this.verificationsCollection = VerificationsResults;
this.publicActions = {
/**
* @swagger
* /api?module=contractVerifier&action=verify:
* get:
* description: Verify contract source
* tags:
* - contract verifier
* parameters:
* - name: request
* in: query
* required: true
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
* @swagger
* /api?module=contractVerifier&action=getVerifiedContracts:
* get:
* description: Gets a list of verified contracts addresses
* tags:
* - contract verifier
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getVerifiedContracts: params => {
params.fields = ['address'];
let query = { match: true };
return this.getPageData(query, params);
},
/**
* @swagger
* /api?module=contractVerifier&action=verify:
* get:
* description: Verify contract source
* tags:
* - contract verifier
* parameters:
* - name: request
* in: query
* required: true
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
verify: async params => {
try {
const { request } = params;
Expand Down
Loading

0 comments on commit 62d7a37

Please sign in to comment.