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

x33g5p2x  于2022-01-17 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(93)

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

Block.readVarInt介绍

暂无

代码示例

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<Transaction>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<Transaction>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

相关文章