socket.io fixes.

This commit is contained in:
Christopher Jeffrey 2016-06-02 02:46:39 -07:00
parent a1cabfb8bd
commit ac21ebd151
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 34 additions and 4 deletions

View File

@ -11,9 +11,13 @@ var Client = bcoin.http.client;
var client = new Client(
argv.url
|| process.env.BCOIN_URL
|| 'localhost:' + network.rpcPort
|| 'http://localhost:' + network.rpcPort
);
client.on('error', function(err) {
bcoin.error(err);
});
function getID() {
if (argv.id)
return argv.id;
@ -189,6 +193,31 @@ function getWalletHistory(callback) {
});
}
function listenWallet(callback) {
var id = getID();
client.listenWallet(id);
client.on('tx', function(tx, map) {
utils.print('TX:');
utils.print(tx);
utils.print(map);
});
client.on('updated', function(tx, map) {
utils.print('TX updated:');
utils.print(tx);
utils.print(map);
});
client.on('confirmed', function(tx, map) {
utils.print('TX updated:');
utils.print(tx);
utils.print(map);
});
client.on('balance', function(tx, map) {
utils.print('Balance:');
utils.print(tx);
utils.print(map);
});
}
function getBalance(callback) {
var id = getID();
client.getWalletBalance(id, function(err, balance) {
@ -244,6 +273,8 @@ function main(callback) {
switch (argv.args.shift()) {
case 'wallet':
return createWallet(callback);
case 'listen':
return listenWallet(callback);
case 'getwallet':
return getWallet(callback);
case 'addkey':

View File

@ -113,7 +113,7 @@ HTTPBase.prototype._initRouter = function _initRouter() {
try {
parsePath(req);
} catch (e) {
done(e);
return done(e);
}
self.emit('request', req, res);

View File

@ -60,7 +60,7 @@ HTTPClient.prototype._init = function _init() {
self.emit('error', err);
});
this.socket.on('open', function() {
this.socket.on('connect', function() {
self.socket.on('version', function(info) {
bcoin.debug('Connected to bcoin server: %s (%s)',
info.version, info.network);

View File

@ -39,7 +39,6 @@ function HTTPServer(options) {
this.loaded = false;
this.server = new HTTPBase(options);
this.io = null;
this._init();
}