コード例 #1
0
 /**
  * Adds a copy of the given byte array as a data element (i.e. PUSHDATA) at the given index in the
  * program.
  */
 public ScriptBuilder data(int index, byte[] data) {
   // implements BIP62
   byte[] copy = Arrays.copyOf(data, data.length);
   int opcode;
   if (data.length == 0) {
     opcode = OP_0;
   } else if (data.length == 1) {
     byte b = data[0];
     if (b >= 1 && b <= 16) opcode = Script.encodeToOpN(b);
     else opcode = 1;
   } else if (data.length < OP_PUSHDATA1) {
     opcode = data.length;
   } else if (data.length < 256) {
     opcode = OP_PUSHDATA1;
   } else if (data.length < 65536) {
     opcode = OP_PUSHDATA2;
   } else {
     throw new RuntimeException("Unimplemented");
   }
   return addChunk(index, new ScriptChunk(opcode, copy));
 }
コード例 #2
0
 /** Adds the given number as a OP_N opcode to the given index in the program. */
 public ScriptBuilder smallNum(int index, int num) {
   checkArgument(num >= 0, "Cannot encode negative numbers with smallNum");
   checkArgument(num <= 16, "Cannot encode numbers larger than 16 with smallNum");
   return addChunk(index, new ScriptChunk(Script.encodeToOpN(num), null));
 }