From d48a7ab6820ad06859334988cafc70b9a7edf375 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 30 Sep 2015 10:32:46 +1000 Subject: [PATCH] address: avoid unnecessary unchunking --- src/address.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/address.js b/src/address.js index d6924b3..e631401 100644 --- a/src/address.js +++ b/src/address.js @@ -18,11 +18,10 @@ function fromBase58Check (address) { function fromOutputScript (scriptPubKey, network) { network = network || networks.bitcoin - var chunks = bscript.decompile(scriptPubKey) - if (bscript.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash) - if (bscript.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash) + if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(3, 23), network.pubKeyHash) + if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(2, 22), network.scriptHash) - throw new Error(bscript.toASM(chunks) + ' has no matching Address') + throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address') } function toBase58Check (hash, version) {