Browse Source

Merge pull request #303 from bitcoinjs/datascript

scripts: add dataOutput convenience function
hk-custom-address
Wei Lu 10 years ago
parent
commit
41da79c58e
  1. 5
      src/scripts.js
  2. 3
      test/fixtures/scripts.json
  3. 15
      test/scripts.js

5
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,

3
test/fixtures/scripts.json

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

15
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)
})
})
})
})
})

Loading…
Cancel
Save