Skip to content

Commit

Permalink
Merge pull request bitcoinjs#530 from bitcoinjs/lesscomp
Browse files Browse the repository at this point in the history
address: fix compiled assumption for fromOutputScript
  • Loading branch information
jprichardson committed Jan 28, 2016
2 parents 4ee194e + 67da1b3 commit 682ba7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function fromBase58Check (address) {
function fromOutputScript (scriptPubKey, network) {
network = network || networks.bitcoin

if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(3, 23), network.pubKeyHash)
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(2, 22), network.scriptHash)
if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(3, 23), network.pubKeyHash)
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(2, 22), network.scriptHash)

throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address')
}
Expand Down
9 changes: 9 additions & 0 deletions test/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ describe('address', function () {
})
})

fixtures.valid.forEach(function (f) {
it('parses (as chunks) ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
var chunks = bscript.decompile(bscript.fromASM(f.script))
var address = baddress.fromOutputScript(chunks, networks[f.network])

assert.strictEqual(address, f.base58check)
})
})

fixtures.invalid.fromOutputScript.forEach(function (f) {
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
var script = bscript.fromASM(f.script)
Expand Down

0 comments on commit 682ba7e

Please sign in to comment.