Browse Source

nulldata: change data to array

addLowRGrinding
Daniel Cousens 7 years ago
parent
commit
41885bfab2
  1. 6
      src/templates/nulldata.js
  2. 4
      test/fixtures/script.json
  3. 17
      test/fixtures/templates.json
  4. 2
      test/templates.js

6
src/templates/nulldata.js

@ -14,15 +14,15 @@ function check (script) {
check.toJSON = function () { return 'null data output' }
function encode (data) {
typeforce(types.Buffer, data)
typeforce([types.Buffer], data)
return bscript.compile([OPS.OP_RETURN, data])
return bscript.compile([OPS.OP_RETURN].concat(data))
}
function decode (buffer) {
typeforce(check, buffer)
return buffer.slice(2)
return bscript.decompile(buffer).slice(1)
}
module.exports = {

4
test/fixtures/script.json

@ -95,6 +95,10 @@
"asm": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef",
"script": "6a14deadffffffffffffffffffffffffffffffffbeef"
},
{
"asm": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef deadffffffffffffffffffffffffffffffffbeef",
"script": "6a14deadffffffffffffffffffffffffffffffffbeef14deadffffffffffffffffffffffffffffffffbeef"
},
{
"asm": "OP_0 OP_0 3044022001ab168e80b863fdec694350b587339bb72a37108ac3c989849251444d13ebba02201811272023e3c1038478eb972a82d3ad431bfc2408e88e4da990f1a7ecbb263901 3045022100aaeb7204c17eee2f2c4ff1c9f8b39b79e75e7fbf33e92cc67ac51be8f15b75f90220659eee314a4943a6384d2b154fa5821ef7a084814d7ee2c6f9f7f0ffb53be34b01",
"script": "0000473044022001ab168e80b863fdec694350b587339bb72a37108ac3c989849251444d13ebba02201811272023e3c1038478eb972a82d3ad431bfc2408e88e4da990f1a7ecbb263901483045022100aaeb7204c17eee2f2c4ff1c9f8b39b79e75e7fbf33e92cc67ac51be8f15b75f90220659eee314a4943a6384d2b154fa5821ef7a084814d7ee2c6f9f7f0ffb53be34b01",

17
test/fixtures/templates.json

@ -113,13 +113,26 @@
},
{
"type": "nulldata",
"data": "06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474",
"data": [
"06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474"
],
"output": "OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474",
"outputHex": "6a2606deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474"
},
{
"type": "nulldata",
"data": "deadffffffffffffffffffffffffffffffffbeef",
"data": [
"deadffffffffffffffffffffffffffffffffbeef",
"deadffffffffffffffffffffffffffffffffbeef"
],
"output": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef deadffffffffffffffffffffffffffffffffbeef",
"outputHex": "6a14deadffffffffffffffffffffffffffffffffbeef14deadffffffffffffffffffffffffffffffffbeef"
},
{
"type": "nulldata",
"data": [
"deadffffffffffffffffffffffffffffffffbeef"
],
"output": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef",
"outputHex": "6a14deadffffffffffffffffffffffffffffffffbeef"
},

2
test/templates.js

@ -499,7 +499,7 @@ describe('script-templates', function () {
fixtures.valid.forEach(function (f) {
if (f.type !== 'nulldata') return
var data = Buffer.from(f.data, 'hex')
var data = f.data.map(function (x) { return Buffer.from(x, 'hex') })
var output = btemplates.nullData.output.encode(data)
it('encodes to ' + f.output, function () {

Loading…
Cancel
Save