From 799c7d61368a528b02c717a99cf41314c8dc12d0 Mon Sep 17 00:00:00 2001 From: emi Date: Fri, 29 Jan 2021 16:25:00 -0700 Subject: [PATCH] Build 1.2.0 --- CHANGELOG.md | 8 ++++ dist/api/modules/ContractVerification.js | 11 ++--- dist/api/modules/VerificationResults.js | 56 ++++++++++++++++++++++++ dist/api/modules/index.js | 2 + dist/api/routes/api.js | 54 +++++++++++++---------- dist/lib/types.js | 1 + package-lock.json | 14 +++--- package.json | 2 +- public/swagger.json | 47 +++++++++++++++++++- 9 files changed, 155 insertions(+), 40 deletions(-) create mode 100644 dist/api/modules/VerificationResults.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e7508f..06650d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dist/api/modules/ContractVerification.js b/dist/api/modules/ContractVerification.js index 99c087e4..b9c461e6 100644 --- a/dist/api/modules/ContractVerification.js +++ b/dist/api/modules/ContractVerification.js @@ -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 @@ -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 @@ -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 = diff --git a/dist/api/modules/VerificationResults.js b/dist/api/modules/VerificationResults.js new file mode 100644 index 00000000..672ac111 --- /dev/null +++ b/dist/api/modules/VerificationResults.js @@ -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; \ No newline at end of file diff --git a/dist/api/modules/index.js b/dist/api/modules/index.js index b7175519..a08b0652 100644 --- a/dist/api/modules/index.js +++ b/dist/api/modules/index.js @@ -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"); @@ -22,6 +23,7 @@ const apiModules = { Stats: _Stats.Stats, Summary: _Summary.Summary, ContractVerification: _ContractVerification.ContractVerification, + VerificationResults: _VerificationResults.VerificationResults, InternalTx: _InternalTx.InternalTx, Balances: _Balances.Balances }; diff --git a/dist/api/routes/api.js b/dist/api/routes/api.js index 5a4ad3d5..3b46e901 100644 --- a/dist/api/routes/api.js +++ b/dist/api/routes/api.js @@ -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 = diff --git a/dist/lib/types.js b/dist/lib/types.js index 12375cf4..d4d39e5c 100644 --- a/dist/lib/types.js +++ b/dist/lib/types.js @@ -71,6 +71,7 @@ const MODULES = { txPending: 'TxPending', extendedStats: 'ExtendedStats', contractVerifier: 'ContractVerification', + verificationResults: 'VerificationResults', internalTransactions: 'InternalTx', balances: 'Balances' };exports.MODULES = MODULES; diff --git a/package-lock.json b/package-lock.json index 63626b62..719527d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.8", + "version": "1.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2240,9 +2240,9 @@ "integrity": "sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=" }, "caniuse-lite": { - "version": "1.0.30001180", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001180.tgz", - "integrity": "sha512-n8JVqXuZMVSPKiPiypjFtDTXc4jWIdjxull0f92WLo7e1MSi3uJ3NvveakSh/aCl1QKFAvIz3vIj0v+0K+FrXw==", + "version": "1.0.30001181", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001181.tgz", + "integrity": "sha512-m5ul/ARCX50JB8BSNM+oiPmQrR5UmngaQ3QThTTp5HcIIQGP/nPBs82BYLE+tigzm3VW+F4BJIhUyaVtEweelQ==", "dev": true }, "chai": { @@ -3057,9 +3057,9 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { - "version": "1.3.648", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.648.tgz", - "integrity": "sha512-4POzwyQ80tkDiBwkxn7IpfzioimrjRSFX1sCQ3pLZsYJ5ERYmwzdq0hZZ3nFP7Z6GtmnSn3xwWDm8FPlMeOoEQ==", + "version": "1.3.649", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.649.tgz", + "integrity": "sha512-ojGDupQ3UMkvPWcTICe4JYe17+o9OLiFMPoduoR72Zp2ILt1mRVeqnxBEd6s/ptekrnsFU+0A4lStfBe/wyG/A==", "dev": true }, "elliptic": { diff --git a/package.json b/package.json index 592d3a92..4da67ffd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.8", + "version": "1.2.0", "description": "", "main": "index.js", "scripts": { diff --git a/public/swagger.json b/public/swagger.json index 8186d25e..87971e4c 100644 --- a/public/swagger.json +++ b/public/swagger.json @@ -1,7 +1,7 @@ { "info": { "title": "rsk-explorer-api", - "version": "1.1.8", + "version": "1.2.0", "description": "explorer API Documentation" }, "swagger": "2.0", @@ -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": {