From 908a415e508e08eb3b0b6347906103057f475fda Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 12 Dec 2014 15:41:15 -0800 Subject: [PATCH] always return array on stopping. --- lib/bitcoind.js | 176 ++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 7f497722..dfcd1c22 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -139,12 +139,12 @@ Bitcoin.instances = {}; Bitcoin.prototype.instances = Bitcoin.instances; Bitcoin.__defineGetter__('global', function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]]; }); Bitcoin.prototype.__defineGetter__('global', function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return Bitcoin.global; }); @@ -372,7 +372,7 @@ Bitcoin.prototype.start = function(options, callback) { }; Bitcoin.prototype.getBlock = function(blockhash, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getBlock(blockhash, function(err, block) { if (err) return callback(err); return callback(null, bitcoin.block(block)); @@ -380,7 +380,7 @@ Bitcoin.prototype.getBlock = function(blockhash, callback) { }; Bitcoin.prototype.getBlockHeight = function(height, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getBlock(+height, function(err, block) { if (err) return callback(err); return callback(null, bitcoin.block(block)); @@ -389,7 +389,7 @@ Bitcoin.prototype.getBlockHeight = function(height, callback) { Bitcoin.prototype.getTransaction = Bitcoin.prototype.getTx = function(txid, blockhash, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; if (typeof txid === 'object' && txid) { var options = txid; callback = blockhash; @@ -420,7 +420,7 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) { }; Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var self = this; var slow = true; @@ -467,42 +467,42 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) }; Bitcoin.prototype.getInfo = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getInfo(); }; Bitcoin.prototype.getPeerInfo = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getPeerInfo(); }; Bitcoin.prototype.getAddresses = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getAddresses(); }; Bitcoin.prototype.getProgress = function(callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getProgress(callback); }; Bitcoin.prototype.setGenerate = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.setGenerate(options || {}); }; Bitcoin.prototype.getGenerate = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getGenerate(options || {}); }; Bitcoin.prototype.getMiningInfo = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getMiningInfo(); }; Bitcoin.prototype.getAddrTransactions = function(address, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoin.db.get('addr-tx/' + address, function(err, records) { var options = { address: address, @@ -553,24 +553,24 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) { }; Bitcoin.prototype.getBestBlock = function(callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var hash = bitcoindjs.getBestBlock(); return bitcoindjs.getBlock(hash, callback); }; Bitcoin.prototype.getChainHeight = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getChainHeight(); }; Bitcoin.prototype.__defineGetter__('chainHeight', function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return this.getChainHeight(); }); Bitcoin.prototype.getBlockByTxid = Bitcoin.prototype.getBlockByTx = function(txid, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoin.db.get('block-tx/' + txid, function(err, block) { if (block) { return self.getBlock(block.hash, function(err, block) { @@ -591,7 +591,7 @@ Bitcoin.prototype.getBlockByTx = function(txid, callback) { Bitcoin.prototype.getBlocksByDate = Bitcoin.prototype.getBlocksByTime = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getBlocksByTime(options, function(err, blocks) { if (err) return callback(err); return callback(null, blocks.map(function(block) { @@ -601,13 +601,13 @@ Bitcoin.prototype.getBlocksByTime = function(options, callback) { }; Bitcoin.prototype.getLastFileIndex = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.getLastFileIndex(); }; Bitcoin.prototype.log = Bitcoin.prototype.info = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; if (this.options.silent) return; if (typeof arguments[0] !== 'string') { var out = util.inspect(arguments[0], null, 20, true); @@ -618,7 +618,7 @@ Bitcoin.prototype.info = function() { }; Bitcoin.prototype.error = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; if (this.options.silent) return; if (typeof arguments[0] !== 'string') { var out = util.inspect(arguments[0], null, 20, true); @@ -630,7 +630,7 @@ Bitcoin.prototype.error = function() { Bitcoin.prototype.stop = Bitcoin.prototype.close = function(callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var self = this; return bitcoindjs.stop(function(err, status) { if (err) { @@ -676,7 +676,7 @@ function Block(data) { return data; } - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var self = this; @@ -704,17 +704,17 @@ Object.defineProperty(Block.prototype, '_blockFlag', { }); Block.isBlock = function(block) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return block._blockFlag === Block.prototype._blockFlag; }; Block.fromHex = function(hex) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoin.block(bitcoindjs.blockFromHex(hex)); }; Block.prototype.getHash = function(enc) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getBlockHex(this); if (!this.hash || this.hash !== data.hash) { this.hash = data.hash; @@ -726,12 +726,12 @@ Block.prototype.getHash = function(enc) { }; Block.prototype.verify = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return this.verified = this.verified || bitcoindjs.verifyBlock(this); }; Block.prototype.toHex = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var hex = Block.toHex(this); if (!this.hex || this.hex !== hex) { this.hex = hex; @@ -740,18 +740,18 @@ Block.prototype.toHex = function() { }; Block.toHex = function(block) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getBlockHex(block); return data.hex; }; Block.prototype.toBinary = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return Block.toBinary(this); }; Block.toBinary = function(block) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getBlockHex(block); return new Buffer(data.hex, 'hex'); }; @@ -773,7 +773,7 @@ function Transaction(data) { return data; } - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var self = this; @@ -798,29 +798,29 @@ Object.defineProperty(Transaction.prototype, '_txFlag', { Transaction.isTransaction = Transaction.isTx = function(tx) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return tx._txFlag === Transaction.prototype._txFlag; }; Transaction.fromHex = function(hex) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoin.tx(bitcoindjs.txFromHex(hex)); }; Transaction.prototype.verify = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return this.verified = this.verified || bitcoindjs.verifyTransaction(this); }; Transaction.prototype.sign = Transaction.prototype.fill = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return Transaction.fill(this, options); }; Transaction.sign = Transaction.fill = function(tx, options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var isTx = bitcoin.tx.isTx(tx) , newTx; @@ -842,7 +842,7 @@ Transaction.fill = function(tx, options) { }; Transaction.prototype.getHash = function(enc) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getTxHex(this); if (!this.txid || this.txid !== data.hash) { this.txid = data.hash; @@ -854,12 +854,12 @@ Transaction.prototype.getHash = function(enc) { }; Transaction.prototype.isCoinbase = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return this.vin.length === 1 && this.vin[0].coinbase; }; Transaction.prototype.toHex = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var hex = Transaction.toHex(this); if (!this.hex || hex !== this.hex) { this.hex = hex; @@ -868,24 +868,24 @@ Transaction.prototype.toHex = function() { }; Transaction.toHex = function(tx) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getTxHex(tx); return data.hex; }; Transaction.prototype.toBinary = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return Transaction.toBinary(this); }; Transaction.toBinary = function(tx) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var data = bitcoindjs.getTxHex(tx); return new Buffer(data.hex, 'hex'); }; Transaction.broadcast = function(tx, options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; if (typeof tx === 'string') { tx = { hex: tx }; } @@ -924,7 +924,7 @@ Transaction.broadcast = function(tx, options, callback) { }; Transaction.prototype.broadcast = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; if (!callback) { callback = options; options = null; @@ -945,7 +945,7 @@ function Addresses(data) { return data; } - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var self = this; @@ -966,7 +966,7 @@ Object.defineProperty(Transaction.prototype, '_addrFlag', { Addresses.isAddresses = Addresses.isAddr = function(addr) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return addr._txFlag === Addresses.prototype._addrFlag; }; @@ -976,7 +976,7 @@ Addresses.isAddr = function(addr) { */ function Wallet() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var obj = function() { return obj; }; @@ -987,91 +987,91 @@ function Wallet() { } Wallet.prototype.createAddress = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletNewAddress(options || {}); }; Wallet.prototype.getAccountAddress = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletGetAccountAddress(options || {}); }; Wallet.prototype.setAccount = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSetAccount(options || {}); }; Wallet.prototype.getAccount = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletGetAccount(options || {}); }; Wallet.prototype.getRecipients = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletGetRecipients(options || {}); }; Wallet.prototype.getRecipient = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; options = options || {}; var label = options.label || label; return bitcoindjs.walletGetRecipients({ _label: label }); }; Wallet.prototype.setRecipient = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSetRecipient(options || {}); }; Wallet.prototype.removeRecipient = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletRemoveRecipient(options || {}); }; Wallet.prototype.sendTo = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSendTo(options || {}, callback); }; Wallet.prototype.sendFrom = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSendFrom(options || {}, callback); }; Wallet.prototype.move = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletMove(options || {}); }; Wallet.prototype.signMessage = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSignMessage(options || {}); }; Wallet.prototype.verifyMessage = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletVerifyMessage(options || {}); }; Wallet.prototype.createMultiSigAddress = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletCreateMultiSigAddress(options || {}); }; Wallet.prototype.getBalance = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletGetBalance(options || {}); }; Wallet.prototype.getUnconfirmedBalance = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletGetUnconfirmedBalance(options || {}); }; // XXX Wallet Transactions Wallet.prototype.listTransactions = Wallet.prototype.getTransactions = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var txs = bitcoindjs.walletListTransactions(options || {}); if (callback) { // Retrieve to regular TXs from disk: @@ -1094,19 +1094,19 @@ Wallet.prototype.getTransactions = function(options, callback) { Wallet.prototype.listReceivedByAddress = Wallet.prototype.getReceivedByAddress = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletReceivedByAddress(options || {}); }; Wallet.prototype.listAccounts = Wallet.prototype.getAccounts = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletListAccounts(options || {}); }; // XXX Wallet Transaction Wallet.prototype.getTransaction = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var tx = bitcoindjs.walletGetTransaction(options || {}); if (callback) { // Retrieve to regular TX from disk: @@ -1121,94 +1121,94 @@ Wallet.prototype.getTransaction = function(options, callback) { }; Wallet.prototype.backup = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletBackup(options || {}); }; Wallet.prototype.decrypt = Wallet.prototype.passphrase = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletPassphrase(options || {}); }; Wallet.prototype.passphraseChange = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletPassphraseChange(options || {}); }; Wallet.prototype.forgetPassphrase = Wallet.prototype.lock = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletLock(options || {}); }; Wallet.prototype.encrypt = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletEncrypt(options || {}); }; Wallet.prototype.encrypted = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletEncrypted(); }; Wallet.prototype.isEncrypted = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return false; return this.encrypted().encrypted; }; Wallet.prototype.isLocked = function() { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return false; return this.encrypted().locked; }; Wallet.prototype.dumpKey = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletDumpKey(options || {}); }; Wallet.prototype.importKey = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletImportKey(options || {}, callback); }; Wallet.prototype.keyPoolRefill = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletKeyPoolRefill(options || {}); }; Wallet.prototype.setTxFee = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletSetTxFee(options || {}); }; Wallet.prototype.dump = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletDumpWallet(options || {}, callback); }; Wallet.prototype.import = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletImportWallet(options || {}, callback); }; Wallet.prototype.changeLabel = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletChangeLabel(options || {}); }; Wallet.prototype.deleteAccount = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletDeleteAccount(options || {}); }; Wallet.prototype.isMine = function(options) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletIsMine(options || {}); }; Wallet.prototype.rescan = function(options, callback) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; return bitcoindjs.walletRescan(options || {}, callback); }; @@ -1221,7 +1221,7 @@ Wallet = new Wallet; var utils = {}; utils.forEach = function(obj, iter, done) { - if (bitcoin.stopping) return; + if (bitcoin.stopping) return []; var pending = obj.length; if (!pending) return done(); var next = function() {