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

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

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

Block.getParams介绍

暂无

代码示例

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

/**
 * Creates a new FilteredBlock from the given Block, using this filter to select transactions. Matches can cause the
 * filter to be updated with the matched element, this ensures that when a filter is applied to a block, spends of
 * matched transactions are also matched. However it means this filter can be mutated by the operation. The returned
 * filtered block already has the matched transactions associated with it.
 */
public synchronized FilteredBlock applyAndUpdate(Block block) {
  List<Transaction> txns = block.getTransactions();
  List<Sha256Hash> txHashes = new ArrayList<>(txns.size());
  List<Transaction> matched = Lists.newArrayList();
  byte[] bits = new byte[(int) Math.ceil(txns.size() / 8.0)];
  for (int i = 0; i < txns.size(); i++) {
    Transaction tx = txns.get(i);
    txHashes.add(tx.getHash());
    if (applyAndUpdate(tx)) {
      Utils.setBitLE(bits, i);
      matched.add(tx);
    }
  }
  PartialMerkleTree pmt = PartialMerkleTree.buildFromLeaves(block.getParams(), bits, txHashes);
  FilteredBlock filteredBlock = new FilteredBlock(block.getParams(), block.cloneAsHeader(), pmt);
  for (Transaction transaction : matched)
    filteredBlock.provideTransaction(transaction);
  return filteredBlock;
}

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

/**
 * Creates a new FilteredBlock from the given Block, using this filter to select transactions. Matches can cause the
 * filter to be updated with the matched element, this ensures that when a filter is applied to a block, spends of
 * matched transactions are also matched. However it means this filter can be mutated by the operation. The returned
 * filtered block already has the matched transactions associated with it.
 */
public synchronized FilteredBlock applyAndUpdate(Block block) {
  List<Transaction> txns = block.getTransactions();
  List<Sha256Hash> txHashes = new ArrayList<Sha256Hash>(txns.size());
  List<Transaction> matched = Lists.newArrayList();
  byte[] bits = new byte[(int) Math.ceil(txns.size() / 8.0)];
  for (int i = 0; i < txns.size(); i++) {
    Transaction tx = txns.get(i);
    txHashes.add(tx.getHash());
    if (applyAndUpdate(tx)) {
      Utils.setBitLE(bits, i);
      matched.add(tx);
    }
  }
  PartialMerkleTree pmt = PartialMerkleTree.buildFromLeaves(block.getParams(), bits, txHashes);
  FilteredBlock filteredBlock = new FilteredBlock(block.getParams(), block.cloneAsHeader(), pmt);
  for (Transaction transaction : matched)
    filteredBlock.provideTransaction(transaction);
  return filteredBlock;
}

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

/**
 * Creates a new FilteredBlock from the given Block, using this filter to select transactions. Matches can cause the
 * filter to be updated with the matched element, this ensures that when a filter is applied to a block, spends of
 * matched transactions are also matched. However it means this filter can be mutated by the operation. The returned
 * filtered block already has the matched transactions associated with it.
 */
public synchronized FilteredBlock applyAndUpdate(Block block) {
  List<Transaction> txns = block.getTransactions();
  List<Sha256Hash> txHashes = new ArrayList<Sha256Hash>(txns.size());
  List<Transaction> matched = Lists.newArrayList();
  byte[] bits = new byte[(int) Math.ceil(txns.size() / 8.0)];
  for (int i = 0; i < txns.size(); i++) {
    Transaction tx = txns.get(i);
    txHashes.add(tx.getHash());
    if (applyAndUpdate(tx)) {
      Utils.setBitLE(bits, i);
      matched.add(tx);
    }
  }
  PartialMerkleTree pmt = PartialMerkleTree.buildFromLeaves(block.getParams(), bits, txHashes);
  FilteredBlock filteredBlock = new FilteredBlock(block.getParams(), block.cloneAsHeader(), pmt);
  for (Transaction transaction : matched)
    filteredBlock.provideTransaction(transaction);
  return filteredBlock;
}

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

/**
 * Creates a new FilteredBlock from the given Block, using this filter to select transactions. Matches can cause the
 * filter to be updated with the matched element, this ensures that when a filter is applied to a block, spends of
 * matched transactions are also matched. However it means this filter can be mutated by the operation. The returned
 * filtered block already has the matched transactions associated with it.
 */
public synchronized FilteredBlock applyAndUpdate(Block block) {
  List<Transaction> txns = block.getTransactions();
  List<Sha256Hash> txHashes = new ArrayList<>(txns.size());
  List<Transaction> matched = Lists.newArrayList();
  byte[] bits = new byte[(int) Math.ceil(txns.size() / 8.0)];
  for (int i = 0; i < txns.size(); i++) {
    Transaction tx = txns.get(i);
    txHashes.add(tx.getHash());
    if (applyAndUpdate(tx)) {
      Utils.setBitLE(bits, i);
      matched.add(tx);
    }
  }
  PartialMerkleTree pmt = PartialMerkleTree.buildFromLeaves(block.getParams(), bits, txHashes);
  FilteredBlock filteredBlock = new FilteredBlock(block.getParams(), block.cloneAsHeader(), pmt);
  for (Transaction transaction : matched)
    filteredBlock.provideTransaction(transaction);
  return filteredBlock;
}

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

public static Block makeSolvedTestBlock(Block prev, Transaction... transactions) throws BlockStoreException {
  Address to = new ECKey().toAddress(prev.getParams());
  Block b = prev.createNextBlock(to);
  // Coinbase tx already exists.
  for (Transaction tx : transactions) {
    b.addTransaction(tx);
  }
  b.solve();
  return b;
}

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

/** Emulates receiving a valid block */
public static BlockPair createFakeBlock(BlockStore blockStore, StoredBlock previousStoredBlock, long version,
                    long timeSeconds, int height,
                    Transaction... transactions) {
  try {
    Block previousBlock = previousStoredBlock.getHeader();
    Address to = new ECKey().toAddress(previousBlock.getParams());
    Block b = previousBlock.createNextBlock(to, version, timeSeconds, height);
    // Coinbase tx was already added.
    for (Transaction tx : transactions) {
      tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
      b.addTransaction(tx);
    }
    b.solve();
    BlockPair pair = new BlockPair();
    pair.block = b;
    pair.storedBlock = previousStoredBlock.build(b);
    blockStore.put(pair.storedBlock);
    blockStore.setChainHead(pair.storedBlock);
    return pair;
  } catch (VerificationException e) {
    throw new RuntimeException(e);  // Cannot happen.
  } catch (BlockStoreException e) {
    throw new RuntimeException(e);  // Cannot happen.
  }
}

相关文章

微信公众号

最新文章

更多