minor fixes.

This commit is contained in:
Christopher Jeffrey 2016-02-10 21:22:28 -08:00
parent f26fb32027
commit 25767d9273
5 changed files with 38 additions and 36 deletions

View File

@ -281,24 +281,20 @@ Address.prototype.getAddress = function getAddress() {
return this.getKeyAddress();
};
Address.prototype._getAddressTable = function _getAddressTable() {
var addressTable = {};
addressTable[this.getAddress()] = true;
return addressTable;
};
Address.prototype.ownOutput = function ownOutput(tx, index) {
var addressTable = this._getAddressTable();
var address = this.getAddress();
var outputs = tx.outputs;
if ((tx instanceof bcoin.output) || (tx instanceof bcoin.coin))
if ((tx instanceof bcoin.output) || (tx instanceof bcoin.coin)) {
outputs = [tx];
tx = null;
}
outputs = outputs.filter(function(output, i) {
if (index != null && index !== i)
return false;
return output.test(addressTable, true);
return output.test(address);
}, this);
if (outputs.length === 0)
@ -308,7 +304,7 @@ Address.prototype.ownOutput = function ownOutput(tx, index) {
};
Address.prototype.ownInput = function ownInput(tx, index) {
var addressTable = this._getAddressTable();
var address = this.getAddress();
var inputs = tx.inputs;
if (tx instanceof bcoin.input) {
@ -324,9 +320,9 @@ Address.prototype.ownInput = function ownInput(tx, index) {
return false;
if (input.output)
return input.output.test(addressTable, true);
return input.output.test(address);
return input.test(addressTable, true);
return input.test(address);
}, this);
if (inputs.length === 0)

View File

@ -305,16 +305,22 @@ Input.prototype.testScript = function testScript(key, redeem, type) {
Input.prototype.test = function test(addressTable) {
var address = this.getAddress();
if (address) {
if (Array.isArray(addressTable)) {
if (addressTable.indexOf(address) !== -1)
return true;
} else {
if (addressTable[address] != null)
return true;
}
if (!address)
return false;
if (typeof addressTable === 'string')
addressTable = [addressTable];
if (Array.isArray(addressTable)) {
addressTable = addressTable.reduce(function(address) {
out[address] = true;
return out;
}, {});
}
if (addressTable[address] != null)
return true;
return false;
};

View File

@ -215,16 +215,22 @@ Output.prototype.testScript = function testScript(key, hash, keys, scriptHash, t
Output.prototype.test = function test(addressTable) {
var address = this.getAddress();
if (address) {
if (Array.isArray(addressTable)) {
if (addressTable.indexOf(address) !== -1)
return true;
} else {
if (addressTable[address] != null)
return true;
}
if (!address)
return false;
if (typeof addressTable === 'string')
addressTable = [addressTable];
if (Array.isArray(addressTable)) {
addressTable = addressTable.reduce(function(out, address) {
out[address] = true;
return out;
}, {});
}
if (addressTable[address] != null)
return true;
return false;
};

View File

@ -378,8 +378,6 @@ TXPool.prototype.getPending = function getPending(address) {
TXPool.prototype.getSent = function getSent(address) {
if (address) {
if (typeof address !== 'string')
address = address.getAddress();
if (this._addresses[address])
return this._addresses[address].sent.clone();
return new bn(0);
@ -389,8 +387,6 @@ TXPool.prototype.getSent = function getSent(address) {
TXPool.prototype.getReceived = function getReceived(address) {
if (address) {
if (typeof address !== 'string')
address = address.getAddress();
if (this._addresses[address])
return this._addresses[address].received.clone();
return new bn(0);
@ -400,8 +396,6 @@ TXPool.prototype.getReceived = function getReceived(address) {
TXPool.prototype.getBalance = function getBalance(address) {
if (address) {
if (typeof address !== 'string')
address = address.getAddress();
if (this._addresses[address])
return this._addresses[address].balance.clone();
return new bn(0);

View File

@ -1319,7 +1319,7 @@ TX.prototype.testInputs = function testInputs(addressTable, index, collect) {
addressTable = [addressTable];
if (Array.isArray(addressTable)) {
addressTable = addressTable.reduce(function(address) {
addressTable = addressTable.reduce(function(out, address) {
out[address] = true;
return out;
}, {});
@ -1361,7 +1361,7 @@ TX.prototype.testOutputs = function testOutputs(addressTable, index, collect) {
addressTable = [addressTable];
if (Array.isArray(addressTable)) {
addressTable = addressTable.reduce(function(address) {
addressTable = addressTable.reduce(function(out, address) {
out[address] = true;
return out;
}, {});