address: fix compiled assumption for fromOutputScript
This commit is contained in:
parent
bda2e28a8f
commit
67da1b30e3
2 changed files with 11 additions and 2 deletions
|
@ -18,8 +18,8 @@ function fromBase58Check (address) {
|
||||||
function fromOutputScript (scriptPubKey, network) {
|
function fromOutputScript (scriptPubKey, network) {
|
||||||
network = network || networks.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(3, 23), network.pubKeyHash)
|
if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(3, 23), network.pubKeyHash)
|
||||||
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(2, 22), network.scriptHash)
|
if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(2, 22), network.scriptHash)
|
||||||
|
|
||||||
throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address')
|
throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address')
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
fixtures.invalid.fromOutputScript.forEach(function (f) {
|
||||||
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
|
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
|
||||||
var script = bscript.fromASM(f.script)
|
var script = bscript.fromASM(f.script)
|
||||||
|
|
Loading…
Reference in a new issue