mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 13:37:24 +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.
|
* shortest encoding possible.
|
||||||
*/
|
*/
|
||||||
public ScriptBuilder number(long num) {
|
public ScriptBuilder number(long num) {
|
||||||
if (num >= 0 && num < 16) {
|
if (num >= 0 && num <= 16) {
|
||||||
return smallNum((int) num);
|
return smallNum((int) num);
|
||||||
} else {
|
} else {
|
||||||
return bigNum(num);
|
return bigNum(num);
|
||||||
@@ -124,7 +124,7 @@ public class ScriptBuilder {
|
|||||||
* uses shortest encoding possible.
|
* uses shortest encoding possible.
|
||||||
*/
|
*/
|
||||||
public ScriptBuilder number(int index, long num) {
|
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));
|
return addChunk(index, new ScriptChunk(Script.encodeToOpN((int) num), null));
|
||||||
} else {
|
} else {
|
||||||
return bigNum(index, num);
|
return bigNum(index, num);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
* Copyright 2014 Andreas Schildbach
|
* Copyright 2014 Andreas Schildbach
|
||||||
|
* Copyright 2017 Thomas König
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
((byte) 133) // Pushed data
|
||||||
}, builder.build().getProgram());
|
}, 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