Skip to content

Commit 41da79c

Browse files
committed
Merge pull request #303 from bitcoinjs/datascript
scripts: add dataOutput convenience function
2 parents 27e69ba + ea66ede commit 41da79c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/scripts.js

+5
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,14 @@ function multisigInput(signatures, scriptPubKey) {
241241
return Script.fromChunks([].concat(ops.OP_0, signatures))
242242
}
243243

244+
function dataOutput(data) {
245+
return Script.fromChunks([ops.OP_RETURN, data])
246+
}
247+
244248
module.exports = {
245249
classifyInput: classifyInput,
246250
classifyOutput: classifyOutput,
251+
dataOutput: dataOutput,
247252
multisigInput: multisigInput,
248253
multisigOutput: multisigOutput,
249254
pubKeyHashInput: pubKeyHashInput,

test/fixtures/scripts.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
},
5252
{
5353
"type": "nulldata",
54-
"scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff"
54+
"data": "deadffffffffffffffffffffffffffffffffbeef",
55+
"scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef"
5556
}
5657
],
5758
"invalid": {

test/scripts.js

+15
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,19 @@ describe('Scripts', function() {
184184
})
185185
})
186186
})
187+
188+
describe('data', function() {
189+
fixtures.valid.forEach(function(f) {
190+
if (f.type !== 'nulldata') return
191+
192+
var data = new Buffer(f.data, 'hex')
193+
var scriptPubKey = scripts.dataOutput(data)
194+
195+
describe('output script', function() {
196+
it('is generated correctly for ' + f.scriptPubKey, function() {
197+
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
198+
})
199+
})
200+
})
201+
})
187202
})

0 commit comments

Comments
 (0)