Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
},
{
"type": "nulldata",
"scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff"
"data": "deadffffffffffffffffffffffffffffffffbeef",
"scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef"
}
],
"invalid": {
Expand Down
15 changes: 15 additions & 0 deletions test/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
})