diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 0f86286a..a47101cc 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -509,7 +509,7 @@ Chain.prototype.add = function add(block, peer) { block.height = entry.height; block.txs.forEach(function(tx) { tx.height = entry.height; - }, this); + }); // Keep track of the number of blocks we // added and the number of orphans resolved. @@ -520,7 +520,7 @@ Chain.prototype.add = function add(block, peer) { this.emit('block', block, peer); this.emit('entry', entry); if (block !== initial) - this.emit('resolved', entry.hash); + this.emit('resolved', block, peer); // Fullfill request this.request.fullfill(hash, block); @@ -541,7 +541,7 @@ Chain.prototype.add = function add(block, peer) { // allow more than 20mb stored in memory. if (this.orphan.size > 20971520) { Object.keys(this.orphan.bmap).forEach(function(hash) { - this.emit('unresolved', hash); + this.emit('unresolved', this.orphan.bmap[hash], peer); }, this); this.orphan.map = {}; this.orphan.bmap = {}; @@ -634,10 +634,6 @@ Chain.prototype.getOrphan = function getOrphan(hash) { return this.orphan.bmap[hash] || null; }; -Chain.prototype.getTip = function getTip() { - return this.tip; -}; - Chain.prototype.isFull = function isFull() { var delta; diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index 1a4a703e..e22655fd 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -355,9 +355,9 @@ TXPool.prototype.getAll = function getAll(address) { TXPool.prototype.getUnspent = function getUnspent(address) { return Object.keys(this._unspent).map(function(key) { return this._unspent[key]; - }, this).filter(function(item) { + }, this).filter(function(unspent) { if (address) { - if (!tx.testInputs(address) && !tx.testOutputs(address)) + if (!unspent.test(address) && !unspent.test(address)) return false; } return true; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 7a821f1b..f415d56a 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -74,7 +74,6 @@ function TX(data, block) { } } - this.unspent = data.unspent || null; this.hardFee = data.hardFee || null; this.subtractFee = data.subtractFee || null; this.changeAddress = data.changeAddress || null; @@ -1023,10 +1022,8 @@ TX.prototype.getInputs = function getInputs(unspent, address, fee) { var lastAdded = 0; var size, newkb, change; - if (fee) { + if (fee) total = cost.add(fee); - this.hardFee = fee; - } // Oldest unspents first unspent = unspent.slice().sort(function(a, b) { @@ -1103,26 +1100,27 @@ TX.prototype.getInputs = function getInputs(unspent, address, fee) { cost: cost, fee: total.sub(cost), total: total, - kb: totalkb + kb: totalkb, + unspent: unspent.slice(0, lastAdded) }; }; TX.prototype.fill = function fill(unspent, address, fee) { var result; - if (unspent) - this.unspent = unspent; + if (!address) + address = this.changeAddress; - if (address) - this.changeAddress = address; + if (!fee) + fee = this.hardFee; - if (fee) - this.hardFee = fee; + assert(unspent); + assert(address); - assert(this.changeAddress); - - result = this.getInputs(this.unspent, this.changeAddress, this.hardFee); + result = this.getInputs(unspent, address, fee); + this.changeAddress = address; + this.hardFee = fee; this.total = result.total; if (!result.inputs) @@ -1425,7 +1423,7 @@ TX.prototype.setLocktime = function setLocktime(locktime) { } }; -TX.prototype.increaseFee = function increaseFee(fee) { +TX.prototype.increaseFee = function increaseFee(unspent, address, fee) { var i, input, result; this.inputs = []; @@ -1433,8 +1431,10 @@ TX.prototype.increaseFee = function increaseFee(fee) { if (this.changeIndex !== -1) this.outputs.splice(this.changeIndex, 1); - this.hardFee = fee || this.getFee().add(new bn(10000)); - result = this.fill(); + if (!fee) + fee = this.getFee().add(new bn(10000)); + + result = this.fill(unspent, address, fee); for (i = 0; i < this.inputs.length; i++) { input = this.inputs[i]; diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 5081ed16..a9a0c174 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -340,7 +340,9 @@ Wallet.prototype.deriveAddress = function deriveAddress(change, index) { } else { data = { path: this.createPath(this.cosignerIndex, change, index), - cosignerIndex: this.cosignerIndex, + cosignerIndex: this.copayBIP45 + ? constants.hd.hardened - 1 + : this.cosignerIndex, change: change, index: index };