当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.getConfidence方法代码示例

本文整理汇总了Java中org.bitcoinj.core.Transaction.getConfidence方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.getConfidence方法的具体用法?Java Transaction.getConfidence怎么用?Java Transaction.getConfidence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.core.Transaction的用法示例。


在下文中一共展示了Transaction.getConfidence方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTransactionList

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
 *
 */
@Override
public List<CoinTransaction> getTransactionList() {
    List<CoinTransaction> transactions = new ArrayList<>();

    Set<Transaction> txs = _coin.getWalletManager().wallet().getTransactions(true);
    for (Transaction tx : txs) {
        Coin amount = tx.getValue(_coin.getWalletManager().wallet());

        String hash = tx.getHash().toString();
        String amountStr = amount.toPlainString();
        String fee = "";
        String confirmationStr = "CONFIRMED";

        if (tx.getFee() != null) {
            fee = tx.getFee().toPlainString();
        }

        TransactionConfidence confidence = tx.getConfidence();
        if (confidence.getDepthInBlocks() < 6) {
            confirmationStr = confidence.getDepthInBlocks() + " CONFIRMATIONS";
        }

        TransactionConfidence.ConfidenceType cType = confidence.getConfidenceType();

        CoinTransaction coinTransaction = new CoinTransaction(fee, hash, amountStr, confirmationStr, tx.getUpdateTime());
        transactions.add(coinTransaction);
    }

    return transactions;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:34,代码来源:BitcoinManager.java

示例2: isSelectable

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
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));
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:13,代码来源:DefaultCoinSelector.java

示例3: tryGetBestConfidence

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
private TransactionConfidence tryGetBestConfidence() {
    TransactionConfidence confidence = null;
    Transaction bestTx = tryDetermineMostConfidentTransaction();
    if (null != bestTx) confidence = bestTx.getConfidence();
    return confidence;
}
 
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:7,代码来源:TransactionList.java

示例4: tryDetermineMostConfidentTransaction

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
private Transaction tryDetermineMostConfidentTransaction() {
    Iterator<Transaction> iterator = transactions.values().iterator();

    if (!iterator.hasNext())
        return null;

    Transaction currentTx = iterator.next();
    TransactionConfidence currentTxConfidence;
    int currentTxRating;

    // first transaction is the best transaction to start with
    Transaction bestTx = currentTx;
    TransactionConfidence bestTxConfidence = bestTx.getConfidence();
    int bestTxRating = mapConfidenceTypeRating(bestTxConfidence.getConfidenceType());

    // if there are more transactions, check'em
    while (iterator.hasNext()) {
        currentTx = iterator.next();

        currentTxConfidence = currentTx.getConfidence();
        currentTxRating = mapConfidenceTypeRating(currentTxConfidence.getConfidenceType());

        if (currentTxRating < bestTxRating) {
            continue;

        } else if (currentTxRating > bestTxRating) {
            bestTx = currentTx;

        } else {
            // rating is equal at this place, let either numBroadcastPeers or DepthInBlocks decide
            switch (currentTxConfidence.getConfidenceType()) {
                case PENDING:
                    if (currentTxConfidence.numBroadcastPeers() > bestTxConfidence.numBroadcastPeers())
                        bestTx = currentTx;
                    break;
                case BUILDING:
                    if (currentTxConfidence.getDepthInBlocks() > bestTxConfidence.getDepthInBlocks())
                        bestTx = currentTx;
                    break;
                default:
            }
        }

        // update confidence and rating to values of new best transaction
        bestTxConfidence = bestTx.getConfidence();
        bestTxRating = mapConfidenceTypeRating(bestTxConfidence.getConfidenceType());
    }

    return bestTx;
}
 
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:51,代码来源:TransactionList.java

示例5: notifyNewBestBlock

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
 * <p>Called by the {@link BlockChain} when a new block on the best chain is seen, AFTER relevant wallet
 * transactions are extracted and sent to us UNLESS the new block caused a re-org, in which case this will
 * not be called (the {@link Wallet#reorganize(StoredBlock, java.util.List, java.util.List)} method will
 * call this one in that case).</p>
 * <p/>
 * <p>Used to update confidence data in each transaction and last seen block hash. Triggers auto saving.
 * Invokes the onWalletChanged event listener if there were any affected transactions.</p>
 */
@Override
public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
    // Check to see if this block has been seen before.
    Sha256Hash newBlockHash = block.getHeader().getHash();
    if (newBlockHash.equals(getLastBlockSeenHash()))
        return;
    lock.lock();
    try {
        // Store the new block hash.
        setLastBlockSeenHash(newBlockHash);
        setLastBlockSeenHeight(block.getHeight());
        setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds());
        // Notify all the BUILDING transactions of the new block.
        // This is so that they can update their depth.
        Set<Transaction> transactions = getTransactions(true);
        for (Transaction tx : transactions) {
            if (ignoreNextNewBlock.contains(tx.getHash())) {
                // tx was already processed in receive() due to it appearing in this block, so we don't want to
                // increment the tx confidence depth twice, it'd result in miscounting.
                ignoreNextNewBlock.remove(tx.getHash());
            } else {
                TransactionConfidence confidence = tx.getConfidence();
                if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
                    // Erase the set of seen peers once the tx is so deep that it seems unlikely to ever go
                    // pending again. We could clear this data the moment a tx is seen in the block chain, but
                    // in cases where the chain re-orgs, this would mean that wallets would perceive a newly
                    // pending tx has zero confidence at all, which would not be right: we expect it to be
                    // included once again. We could have a separate was-in-chain-and-now-isn't confidence type
                    // but this way is backwards compatible with existing software, and the new state probably
                    // wouldn't mean anything different to just remembering peers anyway.
                    if (confidence.incrementDepthInBlocks() > context.getEventHorizon())
                        confidence.clearBroadcastBy();
                    confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
                }
            }
        }

        informConfidenceListenersIfNotReorganizing();
        maybeQueueOnWalletChanged();

        if (hardSaveOnNextBlock) {
            saveNow();
            hardSaveOnNextBlock = false;
        } else {
            // Coalesce writes to avoid throttling on disk access when catching up with the chain.
            saveLater();
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:61,代码来源:Wallet.java


注:本文中的org.bitcoinj.core.Transaction.getConfidence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。