Skip to content

Commit d48a7ab

Browse files
committed
address: avoid unnecessary unchunking
1 parent f60cb2e commit d48a7ab

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/address.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ function fromBase58Check (address) {
1818
function fromOutputScript (scriptPubKey, network) {
1919
network = network || networks.bitcoin
2020

21-
var chunks = bscript.decompile(scriptPubKey)
22-
if (bscript.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash)
23-
if (bscript.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash)
21+
if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(3, 23), network.pubKeyHash)
22+
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(2, 22), network.scriptHash)
2423

25-
throw new Error(bscript.toASM(chunks) + ' has no matching Address')
24+
throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address')
2625
}
2726

2827
function toBase58Check (hash, version) {

0 commit comments

Comments
 (0)