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

x33g5p2x  于2022-01-30 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(80)

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

Transaction.getAppearsInHashes介绍

[英]Returns a map of block [hashes] which contain the transaction mapped to relativity counters, or null if this transaction doesn't have that data because it's not stored in the wallet or because it has never appeared in a block.
[中]返回块[散列]的映射,其中包含映射到相对论计数器的事务,如果此事务没有该数据,则返回null,因为它没有存储在钱包中,或者因为它从未出现在块中。

代码示例

代码示例来源:origin: ICOnator/ICOnator-backend

@Override
public Date getBlockTime() throws MissingTransactionInformationException {
  if (this.blockTime == null) {
    try {
      this.blockTime = bitcoinjTxOutput.getParentTransaction()
          .getAppearsInHashes().keySet().stream()
          .map((blockHash) -> {
            try {
              return bitcoinjBlockStore.get(blockHash);
            } catch (BlockStoreException e) {
              // This can happen if the transaction was seen in a side-chain
              return null;
            }
          })
          .filter(Objects::nonNull)
          .map(StoredBlock::getHeader)
          .map(Block::getTime)
          .min(Date::compareTo).get();
    } catch (Exception e) {
      throw new MissingTransactionInformationException("Couldn't fetch block time.", e);
    }
  }
  return this.blockTime;
}

代码示例来源:origin: ICOnator/ICOnator-backend

@Override
public Long getBlockHeight() throws MissingTransactionInformationException {
  if (this.blockHeight == null) {
    try {
      this.blockHeight = bitcoinjTxOutput.getParentTransaction()
          .getAppearsInHashes().keySet().stream()
          .map((blockHash) -> {
            try {
              return bitcoinjBlockStore.get(blockHash);
            } catch (BlockStoreException e) {
              // This can happen if the transaction was seen in a side-chain
              return null;
            }
          })
          .filter(Objects::nonNull)
          .map(StoredBlock::getHeight)
          .min(Integer::compareTo).get().longValue();
    } catch (Exception e) {
      throw new MissingTransactionInformationException("Couldn't fetch block height.", e);
    }
  }
  return this.blockHeight;
}

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

@Override
  public void onConfidenceChanged(TransactionConfidence conf, ChangeReason reason) {
    // The number of peers that announced this tx has gone up.
    int numSeenPeers = conf.numBroadcastPeers() + rejects.size();
    boolean mined = tx.getAppearsInHashes() != null;
    log.info("broadcastTransaction: {}:  TX {} seen by {} peers{}", reason, tx.getHashAsString(),
        numSeenPeers, mined ? " and mined" : "");
    // Progress callback on the requested thread.
    invokeAndRecord(numSeenPeers, mined);
    if (numSeenPeers >= numWaitingFor || mined) {
      // We've seen the min required number of peers announce the transaction, or it was included
      // in a block. Normally we'd expect to see it fully propagate before it gets mined, but
      // it can be that a block is solved very soon after broadcast, and it's also possible that
      // due to version skew and changes in the relay rules our transaction is not going to
      // fully propagate yet can get mined anyway.
      //
      // Note that we can't wait for the current number of connected peers right now because we
      // could have added more peers after the broadcast took place, which means they won't
      // have seen the transaction. In future when peers sync up their memory pools after they
      // connect we could come back and change this.
      //
      // We're done! It's important that the PeerGroup lock is not held (by this thread) at this
      // point to avoid triggering inversions when the Future completes.
      log.info("broadcastTransaction: {} complete", tx.getHash());
      peerGroup.removePreMessageReceivedEventListener(rejectionListener);
      conf.removeEventListener(this);
      future.set(tx);  // RE-ENTRANCY POINT
    }
  }
}

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

