templates: avoid hex conversions internally
This commit is contained in:
parent
9d9d101b5f
commit
33c3ed4e03
1 changed files with 5 additions and 4 deletions
|
@ -1,26 +1,27 @@
|
||||||
// OP_RETURN 36bytes:[0xaa21a9ed, Hash256(witnessRoot )]
|
// OP_RETURN {aa21a9ed} {commitment}
|
||||||
|
|
||||||
var bscript = require('../../script')
|
var bscript = require('../../script')
|
||||||
var types = require('../../types')
|
var types = require('../../types')
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
var OPS = require('bitcoin-ops')
|
var OPS = require('bitcoin-ops')
|
||||||
|
|
||||||
|
var HEADER = new Buffer('aa21a9ed', 'hex')
|
||||||
|
|
||||||
function check (script) {
|
function check (script) {
|
||||||
var buffer = bscript.compile(script)
|
var buffer = bscript.compile(script)
|
||||||
|
|
||||||
return buffer.length > 37 &&
|
return buffer.length > 37 &&
|
||||||
buffer[0] === OPS.OP_RETURN &&
|
buffer[0] === OPS.OP_RETURN &&
|
||||||
buffer[1] === 0x24 &&
|
buffer[1] === 0x24 &&
|
||||||
buffer.slice(2, 6).toString('hex') === 'aa21a9ed'
|
buffer.slice(2, 6).equals(HEADER)
|
||||||
}
|
}
|
||||||
|
|
||||||
check.toJSON = function () { return 'Witness commitment output' }
|
check.toJSON = function () { return 'Witness commitment output' }
|
||||||
|
|
||||||
function encode (commitment) {
|
function encode (commitment) {
|
||||||
// hash256 0x21 hash160 0xed
|
|
||||||
typeforce(types.Hash256bit, commitment)
|
typeforce(types.Hash256bit, commitment)
|
||||||
|
|
||||||
return bscript.compile([OPS.OP_RETURN, new Buffer('aa21a9ed' + commitment.toString('hex'), 'hex')])
|
return bscript.compile([OPS.OP_RETURN, Buffer.concat([HEADER, commitment])])
|
||||||
}
|
}
|
||||||
|
|
||||||
function decode (buffer) {
|
function decode (buffer) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue