mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
ScriptBuilder: Fix number encoding for 16. It must be encoded with smallNum().
This commit is contained in:
committed by
Andreas Schildbach
parent
e51428dcf6
commit
b890c9a9a1
@@ -112,7 +112,7 @@ public class ScriptBuilder {
|
||||
* shortest encoding possible.
|
||||
*/
|
||||
public ScriptBuilder number(long num) {
|
||||
if (num >= 0 && num < 16) {
|
||||
if (num >= 0 && num <= 16) {
|
||||
return smallNum((int) num);
|
||||
} else {
|
||||
return bigNum(num);
|
||||
@@ -124,7 +124,7 @@ public class ScriptBuilder {
|
||||
* uses shortest encoding possible.
|
||||
*/
|
||||
public ScriptBuilder number(int index, long num) {
|
||||
if (num >= 0 && num < 16) {
|
||||
if (num >= 0 && num <= 16) {
|
||||
return addChunk(index, new ScriptChunk(Script.encodeToOpN((int) num), null));
|
||||
} else {
|
||||
return bigNum(index, num);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
* Copyright 2017 Thomas König
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -491,4 +492,14 @@ public class ScriptTest {
|
||||
((byte) 133) // Pushed data
|
||||
}, builder.build().getProgram());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void numberBuilder16() {
|
||||
ScriptBuilder builder = new ScriptBuilder();
|
||||
// Numbers greater than 16 must be encoded with PUSHDATA
|
||||
builder.number(15).number(16).number(17);
|
||||
builder.number(0, 17).number(1, 16).number(2, 15);
|
||||
Script script = builder.build();
|
||||
assertEquals("PUSHDATA(1)[11] 16 15 15 16 PUSHDATA(1)[11]", script.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user