Merge pull request #303 from bitcoinjs/datascript

scripts: add dataOutput convenience function
This commit is contained in:
Wei Lu 2014-10-23 22:36:00 -07:00
commit 41da79c58e
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))
}
function dataOutput(data) {
return Script.fromChunks([ops.OP_RETURN, data])
}
module.exports = {
classifyInput: classifyInput,
classifyOutput: classifyOutput,
dataOutput: dataOutput,
multisigInput: multisigInput,
multisigOutput: multisigOutput,
pubKeyHashInput: pubKeyHashInput,

View file

@ -51,7 +51,8 @@
},
{
"type": "nulldata",
"scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff"
"data": "deadffffffffffffffffffffffffffffffffbeef",
"scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef"
}
],
"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)
})
})
})
})
})