tendermint
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,37 +7,23 @@ 'use strict'; | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var _require = require('request'), | ||
get = _require.get; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var EventEmitter = require('events'); | ||
var _require = require('http'), | ||
request = _require.request, | ||
STATUS_CODES = _require.STATUS_CODES; | ||
var url = require('url'); | ||
var old = require('old'); | ||
var concat = require('concat-stream'); | ||
var regeneratorRuntime = require('regenerator-runtime'); | ||
var watt = require('watt'); | ||
var camel = require('camelcase'); | ||
var tendermintMethods = require('./methods.js'); | ||
var noop = function noop() { | ||
return regeneratorRuntime; | ||
}; | ||
// hack to prevent standard from complaining about not using `regeneratorRuntime` | ||
function requestBody(method, params) { | ||
return JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: String(Date.now()), | ||
method: method, | ||
params: params | ||
}); | ||
function convertArgs(args) { | ||
for (var k in args) { | ||
var v = args[k]; | ||
if (Buffer.isBuffer(v)) { | ||
args[k] = '0x' + v.toString('hex'); | ||
} else if (v instanceof Uint8Array) { | ||
args[k] = '0x' + Buffer.from(v).toString('hex'); | ||
} | ||
} | ||
return args; | ||
} | ||
var Client = function (_EventEmitter) { | ||
_inherits(Client, _EventEmitter); | ||
var Client = function () { | ||
function Client() { | ||
@@ -48,4 +34,2 @@ var uriString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'localhost:46657'; | ||
var _this = _possibleConstructorReturn(this, (Client.__proto__ || Object.getPrototypeOf(Client)).call(this)); | ||
var uri = url.parse(uriString); | ||
@@ -55,11 +39,3 @@ if (uri.protocol !== 'http' && uri.protocol !== 'tcp') { | ||
} | ||
_this.reqOpts = { | ||
host: uri.hostname, | ||
port: uri.port, | ||
method: 'POST', | ||
path: '/' | ||
}; | ||
_this.call = watt(_this.call, { context: _this }); | ||
return _this; | ||
this.uri = 'http://' + uri.hostname + ':' + uri.port + '/'; | ||
} | ||
@@ -69,58 +45,22 @@ | ||
key: 'call', | ||
value: regeneratorRuntime.mark(function call(method, args, next) { | ||
var req, reqBody, res, err, data; | ||
return regeneratorRuntime.wrap(function call$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
req = request(this.reqOpts, next.arg(0)); | ||
reqBody = requestBody(method, args); | ||
req.write(reqBody); | ||
req.end(); | ||
_context.next = 6; | ||
return; | ||
case 6: | ||
res = _context.sent; | ||
if (!(res.statusCode !== 200)) { | ||
_context.next = 10; | ||
break; | ||
} | ||
err = res.statusCode + ' - ' + STATUS_CODES[res.statusCode]; | ||
throw new Error(err); | ||
case 10: | ||
_context.next = 12; | ||
return res.pipe(concat(next.arg(0))); | ||
case 12: | ||
data = _context.sent; | ||
// buffer response stream | ||
data = JSON.parse(data.toString()); | ||
if (!data.error) { | ||
_context.next = 16; | ||
break; | ||
} | ||
throw new Error(data.error); | ||
case 16: | ||
return _context.abrupt('return', data.result); | ||
case 17: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
value: function call(method, args, cb) { | ||
get({ | ||
uri: method, | ||
baseUrl: this.uri, | ||
qs: convertArgs(args), | ||
json: true | ||
}, function (err, res, data) { | ||
if (err) return cb(err); | ||
if (res.statusCode !== 200) { | ||
var _err = 'Server responded with status code ' + res.statusCode; | ||
return cb(Error(_err)); | ||
} | ||
}, call, this); | ||
}) | ||
if (data.error) return cb(Error(data.error)); | ||
cb(null, data.result); | ||
}); | ||
} | ||
}]); | ||
return Client; | ||
}(EventEmitter); | ||
}(); | ||
@@ -136,16 +76,10 @@ // add methods to Client class based on methods defined in './methods.js' | ||
var _loop = function _loop() { | ||
var method = _step.value; | ||
var name = _step.value; | ||
Client.prototype[camel(method)] = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
Client.prototype[camel(name)] = function (args, cb) { | ||
if (!cb) { | ||
cb = args; | ||
args = null; | ||
} | ||
var cb = args[args.length - 1]; | ||
if (typeof cb !== 'function') { | ||
cb = noop; | ||
} else { | ||
args = args.slice(0, args.length - 1); | ||
} | ||
return this.call(method, args, cb); | ||
return this.call(name, args, cb); | ||
}; | ||
@@ -152,0 +86,0 @@ }; |
'use strict'; | ||
module.exports = ['subscribe', 'unsubscribe', 'status', 'net_info', 'dial_seeds', 'blockchain', 'genesis', 'block', 'validators', 'dump_consensus_state', 'broadcast_tx_commit', 'broadcast_tx_sync', 'broadcast_tx_async', 'unconfirmed_txs', 'num_unconfirmed_txs', 'tmsp_query', 'tmsp_info', 'unsafe_flush_mempool', 'unsafe_set_config', 'unsafe_start_cpu_profiler', 'unsafe_stop_cpu_profiler', 'unsafe_write_heap_profile']; | ||
module.exports = ['subscribe', 'unsubscribe', 'status', 'net_info', 'dial_seeds', 'blockchain', 'genesis', 'block', 'validators', 'dump_consensus_state', 'broadcast_tx_commit', 'broadcast_tx_sync', 'broadcast_tx_async', 'unconfirmed_txs', 'num_unconfirmed_txs', 'abci_query', 'abci_info', 'unsafe_flush_mempool', 'unsafe_set_config', 'unsafe_start_cpu_profiler', 'unsafe_stop_cpu_profiler', 'unsafe_write_heap_profile']; |
{ | ||
"name": "tendermint", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A light client which talks to your Tendermint node over RPC", | ||
@@ -14,17 +14,16 @@ "main": "index.js", | ||
"dependencies": { | ||
"browser-request": "^0.3.3", | ||
"camelcase": "^4.0.0", | ||
"concat-stream": "^1.6.0", | ||
"old": "^0.1.3", | ||
"regenerator-runtime": "^0.10.1", | ||
"watt": "^3.3.0" | ||
"request": "^2.79.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-plugin-transform-regenerator": "^6.21.0", | ||
"babel-preset-es2015": "^6.18.0" | ||
"babel-preset-es2015": "^6.18.0", | ||
"tape": "^4.6.3" | ||
}, | ||
"browser": { | ||
"request": "browser-request" | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"transform-regenerator" | ||
], | ||
"presets": [ | ||
@@ -31,0 +30,0 @@ "es2015" |
'use strict' | ||
const EventEmitter = require('events') | ||
const { request, STATUS_CODES } = require('http') | ||
const { get } = require('request') | ||
const url = require('url') | ||
const old = require('old') | ||
const concat = require('concat-stream') | ||
const regeneratorRuntime = require('regenerator-runtime') | ||
const watt = require('watt') | ||
const camel = require('camelcase') | ||
const tendermintMethods = require('./methods.js') | ||
const noop = () => regeneratorRuntime | ||
// hack to prevent standard from complaining about not using `regeneratorRuntime` | ||
function requestBody (method, params) { | ||
return JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: String(Date.now()), | ||
method, | ||
params | ||
}) | ||
function convertArgs (args) { | ||
for (let k in args) { | ||
let v = args[k] | ||
if (Buffer.isBuffer(v)) { | ||
args[k] = '0x' + v.toString('hex') | ||
} else if (v instanceof Uint8Array) { | ||
args[k] = '0x' + Buffer.from(v).toString('hex') | ||
} | ||
} | ||
return args | ||
} | ||
class Client extends EventEmitter { | ||
class Client { | ||
constructor (uriString = 'localhost:46657') { | ||
super() | ||
let uri = url.parse(uriString) | ||
@@ -33,28 +27,20 @@ if (uri.protocol !== 'http' && uri.protocol !== 'tcp') { | ||
} | ||
this.reqOpts = { | ||
host: uri.hostname, | ||
port: uri.port, | ||
method: 'POST', | ||
path: '/' | ||
} | ||
this.call = watt(this.call, { context: this }) | ||
this.uri = `http://${uri.hostname}:${uri.port}/` | ||
} | ||
* call (method, args, next) { | ||
let req = request(this.reqOpts, next.arg(0)) | ||
let reqBody = requestBody(method, args) | ||
req.write(reqBody) | ||
req.end() | ||
let res = yield // wait for http request callback | ||
if (res.statusCode !== 200) { | ||
let err = `${res.statusCode} - ${STATUS_CODES[res.statusCode]}` | ||
throw new Error(err) | ||
} | ||
let data = yield res.pipe(concat(next.arg(0))) // buffer response stream | ||
data = JSON.parse(data.toString()) | ||
if (data.error) throw new Error(data.error) | ||
return data.result | ||
call (method, args, cb) { | ||
get({ | ||
uri: method, | ||
baseUrl: this.uri, | ||
qs: convertArgs(args), | ||
json: true | ||
}, (err, res, data) => { | ||
if (err) return cb(err) | ||
if (res.statusCode !== 200) { | ||
let err = `Server responded with status code ${res.statusCode}` | ||
return cb(Error(err)) | ||
} | ||
if (data.error) return cb(Error(data.error)) | ||
cb(null, data.result) | ||
}) | ||
} | ||
@@ -64,11 +50,9 @@ } | ||
// add methods to Client class based on methods defined in './methods.js' | ||
for (let method of tendermintMethods) { | ||
Client.prototype[camel(method)] = function (...args) { | ||
let cb = args[args.length - 1] | ||
if (typeof cb !== 'function') { | ||
cb = noop | ||
} else { | ||
args = args.slice(0, args.length - 1) | ||
for (let name of tendermintMethods) { | ||
Client.prototype[camel(name)] = function (args, cb) { | ||
if (!cb) { | ||
cb = args | ||
args = null | ||
} | ||
return this.call(method, args, cb) | ||
return this.call(name, args, cb) | ||
} | ||
@@ -75,0 +59,0 @@ } |
@@ -19,4 +19,4 @@ module.exports = [ | ||
'tmsp_query', | ||
'tmsp_info', | ||
'abci_query', | ||
'abci_info', | ||
@@ -23,0 +23,0 @@ 'unsafe_flush_mempool', |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
67006
4
9
1
168
+ Addedbrowser-request@^0.3.3
+ Addedrequest@^2.79.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbrowser-request@0.3.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
- Removedconcat-stream@^1.6.0
- Removedregenerator-runtime@^0.10.1
- Removedwatt@^3.3.0
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedregenerator-runtime@0.10.5(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsetimmediate@1.0.5(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwatt@3.3.0(transitive)