From 3e0830fe8e8cd7c0e0159823579c2537d612cfad Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 1 Jul 2016 02:25:13 -0700 Subject: [PATCH] do not cache input/output type. --- lib/bcoin/input.js | 41 +++++++++++++---------------------------- lib/bcoin/output.js | 28 +++++++--------------------- lib/bcoin/script.js | 1 - 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index 08f2656c..7bd45903 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -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; }; diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index 00b5e9d5..9296bdf8 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -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; }; diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 6cd95e58..1b8d3c1a 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -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; };