diff --git a/src/scripts.js b/src/scripts.js index b7c4dd5..d768ae2 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -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, diff --git a/test/fixtures/scripts.json b/test/fixtures/scripts.json index 4afdc97..86a7390 100644 --- a/test/fixtures/scripts.json +++ b/test/fixtures/scripts.json @@ -51,7 +51,8 @@ }, { "type": "nulldata", - "scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff" + "data": "deadffffffffffffffffffffffffffffffffbeef", + "scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef" } ], "invalid": { diff --git a/test/scripts.js b/test/scripts.js index 9709ec9..60b4026 100644 --- a/test/scripts.js +++ b/test/scripts.js @@ -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) + }) + }) + }) + }) })