@Test public void chunkTest() throws Script.ScriptParsingException { final String TEST_SCRIPT="5321033e20dea007b39688c6e97427a65aeedd0b47fde14e96631bb0330a403663150c2103b5058635d91ae26306140b90673b89616062c59a80301622f4ed6f8050c65a7f2103c04f34973eee8485e21a014268908d36510ed6f149c0ec3331aa521c6cc3929c2103d87a6d71ab19fda40947450ed2f2240dedc728f9bd373a28a43a93db1677159f54ae"; Script.chunksFromScriptBytes(HexUtils.toBytes(TEST_SCRIPT)); }
protected static byte[][] chunksFromScriptBytes(byte[] script) throws ScriptParsingException { try { ByteReader reader = new ByteReader(script); int numChunks = countChunks(reader); if (numChunks == -1) { throw new ScriptParsingException(script); } byte[][] chunks = new byte[numChunks][]; int index = 0; reader.reset(); while (reader.available() > 0) { int opcode = reader.get(); if (opcode >= 0xF0) { opcode = (opcode << 8) | (reader.get() & 0xFF); } if (opcode > 0 && opcode < OP_PUSHDATA1) { chunks[index++] = reader.getBytes(opcode); } else if (opcode == OP_PUSHDATA1) { int size = ((int) reader.get()) & 0xFF; chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA2) { int size = reader.getShortLE(); chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA4) { int size = reader.getIntLE(); if (size < 0) { throw new ScriptParsingException(script); } chunks[index++] = reader.getBytes(size); } else { chunks[index++] = new byte[] { (byte) opcode }; } } return chunks; } catch (InsufficientBytesException e) { throw new ScriptParsingException(script); } }
Script implements Serializable { protected static byte[][] chunksFromScriptBytes(byte[] script) throws ScriptParsingException { try { ByteReader reader = new ByteReader(script); int numChunks = countChunks(reader); if (numChunks == -1) { throw new ScriptParsingException(script); } byte[][] chunks = new byte[numChunks][]; int index = 0; reader.reset(); while (reader.available() > 0) { int opcode = reader.get(); if (opcode >= 0xF0) { opcode = (opcode << 8) | (reader.get() & 0xFF); } if (opcode > 0 && opcode < OP_PUSHDATA1) { chunks[index++] = reader.getBytes(opcode); } else if (opcode == OP_PUSHDATA1) { int size = ((int) reader.get()) & 0xFF; chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA2) { int size = reader.getShortLE(); chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA4) { int size = reader.getIntLE(); if (size < 0) { throw new ScriptParsingException(script); } chunks[index++] = reader.getBytes(size); } else { chunks[index++] = new byte[] { (byte) opcode }; } } return chunks; } catch (InsufficientBytesException e) { throw new ScriptParsingException(script); } } }
Script implements Serializable { protected static byte[][] chunksFromScriptBytes(byte[] script) throws ScriptParsingException { try { ByteReader reader = new ByteReader(script); int numChunks = countChunks(reader); if (numChunks == -1) { throw new ScriptParsingException(script); } byte[][] chunks = new byte[numChunks][]; int index = 0; reader.reset(); while (reader.available() > 0) { int opcode = reader.get(); if (opcode >= 0xF0) { opcode = (opcode << 8) | (reader.get() & 0xFF); } if (opcode > 0 && opcode < OP_PUSHDATA1) { chunks[index++] = reader.getBytes(opcode); } else if (opcode == OP_PUSHDATA1) { int size = ((int) reader.get()) & 0xFF; chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA2) { int size = reader.getShortLE(); chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA4) { int size = reader.getIntLE(); if (size < 0) { throw new ScriptParsingException(script); } chunks[index++] = reader.getBytes(size); } else { chunks[index++] = new byte[] { (byte) opcode }; } } return chunks; } catch (InsufficientBytesException e) { throw new ScriptParsingException(script); } } protected  Script(byte[] scriptBytes, boolean isCoinBase); }
Script implements Serializable { protected static byte[][] chunksFromScriptBytes(byte[] script) throws ScriptParsingException { try { ByteReader reader = new ByteReader(script); int numChunks = countChunks(reader); if (numChunks == -1) { throw new ScriptParsingException(script); } byte[][] chunks = new byte[numChunks][]; int index = 0; reader.reset(); while (reader.available() > 0) { int opcode = reader.get(); if (opcode >= 0xF0) { opcode = (opcode << 8) | (reader.get() & 0xFF); } if (opcode > 0 && opcode < OP_PUSHDATA1) { chunks[index++] = reader.getBytes(opcode); } else if (opcode == OP_PUSHDATA1) { int size = ((int) reader.get()) & 0xFF; chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA2) { int size = reader.getShortLE(); chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA4) { int size = reader.getIntLE(); if (size < 0) { throw new ScriptParsingException(script); } chunks[index++] = reader.getBytes(size); } else { chunks[index++] = new byte[] { (byte) opcode }; } } return chunks; } catch (InsufficientBytesException e) { throw new ScriptParsingException(script); } } protected  Script(byte[] scriptBytes, boolean isCoinBase); boolean isCoinBase(); static int opToIntValue(byte[] chunk); String dump(int maxLen); String dump(); byte[] getScriptBytes(); }
Script implements Serializable { protected static byte[][] chunksFromScriptBytes(byte[] script) throws ScriptParsingException { try { ByteReader reader = new ByteReader(script); int numChunks = countChunks(reader); if (numChunks == -1) { throw new ScriptParsingException(script); } byte[][] chunks = new byte[numChunks][]; int index = 0; reader.reset(); while (reader.available() > 0) { int opcode = reader.get(); if (opcode >= 0xF0) { opcode = (opcode << 8) | (reader.get() & 0xFF); } if (opcode > 0 && opcode < OP_PUSHDATA1) { chunks[index++] = reader.getBytes(opcode); } else if (opcode == OP_PUSHDATA1) { int size = ((int) reader.get()) & 0xFF; chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA2) { int size = reader.getShortLE(); chunks[index++] = reader.getBytes(size); } else if (opcode == OP_PUSHDATA4) { int size = reader.getIntLE(); if (size < 0) { throw new ScriptParsingException(script); } chunks[index++] = reader.getBytes(size); } else { chunks[index++] = new byte[] { (byte) opcode }; } } return chunks; } catch (InsufficientBytesException e) { throw new ScriptParsingException(script); } } protected  Script(byte[] scriptBytes, boolean isCoinBase); boolean isCoinBase(); static int opToIntValue(byte[] chunk); String dump(int maxLen); String dump(); byte[] getScriptBytes(); static final int OP_FALSE; static final int OP_0; static final int OP_PUSH32; static final int OP_PUSHDATA1; static final int OP_PUSHDATA2; static final int OP_PUSHDATA4; static final int OP_1NEGATE; static final int OP_TRUE; static final int OP_1; static final int OP_2; static final int OP_3; static final int OP_4; static final int OP_5; static final int OP_6; static final int OP_7; static final int OP_8; static final int OP_9; static final int OP_10; static final int OP_11; static final int OP_12; static final int OP_13; static final int OP_14; static final int OP_15; static final int OP_16; static final int OP_NOP; static final int OP_IF; static final int OP_VERIFY; static final int OP_RETURN; static final int OP_IFDUP; static final int OP_DEPTH; static final int OP_DROP; static final int OP_DUP; static final int OP_EQUAL; static final int OP_EQUALVERIFY; static final int OP_MIN; static final int OP_SHA256; static final int OP_HASH160; static final int OP_CHECKSIG; static final int OP_CHECKSIGVERIFY; static final int OP_CHECKMULTISIG; static final int OP_CHECKMULTISIGVERIFY; static final int OP_NOP1; static final int OP_NOP2; static final Map<Integer, String> OP_CODE_MAP; }