bxgateway
Version:
Package for connecting to Bloxroute's gateways
43 lines (42 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class BxgatewayBase extends events_1.EventEmitter {
constructor(dbg) {
super();
this._debug = dbg;
}
subscribe(topic, options) {
if (!this._gw.OPEN)
throw new Error('Websocket connection to gateway closed');
let req = {
id: 1,
method: 'subscribe',
params: [
topic,
options
]
};
this._debug.extend('subscribe')(JSON.stringify(req));
this._gw.send(JSON.stringify(req));
}
sendTransaction(signedTransaction) {
if (!this._gw.OPEN)
throw new Error('Websocket connection to gateway closed');
signedTransaction = signedTransaction.startsWith('0x') ? signedTransaction.slice(2) : signedTransaction;
let req = {
id: 1,
method: 'blxr_tx',
params: {
transaction: signedTransaction
}
};
this._debug.extend('blxr_tx')(JSON.stringify(req));
this._gw.send(JSON.stringify(req));
}
close() {
this._debug('close requested');
this._gw.close();
}
}
exports.default = BxgatewayBase;