Skip to content

Commit 682ba7e

Browse files
committed
Merge pull request bitcoinjs#530 from bitcoinjs/lesscomp
address: fix compiled assumption for fromOutputScript
2 parents 4ee194e + 67da1b3 commit 682ba7e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/address.js

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

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)
21+
if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(3, 23), network.pubKeyHash)
22+
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(2, 22), network.scriptHash)
2323

2424
throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address')
2525
}

test/address.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ describe('address', function () {
3636
})
3737
})
3838

39+
fixtures.valid.forEach(function (f) {
40+
it('parses (as chunks) ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
41+
var chunks = bscript.decompile(bscript.fromASM(f.script))
42+
var address = baddress.fromOutputScript(chunks, networks[f.network])
43+
44+
assert.strictEqual(address, f.base58check)
45+
})
46+
})
47+
3948
fixtures.invalid.fromOutputScript.forEach(function (f) {
4049
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
4150
var script = bscript.fromASM(f.script)

0 commit comments

Comments
 (0)