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

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.1.1 to 1.2.0

63

lib/client.js

@@ -7,2 +7,8 @@ '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; }
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('request'),

@@ -14,2 +20,5 @@ get = _require.get;

var camel = require('camelcase');
var websocket = require('websocket-stream');
var ndjson = require('ndjson');
var pumpify = require('pumpify').obj;
var tendermintMethods = require('./methods.js');

@@ -29,3 +38,5 @@

var Client = function () {
var Client = function (_EventEmitter) {
_inherits(Client, _EventEmitter);
function Client() {

@@ -36,12 +47,38 @@ 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);
if (uri.protocol !== 'http' && uri.protocol !== 'tcp') {
if (uri.protocol !== 'http:' && uri.protocol !== 'ws:') {
uri = url.parse('http://' + uriString);
}
this.uri = 'http://' + uri.hostname + ':' + uri.port + '/';
if (uri.protocol === 'ws:') {
_this.websocket = true;
_this.uri = 'ws://' + uri.hostname + ':' + uri.port + '/websocket';
_this.call = _this.callWs;
_this.connectWs();
} else if (uri.protocol === 'http:') {
_this.uri = 'http://' + uri.hostname + ':' + uri.port + '/';
_this.call = _this.callHttp;
}
return _this;
}
_createClass(Client, [{
key: 'call',
value: function call(method, args, cb) {
key: 'connectWs',
value: function connectWs() {
var _this2 = this;
this.ws = pumpify(ndjson.stringify(), websocket(this.uri));
this.ws.on('error', function (err) {
return _this2.emit('error', err);
});
this.ws.on('data', function (data) {
data = JSON.parse(data);
if (!data.id) return;
_this2.emit(data.id, data.error || null, data.result);
});
}
}, {
key: 'callHttp',
value: function callHttp(method, args, cb) {
get({

@@ -61,6 +98,20 @@ uri: this.uri + method,

}
}, {
key: 'callWs',
value: function callWs(method, args, cb) {
var params = [];
for (var k in args) {
params.push(args[k]);
}var id = Math.random().toString(36);
if (method === 'subscribe') {
this.on(id + '#event', cb);
} else {
this.once(id, cb);
}
this.ws.write({ jsonrpc: '2.0', id: id, method: method, params: params });
}
}]);
return Client;
}();
}(EventEmitter);

@@ -67,0 +118,0 @@ // add methods to Client class based on methods defined in './methods.js'

7

package.json
{
"name": "tendermint",
"version": "1.1.1",
"version": "1.2.0",
"description": "A light client which talks to your Tendermint node over RPC",

@@ -16,4 +16,7 @@ "main": "index.js",

"camelcase": "^4.0.0",
"ndjson": "^1.5.0",
"old": "^0.1.3",
"request": "^2.79.0"
"pumpify": "^1.3.5",
"request": "^2.79.0",
"websocket-stream": "^3.3.3"
},

@@ -20,0 +23,0 @@ "devDependencies": {

'use strict'
const EventEmitter = require('events')
const { get } = require('request')

@@ -7,2 +8,5 @@ const url = require('url')

const camel = require('camelcase')
const websocket = require('websocket-stream')
const ndjson = require('ndjson')
const pumpify = require('pumpify').obj
const tendermintMethods = require('./methods.js')

@@ -22,12 +26,34 @@

class Client {
class Client extends EventEmitter {
constructor (uriString = 'localhost:46657') {
super()
let uri = url.parse(uriString)
if (uri.protocol !== 'http' && uri.protocol !== 'tcp') {
if (uri.protocol !== 'http:' && uri.protocol !== 'ws:') {
uri = url.parse(`http://${uriString}`)
}
this.uri = `http://${uri.hostname}:${uri.port}/`
if (uri.protocol === 'ws:') {
this.websocket = true
this.uri = `ws://${uri.hostname}:${uri.port}/websocket`
this.call = this.callWs
this.connectWs()
} else if (uri.protocol === 'http:') {
this.uri = `http://${uri.hostname}:${uri.port}/`
this.call = this.callHttp
}
}
call (method, args, cb) {
connectWs () {
this.ws = pumpify(
ndjson.stringify(),
websocket(this.uri)
)
this.ws.on('error', (err) => this.emit('error', err))
this.ws.on('data', (data) => {
data = JSON.parse(data)
if (!data.id) return
this.emit(data.id, data.error || null, data.result)
})
}
callHttp (method, args, cb) {
get({

@@ -47,2 +73,15 @@ uri: this.uri + method,

}
callWs (method, args, cb) {
let params = []
for (let k in args) params.push(args[k])
let id = Math.random().toString(36)
if (method === 'subscribe') {
this.on(id + '#event', cb)
} else {
this.once(id, cb)
}
this.ws.write({ jsonrpc: '2.0', id, method, params })
}
}

@@ -49,0 +88,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