Socket
Socket
Sign inDemoInstall

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.9 to 0.2.0

342

dist/ethjs-rpc.js

@@ -66,3 +66,3 @@ /* eslint-disable */

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })

@@ -72,7 +72,115 @@ /************************************************************************/

/* 0 */
/***/ function(module, exports) {
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(setImmediate, clearImmediate) {var nextTick = __webpack_require__(5).nextTick;
var apply = Function.prototype.apply;
var slice = Array.prototype.slice;
var immediateIds = {};
var nextImmediateId = 0;
// DOM APIs, for completeness
exports.setTimeout = function() {
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
};
exports.setInterval = function() {
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
};
exports.clearTimeout =
exports.clearInterval = function(timeout) { timeout.close(); };
function Timeout(id, clearFn) {
this._id = id;
this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
Timeout.prototype.close = function() {
this._clearFn.call(window, this._id);
};
// Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = msecs;
};
exports.unenroll = function(item) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = -1;
};
exports._unrefActive = exports.active = function(item) {
clearTimeout(item._idleTimeoutId);
var msecs = item._idleTimeout;
if (msecs >= 0) {
item._idleTimeoutId = setTimeout(function onTimeout() {
if (item._onTimeout)
item._onTimeout();
}, msecs);
}
};
// That's not how node.js implements it but the exposed api is the same.
exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
var id = nextImmediateId++;
var args = arguments.length < 2 ? false : slice.call(arguments, 1);
immediateIds[id] = true;
nextTick(function onNextTick() {
if (immediateIds[id]) {
// fn.call() is faster so we optimize for the common use-case
// @see http://jsperf.com/call-apply-segu
if (args) {
fn.apply(null, args);
} else {
fn.call(null);
}
// Prevent ids from leaking
exports.clearImmediate(id);
}
});
return id;
};
exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
delete immediateIds[id];
};
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0).setImmediate, __webpack_require__(0).clearImmediate))
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
var isFn = __webpack_require__(3);
var setImmediate = __webpack_require__(4);
module.exports = function (promise) {
if (!isFn(promise.then)) {
throw new TypeError('Expected a promise');
}
return function (cb) {
promise.then(function (data) {
setImmediate(cb, null, data);
}, function (err) {
setImmediate(cb, err);
});
};
};
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
var promiseToCallback = __webpack_require__(1);
module.exports = EthRPC;

@@ -143,13 +251,7 @@

// 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 promiseToCallback(promise)(callback);
}
return undefined;
// only return promise if no callback specified
return promise;
};

@@ -173,2 +275,220 @@

/***/ },
/* 3 */
/***/ function(module, exports) {
"use strict";
'use strict';
var toString = Object.prototype.toString;
module.exports = function (x) {
return toString.call(x) === '[object Function]';
};
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(setImmediate) {'use strict';
module.exports = typeof setImmediate === 'function' ? setImmediate :
function setImmediate() {
var args = [].slice.apply(arguments);
args.splice(1, 0, 0);
setTimeout.apply(null, args);
};
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0).setImmediate))
/***/ },
/* 5 */
/***/ function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }

@@ -175,0 +495,0 @@ /******/ ])

2

dist/ethjs-rpc.min.js

