org.bitcoinj.core.Utils.reverseBytes()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.bitcoinj.core.Utils.reverseBytes()方法的一些代码示例,展示了Utils.reverseBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.reverseBytes()方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:reverseBytes

Utils.reverseBytes介绍

[英]Returns a copy of the given byte array in reverse order.
[中]按相反顺序返回给定字节数组的副本。

代码示例

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
 * Returns a reversed copy of the internal byte array.
 */
public byte[] getReversedBytes() {
  return Utils.reverseBytes(bytes);
}

代码示例来源:origin: greenaddress/GreenBits

/**
 * Returns a reversed copy of the internal byte array.
 */
public byte[] getReversedBytes() {
  return Utils.reverseBytes(bytes);
}

代码示例来源:origin: HashEngineering/dashj

/**
 * Returns a reversed copy of the internal byte array.
 */
public byte[] getReversedBytes() {
  return Utils.reverseBytes(bytes);
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

public static void uint64ToByteStreamLE(BigInteger val, OutputStream stream) throws IOException {
  byte[] bytes = val.toByteArray();
  if (bytes.length > 8) {
    throw new RuntimeException("Input too large to encode into a uint64");
  }
  bytes = reverseBytes(bytes);
  stream.write(bytes);
  if (bytes.length < 8) {
    for (int i = 0; i < 8 - bytes.length; i++)
      stream.write(0);
  }
}

代码示例来源:origin: HashEngineering/dashj

public static void uint64ToByteStreamLE(BigInteger val, OutputStream stream) throws IOException {
  byte[] bytes = val.toByteArray();
  if (bytes.length > 8) {
    throw new RuntimeException("Input too large to encode into a uint64");
  }
  bytes = reverseBytes(bytes);
  stream.write(bytes);
  if (bytes.length < 8) {
    for (int i = 0; i < 8 - bytes.length; i++)
      stream.write(0);
  }
}

代码示例来源:origin: fr.acinq/bitcoinj-core

private static Sha256Hash combineLeftRight(byte[] left, byte[] right) {
  return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(
    reverseBytes(left), 0, 32,
    reverseBytes(right), 0, 32));
}

代码示例来源:origin: greenaddress/GreenBits

private static Sha256Hash combineLeftRight(byte[] left, byte[] right) {
  return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(
    reverseBytes(left), 0, 32,
    reverseBytes(right), 0, 32));
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
 * Creates a new instance that wraps the given hash value, but with byte order reversed.
 *
 * @param rawHashBytes the raw hash bytes to wrap
 * @return a new instance
 * @throws IllegalArgumentException if the given array length is not exactly 32
 */
@SuppressWarnings("deprecation") // the constructor will be made private in the future
public static Sha256Hash wrapReversed(byte[] rawHashBytes) {
  return wrap(Utils.reverseBytes(rawHashBytes));
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

private static Sha256Hash combineLeftRight(byte[] left, byte[] right) {
  return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(
    reverseBytes(left), 0, 32,
    reverseBytes(right), 0, 32));
}

代码示例来源:origin: fr.acinq/bitcoinj-core

/**
 * Creates a new instance that wraps the given hash value, but with byte order reversed.
 *
 * @param rawHashBytes the raw hash bytes to wrap
 * @return a new instance
 * @throws IllegalArgumentException if the given array length is not exactly 32
 */
@SuppressWarnings("deprecation") // the constructor will be made private in the future
public static Sha256Hash wrapReversed(byte[] rawHashBytes) {
  return wrap(Utils.reverseBytes(rawHashBytes));
}

代码示例来源:origin: HashEngineering/dashj

private static Sha256Hash combineLeftRight(byte[] left, byte[] right) {
  return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(
    reverseBytes(left), 0, 32,
    reverseBytes(right), 0, 32));
}

代码示例来源:origin: fr.acinq/bitcoinj-core

protected BigInteger readUint64() throws ProtocolException {
  // Java does not have an unsigned 64 bit type. So scrape it off the wire then flip.
  return new BigInteger(Utils.reverseBytes(readBytes(8)));
}