@Override
  public void onConfidenceChanged(TransactionConfidence conf, ChangeReason reason) {
    // The number of peers that announced this tx has gone up.
    int numSeenPeers = conf.numBroadcastPeers() + rejects.size();
    boolean mined = tx.getAppearsInHashes() != null;
    log.info("broadcastTransaction: {}:  TX {} seen by {} peers{}", reason, tx.getHashAsString(),
        numSeenPeers, mined ? " and mined" : "");
    // Progress callback on the requested thread.
    invokeAndRecord(numSeenPeers, mined);
    if (numSeenPeers >= numWaitingFor || mined) {
      // We've seen the min required number of peers announce the transaction, or it was included
      // in a block. Normally we'd expect to see it fully propagate before it gets mined, but
      // it can be that a block is solved very soon after broadcast, and it's also possible that
      // due to version skew and changes in the relay rules our transaction is not going to
      // fully propagate yet can get mined anyway.
      //
      // Note that we can't wait for the current number of connected peers right now because we
      // could have added more peers after the broadcast took place, which means they won't
      // have seen the transaction. In future when peers sync up their memory pools after they
      // connect we could come back and change this.
      //
      // We're done! It's important that the PeerGroup lock is not held (by this thread) at this
      // point to avoid triggering inversions when the Future completes.
      log.info("broadcastTransaction: {} complete", tx.getHash());
      peerGroup.removePreMessageReceivedEventListener(rejectionListener);
      conf.removeEventListener(this);
      future.set(tx);  // RE-ENTRANCY POINT
    }
  }
}

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

@Override
  public void onConfidenceChanged(TransactionConfidence conf, ChangeReason reason) {
    // The number of peers that announced this tx has gone up.
    int numSeenPeers = conf.numBroadcastPeers() + rejects.size();
    boolean mined = tx.getAppearsInHashes() != null;
    log.info("broadcastTransaction: {}:  TX {} seen by {} peers{}", reason, tx.getHashAsString(),
        numSeenPeers, mined ? " and mined" : "");
    // Progress callback on the requested thread.
    invokeAndRecord(numSeenPeers, mined);
    if (numSeenPeers >= numWaitingFor || mined) {
      // We've seen the min required number of peers announce the transaction, or it was included
      // in a block. Normally we'd expect to see it fully propagate before it gets mined, but
      // it can be that a block is solved very soon after broadcast, and it's also possible that
      // due to version skew and changes in the relay rules our transaction is not going to
      // fully propagate yet can get mined anyway.
      //
      // Note that we can't wait for the current number of connected peers right now because we
      // could have added more peers after the broadcast took place, which means they won't
      // have seen the transaction. In future when peers sync up their memory pools after they
      // connect we could come back and change this.
      //
      // We're done! It's important that the PeerGroup lock is not held (by this thread) at this
      // point to avoid triggering inversions when the Future completes.
      log.info("broadcastTransaction: {} complete", tx.getHash());
      peerGroup.removePreMessageReceivedEventListener(rejectionListener);
      conf.removeEventListener(this);
      future.set(tx);  // RE-ENTRANCY POINT
    }
  }
}

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

@Override
  public void onConfidenceChanged(TransactionConfidence conf, ChangeReason reason) {
    // The number of peers that announced this tx has gone up.
    int numSeenPeers = conf.numBroadcastPeers() + rejects.size();
    boolean mined = tx.getAppearsInHashes() != null;
    log.info("broadcastTransaction: {}:  TX {} seen by {} peers{}", reason, tx.getHashAsString(),
        numSeenPeers, mined ? " and mined" : "");
    // Progress callback on the requested thread.
    invokeAndRecord(numSeenPeers, mined);
    if (numSeenPeers >= numWaitingFor || mined) {
      // We've seen the min required number of peers announce the transaction, or it was included
      // in a block. Normally we'd expect to see it fully propagate before it gets mined, but
      // it can be that a block is solved very soon after broadcast, and it's also possible that
      // due to version skew and changes in the relay rules our transaction is not going to
      // fully propagate yet can get mined anyway.
      //
      // Note that we can't wait for the current number of connected peers right now because we
      // could have added more peers after the broadcast took place, which means they won't
      // have seen the transaction. In future when peers sync up their memory pools after they
      // connect we could come back and change this.
      //
      // We're done! It's important that the PeerGroup lock is not held (by this thread) at this
      // point to avoid triggering inversions when the Future completes.
      log.info("broadcastTransaction: {} complete", tx.getHash());
      peerGroup.removePreMessageReceivedEventListener(rejectionListener);
      conf.removeEventListener(this);
      future.set(tx);  // RE-ENTRANCY POINT
    }
  }
}

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

Map<Sha256Hash, Integer> appearsIn = tx.getAppearsInHashes();
if (appearsIn == null) continue;  // Pending.
for (Map.Entry<Sha256Hash, Integer> block : appearsIn.entrySet())

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

Map<Sha256Hash, Integer> appearsIn = tx.getAppearsInHashes();
if (appearsIn == null) continue;  // Pending.
for (Map.Entry<Sha256Hash, Integer> block : appearsIn.entrySet())

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

Map<Sha256Hash, Integer> appearsIn = tx.getAppearsInHashes();
if (appearsIn == null) continue;  // Pending.
for (Map.Entry<Sha256Hash, Integer> block : appearsIn.entrySet())

代码示例来源:origin: Coinomi/coinomi-android

tx.setLockTime(txFull.getLockTime());
if (txFull.getAppearsInHashes() != null) {
  for (Map.Entry<Sha256Hash, Integer> appears : txFull.getAppearsInHashes().entrySet()) {
    tx.addBlockAppearance(appears.getKey(), appears.getValue());

代码示例来源:origin: openwalletGH/openwallet-android

tx.setLockTime(txFull.getLockTime());
if (txFull.getAppearsInHashes() != null) {
  for (Map.Entry<Sha256Hash, Integer> appears : txFull.getAppearsInHashes().entrySet()) {
    tx.addBlockAppearance(appears.getKey(), appears.getValue());

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

@Test
public void testForking5() throws Exception {
  // Test the standard case in which a block containing identical transactions appears on a side chain.
  Block b1 = PARAMS.getGenesisBlock().createNextBlock(coinsTo);
  chain.add(b1);
  final Transaction t = b1.transactions.get(1);
  assertEquals(FIFTY_COINS, wallet.getBalance());
  // genesis -> b1
  //         -> b2
  Block b2 = PARAMS.getGenesisBlock().createNextBlock(coinsTo);
  Transaction b2coinbase = b2.transactions.get(0);
  b2.transactions.clear();
  b2.addTransaction(b2coinbase);
  b2.addTransaction(t);
  b2.solve();
  chain.add(roundtrip(b2));
  assertEquals(FIFTY_COINS, wallet.getBalance());
  assertTrue(wallet.isConsistent());
  assertEquals(2, wallet.getTransaction(t.getHash()).getAppearsInHashes().size());
  //          -> b2 -> b3
  Block b3 = b2.createNextBlock(someOtherGuy);
  chain.add(b3);
  assertEquals(FIFTY_COINS, wallet.getBalance());
}

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

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

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

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

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

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

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

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

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

assertTrue(tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING);
assertTrue(tx.getConfidence().getDepthInBlocks() == 1);
assertTrue(tx.getAppearsInHashes().keySet().contains(block.getHash()));
assertTrue(tx.getAppearsInHashes().size() == 1);

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

assertTrue(chain.add(roundtrip(b8)));
Threading.waitForUserCode();
assertEquals(2, wallet.getTransaction(tHash).getAppearsInHashes().size());

代码示例来源:origin: Coinomi/coinomi-android

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

代码示例来源:origin: openwalletGH/openwallet-android

final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null) {
  for (Map.Entry<Sha256Hash, Integer> entry : appearsInHashes.entrySet()) {

相关文章

微信公众号

最新文章

更多

Transaction类方法