rm *PushOnly, add isPushOnly and toStack
This commit is contained in:
parent
a023d23907
commit
2bb021ab64
4 changed files with 68 additions and 34 deletions
|
@ -145,8 +145,8 @@ function fromASM (asm) {
|
|||
}))
|
||||
}
|
||||
|
||||
function decompilePushOnly (script) {
|
||||
var chunks = decompile(script)
|
||||
function toStack (chunks) {
|
||||
chunks = decompile(chunks)
|
||||
typeforce(isPushOnly, chunks)
|
||||
|
||||
return chunks.map(function (op) {
|
||||
|
@ -157,11 +157,6 @@ function decompilePushOnly (script) {
|
|||
})
|
||||
}
|
||||
|
||||
function compilePushOnly (chunks) {
|
||||
typeforce(isPushOnly, chunks)
|
||||
return compile(chunks)
|
||||
}
|
||||
|
||||
function isCanonicalPubKey (buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) return false
|
||||
if (buffer.length < 33) return false
|
||||
|
@ -196,12 +191,13 @@ module.exports = {
|
|||
decompile: decompile,
|
||||
fromASM: fromASM,
|
||||
toASM: toASM,
|
||||
compilePushOnly: compilePushOnly,
|
||||
decompilePushOnly: decompilePushOnly,
|
||||
toStack: toStack,
|
||||
|
||||
number: require('./script_number'),
|
||||
|
||||
isCanonicalPubKey: isCanonicalPubKey,
|
||||
isCanonicalSignature: isCanonicalSignature,
|
||||
isPushOnly: isPushOnly,
|
||||
isDefinedHashType: isDefinedHashType
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ function check (script, allowIncomplete) {
|
|||
// is redeemScript a valid script?
|
||||
if (redeemScriptChunks.length === 0) return false
|
||||
|
||||
// is redeemScriptSig push only?
|
||||
if (!bscript.isPushOnly(scriptSigChunks)) return false
|
||||
|
||||
var inputType = bscript.classifyInput(scriptSigChunks, allowIncomplete)
|
||||
var outputType = bscript.classifyOutput(redeemScriptChunks)
|
||||
return inputType === outputType
|
||||
|
@ -23,7 +26,7 @@ function check (script, allowIncomplete) {
|
|||
check.toJSON = function () { return 'scriptHash input' }
|
||||
|
||||
function encode (redeemScriptSig, redeemScript) {
|
||||
var scriptSigChunks = bscript.decompilePushOnly(redeemScriptSig)
|
||||
var scriptSigChunks = bscript.decompile(redeemScriptSig)
|
||||
var serializedScriptPubKey = bscript.compile(redeemScript)
|
||||
|
||||
return bscript.compile([].concat(
|
||||
|
@ -37,7 +40,7 @@ function decode (buffer) {
|
|||
typeforce(check, chunks)
|
||||
|
||||
return {
|
||||
redeemScriptSig: bscript.compilePushOnly(chunks.slice(0, -1)),
|
||||
redeemScriptSig: bscript.compile(chunks.slice(0, -1)),
|
||||
redeemScript: chunks[chunks.length - 1]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue