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

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

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

Transaction.getConfidence介绍

[英]Returns the confidence object for this transaction from the org.bitcoinj.core.TxConfidenceTablereferenced by the implicit Context.
[中]从组织返回此事务的信任对象。比特币。果心由隐式上下文引用的txconfidenceTable。

代码示例

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

/**
 * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable}
 * referenced by the implicit {@link Context}.
 */
public TransactionConfidence getConfidence() {
  return getConfidence(Context.get());
}

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

/**
 * Subtract the supplied depth from the given transactions.
 */
private void subtractDepth(int depthToSubtract, Collection<Transaction> transactions) {
  for (Transaction tx : transactions) {
    if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
      tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract);
      confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
    }
  }
}

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

/**
 * Subtract the supplied depth from the given transactions.
 */
private void subtractDepth(int depthToSubtract, Collection<Transaction> transactions) {
  for (Transaction tx : transactions) {
    if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
      tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract);
      confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
    }
  }
}

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

/**
 * Convenience wrapper around getConfidence().getConfidenceType()
 * @return true if this transaction hasn't been seen in any block yet.
 */
public boolean isPending() {
  return getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.PENDING;
}

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

/**
 * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable}
 * referenced by the given {@link Context}.
 */
public TransactionConfidence getConfidence(Context context) {
  return getConfidence(context.getConfidenceTable());
}

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

/**
 * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable}
 * referenced by the implicit {@link Context}.
 */
public TransactionConfidence getConfidence() {
  return getConfidence(Context.get());
}

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

/**
 * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable}
 * referenced by the implicit {@link Context}.
 */
public TransactionConfidence getConfidence() {
  return getConfidence(Context.get());
}

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

/**
 * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable}
 * referenced by the given {@link Context}.
 */
public TransactionConfidence getConfidence(Context context) {
  return getConfidence(context.getConfidenceTable());
}

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

private void informConfidenceListenersIfNotReorganizing() {
  if (insideReorg)
    return;
  for (Map.Entry<Transaction, TransactionConfidence.Listener.ChangeReason> entry : confidenceChanged.entrySet()) {
    final Transaction tx = entry.getKey();
    tx.getConfidence().queueListeners(entry.getValue());
    queueOnTransactionConfidenceChanged(tx);
  }
  confidenceChanged.clear();
}

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

private void informConfidenceListenersIfNotReorganizing() {
  if (insideReorg)
    return;
  for (Map.Entry<Transaction, TransactionConfidence.Listener.ChangeReason> entry : confidenceChanged.entrySet()) {
    final Transaction tx = entry.getKey();
    tx.getConfidence().queueListeners(entry.getValue());
    queueOnTransactionConfidenceChanged(tx);
  }
  confidenceChanged.clear();
}

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

private void informConfidenceListenersIfNotReorganizing() {
  if (insideReorg)
    return;
  for (Map.Entry<Transaction, TransactionConfidence.Listener.ChangeReason> entry : confidenceChanged.entrySet()) {
    final Transaction tx = entry.getKey();
    tx.getConfidence().queueListeners(entry.getValue());
    queueOnTransactionConfidenceChanged(tx);
  }
  confidenceChanged.clear();
}

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

/**
 * A transaction is mature if it is either a building coinbase tx that is as deep or deeper than the required coinbase depth, or a non-coinbase tx.
 */
public boolean isMature() {
  if (!isCoinBase())
    return true;
  if (getConfidence().getConfidenceType() != ConfidenceType.BUILDING)
    return false;
  return getConfidence().getDepthInBlocks() >= params.getSpendableCoinbaseDepth();
}

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

/**
 * A transaction is mature if it is either a building coinbase tx that is as deep or deeper than the required coinbase depth, or a non-coinbase tx.
 */
public boolean isMature() {
  if (!isCoinBase())
    return true;
  if (getConfidence().getConfidenceType() != ConfidenceType.BUILDING)
    return false;
  return getConfidence().getDepthInBlocks() >= params.getSpendableCoinbaseDepth();
}

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

@Override
  public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) {
    if (tx.getConfidence().getConfidenceType() ==
        TransactionConfidence.ConfidenceType.DEAD) {
      eventDead[0] = tx;
      eventReplacement[0] = tx.getConfidence().getOverridingTransaction();
    }
  }
});

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

public static boolean isSelectable(Transaction tx) {
    // Only pick chain-included transactions, or transactions that are ours and pending.
    TransactionConfidence confidence = tx.getConfidence();
    TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
    return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||

        type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
        confidence.getSource().equals(TransactionConfidence.Source.SELF) &&
        // In regtest mode we expect to have only one peer, so we won't see transactions propagate.
        // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
        (confidence.numBroadcastPeers() > 1 || tx.getParams().getId().equals(NetworkParameters.ID_REGTEST));
  }
}

代码示例来源:origin: blockchain/thunder

@Override
public Transaction getTransaction (Sha256Hash hash) {
  try {
    Transaction transaction = blockExplorer.getBitcoinJTransaction(hash.toString());
    double height = blockExplorer.getTransaction(hash.toString()).getBlockHeight();
    if (height > 0) {
      transaction.getConfidence().setDepthInBlocks((int) (blockChain.getChainHead().getHeight() - height));
    }
    return transaction;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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

public static boolean isSelectable(Transaction tx) {
    // Only pick chain-included transactions, or transactions that are ours and pending.
    TransactionConfidence confidence = tx.getConfidence();
    TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
    return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||

        type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
        confidence.getSource().equals(TransactionConfidence.Source.SELF) &&
        // In regtest mode we expect to have only one peer, so we won't see transactions propagate.
        // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
        (confidence.numBroadcastPeers() > 1 || tx.getParams().getId().equals(NetworkParameters.ID_REGTEST));
  }
}

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

/** Finds if tx is NOT spending other txns which are in the specified confidence type */
private boolean isNotSpendingTxnsInConfidenceType(Transaction tx, ConfidenceType confidenceType) {
  for (TransactionInput txInput : tx.getInputs()) {
    Transaction connectedTx = this.getTransaction(txInput.getOutpoint().getHash());
    if (connectedTx != null && connectedTx.getConfidence().getConfidenceType().equals(confidenceType)) {
      return false;
    }
  }
  return true;
}

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

/** Finds if tx is NOT spending other txns which are in the specified confidence type */
private boolean isNotSpendingTxnsInConfidenceType(Transaction tx, ConfidenceType confidenceType) {
  for (TransactionInput txInput : tx.getInputs()) {
    Transaction connectedTx = this.getTransaction(txInput.getOutpoint().getHash());
    if (connectedTx != null && connectedTx.getConfidence().getConfidenceType().equals(confidenceType)) {
      return false;
    }
  }
  return true;
}

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

@Test
public void testIsMatureReturnsFalseIfTransactionIsCoinbaseAndConfidenceTypeIsNotEqualToBuilding() {
  Transaction tx = FakeTxBuilder.createFakeCoinbaseTx(PARAMS);
  tx.getConfidence().setConfidenceType(ConfidenceType.UNKNOWN);
  assertEquals(tx.isMature(), false);
  tx.getConfidence().setConfidenceType(ConfidenceType.PENDING);
  assertEquals(tx.isMature(), false);
  tx.getConfidence().setConfidenceType(ConfidenceType.DEAD);
  assertEquals(tx.isMature(), false);
}

相关文章

微信公众号

最新文章

更多

Transaction类方法