本文整理了Java中org.bitcoinj.core.Utils.uint32ToByteArrayLE()
方法的一些代码示例,展示了Utils.uint32ToByteArrayLE()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.uint32ToByteArrayLE()
方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:uint32ToByteArrayLE
暂无
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Writes message to to the output stream.
*/
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
// The header array is initialized to zero by Java so we don't have to worry about
// NULL terminating the string here.
for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
}
Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
byte[] hash = Sha256Hash.hashTwice(message);
System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
out.write(header);
out.write(message);
if (log.isDebugEnabled())
log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* Writes message to to the output stream.
*/
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
// The header array is initialized to zero by Java so we don't have to worry about
// NULL terminating the string here.
for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
}
Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
byte[] hash = Sha256Hash.hashTwice(message);
System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
out.write(header);
out.write(message);
if (log.isDebugEnabled())
log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}
代码示例来源:origin: greenaddress/GreenBits
/**
* Writes message to to the output stream.
*/
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
// The header array is initialized to zero by Java so we don't have to worry about
// NULL terminating the string here.
for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
}
Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
byte[] hash = Sha256Hash.hashTwice(message);
System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
out.write(header);
out.write(message);
if (log.isDebugEnabled())
log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}
代码示例来源:origin: HashEngineering/dashj
/**
* Writes message to to the output stream.
*/
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
// The header array is initialized to zero by Java so we don't have to worry about
// NULL terminating the string here.
for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
}
Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
byte[] hash = Sha256Hash.hashTwice(message);
System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
out.write(header);
out.write(message);
if (log.isDebugEnabled())
log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* Encodes the value into its minimal representation.
*
* @return the minimal encoded bytes of the value
*/
public byte[] encode() {
byte[] bytes;
switch (sizeOf(value)) {
case 1:
return new byte[]{(byte) value};
case 3:
return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)};
case 5:
bytes = new byte[5];
bytes[0] = (byte) 254;
Utils.uint32ToByteArrayLE(value, bytes, 1);
return bytes;
default:
bytes = new byte[9];
bytes[0] = (byte) 255;
Utils.uint64ToByteArrayLE(value, bytes, 1);
return bytes;
}
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Encodes the value into its minimal representation.
*
* @return the minimal encoded bytes of the value
*/
public byte[] encode() {
byte[] bytes;
switch (sizeOf(value)) {
case 1:
return new byte[]{(byte) value};
case 3:
return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)};
case 5:
bytes = new byte[5];
bytes[0] = (byte) 254;
Utils.uint32ToByteArrayLE(value, bytes, 1);
return bytes;
default:
bytes = new byte[9];
bytes[0] = (byte) 255;
Utils.uint64ToByteArrayLE(value, bytes, 1);
return bytes;
}
}
}
代码示例来源:origin: greenaddress/GreenBits
/**
* Encodes the value into its minimal representation.
*
* @return the minimal encoded bytes of the value
*/
public byte[] encode() {
byte[] bytes;
switch (sizeOf(value)) {
case 1:
return new byte[]{(byte) value};
case 3:
return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)};
case 5:
bytes = new byte[5];
bytes[0] = (byte) 254;
Utils.uint32ToByteArrayLE(value, bytes, 1);
return bytes;
default:
bytes = new byte[9];
bytes[0] = (byte) 255;
Utils.uint64ToByteArrayLE(value, bytes, 1);
return bytes;
}
}
}
代码示例来源:origin: HashEngineering/dashj
/**
* Encodes the value into its minimal representation.
*
* @return the minimal encoded bytes of the value
*/
public byte[] encode() {
byte[] bytes;
switch (sizeOf(value)) {
case 1:
return new byte[]{(byte) value};
case 3:
return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)};
case 5:
bytes = new byte[5];
bytes[0] = (byte) 254;
Utils.uint32ToByteArrayLE(value, bytes, 1);
return bytes;
default:
bytes = new byte[9];
bytes[0] = (byte) 255;
Utils.uint64ToByteArrayLE(value, bytes, 1);
return bytes;
}
}
}
代码示例来源:origin: HashEngineering/dashj
public Sha256Hash getHash()
{
byte [] dataToHash = new byte[pubKeyCollateralAddress.getBytes().length+8];
Utils.uint32ToByteArrayLE(sigTime, dataToHash, 0);
System.arraycopy(pubKeyCollateralAddress.getBytes(), 0, dataToHash, 8, pubKeyCollateralAddress.getBytes().length);
try {
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(8 + vin.getMessageSize() + pubKeyCollateralAddress.calculateMessageSizeInBytes());
vin.bitcoinSerialize(bos);
Utils.int64ToByteStreamLE(sigTime, bos);
pubKeyCollateralAddress.bitcoinSerialize(bos);
return Sha256Hash.wrapReversed(Sha256Hash.hashTwice((bos.toByteArray())));
}
catch (IOException e)
{
throw new RuntimeException(e); // Cannot happen.
}
}
代码示例来源:origin: greenaddress/GreenBits
Utils.uint32ToByteArrayLE((long)b64Original.block.getTransactions().size(), varIntBytes, 1);
Utils.uint32ToByteArrayLE(((long)b64Original.block.getTransactions().size()) >>> 32, varIntBytes, 5);
stream.write(varIntBytes);
checkState(new VarInt(varIntBytes, 0).value == b64Original.block.getTransactions().size());
Utils.uint32ToByteArrayLE(Script.MAX_SCRIPT_ELEMENT_SIZE + 1, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, b73);
Utils.uint32ToByteArrayLE(Block.MAX_BLOCK_SIGOPS, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, b76);
内容来源于网络,如有侵权,请联系作者删除!