add regular addresses to addressMap.
This commit is contained in:
parent
bfd570e204
commit
da19b6da29
@ -34,6 +34,7 @@ function Address(options) {
|
|||||||
this.storage = options.storage;
|
this.storage = options.storage;
|
||||||
this.label = options.label || '';
|
this.label = options.label || '';
|
||||||
this.derived = !!options.derived;
|
this.derived = !!options.derived;
|
||||||
|
this.addressMap = null;
|
||||||
|
|
||||||
this.key = options.pair || options.key || bcoin.keypair(options);
|
this.key = options.pair || options.key || bcoin.keypair(options);
|
||||||
this.path = options.path;
|
this.path = options.path;
|
||||||
@ -281,8 +282,22 @@ Address.prototype.getAddress = function getAddress() {
|
|||||||
return this.getKeyAddress();
|
return this.getKeyAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Address.prototype._getAddressMap = function _getAddressMap() {
|
||||||
|
if (this.addressMap)
|
||||||
|
return this.addressMap;
|
||||||
|
|
||||||
|
this.addressMap = {};
|
||||||
|
|
||||||
|
this.addressMap[this.getKeyAddress()] = true;
|
||||||
|
|
||||||
|
if (this.prefixType === 'scripthash')
|
||||||
|
this.addressMap[this.getScriptAddress()] = true;
|
||||||
|
|
||||||
|
return this.addressMap;
|
||||||
|
};
|
||||||
|
|
||||||
Address.prototype.ownOutput = function ownOutput(tx, index) {
|
Address.prototype.ownOutput = function ownOutput(tx, index) {
|
||||||
var address = this.getAddress();
|
var addressMap = this._getAddressMap();
|
||||||
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)) {
|
||||||
@ -294,7 +309,7 @@ Address.prototype.ownOutput = function ownOutput(tx, index) {
|
|||||||
if (index != null && index !== i)
|
if (index != null && index !== i)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return output.test(address);
|
return output.test(addressMap);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if (outputs.length === 0)
|
if (outputs.length === 0)
|
||||||
@ -304,7 +319,7 @@ Address.prototype.ownOutput = function ownOutput(tx, index) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Address.prototype.ownInput = function ownInput(tx, index) {
|
Address.prototype.ownInput = function ownInput(tx, index) {
|
||||||
var address = this.getAddress();
|
var addressMap = this._getAddressMap();
|
||||||
var inputs = tx.inputs;
|
var inputs = tx.inputs;
|
||||||
|
|
||||||
if (tx instanceof bcoin.input) {
|
if (tx instanceof bcoin.input) {
|
||||||
@ -320,9 +335,9 @@ Address.prototype.ownInput = function ownInput(tx, index) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (input.output)
|
if (input.output)
|
||||||
return input.output.test(address);
|
return input.output.test(addressMap);
|
||||||
|
|
||||||
return input.test(address);
|
return input.test(addressMap);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if (inputs.length === 0)
|
if (inputs.length === 0)
|
||||||
|
|||||||
@ -312,7 +312,7 @@ Input.prototype.test = function test(addressTable) {
|
|||||||
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;
|
||||||
}, {});
|
}, {});
|
||||||
|
|||||||
@ -372,7 +372,10 @@ Wallet.prototype.deriveAddress = function deriveAddress(change, index) {
|
|||||||
|
|
||||||
address = bcoin.address(options);
|
address = bcoin.address(options);
|
||||||
|
|
||||||
this.addressMap[address.getAddress()] = data.path;
|
this.addressMap[address.getKeyAddress()] = data.path;
|
||||||
|
|
||||||
|
if (this.prefixType === 'scripthash')
|
||||||
|
this.addressMap[address.getScriptAddress()] = data.path;
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user