diff --git a/bin/bcoin-cli b/bin/bcoin-cli index 2bf3ece2..5074d516 100755 --- a/bin/bcoin-cli +++ b/bin/bcoin-cli @@ -244,20 +244,20 @@ function main(callback) { default: utils.print('Unrecognized command.'); utils.print('Commands:'); - utils.print(' $ wallet [id] --keys [hdkeys]' - + ' --type [pubkeyhash/multisig] -m [m-value] + utils.print(' $ wallet [id] --keys [hdkeys]' + + ' --type [pubkeyhash/multisig] -m [m-value]' + ' -n [n-value] --witness: View or create wallet by ID.'); - utils.print(' $ getwallet [id]: View wallet by ID.'); - utils.print(' $ addkey [id] --keys [hdkeys]: Add keys to wallet.'); - utils.print(' $ rmkey [id] --keys [hdkeys]: Remove keys from wallet.'); - utils.print(' $ balance [id]: Get wallet balance.'); - utils.print(' $ history [id]: View wallet TX history.'); - utils.print(' $ send [id] [address] [value] --script [code]: Send transaction.'); - utils.print(' $ zap [id] --now [now] --age [age]: Zap pending wallet TXs.'); - utils.print(' $ mempool: Get mempool snapshot.'); - utils.print(' $ tx [hash/address]: View transactions.'); - utils.print(' $ coin [hash+index/address]: View coins.'); - utils.print(' $ block [hash/height]: View block.'); + utils.print(' $ getwallet [id]: View wallet by ID.'); + utils.print(' $ addkey [id] --keys [hdkeys]: Add keys to wallet.'); + utils.print(' $ rmkey [id] --keys [hdkeys]: Remove keys from wallet.'); + utils.print(' $ balance [id]: Get wallet balance.'); + utils.print(' $ history [id]: View wallet TX history.'); + utils.print(' $ send [id] [address] [value] --script [code]: Send transaction.'); + utils.print(' $ zap [id] --now [now] --age [age]: Zap pending wallet TXs.'); + utils.print(' $ mempool: Get mempool snapshot.'); + utils.print(' $ tx [hash/address]: View transactions.'); + utils.print(' $ coin [hash+index/address]: View coins.'); + utils.print(' $ block [hash/height]: View block.'); return callback(); } } @@ -316,11 +316,13 @@ function parseArg(argv) { } client.getInfo(function(err, info) { - if (err) - throw err; + if (err) { + console.error(err.stack + ''); + return process.exit(1); + } if (!argv.args[0]) - return utils.print(info); + utils.print(info); main(function(err) { if (err) { diff --git a/lib/bcoin/http/client.js b/lib/bcoin/http/client.js index adb71710..26581d1b 100644 --- a/lib/bcoin/http/client.js +++ b/lib/bcoin/http/client.js @@ -47,6 +47,10 @@ Client.prototype._init = function _init() { this.socket = new io.Socket(this.uri); + this.socket.on('error', function(err) { + self.emit('error', err); + }); + this.socket.on('open', function() { self.socket.on('version', function(info) { utils.debug('Connected to bcoin server: %s (%s)', @@ -100,10 +104,6 @@ Client.prototype._init = function _init() { self.emit('balances', balances); }); - self.socket.on('error', function(err) { - self.emit('error', err); - }); - self.loaded = true; self.emit('open'); }); diff --git a/lib/bcoin/http/request.js b/lib/bcoin/http/request.js index 28a5857b..5a1cb825 100644 --- a/lib/bcoin/http/request.js +++ b/lib/bcoin/http/request.js @@ -194,6 +194,11 @@ function request(options, callback, stream) { res.socket.on('end', done); }); + req.on('error', function(err) { + stream.destroy(); + stream.emit('error', err); + }); + if (body) req.write(body);