do not cache input/output type.
This commit is contained in:
parent
59cd4a29fe
commit
3e0830fe8e
@ -204,8 +204,6 @@ function Input(options) {
|
|||||||
this.witness = new bcoin.witness();
|
this.witness = new bcoin.witness();
|
||||||
this.coin = null;
|
this.coin = null;
|
||||||
this.mutable = false;
|
this.mutable = false;
|
||||||
|
|
||||||
this._type = null;
|
|
||||||
this._address = null;
|
this._address = null;
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
@ -267,18 +265,11 @@ Input.prototype.getType = function getType() {
|
|||||||
if (this.coin)
|
if (this.coin)
|
||||||
return this.coin.getType();
|
return this.coin.getType();
|
||||||
|
|
||||||
if (this._type)
|
|
||||||
return this._type;
|
|
||||||
|
|
||||||
if (this.witness.items.length > 0)
|
if (this.witness.items.length > 0)
|
||||||
type = this.witness.getInputType();
|
type = this.witness.getInputType();
|
||||||
|
else
|
||||||
if (!type || type === 'unknown')
|
|
||||||
type = this.script.getInputType();
|
type = this.script.getInputType();
|
||||||
|
|
||||||
if (!this.mutable)
|
|
||||||
this._type = type;
|
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -295,18 +286,12 @@ Input.prototype.getRedeem = function getRedeem() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.coin) {
|
if (!this.coin) {
|
||||||
if (this.script.isScripthashInput()) {
|
|
||||||
redeem = this.script.getRedeem();
|
|
||||||
|
|
||||||
if (redeem && redeem.isWitnessScripthash())
|
|
||||||
redeem = this.witness.getRedeem();
|
|
||||||
|
|
||||||
return redeem;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.witness.isScripthashInput())
|
if (this.witness.isScripthashInput())
|
||||||
return this.witness.getRedeem();
|
return this.witness.getRedeem();
|
||||||
|
|
||||||
|
if (this.script.isScripthashInput())
|
||||||
|
return this.script.getRedeem();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,17 +345,17 @@ Input.prototype.getAddress = function getAddress() {
|
|||||||
if (this.coin)
|
if (this.coin)
|
||||||
return this.coin.getAddress();
|
return this.coin.getAddress();
|
||||||
|
|
||||||
if (this._address)
|
address = this._address;
|
||||||
return this._address;
|
|
||||||
|
|
||||||
if (this.witness.items.length > 0)
|
if (!address) {
|
||||||
address = this.witness.getInputAddress();
|
if (this.witness.items.length > 0)
|
||||||
|
address = this.witness.getInputAddress();
|
||||||
|
else
|
||||||
|
address = this.script.getInputAddress();
|
||||||
|
|
||||||
if (!address)
|
if (!this.mutable)
|
||||||
address = this.script.getInputAddress();
|
this._address = address;
|
||||||
|
}
|
||||||
if (!this.mutable)
|
|
||||||
this._address = address;
|
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -31,8 +31,6 @@ function Output(options) {
|
|||||||
this.value = 0;
|
this.value = 0;
|
||||||
this.script = new bcoin.script();
|
this.script = new bcoin.script();
|
||||||
this.mutable = false;
|
this.mutable = false;
|
||||||
|
|
||||||
this._type = null;
|
|
||||||
this._address = null;
|
this._address = null;
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
@ -79,17 +77,7 @@ Output.fromOptions = function fromOptions(options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Output.prototype.getType = function getType() {
|
Output.prototype.getType = function getType() {
|
||||||
var type;
|
return this.script.getType();
|
||||||
|
|
||||||
if (this._type)
|
|
||||||
return this._type;
|
|
||||||
|
|
||||||
type = this.script.getType();
|
|
||||||
|
|
||||||
if (!this.mutable)
|
|
||||||
this._type = type;
|
|
||||||
|
|
||||||
return type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,15 +86,13 @@ Output.prototype.getType = function getType() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Output.prototype.getAddress = function getAddress() {
|
Output.prototype.getAddress = function getAddress() {
|
||||||
var address;
|
var address = this._address;
|
||||||
|
|
||||||
if (this._address)
|
if (!address) {
|
||||||
return this._address;
|
address = this.script.getAddress();
|
||||||
|
if (!this.mutable)
|
||||||
address = this.script.getAddress();
|
this._address = address;
|
||||||
|
}
|
||||||
if (!this.mutable)
|
|
||||||
this._address = address;
|
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -61,7 +61,6 @@ Witness.prototype.__defineSetter__('length', function(length) {
|
|||||||
|
|
||||||
Witness.prototype.fromOptions = function fromOptions(options) {
|
Witness.prototype.fromOptions = function fromOptions(options) {
|
||||||
this.items = options.items || options;
|
this.items = options.items || options;
|
||||||
this.redeem = null;
|
|
||||||
assert(Array.isArray(this.items));
|
assert(Array.isArray(this.items));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user