script: use isPushOnly internally

This commit is contained in:
Daniel Cousens 2016-11-14 16:03:06 +11:00 committed by Daniel Cousens
parent 8df1b45699
commit b1daff1108

View file

@ -21,8 +21,12 @@ function isOPInt (value) {
(value === OPS.OP_1NEGATE) (value === OPS.OP_1NEGATE)
} }
function pushOnlyChunk (value) { function isPushOnlyChunk (value) {
return types.oneOf(Buffer, isOPInt) return types.Buffer(value) || isOPInt(value)
}
function isPushOnly (value) {
return types.Array(value) && value.every(isPushOnlyChunk)
} }
function compile (chunks) { function compile (chunks) {
@ -143,7 +147,7 @@ function fromASM (asm) {
function decompilePushOnly (script) { function decompilePushOnly (script) {
var chunks = decompile(script) var chunks = decompile(script)
typeforce([pushOnlyChunk], chunks) typeforce(isPushOnly, chunks)
return chunks.map(function (op) { return chunks.map(function (op) {
if (Buffer.isBuffer(op)) return op if (Buffer.isBuffer(op)) return op
@ -154,7 +158,7 @@ function decompilePushOnly (script) {
} }
function compilePushOnly (chunks) { function compilePushOnly (chunks) {
typeforce([pushOnlyChunk], chunks) typeforce(isPushOnly, chunks)
return compile(chunks) return compile(chunks)
} }