diff --git a/CHANGELOG.md b/CHANGELOG.md index e53767c..ea5ce96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,65 +1,8 @@ -# 0.2.0 -- handle 500 errors better +# 0.1.1 -- handle errors better -1. Handles 500/404/303 errors +1. Better error handling -# 0.1.8 -- bn formatting update - -1. Bignumber formatting update - -# 0.1.7 -- Better RPC error handling - -1. Better RPC error handling - -# 0.1.6 -- Strinigy RPC error - -1. Added JSON.strinify for RPC error handling - -# 0.1.5 -- format update - -1. Tigher formatting enforcement -2. Small schema update - -# 0.1.4 -- less dependencies - -1. Better formatting -2. Less dependencies -3. ID generation done in house -4. 25kb less file size -5. More docs - -# 0.1.2 -- config fixes - -1. webpack config updates -2. build config updates - -# 0.1.1 -- new packages - -1. new ethjs-format -2. more docs - -# 0.0.5 -- refactor - -1. code cleanup -2. more coverage -3. better error handling -4. less dependencies - -# 0.0.4 -- promises, louder errors, more tests - -1. added promises -2. louder errors -3. more test coverage - -# 0.0.3 -- options with debug logging and other features - -1. added low level complete logging `new Eth(provider, { debug: false, logger: console, jsonSpace: 0 })` -2. more tests - -# 0.0.2 -- handle eth_getFilterChanges during Block and Pending Tx filter - -1. handle getFilterChanges during BlockFilter and PendingTxFilter. - -# 0.0.1 -- ethjs-query +# 0.1.0 -- ethjs-rpc 1. Basic testing 2. Basic docs diff --git a/dist/ethjs-rpc.js b/dist/ethjs-rpc.js index 05d3cf4..f34e0df 100644 --- a/dist/ethjs-rpc.js +++ b/dist/ethjs-rpc.js @@ -121,7 +121,7 @@ EthRPC.prototype.sendAsync = function sendAsync(payload, cb) { var responseObject = response || {}; if (err || responseObject.error) { - var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(payload, null, self.options.jsonSpace) + ' ' + (err || JSON.stringify(response.error, null, self.options.jsonSpace)); + var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(payload, null, self.options.jsonSpace) + ' ' + (err || JSON.stringify(responseObject.error, null, self.options.jsonSpace)); return cb(new Error(payloadErrorMessage), null); } diff --git a/dist/ethjs-rpc.js.map b/dist/ethjs-rpc.js.map index 40b1ab9..ffd9a88 100644 --- a/dist/ethjs-rpc.js.map +++ b/dist/ethjs-rpc.js.map @@ -1 +1 @@ -{"version":3,"file":"ethjs-rpc.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap ba0ea6eddc1e78731ab0","webpack:///./lib/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"EthRPC\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"EthRPC\"] = factory();\n\telse\n\t\troot[\"EthRPC\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmory imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmory exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tObject.defineProperty(exports, name, {\n \t\t\tconfigurable: false,\n \t\t\tenumerable: true,\n \t\t\tget: getter\n \t\t});\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap ba0ea6eddc1e78731ab0","'use strict';\n\nmodule.exports = EthRPC;\n\n/**\n * Constructs the EthRPC instance\n *\n * @method EthRPC\n * @param {Object} cprovider the eth rpc provider web3 standard..\n * @param {Object} options the options, if any\n * @returns {Object} ethrpc instance\n */\nfunction EthRPC(cprovider, options) {\n var self = this;\n var optionsObject = options || {};\n\n if (!(this instanceof EthRPC)) {\n throw new Error('[ethjs-rpc] the EthRPC object requires the \"new\" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');\n }\n\n self.options = Object.assign({\n jsonSpace: optionsObject.jsonSpace || 0,\n max: optionsObject.max || 9999999999999\n });\n self.idCounter = Math.floor(Math.random() * self.options.max);\n self.setProvider = function (provider) {\n if (typeof provider !== 'object') {\n 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);\\')');\n }\n\n self.currentProvider = provider;\n };\n self.setProvider(cprovider);\n}\n\n/**\n * The main send async method\n *\n * @method sendAsync\n * @param {Object} payload the rpc payload object\n * @param {Function} cb the async standard callback\n * @callback {Object|Array|Boolean|String} vary result instance output\n */\nEthRPC.prototype.sendAsync = function sendAsync(payload, cb) {\n var self = this;\n self.idCounter = self.idCounter % self.options.max;\n self.currentProvider.sendAsync(createPayload(payload, self.idCounter++), function (err, response) {\n var responseObject = response || {};\n\n if (err || responseObject.error) {\n var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(payload, null, self.options.jsonSpace) + ' ' + (err || JSON.stringify(response.error, null, self.options.jsonSpace));\n return cb(new Error(payloadErrorMessage), null);\n }\n\n return cb(null, responseObject.result);\n });\n};\n\n/**\n * A simple create payload method\n *\n * @method createPayload\n * @param {Object} data the rpc payload data\n * @param {String} id the rpc data payload ID\n * @returns {Object} payload the completed payload object\n */\nfunction createPayload(data, id) {\n return Object.assign({\n id: id,\n jsonrpc: '2.0',\n params: []\n }, data);\n}\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/index.js\n// module id = 0\n// module chunks = 0"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;ACrDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"ethjs-rpc.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 841feff28c4c257809b8","webpack:///./lib/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"EthRPC\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"EthRPC\"] = factory();\n\telse\n\t\troot[\"EthRPC\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmory imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmory exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tObject.defineProperty(exports, name, {\n \t\t\tconfigurable: false,\n \t\t\tenumerable: true,\n \t\t\tget: getter\n \t\t});\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 841feff28c4c257809b8","'use strict';\n\nmodule.exports = EthRPC;\n\n/**\n * Constructs the EthRPC instance\n *\n * @method EthRPC\n * @param {Object} cprovider the eth rpc provider web3 standard..\n * @param {Object} options the options, if any\n * @returns {Object} ethrpc instance\n */\nfunction EthRPC(cprovider, options) {\n var self = this;\n var optionsObject = options || {};\n\n if (!(this instanceof EthRPC)) {\n throw new Error('[ethjs-rpc] the EthRPC object requires the \"new\" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');\n }\n\n self.options = Object.assign({\n jsonSpace: optionsObject.jsonSpace || 0,\n max: optionsObject.max || 9999999999999\n });\n self.idCounter = Math.floor(Math.random() * self.options.max);\n self.setProvider = function (provider) {\n if (typeof provider !== 'object') {\n 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);\\')');\n }\n\n self.currentProvider = provider;\n };\n self.setProvider(cprovider);\n}\n\n/**\n * The main send async method\n *\n * @method sendAsync\n * @param {Object} payload the rpc payload object\n * @param {Function} cb the async standard callback\n * @callback {Object|Array|Boolean|String} vary result instance output\n */\nEthRPC.prototype.sendAsync = function sendAsync(payload, cb) {\n var self = this;\n self.idCounter = self.idCounter % self.options.max;\n self.currentProvider.sendAsync(createPayload(payload, self.idCounter++), function (err, response) {\n var responseObject = response || {};\n\n if (err || responseObject.error) {\n var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(payload, null, self.options.jsonSpace) + ' ' + (err || JSON.stringify(responseObject.error, null, self.options.jsonSpace));\n return cb(new Error(payloadErrorMessage), null);\n }\n\n return cb(null, responseObject.result);\n });\n};\n\n/**\n * A simple create payload method\n *\n * @method createPayload\n * @param {Object} data the rpc payload data\n * @param {String} id the rpc data payload ID\n * @returns {Object} payload the completed payload object\n */\nfunction createPayload(data, id) {\n return Object.assign({\n id: id,\n jsonrpc: '2.0',\n params: []\n }, data);\n}\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/index.js\n// module id = 0\n// module chunks = 0"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;ACrDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;","sourceRoot":""} \ No newline at end of file diff --git a/dist/ethjs-rpc.min.js b/dist/ethjs-rpc.min.js index 923c23f..0055fd9 100644 --- a/dist/ethjs-rpc.min.js +++ b/dist/ethjs-rpc.min.js @@ -1 +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,e.currentProvider.sendAsync(o(t,e.idCounter++),function(o,n){var i=n||{};if(o||i.error){var s="[ethjs-rpc] "+(i.error&&"rpc"||"")+" error with payload "+JSON.stringify(t,null,e.options.jsonSpace)+" "+(o||JSON.stringify(n.error,null,e.options.jsonSpace));return r(Error(s),null)}return r(null,i.result)})}}])}); \ No newline at end of file +!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,e.currentProvider.sendAsync(o(t,e.idCounter++),function(o,n){var i=n||{};if(o||i.error){var s="[ethjs-rpc] "+(i.error&&"rpc"||"")+" error with payload "+JSON.stringify(t,null,e.options.jsonSpace)+" "+(o||JSON.stringify(i.error,null,e.options.jsonSpace));return r(Error(s),null)}return r(null,i.result)})}}])}); \ No newline at end of file diff --git a/package.json b/package.json index f3fb611..c35566c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ethjs-rpc", - "version": "0.1.0", + "version": "0.1.1", "description": "A super simple module for querying the Ethereum RPC layer without formatting.", "main": "lib/index.js", "files": [ diff --git a/src/index.js b/src/index.js index e6a83fc..48a9214 100644 --- a/src/index.js +++ b/src/index.js @@ -42,7 +42,7 @@ EthRPC.prototype.sendAsync = function sendAsync(payload, cb) { const responseObject = response || {}; if (err || responseObject.error) { - const payloadErrorMessage = `[ethjs-rpc] ${(responseObject.error && 'rpc' || '')} error with payload ${JSON.stringify(payload, null, self.options.jsonSpace)} ${err || (JSON.stringify(response.error, null, self.options.jsonSpace))}`; + const payloadErrorMessage = `[ethjs-rpc] ${(responseObject.error && 'rpc' || '')} error with payload ${JSON.stringify(payload, null, self.options.jsonSpace)} ${err || (JSON.stringify(responseObject.error, null, self.options.jsonSpace))}`; return cb(new Error(payloadErrorMessage), null); }