@@ -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++),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}}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("EthRPC",[],e):"object"==typeof exports?exports.EthRPC=e():t.EthRPC=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,e,n){Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,n){(function(t,r){function o(t,e){this._id=t,this._clearFn=e}var i=n(5).nextTick,u=Function.prototype.apply,c=Array.prototype.slice,l={},s=0;e.setTimeout=function(){return new o(u.call(setTimeout,window,arguments),clearTimeout)},e.setInterval=function(){return new o(u.call(setInterval,window,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(window,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;0>e||(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},e.setImmediate="function"==typeof t?t:function(t){var n=s++,r=arguments.length>=2&&c.call(arguments,1);return l[n]=!0,i(function(){l[n]&&(r?t.apply(null,r):t.call(null),e.clearImmediate(n))}),n},e.clearImmediate="function"==typeof r?r:function(t){delete l[t]}}).call(e,n(0).setImmediate,n(0).clearImmediate)},function(t,e,n){"use strict";var r=n(3),o=n(4);t.exports=function(t){if(!r(t.then))throw new TypeError("Expected a promise");return function(e){t.then(function(t){o(e,null,t)},function(t){o(e,t)})}}},function(t,e,n){"use strict";function r(t,e){var n=this,o=e||{};if(!(this instanceof r))throw Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');n.options=Object.assign({jsonSpace:o.jsonSpace||0,max:o.max||9999999999999}),n.idCounter=Math.floor(Math.random()*n.options.max),(n.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);')");n.currentProvider=t})(t)}function o(t,e){return Object.assign({},{id:e,jsonrpc:"2.0",params:[]},t)}var i=n(1);t.exports=r,r.prototype.sendAsync=function(t,e){var n=this;n.idCounter=n.idCounter%n.options.max;var r=o(t,n.idCounter++),u=new Promise(function(t,e){n.currentProvider.sendAsync(r,function(o,i){var u=i||{};if(o||u.error){var c="[ethjs-rpc] "+(u.error&&"rpc"||"")+" error with payload "+JSON.stringify(r,null,n.options.jsonSpace)+" "+(o?o+"":JSON.stringify(u.error,null,n.options.jsonSpace)),l=Error(c);return l.value=o||u.error,void e(l)}t(u.result)})});return e?i(u)(e):u}},function(t,e){"use strict";var n=Object.prototype.toString;t.exports=function(t){return"[object Function]"===n.call(t)}},function(t,e,n){"use strict";(function(e){t.exports="function"==typeof e?e:function(){var t=[].slice.apply(arguments);t.splice(1,0,0),setTimeout.apply(null,t)}}).call(e,n(0).setImmediate)},function(t,e){function n(){throw Error("setTimeout has not been defined")}function r(){throw Error("clearTimeout has not been defined")}function o(t){if(a===setTimeout)return setTimeout(t,0);if((a===n||!a)&&setTimeout)return a=setTimeout,setTimeout(t,0);try{return a(t,0)}catch(e){try{return a.call(null,t,0)}catch(e){return a.call(this,t,0)}}}function i(t){if(f===clearTimeout)return clearTimeout(t);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(t);try{return f(t)}catch(e){try{return f.call(null,t)}catch(e){return f.call(this,t)}}}function u(){h&&m&&(h=!1,m.length?d=m.concat(d):y=-1,d.length&&c())}function c(){if(!h){var t=o(u);h=!0;for(var e=d.length;e;){for(m=d,d=[];++y<e;)m&&m[y].run();y=-1,e=d.length}m=null,h=!1,i(t)}}function l(t,e){this.fun=t,this.array=e}function s(){}var a,f,p=t.exports={};!function(){try{a="function"==typeof setTimeout?setTimeout:n}catch(t){a=n}try{f="function"==typeof clearTimeout?clearTimeout:r}catch(t){f=r}}();var m,d=[],h=!1,y=-1;p.nextTick=function(t){var e=Array(arguments.length-1);if(arguments.length>1)for(var n=1;arguments.length>n;n++)e[n-1]=arguments[n];d.push(new l(t,e)),1!==d.length||h||o(c)},l.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=s,p.addListener=s,p.once=s,p.off=s,p.removeListener=s,p.removeAllListeners=s,p.emit=s,p.prependListener=s,p.prependOnceListener=s,p.listeners=function(t){return[]},p.binding=function(t){throw Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(t){throw Error("process.chdir is not supported")},p.umask=function(){return 0}}])});
'use strict';
var promiseToCallback = require('promise-to-callback');
module.exports = EthRPC;

@@ -68,13 +70,7 @@

// 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 promiseToCallback(promise)(callback);
}
return undefined;
// only return promise if no callback specified
return promise;
};

@@ -81,0 +77,0 @@

@@ -43,3 +43,3 @@ 'use strict';

return console.log(error);
});
}); // eslint-disable-line
});

