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

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

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

Utils.decodeMPI介绍

[英]MPI encoded numbers are produced by the OpenSSL BN_bn2mpi function. They consist of a 4 byte big endian length field, followed by the stated number of bytes representing the number in big endian format (with a sign bit).
[中]MPI编码的数字由OpenSSL BN_bn2mpi函数生成。它们由一个4字节的big-endian长度字段组成,后跟以big-endian格式表示数字的指定字节数(带符号位)。

代码示例

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

/**
 * <p>The "compact" format is a representation of a whole number N using an unsigned 32 bit number similar to a
 * floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can
 * be thought of as "number of bytes of N". The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents
 * the sign of N. Therefore, N = (-1^sign) * mantissa * 256^(exponent-3).</p>
 *
 * <p>Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). MPI uses the most significant bit of the
 * first byte as sign. Thus 0x1234560000 is compact 0x05123456 and 0xc0de000000 is compact 0x0600c0de. Compact
 * 0x05c0de00 would be -0x40de000000.</p>
 *
 * <p>Bitcoin only uses this "compact" format for encoding difficulty targets, which are unsigned 256bit quantities.
 * Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident.</p>
 */
public static BigInteger decodeCompactBits(long compact) {
  int size = ((int) (compact >> 24)) & 0xFF;
  byte[] bytes = new byte[4 + size];
  bytes[3] = (byte) size;
  if (size >= 1) bytes[4] = (byte) ((compact >> 16) & 0xFF);
  if (size >= 2) bytes[5] = (byte) ((compact >> 8) & 0xFF);
  if (size >= 3) bytes[6] = (byte) (compact & 0xFF);
  return decodeMPI(bytes, true);
}

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

/**
 * <p>The "compact" format is a representation of a whole number N using an unsigned 32 bit number similar to a
 * floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can
 * be thought of as "number of bytes of N". The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents
 * the sign of N. Therefore, N = (-1^sign) * mantissa * 256^(exponent-3).</p>
 *
 * <p>Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). MPI uses the most significant bit of the
 * first byte as sign. Thus 0x1234560000 is compact 0x05123456 and 0xc0de000000 is compact 0x0600c0de. Compact
 * 0x05c0de00 would be -0x40de000000.</p>
 *
 * <p>Bitcoin only uses this "compact" format for encoding difficulty targets, which are unsigned 256bit quantities.
 * Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident.</p>
 */
public static BigInteger decodeCompactBits(long compact) {
  int size = ((int) (compact >> 24)) & 0xFF;
  byte[] bytes = new byte[4 + size];
  bytes[3] = (byte) size;
  if (size >= 1) bytes[4] = (byte) ((compact >> 16) & 0xFF);
  if (size >= 2) bytes[5] = (byte) ((compact >> 8) & 0xFF);
  if (size >= 3) bytes[6] = (byte) (compact & 0xFF);
  return decodeMPI(bytes, true);
}

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

/**
 * <p>The "compact" format is a representation of a whole number N using an unsigned 32 bit number similar to a
 * floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can
 * be thought of as "number of bytes of N". The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents
 * the sign of N. Therefore, N = (-1^sign) * mantissa * 256^(exponent-3).</p>
 *
 * <p>Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). MPI uses the most significant bit of the
 * first byte as sign. Thus 0x1234560000 is compact 0x05123456 and 0xc0de000000 is compact 0x0600c0de. Compact
 * 0x05c0de00 would be -0x40de000000.</p>
 *
 * <p>Bitcoin only uses this "compact" format for encoding difficulty targets, which are unsigned 256bit quantities.
 * Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident.</p>
 */
public static BigInteger decodeCompactBits(long compact) {
  int size = ((int) (compact >> 24)) & 0xFF;
  byte[] bytes = new byte[4 + size];
  bytes[3] = (byte) size;
  if (size >= 1) bytes[4] = (byte) ((compact >> 16) & 0xFF);
  if (size >= 2) bytes[5] = (byte) ((compact >> 8) & 0xFF);
  if (size >= 3) bytes[6] = (byte) (compact & 0xFF);
  return decodeMPI(bytes, true);
}

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

