scripts: add dataOutput convenience function
This commit is contained in:
parent
27e69ba716
commit
ea66edeb5c
3 changed files with 22 additions and 1 deletions
|
@ -241,9 +241,14 @@ function multisigInput(signatures, scriptPubKey) {
|
||||||
return Script.fromChunks([].concat(ops.OP_0, signatures))
|
return Script.fromChunks([].concat(ops.OP_0, signatures))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dataOutput(data) {
|
||||||
|
return Script.fromChunks([ops.OP_RETURN, data])
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
classifyInput: classifyInput,
|
classifyInput: classifyInput,
|
||||||
classifyOutput: classifyOutput,
|
classifyOutput: classifyOutput,
|
||||||
|
dataOutput: dataOutput,
|
||||||
multisigInput: multisigInput,
|
multisigInput: multisigInput,
|
||||||
multisigOutput: multisigOutput,
|
multisigOutput: multisigOutput,
|
||||||
pubKeyHashInput: pubKeyHashInput,
|
pubKeyHashInput: pubKeyHashInput,
|
||||||
|
|
3
test/fixtures/scripts.json
vendored
3
test/fixtures/scripts.json
vendored
|
@ -51,7 +51,8 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "nulldata",
|
"type": "nulldata",
|
||||||
"scriptPubKey": "OP_RETURN ffffffffffffffffffffffffffffffffffffffff"
|
"data": "deadffffffffffffffffffffffffffffffffbeef",
|
||||||
|
"scriptPubKey": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"invalid": {
|
"invalid": {
|
||||||
|
|
|
@ -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…
Reference in a new issue