templates: add toJSON for clearer error message
This commit is contained in:
parent
ce5babde83
commit
0c67f5e585
@ -19,6 +19,7 @@ function check (script, allowIncomplete) {
|
|||||||
|
|
||||||
return chunks.slice(1).every(bscript.isCanonicalSignature)
|
return chunks.slice(1).every(bscript.isCanonicalSignature)
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'multi-sig input' }
|
||||||
|
|
||||||
function encode (signatures, scriptPubKey) {
|
function encode (signatures, scriptPubKey) {
|
||||||
typeforce([partialSignature], signatures)
|
typeforce([partialSignature], signatures)
|
||||||
|
|||||||
@ -25,6 +25,7 @@ function check (script, allowIncomplete) {
|
|||||||
var keys = chunks.slice(1, -2)
|
var keys = chunks.slice(1, -2)
|
||||||
return keys.every(bscript.isCanonicalPubKey)
|
return keys.every(bscript.isCanonicalPubKey)
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'multi-sig output' }
|
||||||
|
|
||||||
function encode (m, pubKeys) {
|
function encode (m, pubKeys) {
|
||||||
typeforce({
|
typeforce({
|
||||||
|
|||||||
@ -11,6 +11,7 @@ function check (script) {
|
|||||||
return buffer.length > 1 &&
|
return buffer.length > 1 &&
|
||||||
buffer[0] === OPS.OP_RETURN
|
buffer[0] === OPS.OP_RETURN
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'null data output' }
|
||||||
|
|
||||||
function encode (data) {
|
function encode (data) {
|
||||||
typeforce(types.Buffer, data)
|
typeforce(types.Buffer, data)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ function check (script) {
|
|||||||
return chunks.length === 1 &&
|
return chunks.length === 1 &&
|
||||||
bscript.isCanonicalSignature(chunks[0])
|
bscript.isCanonicalSignature(chunks[0])
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'pubKey input' }
|
||||||
|
|
||||||
function encode (signature) {
|
function encode (signature) {
|
||||||
typeforce(types.Buffer, signature)
|
typeforce(types.Buffer, signature)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ function check (script) {
|
|||||||
bscript.isCanonicalPubKey(chunks[0]) &&
|
bscript.isCanonicalPubKey(chunks[0]) &&
|
||||||
chunks[1] === OPS.OP_CHECKSIG
|
chunks[1] === OPS.OP_CHECKSIG
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'pubKey output' }
|
||||||
|
|
||||||
function encode (pubKey) {
|
function encode (pubKey) {
|
||||||
typeforce(bscript.isCanonicalPubKey, pubKey)
|
typeforce(bscript.isCanonicalPubKey, pubKey)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ function check (script) {
|
|||||||
bscript.isCanonicalSignature(chunks[0]) &&
|
bscript.isCanonicalSignature(chunks[0]) &&
|
||||||
bscript.isCanonicalPubKey(chunks[1])
|
bscript.isCanonicalPubKey(chunks[1])
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'pubKeyHash input' }
|
||||||
|
|
||||||
function encode (signature, pubKey) {
|
function encode (signature, pubKey) {
|
||||||
typeforce({
|
typeforce({
|
||||||
|
|||||||
@ -15,6 +15,7 @@ function check (script) {
|
|||||||
buffer[23] === OPS.OP_EQUALVERIFY &&
|
buffer[23] === OPS.OP_EQUALVERIFY &&
|
||||||
buffer[24] === OPS.OP_CHECKSIG
|
buffer[24] === OPS.OP_CHECKSIG
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'pubKeyHash output' }
|
||||||
|
|
||||||
function encode (pubKeyHash) {
|
function encode (pubKeyHash) {
|
||||||
typeforce(types.Hash160bit, pubKeyHash)
|
typeforce(types.Hash160bit, pubKeyHash)
|
||||||
|
|||||||
@ -20,6 +20,7 @@ function check (script, allowIncomplete) {
|
|||||||
var outputType = bscript.classifyOutput(redeemScriptChunks)
|
var outputType = bscript.classifyOutput(redeemScriptChunks)
|
||||||
return inputType === outputType
|
return inputType === outputType
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'scriptHash input' }
|
||||||
|
|
||||||
function encode (scriptSignature, scriptPubKey) {
|
function encode (scriptSignature, scriptPubKey) {
|
||||||
var scriptSigChunks = bscript.decompile(scriptSignature)
|
var scriptSigChunks = bscript.decompile(scriptSignature)
|
||||||
|
|||||||
@ -13,6 +13,7 @@ function check (script) {
|
|||||||
buffer[1] === 0x14 &&
|
buffer[1] === 0x14 &&
|
||||||
buffer[22] === OPS.OP_EQUAL
|
buffer[22] === OPS.OP_EQUAL
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'scriptHash output' }
|
||||||
|
|
||||||
function encode (scriptHash) {
|
function encode (scriptHash) {
|
||||||
typeforce(types.Hash160bit, scriptHash)
|
typeforce(types.Hash160bit, scriptHash)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ function check (script) {
|
|||||||
buffer[0] === OPS.OP_0 &&
|
buffer[0] === OPS.OP_0 &&
|
||||||
buffer[1] === 0x14
|
buffer[1] === 0x14
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'Witness pubKeyHash output' }
|
||||||
|
|
||||||
function encode (pubKeyHash) {
|
function encode (pubKeyHash) {
|
||||||
typeforce(types.Hash160bit, pubKeyHash)
|
typeforce(types.Hash160bit, pubKeyHash)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ function check (script) {
|
|||||||
buffer[0] === OPS.OP_0 &&
|
buffer[0] === OPS.OP_0 &&
|
||||||
buffer[1] === 0x20
|
buffer[1] === 0x20
|
||||||
}
|
}
|
||||||
|
check.toJSON = function () { return 'Witness scriptHash output' }
|
||||||
|
|
||||||
function encode (scriptHash) {
|
function encode (scriptHash) {
|
||||||
typeforce(types.Hash256bit, scriptHash)
|
typeforce(types.Hash256bit, scriptHash)
|
||||||
|
|||||||
@ -323,17 +323,22 @@ describe('script-templates', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('witnessScriptHash.outputs.encode', function () {
|
describe('witnessScriptHash.output', function () {
|
||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
if (f.type !== 'witnessscripthash') return
|
if (f.type !== 'witnessscripthash') return
|
||||||
if (!f.scriptPubKey) return
|
if (!f.scriptPubKey) return
|
||||||
|
|
||||||
it('returns ' + f.scriptPubKey, function () {
|
var witnessScriptPubKey = bscript.fromASM(f.witnessScriptPubKey)
|
||||||
var witnessScriptPubKey = bscript.fromASM(f.witnessScriptPubKey)
|
var scriptHash = bcrypto.hash256(witnessScriptPubKey)
|
||||||
var scriptPubKey = bscript.witnessScriptHash.output.encode(bcrypto.hash256(witnessScriptPubKey))
|
var scriptPubKey = bscript.witnessScriptHash.output.encode(scriptHash)
|
||||||
|
|
||||||
|
it('encodes to ' + f.scriptPubKey, function () {
|
||||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('decodes to ' + scriptHash.toString('hex'), function () {
|
||||||
|
assert.deepEqual(bscript.witnessScriptHash.output.decode(scriptHash), witnessScriptPubKey)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
fixtures.invalid.witnessScriptHash.outputs.forEach(function (f) {
|
fixtures.invalid.witnessScriptHash.outputs.forEach(function (f) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user