@@ -109,2 +109,43 @@ });

});
describe('sendAsync - error handling', function () {
// this test relies on disabling mocha's default handling of "uncaughtException"
// see https://github.com/mochajs/mocha/issues/2452
var uncaughtExceptionListeners = void 0;
before(function () {
// Stop Mocha from handling uncaughtExceptions.
uncaughtExceptionListeners = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
});
after(function () {
// Resume normal Mocha handling of uncaughtExceptions.
uncaughtExceptionListeners.forEach(function (listener) {
process.on('uncaughtException', listener);
});
});
it('should call the callback only once', function (done) {
var eth = new EthRPC(provider);
var errorMessage = 'boom!';
var callbackCalled = 0;
var uncaughtException = void 0;
process.prependOnceListener('uncaughtException', function (err) {
uncaughtException = err;
});
eth.sendAsync({ method: 'eth_accounts' }, function () {
callbackCalled++;
throw new Error(errorMessage);
});
setTimeout(function () {
assert.equal(callbackCalled, 1, 'callback called only once.');
assert.equal(uncaughtException.message, errorMessage, 'saw expected uncaughtException');
done();
}, 200);
});
});
});
{
"name": "ethjs-rpc",
"version": "0.1.9",
"version": "0.2.0",
"description": "A super simple module for querying the Ethereum RPC layer without formatting.",

@@ -119,5 +119,6 @@ "main": "lib/index.js",

},
"dependencies": {},
"dependencies": {
"promise-to-callback": "^1.0.0"
},
"devDependencies": {
"ethjs-format": "0.1.8",
"babel-cli": "6.18.0",

@@ -149,10 +150,7 @@ "babel-core": "6.18.2",

"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",
"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",

@@ -164,9 +162,13 @@ "eslint-config-airbnb": "9.0.1",

"eslint-plugin-react": "5.1.1",
"ethjs-provider-http": "*",
"ethereumjs-testrpc": "3.0.2",
"ethjs-abi": "0.0.1",
"ethjs-format": "0.1.8",
"ethjs-provider-http": "*",
"istanbul": "0.4.5",
"json-loader": "0.5.4",
"lint-staged": "1.0.1",
"mocha": "3.2.0",
"pre-commit": "1.1.3"
"mocha": "^5.1.1",
"pre-commit": "1.1.3",
"rimraf": "2.3.4",
"webpack": "2.1.0-beta.15"
},

@@ -173,0 +175,0 @@ "lint-staged": {

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

const promiseToCallback = require('promise-to-callback');
module.exports = EthRPC;

@@ -62,13 +64,7 @@

// 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 promiseToCallback(promise)(callback);
}
return undefined;
// only return promise if no callback specified
return promise;
};

@@ -75,0 +71,0 @@

@@ -39,3 +39,3 @@ const EthRPC = require('../index.js');

})
.catch((error) => console.log(error));
.catch((error) => console.log(error)); // eslint-disable-line
});

@@ -103,2 +103,43 @@ });

});
describe('sendAsync - error handling', () => {
// this test relies on disabling mocha's default handling of "uncaughtException"
// see https://github.com/mochajs/mocha/issues/2452
let uncaughtExceptionListeners;
before(() => {
// Stop Mocha from handling uncaughtExceptions.
uncaughtExceptionListeners = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
});
after(() => {
// Resume normal Mocha handling of uncaughtExceptions.
uncaughtExceptionListeners.forEach((listener) => {
process.on('uncaughtException', listener);
});
});
it('should call the callback only once', (done) => {
const eth = new EthRPC(provider);
const errorMessage = 'boom!';
let callbackCalled = 0;
let uncaughtException;
process.prependOnceListener('uncaughtException', (err) => {
uncaughtException = err;
});
eth.sendAsync({ method: 'eth_accounts' }, () => {
callbackCalled++;
throw new Error(errorMessage);
});
setTimeout(() => {
assert.equal(callbackCalled, 1, 'callback called only once.');
assert.equal(uncaughtException.message, errorMessage, 'saw expected uncaughtException');
done();
}, 200);
});
});
});

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