代码示例来源:origin: HashEngineering/dashj

/**
 * Creates a new instance that wraps the given hash value, but with byte order reversed.
 *
 * @param rawHashBytes the raw hash bytes to wrap
 * @return a new instance
 * @throws IllegalArgumentException if the given array length is not exactly 32
 */
@SuppressWarnings("deprecation") // the constructor will be made private in the future
public static Sha256Hash wrapReversed(byte[] rawHashBytes) {
  return wrap(Utils.reverseBytes(rawHashBytes));
}

代码示例来源:origin: HashEngineering/dashj

/**
 * Cast a script chunk to a BigInteger.
 *
 * @see #castToBigInteger(byte[], int, boolean) for values with different maximum
 * sizes.
 * @throws ScriptException if the chunk is longer than 4 bytes.
 */
private static BigInteger castToBigInteger(byte[] chunk) throws ScriptException {
  if (chunk.length > 4)
    throw new ScriptException("Script attempted to use an integer larger than 4 bytes");
  return Utils.decodeMPI(Utils.reverseBytes(chunk), false);
}

代码示例来源:origin: dogecoin/libdohj

private ScryptHash calculateScryptHash() {
  try {
    ByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(HEADER_SIZE);
    writeHeader(bos);
    return new ScryptHash(reverseBytes(scryptDigest(bos.toByteArray())));
  } catch (IOException e) {
    throw new RuntimeException(e); // Cannot happen.
  } catch (GeneralSecurityException e) {
    throw new RuntimeException(e); // Cannot happen.
  }
}

代码示例来源:origin: dogecoin/libdohj

@Override
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
  stream.write(new VarInt(hashes.size()).encode());
  for (Sha256Hash hash: hashes) {
      stream.write(Utils.reverseBytes(hash.getBytes()));
  }
  Utils.uint32ToByteStreamLE(index, stream);
}

代码示例来源:origin: dogecoin/libdohj

@Override
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
  transaction.bitcoinSerialize(stream);
  stream.write(Utils.reverseBytes(hashBlock.getBytes()));
  coinbaseBranch.bitcoinSerialize(stream);
  chainMerkleBranch.bitcoinSerialize(stream);
  parentBlockHeader.bitcoinSerializeToStream(stream);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void testReverseBytes() {
  assertArrayEquals(new byte[]{1, 2, 3, 4, 5}, Utils.reverseBytes(new byte[]{5, 4, 3, 2, 1}));
}

代码示例来源:origin: fr.acinq/bitcoinj-core

public static Script createCLTVPaymentChannelOutput(BigInteger time, ECKey from, ECKey to) {
  byte[] timeBytes = Utils.reverseBytes(Utils.encodeMPI(time, false));
  if (timeBytes.length > 5) {
    throw new RuntimeException("Time too large to encode as 5-byte int");
  }
  return new ScriptBuilder().op(OP_IF)
      .data(to.getPubKey()).op(OP_CHECKSIGVERIFY)
      .op(OP_ELSE)
      .data(timeBytes).op(OP_CHECKLOCKTIMEVERIFY).op(OP_DROP)
      .op(OP_ENDIF)
      .data(from.getPubKey()).op(OP_CHECKSIG).build();
}

代码示例来源:origin: HashEngineering/dashj

public static Script createCLTVPaymentChannelOutput(BigInteger time, ECKey from, ECKey to) {
  byte[] timeBytes = Utils.reverseBytes(Utils.encodeMPI(time, false));
  if (timeBytes.length > 5) {
    throw new RuntimeException("Time too large to encode as 5-byte int");
  }
  return new ScriptBuilder().op(OP_IF)
      .data(to.getPubKey()).op(OP_CHECKSIGVERIFY)
      .op(OP_ELSE)
      .data(timeBytes).op(OP_CHECKLOCKTIMEVERIFY).op(OP_DROP)
      .op(OP_ENDIF)
      .data(from.getPubKey()).op(OP_CHECKSIG).build();
}

相关文章