@Test public void testShortestPossibleDataPush() { assertTrue("empty push", new ScriptBuilder().data(new byte[0]).build().getChunks().get(0) .isShortestPossiblePushData()); for (byte i = -1; i < 127; i++) assertTrue("push of single byte " + i, new ScriptBuilder().data(new byte[] { i }).build().getChunks() .get(0).isShortestPossiblePushData()); for (int len = 2; len < Script.MAX_SCRIPT_ELEMENT_SIZE; len++) assertTrue("push of " + len + " bytes", new ScriptBuilder().data(new byte[len]).build().getChunks().get(0) .isShortestPossiblePushData()); for (byte i = 1; i <= 16; i++) assertFalse("push of smallnum " + i, new ScriptChunk(1, new byte[] { i }).isShortestPossiblePushData()); assertFalse("push of 75 bytes", new ScriptChunk(OP_PUSHDATA1, new byte[75]).isShortestPossiblePushData()); assertFalse("push of 255 bytes", new ScriptChunk(OP_PUSHDATA2, new byte[255]).isShortestPossiblePushData()); assertFalse("push of 65535 bytes", new ScriptChunk(OP_PUSHDATA4, new byte[65535]).isShortestPossiblePushData()); }
public boolean isShortestPossiblePushData() { checkState(isPushData()); if (data == null) return true; if (data.length == 0) return opcode == OP_0; if (data.length == 1) { byte b = data[0]; if (b >= 0x01 && b <= 0x10) return opcode == OP_1 + b - 1; if ((b & 0xFF) == 0x81) return opcode == OP_1NEGATE; } if (data.length < OP_PUSHDATA1) return opcode == data.length; if (data.length < 256) return opcode == OP_PUSHDATA1; if (data.length < 65536) return opcode == OP_PUSHDATA2; return opcode == OP_PUSHDATA4; }
ScriptChunk { public boolean isShortestPossiblePushData() { checkState(isPushData()); if (data == null) return true; if (data.length == 0) return opcode == OP_0; if (data.length == 1) { byte b = data[0]; if (b >= 0x01 && b <= 0x10) return opcode == OP_1 + b - 1; if ((b & 0xFF) == 0x81) return opcode == OP_1NEGATE; } if (data.length < OP_PUSHDATA1) return opcode == data.length; if (data.length < 256) return opcode == OP_PUSHDATA1; if (data.length < 65536) return opcode == OP_PUSHDATA2; return opcode == OP_PUSHDATA4; } }
ScriptChunk { public boolean isShortestPossiblePushData() { checkState(isPushData()); if (data == null) return true; if (data.length == 0) return opcode == OP_0; if (data.length == 1) { byte b = data[0]; if (b >= 0x01 && b <= 0x10) return opcode == OP_1 + b - 1; if ((b & 0xFF) == 0x81) return opcode == OP_1NEGATE; } if (data.length < OP_PUSHDATA1) return opcode == data.length; if (data.length < 256) return opcode == OP_PUSHDATA1; if (data.length < 65536) return opcode == OP_PUSHDATA2; return opcode == OP_PUSHDATA4; } ScriptChunk(int opcode, @Nullable byte[] data); }
ScriptChunk { public boolean isShortestPossiblePushData() { checkState(isPushData()); if (data == null) return true; if (data.length == 0) return opcode == OP_0; if (data.length == 1) { byte b = data[0]; if (b >= 0x01 && b <= 0x10) return opcode == OP_1 + b - 1; if ((b & 0xFF) == 0x81) return opcode == OP_1NEGATE; } if (data.length < OP_PUSHDATA1) return opcode == data.length; if (data.length < 256) return opcode == OP_PUSHDATA1; if (data.length < 65536) return opcode == OP_PUSHDATA2; return opcode == OP_PUSHDATA4; } ScriptChunk(int opcode, @Nullable byte[] data); boolean equalsOpCode(int opcode); boolean isOpCode(); boolean isPushData(); int decodeOpN(); boolean isShortestPossiblePushData(); void write(OutputStream stream); byte[] toByteArray(); int size(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
ScriptChunk { public boolean isShortestPossiblePushData() { checkState(isPushData()); if (data == null) return true; if (data.length == 0) return opcode == OP_0; if (data.length == 1) { byte b = data[0]; if (b >= 0x01 && b <= 0x10) return opcode == OP_1 + b - 1; if ((b & 0xFF) == 0x81) return opcode == OP_1NEGATE; } if (data.length < OP_PUSHDATA1) return opcode == data.length; if (data.length < 256) return opcode == OP_PUSHDATA1; if (data.length < 65536) return opcode == OP_PUSHDATA2; return opcode == OP_PUSHDATA4; } ScriptChunk(int opcode, @Nullable byte[] data); boolean equalsOpCode(int opcode); boolean isOpCode(); boolean isPushData(); int decodeOpN(); boolean isShortestPossiblePushData(); void write(OutputStream stream); byte[] toByteArray(); int size(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); final int opcode; @Nullable
    final byte[] data; }