Socket
Socket
Sign inDemoInstall

@metamask/ethjs-rpc

Package Overview
Dependencies
Maintainers
12
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/ethjs-rpc - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

8

CHANGELOG.md

@@ -9,2 +9,7 @@ # Changelog

## [0.3.2]
### Fixed
- Downgrade babel from 7.2 to 6.18.2 ([#28](https://github.com/MetaMask/ethjs-rpc/pull/28))
- The upgrade of babel in `0.3.1` was actually breaking. It's downgraded again and will be re-released in `0.4.0`.
## [0.3.1]

@@ -64,3 +69,4 @@ ### Changed

[Unreleased]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.1...HEAD
[Unreleased]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.2...HEAD
[0.3.2]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.0...v0.3.1

@@ -67,0 +73,0 @@ [0.3.0]: https://github.com/MetaMask/ethjs-rpc/compare/v0.2.0...v0.3.0

@@ -112,2 +112,3 @@ /* eslint-disable */

var promiseToCallback = __webpack_require__(2);
module.exports = EthRPC;

@@ -126,5 +127,7 @@

var optionsObject = options || {};
if (!(this instanceof EthRPC)) {
throw new Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');
}
self.options = Object.assign({

@@ -137,4 +140,5 @@ jsonSpace: optionsObject.jsonSpace || 0,

if (typeof provider !== 'object') {
throw new Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '" + typeof provider + "' (i.e. 'const eth = new EthRPC(provider);')");
throw new Error('[ethjs-rpc] the EthRPC object requires that the first input \'provider\' must be an object, got \'' + typeof provider + '\' (i.e. \'const eth = new EthRPC(provider);\')');
}
self.currentProvider = provider;

@@ -157,7 +161,9 @@ };

var parsedPayload = createPayload(payload, self.idCounter++);
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
if (err || responseObject.error) {
var payloadErrorMessage = "[ethjs-rpc] " + (responseObject.error && 'rpc' || '') + " error with payload " + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + " " + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);

@@ -168,2 +174,3 @@ payloadError.value = err || responseObject.error;

}
resolve(responseObject.result);

@@ -173,2 +180,3 @@ return;

});
if (callback) {

@@ -175,0 +183,0 @@ // connect promise resolve handlers to callback

14

lib/index.js

@@ -1,4 +0,5 @@

"use strict";
'use strict';
var promiseToCallback = require('promise-to-callback');
module.exports = EthRPC;

@@ -17,5 +18,7 @@

var optionsObject = options || {};
if (!(this instanceof EthRPC)) {
throw new Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');
}
self.options = Object.assign({

@@ -28,4 +31,5 @@ jsonSpace: optionsObject.jsonSpace || 0,

if (typeof provider !== 'object') {
throw new Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '" + typeof provider + "' (i.e. 'const eth = new EthRPC(provider);')");
throw new Error('[ethjs-rpc] the EthRPC object requires that the first input \'provider\' must be an object, got \'' + typeof provider + '\' (i.e. \'const eth = new EthRPC(provider);\')');
}
self.currentProvider = provider;

@@ -48,7 +52,9 @@ };

var parsedPayload = createPayload(payload, self.idCounter++);
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
if (err || responseObject.error) {
var payloadErrorMessage = "[ethjs-rpc] " + (responseObject.error && 'rpc' || '') + " error with payload " + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + " " + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);

@@ -59,2 +65,3 @@ payloadError.value = err || responseObject.error;

}
resolve(responseObject.result);

@@ -64,2 +71,3 @@ return;

});
if (callback) {

@@ -66,0 +74,0 @@ // connect promise resolve handlers to callback

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,5 +6,6 @@ var EthRPC = require('../index.js');

var TestRPC = require('ganache-cli');
var HTTPProvider = require('ethjs-provider-http');
var HTTPProvider = require('@metamask/ethjs-provider-http');
var provider = TestRPC.provider({});
var provider2 = TestRPC.provider({});
describe('ethjs-rpc', function () {

@@ -14,2 +15,3 @@ describe('construction', function () {

var eth = new EthRPC(provider);
assert.equal(typeof eth, 'object');

@@ -19,4 +21,5 @@ assert.equal(typeof eth.currentProvider, 'object');

});
it('should throw when invalid construction params', function () {
assert["throws"](function () {
assert.throws(function () {
return EthRPC(provider);

@@ -30,18 +33,14 @@ }, Error); // eslint-disable-line

var eth = new EthRPC(provider);
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
assert.equal(err, null);
eth.setProvider(provider2);
eth.sendAsync({
method: 'eth_accounts'
}, function (err2, accounts2) {
eth.sendAsync({ method: 'eth_accounts' }, function (err2, accounts2) {
assert.equal(err2, null);
assert.notDeepEqual(accounts1, accounts2);
eth.sendAsync({
method: 'eth_accounts'
}).then(function (accounts3) {
eth.sendAsync({ method: 'eth_accounts' }).then(function (accounts3) {
assert.deepEqual(accounts3, accounts2);
done();
})["catch"](function (error) {
})['catch'](function (error) {
return console.log(error);

@@ -54,3 +53,3 @@ }); // eslint-disable-line

it('should handle invalid provider', function () {
assert["throws"](function () {
assert.throws(function () {
return new EthRPC(23423);

@@ -60,8 +59,7 @@ }, Error);

});
describe('sendAsync', function () {
it('should handle normal calls', function (done) {
var eth = new EthRPC(provider);
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
assert.equal(err, null);

@@ -73,13 +71,8 @@ assert.equal(Array.isArray(accounts1), true);

});
it('should handle invalid response', function (done) {
var eth = new EthRPC({
sendAsync: function sendAsync(payload, cb) {
cb(null, {
error: 'Some Error!!'
});
}
});
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
var eth = new EthRPC({ sendAsync: function sendAsync(payload, cb) {
cb(null, { error: 'Some Error!!' });
} });
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
assert.equal(typeof err, 'object');

@@ -90,2 +83,3 @@ assert.equal(accounts1, null);

});
it('should handle invalid response from infura ropsten geth/parity nodes', function (done) {

@@ -98,13 +92,7 @@ var infuraProvider = new HTTPProvider('https://ropsten.infura.io');

params: [{
'gas': '0x2dc6c0',
// eslint-disable-line
'value': '0x00',
// eslint-disable-line
'from': '0x70ad465e0bab6504002ad58c744ed89c7da38524',
// eslint-disable-line
'to': '0xad7d27bc87dba2f5ebcaeb1e7670a1d18104087b',
// eslint-disable-line
'data': '0xd89b73d00000000000000000000000000000000000000000000000000000000000000000'
}, 'latest'],
// eslint-disable-line
'gas': '0x2dc6c0', // eslint-disable-line
'value': '0x00', // eslint-disable-line
'from': '0x70ad465e0bab6504002ad58c744ed89c7da38524', // eslint-disable-line
'to': '0xad7d27bc87dba2f5ebcaeb1e7670a1d18104087b', // eslint-disable-line
'data': '0xd89b73d00000000000000000000000000000000000000000000000000000000000000000' }, 'latest'], // eslint-disable-line
'method': 'eth_call' // eslint-disable-line

@@ -117,11 +105,8 @@ }, function (err, accounts1) {

});
it('should handle invalid errors', function (done) {
var eth = new EthRPC({
sendAsync: function sendAsync(payload, cb) {
var eth = new EthRPC({ sendAsync: function sendAsync(payload, cb) {
cb('Some error!');
}
});
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
} });
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
assert.equal(typeof err, 'object');

@@ -133,2 +118,3 @@ assert.equal(accounts1, null);

});
describe('sendAsync - error handling', function () {

@@ -138,3 +124,4 @@ // this test relies on disabling mocha's default handling of "uncaughtException"

var uncaughtExceptionListeners;
var uncaughtExceptionListeners = void 0;
before(function () {

@@ -145,2 +132,3 @@ // Stop Mocha from handling uncaughtExceptions.

});
after(function () {

@@ -152,2 +140,3 @@ // Resume normal Mocha handling of uncaughtExceptions.

});
it('should call the callback only once', function (done) {

@@ -157,12 +146,12 @@ var eth = new EthRPC(provider);

var callbackCalled = 0;
var uncaughtException;
var uncaughtException = void 0;
process.prependOnceListener('uncaughtException', function (err) {
uncaughtException = err;
});
eth.sendAsync({
method: 'eth_accounts'
}, function () {
eth.sendAsync({ method: 'eth_accounts' }, function () {
callbackCalled++;
throw new Error(errorMessage);
});
setTimeout(function () {

@@ -169,0 +158,0 @@ assert.equal(callbackCalled, 1, 'callback called only once.');

{
"name": "@metamask/ethjs-rpc",
"version": "0.3.1",
"version": "0.3.2",
"description": "A super simple module for querying the Ethereum RPC layer without formatting.",

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

[
"@babel/plugin-transform-template-literals",
"transform-es2015-template-literals",
{

@@ -61,8 +61,8 @@ "loose": true

],
"@babel/plugin-transform-literals",
"@babel/plugin-transform-function-name",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-transform-block-scoped-functions",
"transform-es2015-literals",
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
[
"@babel/plugin-transform-classes",
"transform-es2015-classes",
{

@@ -72,6 +72,6 @@ "loose": true

],
"@babel/plugin-transform-object-super",
"@babel/plugin-transform-shorthand-properties",
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
[
"@babel/plugin-transform-computed-properties",
"transform-es2015-computed-properties",
{

@@ -82,3 +82,3 @@ "loose": true

[
"@babel/plugin-transform-for-of",
"transform-es2015-for-of",
{

@@ -88,6 +88,7 @@ "loose": true

],
"@babel/plugin-transform-sticky-regex",
"@babel/plugin-transform-unicode-regex",
"transform-es2015-sticky-regex",
"transform-es2015-unicode-regex",
"check-es2015-constants",
[
"@babel/plugin-transform-spread",
"transform-es2015-spread",
{

@@ -97,5 +98,5 @@ "loose": true

],
"@babel/plugin-transform-parameters",
"transform-es2015-parameters",
[
"@babel/plugin-transform-destructuring",
"transform-es2015-destructuring",
{

@@ -105,6 +106,6 @@ "loose": true

],
"@babel/plugin-transform-block-scoping",
"@babel/plugin-transform-object-rest-spread",
"@babel/plugin-transform-member-expression-literals",
"@babel/plugin-transform-property-literals"
"transform-es2015-block-scoping",
"transform-object-rest-spread",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
],

@@ -115,3 +116,3 @@ "env": {

[
"@babel/plugin-transform-modules-commonjs",
"transform-es2015-modules-commonjs",
{

@@ -129,27 +130,29 @@ "loose": true

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/eslint-parser": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-block-scoped-functions": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-classes": "^7.0.0",
"@babel/plugin-transform-computed-properties": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.0.0",
"@babel/plugin-transform-for-of": "^7.0.0",
"@babel/plugin-transform-function-name": "^7.0.0",
"@babel/plugin-transform-literals": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-object-super": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/plugin-transform-sticky-regex": "^7.0.0",
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/plugin-transform-unicode-regex": "^7.0.0",
"@babel/plugin-transform-member-expression-literals": "^7.0.0",
"@babel/plugin-transform-property-literals": "^7.0.0",
"@babel/plugin-transform-object-rest-spread": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.0",
"@metamask/ethjs-provider-http": "^0.2.0",
"babel-cli": "6.18.0",
"babel-core": "6.18.2",
"babel-eslint": "7.1.0",
"babel-loader": "6.2.8",
"babel-plugin-check-es2015-constants": "6.8.0",
"babel-plugin-transform-es2015-arrow-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoped-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoping": "6.18.0",
"babel-plugin-transform-es2015-classes": "6.18.0",
"babel-plugin-transform-es2015-computed-properties": "6.8.0",
"babel-plugin-transform-es2015-destructuring": "6.19.0",
"babel-plugin-transform-es2015-for-of": "6.18.0",
"babel-plugin-transform-es2015-function-name": "6.9.0",
"babel-plugin-transform-es2015-literals": "6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "6.18.0",
"babel-plugin-transform-es2015-object-super": "6.8.0",
"babel-plugin-transform-es2015-parameters": "6.18.0",
"babel-plugin-transform-es2015-shorthand-properties": "6.18.0",
"babel-plugin-transform-es2015-spread": "6.8.0",
"babel-plugin-transform-es2015-sticky-regex": "6.8.0",
"babel-plugin-transform-es2015-template-literals": "6.8.0",
"babel-plugin-transform-es2015-unicode-regex": "6.11.0",
"babel-plugin-transform-es3-member-expression-literals": "6.5.0",
"babel-plugin-transform-es3-property-literals": "6.5.0",
"babel-plugin-transform-object-rest-spread": "6.19.0",
"babel-register": "6.18.0",
"bignumber.js": "3.0.1",

@@ -164,5 +167,2 @@ "chai": "3.5.0",

"eslint-plugin-react": "5.1.1",
"ethjs-abi": "0.0.1",
"ethjs-format": "0.1.8",
"ethjs-provider-http": "*",
"ganache-cli": "6.12.2",

@@ -181,3 +181,3 @@ "istanbul": "0.4.5",

"eslintConfig": {
"parser": "@babel/eslint-parser",
"parser": "babel-eslint",
"extends": "airbnb",

@@ -191,3 +191,2 @@ "env": {

"ecmaVersion": 6,
"requireConfigFile": false,
"sourceType": "module"

@@ -194,0 +193,0 @@ },

@@ -26,3 +26,3 @@ ## ethjs-rpc

```js
const HttpProvider = require('ethjs-provider-http');
const HttpProvider = require('@metamask/ethjs-provider-http');
const EthRPC = require('ethjs-rpc');

@@ -29,0 +29,0 @@ const eth = new EthRPC(new HttpProvider('http://localhost:8545'));

const EthRPC = require('../index.js');
const assert = require('chai').assert;
const TestRPC = require('ganache-cli');
const HTTPProvider = require('ethjs-provider-http');
const HTTPProvider = require('@metamask/ethjs-provider-http');
const provider = TestRPC.provider({});

@@ -6,0 +6,0 @@ const provider2 = TestRPC.provider({});

Sorry, the diff of this file is not supported yet

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