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

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

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

Block.getPrevBlockHash介绍

[英]Returns the hash of the previous block in the chain, as defined by the block header.
[中]返回链中上一个块的哈希值,由块头定义。

代码示例

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

/**
 * An orphan block is one that does not connect to the chain anywhere (ie we can't find its parent, therefore
 * it's an orphan). Typically this occurs when we are downloading the chain and didn't reach the head yet, and/or
 * if a block is solved whilst we are downloading. It's possible that we see a small amount of orphan blocks which
 * chain together, this method tries walking backwards through the known orphan blocks to find the bottom-most.
 *
 * @return from or one of froms parents, or null if "from" does not identify an orphan block
 */
@Nullable
public Block getOrphanRoot(Sha256Hash from) {
  lock.lock();
  try {
    OrphanBlock cursor = orphanBlocks.get(from);
    if (cursor == null)
      return null;
    OrphanBlock tmp;
    while ((tmp = orphanBlocks.get(cursor.block.getPrevBlockHash())) != null) {
      cursor = tmp;
    }
    return cursor.block;
  } finally {
    lock.unlock();
  }
}

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

/**
 * An orphan block is one that does not connect to the chain anywhere (ie we can't find its parent, therefore
 * it's an orphan). Typically this occurs when we are downloading the chain and didn't reach the head yet, and/or
 * if a block is solved whilst we are downloading. It's possible that we see a small amount of orphan blocks which
 * chain together, this method tries walking backwards through the known orphan blocks to find the bottom-most.
 *
 * @return from or one of froms parents, or null if "from" does not identify an orphan block
 */
@Nullable
public Block getOrphanRoot(Sha256Hash from) {
  lock.lock();
  try {
    OrphanBlock cursor = orphanBlocks.get(from);
    if (cursor == null)
      return null;
    OrphanBlock tmp;
    while ((tmp = orphanBlocks.get(cursor.block.getPrevBlockHash())) != null) {
      cursor = tmp;
    }
    return cursor.block;
  } finally {
    lock.unlock();
  }
}

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

/**
 * An orphan block is one that does not connect to the chain anywhere (ie we can't find its parent, therefore
 * it's an orphan). Typically this occurs when we are downloading the chain and didn't reach the head yet, and/or
 * if a block is solved whilst we are downloading. It's possible that we see a small amount of orphan blocks which
 * chain together, this method tries walking backwards through the known orphan blocks to find the bottom-most.
 *
 * @return from or one of froms parents, or null if "from" does not identify an orphan block
 */
@Nullable
public Block getOrphanRoot(Sha256Hash from) {
  lock.lock();
  try {
    OrphanBlock cursor = orphanBlocks.get(from);
    if (cursor == null)
      return null;
    OrphanBlock tmp;
    while ((tmp = orphanBlocks.get(cursor.block.getPrevBlockHash())) != null) {
      cursor = tmp;
    }
    return cursor.block;
  } finally {
    lock.unlock();
  }
}

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

/**
 * An orphan block is one that does not connect to the chain anywhere (ie we can't find its parent, therefore
 * it's an orphan). Typically this occurs when we are downloading the chain and didn't reach the head yet, and/or
 * if a block is solved whilst we are downloading. It's possible that we see a small amount of orphan blocks which
 * chain together, this method tries walking backwards through the known orphan blocks to find the bottom-most.
 *
 * @return from or one of froms parents, or null if "from" does not identify an orphan block
 */
@Nullable
public Block getOrphanRoot(Sha256Hash from) {
  lock.lock();
  try {
    OrphanBlock cursor = orphanBlocks.get(from);
    if (cursor == null)
      return null;
    OrphanBlock tmp;
    while ((tmp = orphanBlocks.get(cursor.block.getPrevBlockHash())) != null) {
      cursor = tmp;
    }
    return cursor.block;
  } finally {
    lock.unlock();
  }
}

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

/**
 * Given a block store, looks up the previous block in this chain. Convenience method for doing
 * <tt>store.get(this.getHeader().getPrevBlockHash())</tt>.
 *
 * @return the previous block in the chain or null if it was not found in the store.
 */
