scripts: add dataOutput convenience function

This commit is contained in:
Daniel Cousens 2014-10-19 12:29:40 +11:00
parent 27e69ba716
commit ea66edeb5c
3 changed files with 22 additions and 1 deletions

View file

@ -241,9 +241,14 @@ function multisigInput(signatures, scriptPubKey) {
return Script.fromChunks([].concat(ops.OP_0, signatures)) return Script.fromChunks([].concat(ops.OP_0, signatures))
} }
function dataOutput(data) {
return Script.fromChunks([ops.OP_RETURN, data])
}
module.exports = { module.exports = {
classifyInput: classifyInput, classifyInput: classifyInput,
classifyOutput: classifyOutput, classifyOutput: classifyOutput,
dataOutput: dataOutput,
multisigInput: multisigInput, multisigInput: multisigInput,
multisigOutput: multisigOutput, multisigOutput: multisigOutput,
pubKeyHashInput: pubKeyHashInput, pubKeyHashInput: pubKeyHashInput,

View file

@ -51,7 +51,8 @@
}, },
{ {
"type": "nulldata", "type": "nulldata",
"scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff" "data": "deadffffffffffffffffffffffffffffffffbeef",
"scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef"
} }
], ],
"invalid": { "invalid": {

View file

@ -184,4 +184,19 @@ describe('Scripts', function() {
}) })
}) })
}) })
describe('data', function() {
fixtures.valid.forEach(function(f) {
if (f.type !== 'nulldata') return
var data = new Buffer(f.data, 'hex')
var scriptPubKey = scripts.dataOutput(data)
describe('output script', function() {
it('is generated correctly for ' + f.scriptPubKey, function() {
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
})
})
})
})
}) })