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.coin = null;
|
||||
this.mutable = false;
|
||||
|
||||
this._type = null;
|
||||
this._address = null;
|
||||
|
||||
if (options)
|
||||
@ -267,18 +265,11 @@ Input.prototype.getType = function getType() {
|
||||
if (this.coin)
|
||||
return this.coin.getType();
|
||||
|
||||
if (this._type)
|
||||
return this._type;
|
||||
|
||||
if (this.witness.items.length > 0)
|
||||
type = this.witness.getInputType();
|
||||
|
||||
if (!type || type === 'unknown')
|
||||
else
|
||||
type = this.script.getInputType();
|
||||
|
||||
if (!this.mutable)
|
||||
this._type = type;
|
||||
|
||||
return type;
|
||||
};
|
||||
|
||||
@ -295,18 +286,12 @@ Input.prototype.getRedeem = function getRedeem() {
|
||||
return;
|
||||
|
||||
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())
|
||||
return this.witness.getRedeem();
|
||||
|
||||
if (this.script.isScripthashInput())
|
||||
return this.script.getRedeem();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -360,17 +345,17 @@ Input.prototype.getAddress = function getAddress() {
|
||||
if (this.coin)
|
||||
return this.coin.getAddress();
|
||||
|
||||
if (this._address)
|
||||
return this._address;
|
||||
address = this._address;
|
||||
|
||||
if (this.witness.items.length > 0)
|
||||
address = this.witness.getInputAddress();
|
||||
if (!address) {
|
||||
if (this.witness.items.length > 0)
|
||||
address = this.witness.getInputAddress();
|
||||
else
|
||||
address = this.script.getInputAddress();
|
||||
|
||||
if (!address)
|
||||
address = this.script.getInputAddress();
|
||||
|
||||
if (!this.mutable)
|
||||
this._address = address;
|
||||
if (!this.mutable)
|
||||
this._address = address;
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
|
||||
@ -31,8 +31,6 @@ function Output(options) {
|
||||
this.value = 0;
|
||||
this.script = new bcoin.script();
|
||||
this.mutable = false;
|
||||
|
||||
this._type = null;
|
||||
this._address = null;
|
||||
|
||||
if (options)
|
||||
@ -79,17 +77,7 @@ Output.fromOptions = function fromOptions(options) {
|
||||
*/
|
||||
|
||||
Output.prototype.getType = function getType() {
|
||||
var type;
|
||||
|
||||
if (this._type)
|
||||
return this._type;
|
||||
|
||||
type = this.script.getType();
|
||||
|
||||
if (!this.mutable)
|
||||
this._type = type;
|
||||
|
||||
return type;
|
||||
return this.script.getType();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -98,15 +86,13 @@ Output.prototype.getType = function getType() {
|
||||
*/
|
||||
|
||||
Output.prototype.getAddress = function getAddress() {
|
||||
var address;
|
||||
var address = this._address;
|
||||
|
||||
if (this._address)
|
||||
return this._address;
|
||||
|
||||
address = this.script.getAddress();
|
||||
|
||||
if (!this.mutable)
|
||||
this._address = address;
|
||||
if (!address) {
|
||||
address = this.script.getAddress();
|
||||
if (!this.mutable)
|
||||
this._address = address;
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
|
||||
@ -61,7 +61,6 @@ Witness.prototype.__defineSetter__('length', function(length) {
|
||||
|
||||
Witness.prototype.fromOptions = function fromOptions(options) {
|
||||
this.items = options.items || options;
|
||||
this.redeem = null;
|
||||
assert(Array.isArray(this.items));
|
||||
return this;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user