minor fixes.

This commit is contained in:
Christopher Jeffrey 2016-02-12 01:20:05 -08:00
parent a788f151b1
commit 686dcbcdd9
4 changed files with 25 additions and 27 deletions

View File

@ -509,7 +509,7 @@ Chain.prototype.add = function add(block, peer) {
block.height = entry.height; block.height = entry.height;
block.txs.forEach(function(tx) { block.txs.forEach(function(tx) {
tx.height = entry.height; tx.height = entry.height;
}, this); });
// Keep track of the number of blocks we // Keep track of the number of blocks we
// added and the number of orphans resolved. // 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('block', block, peer);
this.emit('entry', entry); this.emit('entry', entry);
if (block !== initial) if (block !== initial)
this.emit('resolved', entry.hash); this.emit('resolved', block, peer);
// Fullfill request // Fullfill request
this.request.fullfill(hash, block); this.request.fullfill(hash, block);
@ -541,7 +541,7 @@ Chain.prototype.add = function add(block, peer) {
// allow more than 20mb stored in memory. // allow more than 20mb stored in memory.
if (this.orphan.size > 20971520) { if (this.orphan.size > 20971520) {
Object.keys(this.orphan.bmap).forEach(function(hash) { Object.keys(this.orphan.bmap).forEach(function(hash) {
this.emit('unresolved', hash); this.emit('unresolved', this.orphan.bmap[hash], peer);
}, this); }, this);
this.orphan.map = {}; this.orphan.map = {};
this.orphan.bmap = {}; this.orphan.bmap = {};
@ -634,10 +634,6 @@ Chain.prototype.getOrphan = function getOrphan(hash) {
return this.orphan.bmap[hash] || null; return this.orphan.bmap[hash] || null;
}; };
Chain.prototype.getTip = function getTip() {
return this.tip;
};
Chain.prototype.isFull = function isFull() { Chain.prototype.isFull = function isFull() {
var delta; var delta;

View File

@ -355,9 +355,9 @@ TXPool.prototype.getAll = function getAll(address) {
TXPool.prototype.getUnspent = function getUnspent(address) { TXPool.prototype.getUnspent = function getUnspent(address) {
return Object.keys(this._unspent).map(function(key) { return Object.keys(this._unspent).map(function(key) {
return this._unspent[key]; return this._unspent[key];
}, this).filter(function(item) { }, this).filter(function(unspent) {
if (address) { if (address) {
if (!tx.testInputs(address) && !tx.testOutputs(address)) if (!unspent.test(address) && !unspent.test(address))
return false; return false;
} }
return true; return true;

View File

@ -74,7 +74,6 @@ function TX(data, block) {
} }
} }
this.unspent = data.unspent || null;
this.hardFee = data.hardFee || null; this.hardFee = data.hardFee || null;
this.subtractFee = data.subtractFee || null; this.subtractFee = data.subtractFee || null;
this.changeAddress = data.changeAddress || null; this.changeAddress = data.changeAddress || null;
@ -1023,10 +1022,8 @@ TX.prototype.getInputs = function getInputs(unspent, address, fee) {
var lastAdded = 0; var lastAdded = 0;
var size, newkb, change; var size, newkb, change;
if (fee) { if (fee)
total = cost.add(fee); total = cost.add(fee);
this.hardFee = fee;
}
// Oldest unspents first // Oldest unspents first
unspent = unspent.slice().sort(function(a, b) { unspent = unspent.slice().sort(function(a, b) {
@ -1103,26 +1100,27 @@ TX.prototype.getInputs = function getInputs(unspent, address, fee) {
cost: cost, cost: cost,
fee: total.sub(cost), fee: total.sub(cost),
total: total, total: total,
kb: totalkb kb: totalkb,
unspent: unspent.slice(0, lastAdded)
}; };
}; };
TX.prototype.fill = function fill(unspent, address, fee) { TX.prototype.fill = function fill(unspent, address, fee) {
var result; var result;
if (unspent) if (!address)
this.unspent = unspent; address = this.changeAddress;
if (address) if (!fee)
this.changeAddress = address; fee = this.hardFee;
if (fee) assert(unspent);
this.hardFee = fee; assert(address);
assert(this.changeAddress); result = this.getInputs(unspent, address, fee);
result = this.getInputs(this.unspent, this.changeAddress, this.hardFee);
this.changeAddress = address;
this.hardFee = fee;
this.total = result.total; this.total = result.total;
if (!result.inputs) 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; var i, input, result;
this.inputs = []; this.inputs = [];
@ -1433,8 +1431,10 @@ TX.prototype.increaseFee = function increaseFee(fee) {
if (this.changeIndex !== -1) if (this.changeIndex !== -1)
this.outputs.splice(this.changeIndex, 1); this.outputs.splice(this.changeIndex, 1);
this.hardFee = fee || this.getFee().add(new bn(10000)); if (!fee)
result = this.fill(); fee = this.getFee().add(new bn(10000));
result = this.fill(unspent, address, fee);
for (i = 0; i < this.inputs.length; i++) { for (i = 0; i < this.inputs.length; i++) {
input = this.inputs[i]; input = this.inputs[i];

View File

@ -340,7 +340,9 @@ Wallet.prototype.deriveAddress = function deriveAddress(change, index) {
} else { } else {
data = { data = {
path: this.createPath(this.cosignerIndex, change, index), path: this.createPath(this.cosignerIndex, change, index),
cosignerIndex: this.cosignerIndex, cosignerIndex: this.copayBIP45
? constants.hd.hardened - 1
: this.cosignerIndex,
change: change, change: change,
index: index index: index
}; };