public StoredBlock getPrev(BlockStore store) throws BlockStoreException {
  return store.get(getHeader().getPrevBlockHash());
}

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

/**
 * Given a block store, looks up the previous block in this chain. Convenience method for doing
 * <tt>store.get(this.getHeader().getPrevBlockHash())</tt>.
 *
 * @return the previous block in the chain or null if it was not found in the store.
 */
public StoredBlock getPrev(BlockStore store) throws BlockStoreException {
  return store.get(getHeader().getPrevBlockHash());
}

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

/**
 * Given a block store, looks up the previous block in this chain. Convenience method for doing
 * <tt>store.get(this.getHeader().getPrevBlockHash())</tt>.
 *
 * @return the previous block in the chain or null if it was not found in the store.
 */
public StoredBlock getPrev(BlockStore store) throws BlockStoreException {
  return store.get(getHeader().getPrevBlockHash());
}

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

/**
 * Given a block store, looks up the previous block in this chain. Convenience method for doing
 * <tt>store.get(this.getHeader().getPrevBlockHash())</tt>.
 *
 * @return the previous block in the chain or null if it was not found in the store.
 */
public StoredBlock getPrev(BlockStore store) throws BlockStoreException {
  return store.get(getHeader().getPrevBlockHash());
}

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

/**
 * Returns a multi-line string containing a description of the contents of
 * the block. Use for debugging purposes only.
 */
@Override
public String toString() {
  StringBuilder s = new StringBuilder();
  s.append(" block: \n");
  s.append("   hash: ").append(getHashAsString()).append('\n');
  s.append("   version: ").append(version);
  String bips = Joiner.on(", ").skipNulls().join(isBIP34() ? "BIP34" : null, isBIP66() ? "BIP66" : null,
      isBIP65() ? "BIP65" : null);
  if (!bips.isEmpty())
    s.append(" (").append(bips).append(')');
  s.append('\n');
  s.append("   previous block: ").append(getPrevBlockHash()).append("\n");
  s.append("   merkle root: ").append(getMerkleRoot()).append("\n");
  s.append("   time: ").append(time).append(" (").append(Utils.dateTimeFormat(time * 1000)).append(")\n");
  s.append("   difficulty target (nBits): ").append(difficultyTarget).append("\n");
  s.append("   nonce: ").append(nonce).append("\n");
  if (transactions != null && transactions.size() > 0) {
    s.append("   with ").append(transactions.size()).append(" transaction(s):\n");
    for (Transaction tx : transactions) {
      s.append(tx);
    }
  }
  return s.toString();
}

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

/**
 * Returns a multi-line string containing a description of the contents of
 * the block. Use for debugging purposes only.
 */
@Override
public String toString() {
  StringBuilder s = new StringBuilder();
  s.append(" block: \n");
  s.append("   hash: ").append(getHashAsString()).append('\n');
  s.append("   version: ").append(version);
  String bips = Joiner.on(", ").skipNulls().join(isBIP34() ? "BIP34" : null, isBIP66() ? "BIP66" : null,
      isBIP65() ? "BIP65" : null);
  if (!bips.isEmpty())
    s.append(" (").append(bips).append(')');
  s.append('\n');
  s.append("   previous block: ").append(getPrevBlockHash()).append("\n");
  s.append("   merkle root: ").append(getMerkleRoot()).append("\n");
  s.append("   time: ").append(time).append(" (").append(Utils.dateTimeFormat(time * 1000)).append(")\n");
  s.append("   difficulty target (nBits): ").append(difficultyTarget).append("\n");
  s.append("   nonce: ").append(nonce).append("\n");
  if (transactions != null && transactions.size() > 0) {
    s.append("   with ").append(transactions.size()).append(" transaction(s):\n");
    for (Transaction tx : transactions) {
      s.append(tx);
    }
  }
  return s.toString();
}

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

/**
 * Returns a multi-line string containing a description of the contents of
 * the block. Use for debugging purposes only.
 */
@Override
public String toString() {
  StringBuilder s = new StringBuilder();
  s.append(" block: \n");
  s.append("   hash: ").append(getHashAsString()).append('\n');
  s.append("   version: ").append(version);
  String bips = Joiner.on(", ").skipNulls().join(isBIP34() ? "BIP34" : null, isBIP66() ? "BIP66" : null,
      isBIP65() ? "BIP65" : null);
  if (!bips.isEmpty())
    s.append(" (").append(bips).append(')');
  s.append('\n');
  s.append("   previous block: ").append(getPrevBlockHash()).append("\n");
  s.append("   merkle root: ").append(getMerkleRoot()).append("\n");
  s.append("   time: ").append(time).append(" (").append(Utils.dateTimeFormat(time * 1000)).append(")\n");
  s.append("   difficulty target (nBits): ").append(difficultyTarget).append("\n");
  s.append("   nonce: ").append(nonce).append("\n");
  if (transactions != null && transactions.size() > 0) {
    s.append("   with ").append(transactions.size()).append(" transaction(s):\n");
    for (Transaction tx : transactions) {
      s.append(tx);
    }
  }
  return s.toString();
}

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

/**
 * Returns a multi-line string containing a description of the contents of
 * the block. Use for debugging purposes only.
 */
@Override
public String toString() {
  StringBuilder s = new StringBuilder();
  s.append(" block: \n");
  s.append("   hash: ").append(getHashAsString()).append('\n');
  s.append("   version: ").append(version);
  String bips = Joiner.on(", ").skipNulls().join(isBIP34() ? "BIP34" : null, isBIP66() ? "BIP66" : null,
      isBIP65() ? "BIP65" : null);
  if (!bips.isEmpty())
    s.append(" (").append(bips).append(')');
  s.append('\n');
  s.append("   previous block: ").append(getPrevBlockHash()).append("\n");
  s.append("   merkle root: ").append(getMerkleRoot()).append("\n");
  s.append("   time: ").append(time).append(" (").append(Utils.dateTimeFormat(time * 1000)).append(")\n");
  s.append("   difficulty target (nBits): ").append(difficultyTarget).append("\n");
  s.append("   nonce: ").append(nonce).append("\n");
  if (transactions != null && transactions.size() > 0) {
    s.append("   with ").append(transactions.size()).append(" transaction(s):\n");
    for (Transaction tx : transactions) {
      s.append(tx);
    }
  }
  return s.toString();
}

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

OrphanBlock orphanBlock = iter.next();
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {

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

OrphanBlock orphanBlock = iter.next();
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {

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

OrphanBlock orphanBlock = iter.next();
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {

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

OrphanBlock orphanBlock = iter.next();
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {

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

"Difficulty transition point but we did not find a way back to the genesis block.");
cursor = blockStore.get(cursor.getHeader().getPrevBlockHash());

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

"Difficulty transition point but we did not find a way back to the last transition point. Not found: " + hash);
hash = cursor.getHeader().getPrevBlockHash();

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

"Difficulty transition point but we did not find a way back to the last transition point. Not found: " + hash);
hash = cursor.getHeader().getPrevBlockHash();

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

public BlockAndValidity(NewBlock block, boolean connects, boolean throwsException, Sha256Hash hashChainTipAfterBlock, int heightAfterBlock, String blockName) {
  this(block.block, connects, throwsException, hashChainTipAfterBlock, heightAfterBlock, blockName);
  coinbaseBlockMap.put(block.getCoinbaseOutput().outpoint.getHash(), block.getHash());
  Integer blockHeight = blockToHeightMap.get(block.block.getPrevBlockHash());
  if (blockHeight != null) {
    blockHeight++;
    for (Transaction t : block.block.getTransactions())
      for (TransactionInput in : t.getInputs()) {
        Sha256Hash blockSpendingHash = coinbaseBlockMap.get(in.getOutpoint().getHash());
        checkState(blockSpendingHash == null || blockToHeightMap.get(blockSpendingHash) == null ||
            blockToHeightMap.get(blockSpendingHash) == blockHeight - params.getSpendableCoinbaseDepth());
      }
  }
}

相关文章

微信公众号

最新文章

更多