Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

ethjs-rpc

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.7

8

CHANGELOG.md

@@ -0,1 +1,9 @@

# 0.1.7 -- added promises
1. Added promise support (why did I not do this before..)
# 0.1.6 -- fix RPC error handling
1. fix RPC error handling for geth nodes
# 0.1.5 -- package json fix

@@ -2,0 +10,0 @@

24

dist/ethjs-rpc.js

@@ -119,15 +119,21 @@ /* eslint-disable */

var self = this;
var callback = cb || function () {};
self.idCounter = self.idCounter % self.options.max;
var parsedPayload = createPayload(payload, self.idCounter++);
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) + ' ' + (String(err) || JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);
payloadError.value = err || responseObject.error;
return cb(payloadError, null);
}
return new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
return cb(null, responseObject.result);
if (err || responseObject.error) {
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (String(err) || JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);
payloadError.value = err || responseObject.error;
reject(payloadError);
return callback(payloadError, null);
}
resolve(responseObject.result);
return callback(null, responseObject.result);
});
});

@@ -134,0 +140,0 @@ };

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

!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("EthRPC",[],r):"object"==typeof exports?exports.EthRPC=r():t.EthRPC=r()}(this,function(){return function(t){function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var e={};return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,r,e){Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:e})},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=0)}([function(t,r){"use strict";function e(t,r){var o=this,n=r||{};if(!(this instanceof e))throw Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');o.options=Object.assign({jsonSpace:n.jsonSpace||0,max:n.max||9999999999999}),o.idCounter=Math.floor(Math.random()*o.options.max),(o.setProvider=function(t){if("object"!=typeof t)throw Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '"+typeof t+"' (i.e. 'const eth = new EthRPC(provider);')");o.currentProvider=t})(t)}function o(t,r){return Object.assign({},{id:r,jsonrpc:"2.0",params:[]},t)}t.exports=e,e.prototype.sendAsync=function(t,r){var e=this;e.idCounter=e.idCounter%e.options.max;var n=o(t,e.idCounter++);e.currentProvider.sendAsync(n,function(t,o){var i=o||{};if(t||i.error){var s="[ethjs-rpc] "+(i.error&&"rpc"||"")+" error with payload "+JSON.stringify(n,null,e.options.jsonSpace)+" "+(t+""||JSON.stringify(i.error,null,e.options.jsonSpace)),c=Error(s);return c.value=t||i.error,r(c,null)}return r(null,i.result)})}}])});
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("EthRPC",[],r):"object"==typeof exports?exports.EthRPC=r():t.EthRPC=r()}(this,function(){return function(t){function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var e={};return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,r,e){Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:e})},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=0)}([function(t,r){"use strict";function e(t,r){var o=this,n=r||{};if(!(this instanceof e))throw Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');o.options=Object.assign({jsonSpace:n.jsonSpace||0,max:n.max||9999999999999}),o.idCounter=Math.floor(Math.random()*o.options.max),(o.setProvider=function(t){if("object"!=typeof t)throw Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '"+typeof t+"' (i.e. 'const eth = new EthRPC(provider);')");o.currentProvider=t})(t)}function o(t,r){return Object.assign({},{id:r,jsonrpc:"2.0",params:[]},t)}t.exports=e,e.prototype.sendAsync=function(t,r){var e=this,n=r||function(){};e.idCounter=e.idCounter%e.options.max;var i=o(t,e.idCounter++);return new Promise(function(t,r){e.currentProvider.sendAsync(i,function(o,s){var c=s||{};if(o||c.error){var u="[ethjs-rpc] "+(c.error&&"rpc"||"")+" error with payload "+JSON.stringify(i,null,e.options.jsonSpace)+" "+(o+""||JSON.stringify(c.error,null,e.options.jsonSpace)),p=Error(u);return p.value=o||c.error,r(p),n(p,null)}return t(c.result),n(null,c.result)})})}}])});

@@ -46,15 +46,21 @@ 'use strict';

var self = this;
var callback = cb || function () {};
self.idCounter = self.idCounter % self.options.max;
var parsedPayload = createPayload(payload, self.idCounter++);
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) + ' ' + (String(err) || JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);
payloadError.value = err || responseObject.error;
return cb(payloadError, null);
}
return new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
return cb(null, responseObject.result);
if (err || responseObject.error) {
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (String(err) || JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);
payloadError.value = err || responseObject.error;
reject(payloadError);
return callback(payloadError, null);
}
resolve(responseObject.result);
return callback(null, responseObject.result);
});
});

@@ -61,0 +67,0 @@ };

@@ -6,2 +6,3 @@ 'use strict';

var TestRPC = require('ethereumjs-testrpc');
var HTTPProvider = require('ethjs-provider-http');
var provider = TestRPC.provider({});

@@ -37,3 +38,9 @@ var provider2 = TestRPC.provider({});

assert.notDeepEqual(accounts1, accounts2);
done();
eth.sendAsync({ method: 'eth_accounts' }).then(function (accounts3) {
assert.deepEqual(accounts3, accounts2);
done();
})['catch'](function (error) {
return console.log(error);
});
});

@@ -72,2 +79,22 @@ });

it('should handle invalid response from infura ropsten geth/parity nodes', function (done) {
var infuraProvider = new HTTPProvider('https://ropsten.infura.io');
var eth = new EthRPC(infuraProvider);
eth.sendAsync({
id: 8883061436998317,
jsonrpc: '2.0',
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
'method': 'eth_call' // eslint-disable-line
}, function (err, accounts1) {
assert.equal(typeof err, 'object');
assert.equal(accounts1, null);
done();
});
});
it('should handle invalid errors', function (done) {

@@ -74,0 +101,0 @@ var eth = new EthRPC({ sendAsync: function sendAsync(payload, cb) {

{
"name": "ethjs-rpc",
"version": "0.1.5",
"version": "0.1.7",
"description": "A super simple module for querying the Ethereum RPC layer without formatting.",

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

"eslint-plugin-react": "5.1.1",
"ethjs-provider-http": "*",
"ethereumjs-testrpc": "3.0.2",

@@ -165,0 +166,0 @@ "ethjs-abi": "0.0.1",

@@ -40,15 +40,21 @@ module.exports = EthRPC;

const self = this;
const callback = cb || (() => {});
self.idCounter = self.idCounter % self.options.max;
const parsedPayload = createPayload(payload, self.idCounter++);
self.currentProvider.sendAsync(parsedPayload, (err, response) => {
const responseObject = response || {};
if (err || responseObject.error) {
const payloadErrorMessage = `[ethjs-rpc] ${(responseObject.error && 'rpc' || '')} error with payload ${JSON.stringify(parsedPayload, null, self.options.jsonSpace)} ${String(err) || (JSON.stringify(responseObject.error, null, self.options.jsonSpace))}`;
const payloadError = new Error(payloadErrorMessage);
payloadError.value = (err || responseObject.error);
return cb(payloadError, null);
}
return new Promise((resolve, reject) => {
self.currentProvider.sendAsync(parsedPayload, (err, response) => {
const responseObject = response || {};
return cb(null, responseObject.result);
if (err || responseObject.error) {
const payloadErrorMessage = `[ethjs-rpc] ${(responseObject.error && 'rpc' || '')} error with payload ${JSON.stringify(parsedPayload, null, self.options.jsonSpace)} ${String(err) || (JSON.stringify(responseObject.error, null, self.options.jsonSpace))}`;
const payloadError = new Error(payloadErrorMessage);
payloadError.value = (err || responseObject.error);
reject(payloadError);
return callback(payloadError, null);
}
resolve(responseObject.result);
return callback(null, responseObject.result);
});
});

@@ -55,0 +61,0 @@ };

const EthRPC = require('../index.js');
const assert = require('chai').assert;
const TestRPC = require('ethereumjs-testrpc');
const HTTPProvider = require('ethjs-provider-http');
const provider = TestRPC.provider({});

@@ -32,3 +33,9 @@ const provider2 = TestRPC.provider({});

assert.notDeepEqual(accounts1, accounts2);
done();
eth.sendAsync({ method: 'eth_accounts' })
.then((accounts3) => {
assert.deepEqual(accounts3, accounts2);
done();
})
.catch((error) => console.log(error));
});

@@ -65,2 +72,22 @@ });

it('should handle invalid response from infura ropsten geth/parity nodes', (done) => {
const infuraProvider = new HTTPProvider('https://ropsten.infura.io');
const eth = new EthRPC(infuraProvider);
eth.sendAsync({
id: 8883061436998317,
jsonrpc: '2.0',
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
'method': 'eth_call' // eslint-disable-line
}, (err, accounts1) => {
assert.equal(typeof err, 'object');
assert.equal(accounts1, null);
done();
});
});
it('should handle invalid errors', (done) => {

@@ -67,0 +94,0 @@ const eth = new EthRPC({ sendAsync: (payload, cb) => {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc