本文整理了Java中org.bitcoinj.core.Utils.readUint32()
方法的一些代码示例,展示了Utils.readUint32()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.readUint32()
方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:readUint32
[英]Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format.
[中]将字节数组中的4个字节(从偏移量开始)解析为little endian格式的无符号32位整数。
代码示例来源:origin: fr.acinq/bitcoinj-core
protected long readUint32() throws ProtocolException {
try {
long u = Utils.readUint32(payload, cursor);
cursor += 4;
return u;
} catch (ArrayIndexOutOfBoundsException e) {
throw new ProtocolException(e);
}
}
代码示例来源:origin: greenaddress/GreenBits
protected long readUint32() throws ProtocolException {
try {
long u = Utils.readUint32(payload, cursor);
cursor += 4;
return u;
} catch (ArrayIndexOutOfBoundsException e) {
throw new ProtocolException(e);
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
protected long readUint32() throws ProtocolException {
try {
long u = Utils.readUint32(payload, cursor);
cursor += 4;
return u;
} catch (ArrayIndexOutOfBoundsException e) {
throw new ProtocolException(e);
}
}
代码示例来源:origin: HashEngineering/dashj
protected long readUint32() throws ProtocolException {
try {
long u = Utils.readUint32(payload, cursor);
cursor += 4;
return u;
} catch (ArrayIndexOutOfBoundsException e) {
throw new ProtocolException(e);
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* 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)
}
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* 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)
}
}
代码示例来源:origin: HashEngineering/dashj
/**
* 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)
}
}
代码示例来源:origin: greenaddress/GreenBits
/**
* 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)
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
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;
}
}
代码示例来源:origin: fr.acinq/bitcoinj-core
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;
}
}
代码示例来源:origin: HashEngineering/dashj
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;
}
}
代码示例来源:origin: greenaddress/GreenBits
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;
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
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;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
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;
}
代码示例来源:origin: greenaddress/GreenBits
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;
}
代码示例来源:origin: HashEngineering/dashj
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;
}
代码示例来源:origin: HashEngineering/dashj
pchMsgTmp = (int)Utils.readUint32(vchData, magicMessage.length());
代码示例来源:origin: HashEngineering/dashj
pchMsgTmp = (int)Utils.readUint32(vchData, strMagicMessage.length());
代码示例来源:origin: dogecoin/libdohj
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!