/**
 * <p>The "compact" format is a representation of a whole number N using an unsigned 32 bit number similar to a
 * floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can
 * be thought of as "number of bytes of N". The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents
 * the sign of N. Therefore, N = (-1^sign) * mantissa * 256^(exponent-3).</p>
 *
 * <p>Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). MPI uses the most significant bit of the
 * first byte as sign. Thus 0x1234560000 is compact 0x05123456 and 0xc0de000000 is compact 0x0600c0de. Compact
 * 0x05c0de00 would be -0x40de000000.</p>
 *
 * <p>Bitcoin only uses this "compact" format for encoding difficulty targets, which are unsigned 256bit quantities.
 * Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident.</p>
 */
public static BigInteger decodeCompactBits(long compact) {
  int size = ((int) (compact >> 24)) & 0xFF;
  byte[] bytes = new byte[4 + size];
  bytes[3] = (byte) size;
  if (size >= 1) bytes[4] = (byte) ((compact >> 16) & 0xFF);
  if (size >= 2) bytes[5] = (byte) ((compact >> 8) & 0xFF);
  if (size >= 3) bytes[6] = (byte) (compact & 0xFF);
  return decodeMPI(bytes, true);
}

代码示例来源: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: cash.bitcoinj/bitcoinj-core

/**
 * Cast a script chunk to a BigInteger.
 *
 * @see #castToBigInteger(byte[], int) 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: greenaddress/GreenBits

/**
 * Cast a script chunk to a BigInteger.
 *
 * @see #castToBigInteger(byte[], int) 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: cash.bitcoinj/bitcoinj-core

/**
 * Cast a script chunk to a BigInteger. Normally you would want
 * {@link #castToBigInteger(byte[])} instead, this is only for cases where
 * the normal maximum length does not apply (i.e. CHECKLOCKTIMEVERIFY).
 *
 * @param maxLength the maximum length in bytes.
 * @throws ScriptException if the chunk is longer than the specified maximum.
 */
private static BigInteger castToBigInteger(final byte[] chunk, final int maxLength) throws ScriptException {
  if (chunk.length > maxLength)
    throw new ScriptException("Script attempted to use an integer larger than "
      + maxLength + " bytes");
  return Utils.decodeMPI(Utils.reverseBytes(chunk), false);
}

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

/**
 * Cast a script chunk to a BigInteger. Normally you would want
 * {@link #castToBigInteger(byte[])} instead, this is only for cases where
 * the normal maximum length does not apply (i.e. CHECKLOCKTIMEVERIFY).
 *
 * @param maxLength the maximum length in bytes.
 * @throws ScriptException if the chunk is longer than the specified maximum.
 */
private static BigInteger castToBigInteger(final byte[] chunk, final int maxLength) throws ScriptException {
  if (chunk.length > maxLength)
    throw new ScriptException("Script attempted to use an integer larger than "
      + maxLength + " bytes");
  return Utils.decodeMPI(Utils.reverseBytes(chunk), false);
}

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

/**
 * Cast a script chunk to a BigInteger. Normally you would want
 * {@link #castToBigInteger(byte[], boolean)} instead, this is only for cases where
 * the normal maximum length does not apply (i.e. CHECKLOCKTIMEVERIFY).
 *
 * @param maxLength the maximum length in bytes.
 * @throws ScriptException if the chunk is longer than the specified maximum.
 */
private static BigInteger castToBigInteger(final byte[] chunk, final int maxLength) throws ScriptException {
  if (chunk.length > maxLength)
    throw new ScriptException("Script attempted to use an integer larger than "
      + maxLength + " bytes");
  return Utils.decodeMPI(Utils.reverseBytes(chunk), false);
}

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

return Utils.decodeMPI(Utils.reverseBytes(chunk), false);

相关文章