Browse Source

bscript.compie - minimal encoding of -1 stack element

hk-custom-address
Thomas Kerin 8 years ago
committed by Daniel Cousens
parent
commit
8552867695
  1. 8
      src/script.js
  2. 7
      test/fixtures/script.json

8
src/script.js

@ -39,7 +39,7 @@ function compile (chunks) {
// data chunk
if (Buffer.isBuffer(chunk)) {
// adhere to BIP62.3, minimal push policy
if (chunk.length === 1 && chunk[0] >= 1 && chunk[0] <= 16) {
if (chunk.length === 1 && (chunk[0] === 0x81 || chunk[0] >= 1 && chunk[0] <= 16)) {
return accum + 1
}
@ -64,6 +64,12 @@ function compile (chunks) {
return
}
if (chunk.length === 1 && chunk[0] === 0x81) {
buffer.writeUInt8(OPS.OP_1NEGATE, offset)
offset += 1
return
}
offset += bufferutils.writePushDataInt(buffer, chunk.length, offset)
chunk.copy(buffer, offset)

7
test/fixtures/script.json

@ -1,5 +1,12 @@
{
"valid": [
{
"asm": "OP_1NEGATE",
"script": "4f",
"stack": [
"81"
]
},
{
"asm": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",
"script": "47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",

Loading…
Cancel
Save