Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethjs-rpc

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethjs-rpc - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

4

CHANGELOG.md

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

# 0.1.9 -- added promises
1. Fixed major callback / promise issue thanks to Kumavis!! (i.e. unhandled promise rejection swollowing errors)
# 0.1.7 -- added promises

@@ -2,0 +6,0 @@

51

dist/ethjs-rpc.js

@@ -15,10 +15,10 @@ /* eslint-disable */

/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)

@@ -30,23 +30,23 @@ /******/ var module = installedModules[moduleId] = {

/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmory imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmory exports

@@ -60,9 +60,9 @@ /******/ __webpack_require__.d = function(exports, name, getter) {

/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports

@@ -120,9 +120,8 @@ /******/ return __webpack_require__(__webpack_require__.s = 0);

*/
EthRPC.prototype.sendAsync = function sendAsync(payload, cb) {
EthRPC.prototype.sendAsync = function sendAsync(payload, callback) {
var self = this;
var callback = cb || function () {};
self.idCounter = self.idCounter % self.options.max;
var parsedPayload = createPayload(payload, self.idCounter++);
return new Promise(function (resolve, reject) {
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {

@@ -136,9 +135,23 @@ var responseObject = response || {};

reject(payloadError);
return callback(payloadError, null);
return;
}
resolve(responseObject.result);
return callback(null, responseObject.result);
return;
});
});
if (callback) {
// connect promise resolve handlers to callback
promise.then(function (result) {
callback(null, result);
})['catch'](function (err) {
callback(err);
});
} else {
// only return promise if no callback specified
return promise;
}
return undefined;
};

@@ -145,0 +158,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,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?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)})})}}])});
!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++),i=new Promise(function(t,r){e.currentProvider.sendAsync(n,function(o,i){var c=i||{};if(o||c.error){var s="[ethjs-rpc] "+(c.error&&"rpc"||"")+" error with payload "+JSON.stringify(n,null,e.options.jsonSpace)+" "+(o?o+"":JSON.stringify(c.error,null,e.options.jsonSpace)),u=Error(s);return u.value=o||c.error,void r(u)}t(c.result)})});return r?void i.then(function(t){r(null,t)})["catch"](function(t){r(t)}):i}}])});

@@ -44,9 +44,8 @@ 'use strict';

*/
EthRPC.prototype.sendAsync = function sendAsync(payload, cb) {
EthRPC.prototype.sendAsync = function sendAsync(payload, callback) {
var self = this;
var callback = cb || function () {};
self.idCounter = self.idCounter % self.options.max;
var parsedPayload = createPayload(payload, self.idCounter++);
return new Promise(function (resolve, reject) {
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {

@@ -60,9 +59,23 @@ var responseObject = response || {};

reject(payloadError);
return callback(payloadError, null);
return;
}
resolve(responseObject.result);
return callback(null, responseObject.result);
return;
});
});
if (callback) {
// connect promise resolve handlers to callback
promise.then(function (result) {
callback(null, result);
})['catch'](function (err) {
callback(err);
});
} else {
// only return promise if no callback specified
return promise;
}
return undefined;
};

@@ -69,0 +82,0 @@

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

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

},
"dependencies": {
},
"dependencies": {},
"devDependencies": {

@@ -123,0 +122,0 @@ "ethjs-format": "0.1.8",

@@ -38,9 +38,8 @@ module.exports = EthRPC;

*/
EthRPC.prototype.sendAsync = function sendAsync(payload, cb) {
EthRPC.prototype.sendAsync = function sendAsync(payload, callback) {
const self = this;
const callback = cb || (() => {});
self.idCounter = self.idCounter % self.options.max;
const parsedPayload = createPayload(payload, self.idCounter++);
return new Promise((resolve, reject) => {
const promise = new Promise((resolve, reject) => {
self.currentProvider.sendAsync(parsedPayload, (err, response) => {

@@ -54,9 +53,23 @@ const responseObject = response || {};

reject(payloadError);
return callback(payloadError, null);
return;
}
resolve(responseObject.result);
return callback(null, responseObject.result);
return;
});
});
if (callback) {
// connect promise resolve handlers to callback
promise.then((result) => {
callback(null, result);
}).catch((err) => {
callback(err);
});
} else {
// only return promise if no callback specified
return promise;
}
return undefined;
};

@@ -63,0 +76,0 @@

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