From 03ddc79dfc993ae659db39bbc6556c090fc9dd3f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 20 Dec 2017 09:50:17 -0800 Subject: [PATCH] script/address: fix addr checking for nested p2sh inputs. --- lib/primitives/input.js | 10 +++++++--- lib/script/script.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/primitives/input.js b/lib/primitives/input.js index 1ab11cb4..9731bb9f 100644 --- a/lib/primitives/input.js +++ b/lib/primitives/input.js @@ -210,20 +210,24 @@ class Input { if (coin) return coin.getAddress(); + if (this.script.code.length > 0) + return this.script.getInputAddress(); + if (this.witness.items.length > 0) return this.witness.getInputAddress(); - return this.script.getInputAddress(); + return null; } /** * Get the address hash. + * @param {Coin?} coin * @param {String?} enc * @returns {Hash} hash */ - getHash(enc) { - const addr = this.getAddress(); + getHash(coin, enc) { + const addr = this.getAddress(coin); if (!addr) return null; diff --git a/lib/script/script.js b/lib/script/script.js index 1feb2867..faf2605d 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -2337,7 +2337,7 @@ class Script { */ isScripthashInput() { - if (this.code.length < 2) + if (this.code.length < 1) return false; // Grab the raw redeem script.