Socket
Socket
Sign inDemoInstall

tendermint

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tendermint - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

test.js

138

lib/client.js

@@ -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

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