Socket
Socket
Sign inDemoInstall

ethjs-query

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethjs-query - npm Package Compare versions

Comparing version 0.3.7 to 0.3.8

159

lib/index.js
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _defineProperty = require('babel-runtime/core-js/object/define-property');
var _defineProperty2 = _interopRequireDefault(_defineProperty);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var format = require('ethjs-format');

@@ -46,3 +20,3 @@ var EthRPC = require('ethjs-rpc');

self.options = (0, _assign2['default'])({
self.options = Object.assign({
debug: optionsObject.debug || false,

@@ -61,4 +35,4 @@ logger: optionsObject.logger || console,

(0, _keys2['default'])(format.schema.methods).forEach(function (rpcMethodName) {
(0, _defineProperty2['default'])(Eth.prototype, rpcMethodName.replace('eth_', ''), {
Object.keys(format.schema.methods).forEach(function (rpcMethodName) {
Object.defineProperty(Eth.prototype, rpcMethodName.replace('eth_', ''), {
enumerable: true,

@@ -71,78 +45,2 @@ value: generateFnFor(rpcMethodName, format.schema.methods[rpcMethodName])

return function outputMethod() {
var performCall = function () {
var _ref = (0, _asyncToGenerator3['default'])( /*#__PURE__*/_regenerator2['default'].mark(function _callee() {
var result, methodOutputs, outputError;
return _regenerator2['default'].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(args.length < methodObject[2])) {
_context.next = 2;
break;
}
throw new Error('[ethjs-query] method \'' + protoMethodName + '\' requires at least ' + methodObject[2] + ' input (format type ' + methodObject[0][0] + '), ' + args.length + ' provided. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#' + rpcMethodName.toLowerCase());
case 2:
if (!(args.length > methodObject[0].length)) {
_context.next = 4;
break;
}
throw new Error('[ethjs-query] method \'' + protoMethodName + '\' requires at most ' + methodObject[0].length + ' params, ' + args.length + ' provided \'' + (0, _stringify2['default'])(args, null, self.options.jsonSpace) + '\'. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#' + rpcMethodName.toLowerCase());
case 4:
// set default block
if (methodObject[3] && args.length < methodObject[3]) {
args.push('latest');
}
// format inputs
this.log('attempting method formatting for \'' + protoMethodName + '\' with inputs ' + (0, _stringify2['default'])(args, null, this.options.jsonSpace));
_context.prev = 6;
inputs = format.formatInputs(rpcMethodName, args);
this.log('method formatting success for \'' + protoMethodName + '\' with formatted result: ' + (0, _stringify2['default'])(inputs, null, this.options.jsonSpace));
_context.next = 14;
break;
case 11:
_context.prev = 11;
_context.t0 = _context['catch'](6);
throw new Error('[ethjs-query] while formatting inputs \'' + (0, _stringify2['default'])(args, null, this.options.jsonSpace) + '\' for method \'' + protoMethodName + '\' error: ' + _context.t0);
case 14:
_context.next = 16;
return this.rpc.sendAsync({ method: rpcMethodName, params: inputs });
case 16:
result = _context.sent;
_context.prev = 17;
this.log('attempting method formatting for \'' + protoMethodName + '\' with raw outputs: ' + (0, _stringify2['default'])(result, null, this.options.jsonSpace));
methodOutputs = format.formatOutputs(rpcMethodName, result);
this.log('method formatting success for \'' + protoMethodName + '\' formatted result: ' + (0, _stringify2['default'])(methodOutputs, null, this.options.jsonSpace));
return _context.abrupt('return', methodOutputs);
case 24:
_context.prev = 24;
_context.t1 = _context['catch'](17);
outputError = new Error('[ethjs-query] while formatting outputs from RPC \'' + (0, _stringify2['default'])(result, null, this.options.jsonSpace) + '\' for method \'' + protoMethodName + '\' ' + _context.t1);
throw outputError;
case 28:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[6, 11], [17, 24]]);
}));
return function performCall() {
return _ref.apply(this, arguments);
};
}();
var callback = null; // eslint-disable-line

@@ -168,3 +66,54 @@ var inputs = null; // eslint-disable-line

return promise;
function performCall() {
var _this = this;
return new Promise(function (resolve, reject) {
// validate arg length
if (args.length < methodObject[2]) {
reject(new Error('[ethjs-query] method \'' + protoMethodName + '\' requires at least ' + methodObject[2] + ' input (format type ' + methodObject[0][0] + '), ' + args.length + ' provided. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#' + rpcMethodName.toLowerCase()));
return;
}
if (args.length > methodObject[0].length) {
reject(new Error('[ethjs-query] method \'' + protoMethodName + '\' requires at most ' + methodObject[0].length + ' params, ' + args.length + ' provided \'' + JSON.stringify(args, null, self.options.jsonSpace) + '\'. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#' + rpcMethodName.toLowerCase()));
return;
}
// set default block
if (methodObject[3] && args.length < methodObject[3]) {
args.push('latest');
}
// format inputs
_this.log('attempting method formatting for \'' + protoMethodName + '\' with inputs ' + JSON.stringify(args, null, _this.options.jsonSpace));
try {
inputs = format.formatInputs(rpcMethodName, args);
_this.log('method formatting success for \'' + protoMethodName + '\' with formatted result: ' + JSON.stringify(inputs, null, _this.options.jsonSpace));
} catch (formattingError) {
reject(new Error('[ethjs-query] while formatting inputs \'' + JSON.stringify(args, null, _this.options.jsonSpace) + '\' for method \'' + protoMethodName + '\' error: ' + formattingError));
return;
}
// perform rpc call
_this.rpc.sendAsync({ method: rpcMethodName, params: inputs }).then(function (result) {
// format result
try {
_this.log('attempting method formatting for \'' + protoMethodName + '\' with raw outputs: ' + JSON.stringify(result, null, _this.options.jsonSpace));
var methodOutputs = format.formatOutputs(rpcMethodName, result);
_this.log('method formatting success for \'' + protoMethodName + '\' formatted result: ' + JSON.stringify(methodOutputs, null, _this.options.jsonSpace));
resolve(methodOutputs);
return;
} catch (outputFormattingError) {
var outputError = new Error('[ethjs-query] while formatting outputs from RPC \'' + JSON.stringify(result, null, _this.options.jsonSpace) + '\' for method \'' + protoMethodName + '\' ' + outputFormattingError);
reject(outputError);
return;
}
})['catch'](function (error) {
var outputError = new Error('[ethjs-query] while formatting outputs from RPC \'' + JSON.stringify(error, null, _this.options.jsonSpace) + '\'');
reject(outputError);
return;
});
});
}
};
}

@@ -285,14 +285,2 @@ 'use strict';

it('should function while eth_compileSolidity', function (done) {
var eth = new Eth(provider);
var testSolidity = 'pragma solidity ^0.4.0;\n\n /// @title Voting with delegation.\n contract Ballot {\n function () public payable {\n }\n\n uint256 public cool;\n }\n ';
eth.compileSolidity(testSolidity, function (err, result) {
assert.ok(err);
assert.ok(err.message.includes('Method eth_compileSolidity not supported.'));
assert.equal(result, null);
done();
});
});
it('should function while eth_estimateGas', function (done) {

@@ -299,0 +287,0 @@ var eth = new Eth(provider);

{
"name": "ethjs-query",
"version": "0.3.7",
"version": "0.3.8",
"description": "A simple query layer for the Ethereum RPC.",

@@ -104,6 +104,3 @@ "main": "lib/index.js",

"transform-es3-member-expression-literals",
"transform-es3-property-literals",
"transform-async-to-generator",
"transform-regenerator",
"transform-runtime"
"transform-es3-property-literals"
],

@@ -126,3 +123,4 @@ "env": {

"ethjs-rpc": "0.2.0",
"promise-to-callback": "^1.0.0"
"promise-to-callback": "^1.0.0",
"babel-runtime": "^6.26.0"
},

@@ -135,3 +133,2 @@ "devDependencies": {

"babel-plugin-check-es2015-constants": "6.8.0",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-es2015-arrow-functions": "6.8.0",

@@ -157,14 +154,8 @@ "babel-plugin-transform-es2015-block-scoped-functions": "6.8.0",

"babel-plugin-transform-object-rest-spread": "6.19.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-register": "6.18.0",
"check-es3-syntax-cli": "0.1.3",
"webpack": "2.1.0-beta.15",
"json-loader": "0.5.4",
"rimraf": "2.3.4",
"cross-env": "1.0.7",
"hard-rejection": "^1.0.0",
"bignumber.js": "3.0.1",
"chai": "3.5.0",
"check-es3-syntax-cli": "0.1.3",
"coveralls": "2.11.9",
"cross-env": "1.0.7",
"eslint": "2.10.1",

@@ -178,6 +169,10 @@ "eslint-config-airbnb": "9.0.1",

"ganache-core": "^2.1.0",
"hard-rejection": "^1.0.0",
"istanbul": "0.4.5",
"json-loader": "0.5.4",
"lint-staged": "1.0.1",
"mocha": "3.2.0",
"pre-commit": "1.1.3"
"pre-commit": "1.1.3",
"rimraf": "2.3.4",
"webpack": "2.1.0-beta.15"
},

@@ -184,0 +179,0 @@ "lint-staged": {

@@ -58,40 +58,53 @@ const format = require('ethjs-format');

async function performCall() {
// validate arg length
if (args.length < methodObject[2]) {
throw new Error(`[ethjs-query] method '${protoMethodName}' requires at least ${methodObject[2]} input (format type ${methodObject[0][0]}), ${args.length} provided. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#${rpcMethodName.toLowerCase()}`);
}
if (args.length > methodObject[0].length) {
throw new Error(`[ethjs-query] method '${protoMethodName}' requires at most ${methodObject[0].length} params, ${args.length} provided '${JSON.stringify(args, null, self.options.jsonSpace)}'. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#${rpcMethodName.toLowerCase()}`);
}
function performCall() {
return new Promise((resolve, reject) => {
// validate arg length
if (args.length < methodObject[2]) {
reject(new Error(`[ethjs-query] method '${protoMethodName}' requires at least ${methodObject[2]} input (format type ${methodObject[0][0]}), ${args.length} provided. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#${rpcMethodName.toLowerCase()}`));
return;
}
if (args.length > methodObject[0].length) {
reject(new Error(`[ethjs-query] method '${protoMethodName}' requires at most ${methodObject[0].length} params, ${args.length} provided '${JSON.stringify(args, null, self.options.jsonSpace)}'. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#${rpcMethodName.toLowerCase()}`));
return;
}
// set default block
if (methodObject[3] && args.length < methodObject[3]) {
args.push('latest');
}
// set default block
if (methodObject[3] && args.length < methodObject[3]) {
args.push('latest');
}
// format inputs
this.log(`attempting method formatting for '${protoMethodName}' with inputs ${JSON.stringify(args, null, this.options.jsonSpace)}`);
try {
inputs = format.formatInputs(rpcMethodName, args);
this.log(`method formatting success for '${protoMethodName}' with formatted result: ${JSON.stringify(inputs, null, this.options.jsonSpace)}`);
} catch (formattingError) {
throw new Error(`[ethjs-query] while formatting inputs '${JSON.stringify(args, null, this.options.jsonSpace)}' for method '${protoMethodName}' error: ${formattingError}`);
}
// format inputs
this.log(`attempting method formatting for '${protoMethodName}' with inputs ${JSON.stringify(args, null, this.options.jsonSpace)}`);
try {
inputs = format.formatInputs(rpcMethodName, args);
this.log(`method formatting success for '${protoMethodName}' with formatted result: ${JSON.stringify(inputs, null, this.options.jsonSpace)}`);
} catch (formattingError) {
reject(new Error(`[ethjs-query] while formatting inputs '${JSON.stringify(args, null, this.options.jsonSpace)}' for method '${protoMethodName}' error: ${formattingError}`));
return;
}
// perform rpc call
const result = await this.rpc.sendAsync({ method: rpcMethodName, params: inputs });
// format result
try {
this.log(`attempting method formatting for '${protoMethodName}' with raw outputs: ${JSON.stringify(result, null, this.options.jsonSpace)}`);
const methodOutputs = format.formatOutputs(rpcMethodName, result);
this.log(`method formatting success for '${protoMethodName}' formatted result: ${JSON.stringify(methodOutputs, null, this.options.jsonSpace)}`);
return methodOutputs;
} catch (outputFormattingError) {
const outputError = new Error(`[ethjs-query] while formatting outputs from RPC '${JSON.stringify(result, null, this.options.jsonSpace)}' for method '${protoMethodName}' ${outputFormattingError}`);
throw outputError;
}
// perform rpc call
this.rpc.sendAsync({ method: rpcMethodName, params: inputs })
.then(result => {
// format result
try {
this.log(`attempting method formatting for '${protoMethodName}' with raw outputs: ${JSON.stringify(result, null, this.options.jsonSpace)}`);
const methodOutputs = format.formatOutputs(rpcMethodName, result);
this.log(`method formatting success for '${protoMethodName}' formatted result: ${JSON.stringify(methodOutputs, null, this.options.jsonSpace)}`);
resolve(methodOutputs);
return;
} catch (outputFormattingError) {
const outputError = new Error(`[ethjs-query] while formatting outputs from RPC '${JSON.stringify(result, null, this.options.jsonSpace)}' for method '${protoMethodName}' ${outputFormattingError}`);
reject(outputError);
return;
}
})
.catch(error => {
const outputError = new Error(`[ethjs-query] while formatting outputs from RPC '${JSON.stringify(error, null, this.options.jsonSpace)}'`);
reject(outputError);
return;
});
});
}
};
}

@@ -291,23 +291,2 @@ require('hard-rejection')();

it('should function while eth_compileSolidity', (done) => {
const eth = new Eth(provider);
const testSolidity = `pragma solidity ^0.4.0;
/// @title Voting with delegation.
contract Ballot {
function () public payable {
}
uint256 public cool;
}
`;
eth.compileSolidity(testSolidity, (err, result) => {
assert.ok(err);
assert.ok(err.message.includes('Method eth_compileSolidity not supported.'));
assert.equal(result, null);
done();
});
});
it('should function while eth_estimateGas', (done) => {

@@ -314,0 +293,0 @@ const eth = new Eth(provider);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc