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

View File

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

View File

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

View File

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

View File

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