Пример #1
0
  protected static boolean isScriptInputStandard(byte[][] chunks) throws ScriptParsingException {
    try {
      if (chunks.length != 2) {
        return false;
      }

      // Verify that first chunk contains two DER encoded BigIntegers
      ByteReader reader = new ByteReader(chunks[0]);

      // Read tag, must be 0x30
      if ((((int) reader.get()) & 0xFF) != 0x30) {
        return false;
      }

      // Read total length as a byte, standard inputs never get longer than
      // this
      int length = ((int) reader.get()) & 0xFF;

      // Read first type, must be 0x02
      if ((((int) reader.get()) & 0xFF) != 0x02) {
        return false;
      }

      // Read first length
      int length1 = ((int) reader.get()) & 0xFF;
      reader.skip(length1);

      // Read second type, must be 0x02
      if ((((int) reader.get()) & 0xFF) != 0x02) {
        return false;
      }

      // Read second length
      int length2 = ((int) reader.get()) & 0xFF;
      reader.skip(length2);

      // Validate that the lengths add up to the total
      if (2 + length1 + 2 + length2 != length) {
        return false;
      }

      // Make sure that we have a hash type at the end
      if (reader.available() != 1) {
        return false;
      }

      // XXX we may want to add more checks to verify public key length in
      // second chunk
      return true;
    } catch (InsufficientBytesException e) {
      throw new ScriptParsingException(
          "Unable to parse " + ScriptInputStandard.class.getSimpleName());
    }
  }
Пример #2
0
 public OutPoint(ByteReader reader) throws InsufficientBytesException {
   this.hash = reader.getSha256Hash();
   this.index = (int) reader.getCompactInt();
 }