Skip to content

Commit

Permalink
Build 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Jan 29, 2021
1 parent 58a808a commit 799c7d6
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 40 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog
## [1.1.9] - 2021-01-29

### Added

- Support POST in /api routes.
- API module: VerificationResults

## [1.1.8] - 2021-01-28

#### Changed

- Dependencies: nod3 to @rsksmart/nod3
Expand Down
11 changes: 3 additions & 8 deletions dist/api/modules/ContractVerification.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ var _types = require("../../lib/types");

class ContractVerification extends _DataCollector.DataCollectorItem {
constructor(collections, name) {
const { ContractVerification, VerificationsResults } = collections;
const { ContractVerification } = collections;
super(ContractVerification, name);
this.verificationsCollection = VerificationsResults;
this.publicActions = {
/**
* @swagger
Expand All @@ -27,9 +26,7 @@ class ContractVerification extends _DataCollector.DataCollectorItem {
* $ref: '#/responses/NotFound'
*/
getVerifiedContracts: params => {
params.fields = { address: 1 };
let query = { match: true };
return this.getPageData(query, params);
return this.parent.getModule('VerificationResults').run('getResults', params);
},
/**
* @swagger
Expand Down Expand Up @@ -163,9 +160,7 @@ class ContractVerification extends _DataCollector.DataCollectorItem {
* $ref: '#/responses/NotFound'
*/
isVerified: async params => {
const { address } = params;
const data = await this.verificationsCollection.findOne({ address });
return { data };
return this.parent.getModule('VerificationResults').run('getVerification', params);
} };

}}exports.ContractVerification = ContractVerification;var _default =
Expand Down
56 changes: 56 additions & 0 deletions dist/api/modules/VerificationResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.VerificationResults = void 0;var _DataCollector = require("../lib/DataCollector");

class VerificationResults extends _DataCollector.DataCollectorItem {
constructor(collections, name) {
const { VerificationsResults } = collections;
super(VerificationsResults, name);
this.publicActions = {
/**
* @swagger
* /api?module=verificationResults&action=getResults:
* get:
* description: Gets a list of verified contracts addresses
* tags:
* - verification results
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getResults: params => {
params.fields = { address: 1 };
let query = { match: true };
return this.getPageData(query, params);
},
/**
* @swagger
* /api?module=verificationResults&action=getVerification:
* get:
* description: Checks if a contract was verified
* tags:
* - verification results
* parameters:
* - name: address
* in: query
* required: true
* responses:
* 200:
* $ref: '#/definitions/Response'
* 400:
* $ref: '#/responses/BadRequest'
* 404:
* $ref: '#/responses/NotFound'
*/
getVerification: async params => {
const { address } = params;
const query = { address, match: true };
return this.getItem(query, params);
} };

}}exports.VerificationResults = VerificationResults;var _default =


VerificationResults;exports.default = _default;
2 changes: 2 additions & 0 deletions dist/api/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var _TxPending = require("./TxPending");
var _Stats = require("./Stats");
var _Summary = require("./Summary");

var _VerificationResults = require("./VerificationResults");
var _ContractVerification = require("./ContractVerification");
var _InternalTx = require("./InternalTx");
var _Balances = require("./Balances");
Expand All @@ -22,6 +23,7 @@ const apiModules = {
Stats: _Stats.Stats,
Summary: _Summary.Summary,
ContractVerification: _ContractVerification.ContractVerification,
VerificationResults: _VerificationResults.VerificationResults,
InternalTx: _InternalTx.InternalTx,
Balances: _Balances.Balances };

Expand Down
54 changes: 31 additions & 23 deletions dist/api/routes/api.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _express = _interopRequireDefault(require("express"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _express = _interopRequireDefault(require("express"));
var _bodyParser = _interopRequireDefault(require("body-parser"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
const router = _express.default.Router();

const Routes = ({ log, api }) => {
router.use('/', (req, res, next) => {
const getResult = async (api, { module, action, params }) => {
try {
const params = req.query;
if (Object.keys(params).length === 0) {
res.send(api.info());
} else {
const { module, action } = req.query;
if (!module) throw new Error(`invalid module: ${module}`);
if (!action) throw new Error(`invalid action: ${action}`);
next();
}
} catch (err) {
log.debug(err);
res.status(400).send();
}
});

router.get('/', async (req, res, next) => {
try {
const params = req.query;
const { module, action } = req.query;
delete params.module;
delete params.action;
const { result } = await api.run({ module, action, params });
if (!result) throw new Error('Missing result');
if (!result.data) throw new Error('Missing data');
return result;
} catch (err) {
return Promise.reject(err);
}
};
const sendResult = async (api, res, { module, action, params }) => {
let result;
try {
if (!!module !== !!action) {
res.status(400).send();
return;
}
if (!module && !action) result = api.info();else
result = await getResult(api, { module, action, params });
if (!result) throw new Error('Empty result');
res.send(result);
} catch (err) {
res.status(404).send();
log.error(err);
}
};

router.get('/', (req, res, next) => {
const params = req.query;
const { module, action } = params;
delete params.module;
delete params.action;
return sendResult(api, res, { module, action, params });
});

router.post('/', _bodyParser.default.json(), (req, res, next) => {
return sendResult(api, res, req.body);
});

return router;
};var _default =

Expand Down
1 change: 1 addition & 0 deletions dist/lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const MODULES = {
txPending: 'TxPending',
extendedStats: 'ExtendedStats',
contractVerifier: 'ContractVerification',
verificationResults: 'VerificationResults',
internalTransactions: 'InternalTx',
balances: 'Balances' };exports.MODULES = MODULES;

Expand Down
14 changes: 7 additions & 7 deletions 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.1.8",
"version": "1.2.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
47 changes: 46 additions & 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.1.8",
"version": "1.2.0",
"description": "explorer API Documentation"
},
"swagger": "2.0",
Expand Down Expand Up @@ -1846,6 +1846,51 @@
}
}
}
},
"/api?module=verificationResults&action=getResults": {
"get": {
"description": "Gets a list of verified contracts addresses",
"tags": [
"verification results"
],
"responses": {
"200": {
"$ref": "#/definitions/Response"
},
"400": {
"$ref": "#/responses/BadRequest"
},
"404": {
"$ref": "#/responses/NotFound"
}
}
}
},
"/api?module=verificationResults&action=getVerification": {
"get": {
"description": "Checks if a contract was verified",
"tags": [
"verification results"
],
"parameters": [
{
"name": "address",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/definitions/Response"
},
"400": {
"$ref": "#/responses/BadRequest"
},
"404": {
"$ref": "#/responses/NotFound"
}
}
}
}
},
"definitions": {
Expand Down

0 comments on commit 799c7d6

Please sign in to comment.