2016-11-02 12:30:37 +11:00
|
|
|
// OP_RETURN {data}
|
|
|
|
|
2018-06-25 16:25:12 +10:00
|
|
|
const bscript = require('../script')
|
|
|
|
const types = require('../types')
|
|
|
|
const typeforce = require('typeforce')
|
|
|
|
const OPS = require('bitcoin-ops')
|
2016-11-02 12:30:37 +11:00
|
|
|
|
|
|
|
function check (script) {
|
|
|
|
var buffer = bscript.compile(script)
|
|
|
|
|
|
|
|
return buffer.length > 1 &&
|
|
|
|
buffer[0] === OPS.OP_RETURN
|
|
|
|
}
|
2016-11-02 14:33:46 +11:00
|
|
|
check.toJSON = function () { return 'null data output' }
|
2016-11-02 12:30:37 +11:00
|
|
|
|
|
|
|
function encode (data) {
|
2018-04-14 01:59:56 +10:00
|
|
|
typeforce([types.Buffer], data)
|
2016-11-02 12:30:37 +11:00
|
|
|
|
2018-04-14 01:59:56 +10:00
|
|
|
return bscript.compile([OPS.OP_RETURN].concat(data))
|
2016-11-02 12:30:37 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
function decode (buffer) {
|
|
|
|
typeforce(check, buffer)
|
|
|
|
|
2018-04-14 01:59:56 +10:00
|
|
|
return bscript.decompile(buffer).slice(1)
|
2016-11-02 12:30:37 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
output: {
|
|
|
|
check: check,
|
|
|
|
decode: decode,
|
|
|
|
encode: encode
|
|
|
|
}
|
|
|
|
}
|