protected long readUint32() throws ProtocolException { try { long u = Utils.readUint32(payload, cursor); cursor += 4; return u; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
protected long readUint32() throws ProtocolException { try { long u = Utils.readUint32(payload, cursor); cursor += 4; return u; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
protected long readUint32() throws ProtocolException { try { long u = Utils.readUint32(payload, cursor); cursor += 4; return u; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
protected long readUint32() throws ProtocolException { try { long u = Utils.readUint32(payload, cursor); cursor += 4; return u; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
/** * Constructs a new VarInt with the value parsed from the specified offset of the given buffer. * * @param buf the buffer containing the value * @param offset the offset of the value */ public VarInt(byte[] buf, int offset) { int first = 0xFF & buf[offset]; if (first < 253) { value = first; originallyEncodedSize = 1; // 1 data byte (8 bits) } else if (first == 253) { value = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8); originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits) } else if (first == 254) { value = Utils.readUint32(buf, offset + 1); originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits) } else { value = Utils.readInt64(buf, offset + 1); originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits) } }
/** * Constructs a new VarInt with the value parsed from the specified offset of the given buffer. * * @param buf the buffer containing the value * @param offset the offset of the value */ public VarInt(byte[] buf, int offset) { int first = 0xFF & buf[offset]; if (first < 253) { value = first; originallyEncodedSize = 1; // 1 data byte (8 bits) } else if (first == 253) { value = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8); originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits) } else if (first == 254) { value = Utils.readUint32(buf, offset + 1); originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits) } else { value = Utils.readInt64(buf, offset + 1); originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits) } }
/** * Constructs a new VarInt with the value parsed from the specified offset of the given buffer. * * @param buf the buffer containing the value * @param offset the offset of the value */ public VarInt(byte[] buf, int offset) { int first = 0xFF & buf[offset]; if (first < 253) { value = first; originallyEncodedSize = 1; // 1 data byte (8 bits) } else if (first == 253) { value = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8); originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits) } else if (first == 254) { value = Utils.readUint32(buf, offset + 1); originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits) } else { value = Utils.readInt64(buf, offset + 1); originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits) } }
/** * Constructs a new VarInt with the value parsed from the specified offset of the given buffer. * * @param buf the buffer containing the value * @param offset the offset of the value */ public VarInt(byte[] buf, int offset) { int first = 0xFF & buf[offset]; if (first < 253) { value = first; originallyEncodedSize = 1; // 1 data byte (8 bits) } else if (first == 253) { value = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8); originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits) } else if (first == 254) { value = Utils.readUint32(buf, offset + 1); originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits) } else { value = Utils.readInt64(buf, offset + 1); originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits) } }
public BitcoinPacketHeader(ByteBuffer in) throws ProtocolException, BufferUnderflowException { header = new byte[HEADER_LENGTH]; in.get(header, 0, header.length); int cursor = 0; // The command is a NULL terminated string, unless the command fills all twelve bytes // in which case the termination is implicit. for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ; byte[] commandBytes = new byte[cursor]; System.arraycopy(header, 0, commandBytes, 0, cursor); command = Utils.toString(commandBytes, "US-ASCII"); cursor = COMMAND_LEN; size = (int) readUint32(header, cursor); cursor += 4; if (size > Message.MAX_SIZE || size < 0) throw new ProtocolException("Message size too large: " + size); // Old clients don't send the checksum. checksum = new byte[4]; // Note that the size read above includes the checksum bytes. System.arraycopy(header, cursor, checksum, 0, 4); cursor += 4; } }
public BitcoinPacketHeader(ByteBuffer in) throws ProtocolException, BufferUnderflowException { header = new byte[HEADER_LENGTH]; in.get(header, 0, header.length); int cursor = 0; // The command is a NULL terminated string, unless the command fills all twelve bytes // in which case the termination is implicit. for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ; byte[] commandBytes = new byte[cursor]; System.arraycopy(header, 0, commandBytes, 0, cursor); command = Utils.toString(commandBytes, "US-ASCII"); cursor = COMMAND_LEN; size = (int) readUint32(header, cursor); cursor += 4; if (size > Message.MAX_SIZE || size < 0) throw new ProtocolException("Message size too large: " + size); // Old clients don't send the checksum. checksum = new byte[4]; // Note that the size read above includes the checksum bytes. System.arraycopy(header, cursor, checksum, 0, 4); cursor += 4; } }
public BitcoinPacketHeader(ByteBuffer in) throws ProtocolException, BufferUnderflowException { header = new byte[HEADER_LENGTH]; in.get(header, 0, header.length); int cursor = 0; // The command is a NULL terminated string, unless the command fills all twelve bytes // in which case the termination is implicit. for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ; byte[] commandBytes = new byte[cursor]; System.arraycopy(header, 0, commandBytes, 0, cursor); command = Utils.toString(commandBytes, "US-ASCII"); cursor = COMMAND_LEN; size = (int) readUint32(header, cursor); cursor += 4; if (size > Message.MAX_SIZE || size < 0) throw new ProtocolException("Message size too large: " + size); // Old clients don't send the checksum. checksum = new byte[4]; // Note that the size read above includes the checksum bytes. System.arraycopy(header, cursor, checksum, 0, 4); cursor += 4; } }
public BitcoinPacketHeader(ByteBuffer in) throws ProtocolException, BufferUnderflowException { header = new byte[HEADER_LENGTH]; in.get(header, 0, header.length); int cursor = 0; // The command is a NULL terminated string, unless the command fills all twelve bytes // in which case the termination is implicit. for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ; byte[] commandBytes = new byte[cursor]; System.arraycopy(header, 0, commandBytes, 0, cursor); command = Utils.toString(commandBytes, "US-ASCII"); cursor = COMMAND_LEN; size = (int) readUint32(header, cursor); cursor += 4; if (size > Message.MAX_SIZE || size < 0) throw new ProtocolException("Message size too large: " + size); // Old clients don't send the checksum. checksum = new byte[4]; // Note that the size read above includes the checksum bytes. System.arraycopy(header, cursor, checksum, 0, 4); cursor += 4; } }
public UTXO(InputStream in) throws IOException { byte[] valueBytes = new byte[8]; if (in.read(valueBytes, 0, 8) != 8) throw new EOFException(); value = Coin.valueOf(Utils.readInt64(valueBytes, 0)); int scriptBytesLength = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] scriptBytes = new byte[scriptBytesLength]; if (in.read(scriptBytes) != scriptBytesLength) throw new EOFException(); script = new Script(scriptBytes); byte[] hashBytes = new byte[32]; if (in.read(hashBytes) != 32) throw new EOFException(); hash = Sha256Hash.wrap(hashBytes); byte[] indexBytes = new byte[4]; if (in.read(indexBytes) != 4) throw new EOFException(); index = Utils.readUint32(indexBytes, 0); height = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] coinbaseByte = new byte[1]; in.read(coinbaseByte); coinbase = coinbaseByte[0] == 1; }
public void deserializeFromStream(InputStream in) throws IOException { byte[] valueBytes = new byte[8]; if (in.read(valueBytes, 0, 8) != 8) throw new EOFException(); value = Coin.valueOf(Utils.readInt64(valueBytes, 0)); int scriptBytesLength = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] scriptBytes = new byte[scriptBytesLength]; if (in.read(scriptBytes) != scriptBytesLength) throw new EOFException(); script = new Script(scriptBytes); byte[] hashBytes = new byte[32]; if (in.read(hashBytes) != 32) throw new EOFException(); hash = Sha256Hash.wrap(hashBytes); byte[] indexBytes = new byte[4]; if (in.read(indexBytes) != 4) throw new EOFException(); index = Utils.readUint32(indexBytes, 0); height = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] coinbaseByte = new byte[1]; in.read(coinbaseByte); coinbase = coinbaseByte[0] == 1; }
public void deserializeFromStream(InputStream in) throws IOException { byte[] valueBytes = new byte[8]; if (in.read(valueBytes, 0, 8) != 8) throw new EOFException(); value = Coin.valueOf(Utils.readInt64(valueBytes, 0)); int scriptBytesLength = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] scriptBytes = new byte[scriptBytesLength]; if (in.read(scriptBytes) != scriptBytesLength) throw new EOFException(); script = new Script(scriptBytes); byte[] hashBytes = new byte[32]; if (in.read(hashBytes) != 32) throw new EOFException(); hash = Sha256Hash.wrap(hashBytes); byte[] indexBytes = new byte[4]; if (in.read(indexBytes) != 4) throw new EOFException(); index = Utils.readUint32(indexBytes, 0); height = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] coinbaseByte = new byte[1]; in.read(coinbaseByte); coinbase = coinbaseByte[0] == 1; }
public UTXO(InputStream in) throws IOException { byte[] valueBytes = new byte[8]; if (in.read(valueBytes, 0, 8) != 8) throw new EOFException(); value = Coin.valueOf(Utils.readInt64(valueBytes, 0)); int scriptBytesLength = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] scriptBytes = new byte[scriptBytesLength]; if (in.read(scriptBytes) != scriptBytesLength) throw new EOFException(); script = new Script(scriptBytes); byte[] hashBytes = new byte[32]; if (in.read(hashBytes) != 32) throw new EOFException(); hash = Sha256Hash.wrap(hashBytes); byte[] indexBytes = new byte[4]; if (in.read(indexBytes) != 4) throw new EOFException(); index = Utils.readUint32(indexBytes, 0); height = ((in.read() & 0xFF)) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); byte[] coinbaseByte = new byte[1]; in.read(coinbaseByte); coinbase = coinbaseByte[0] == 1; }
pchMsgTmp = (int)Utils.readUint32(vchData, magicMessage.length());
pchMsgTmp = (int)Utils.readUint32(vchData, strMagicMessage.length());
@Override public FilteredBlock makeFilteredBlock(byte[] payloadBytes) throws ProtocolException { long blockVersion = Utils.readUint32(payloadBytes, 0); int headerSize = Block.HEADER_SIZE; byte[] headerBytes = new byte[Block.HEADER_SIZE + 1]; System.arraycopy(payloadBytes, 0, headerBytes, 0, headerSize); headerBytes[80] = 0; // Need to provide 0 transactions so the block header can be constructed if (this.getParameters() instanceof AuxPoWNetworkParameters) { final AuxPoWNetworkParameters auxPoWParams = (AuxPoWNetworkParameters) this.getParameters(); if (auxPoWParams.isAuxPoWBlockVersion(blockVersion)) { final AltcoinBlock header = (AltcoinBlock) makeBlock(headerBytes, 0, Message.UNKNOWN_LENGTH); final AuxPoW auxpow = new AuxPoW(this.getParameters(), payloadBytes, Block.HEADER_SIZE, null, this); header.setAuxPoW(auxpow); int pmtOffset = headerSize + auxpow.getMessageSize(); int pmtLength = payloadBytes.length - pmtOffset; byte[] pmtBytes = new byte[pmtLength]; System.arraycopy(payloadBytes, pmtOffset, pmtBytes, 0, pmtLength); PartialMerkleTree pmt = new PartialMerkleTree(this.getParameters(), pmtBytes, 0); return new FilteredBlock(this.getParameters(), header, pmt); } } // We are either not in AuxPoW mode, or the block is not an AuxPoW block. return super.makeFilteredBlock(payloadBytes); } }