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


Java Transaction.verify方法代码示例

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


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

示例1: receivePending

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
 * <p>Called when we have found a transaction (via network broadcast or otherwise) that is relevant to this wallet
 * and want to record it. Note that we <b>cannot verify these transactions at all</b>, they may spend fictional
 * coins or be otherwise invalid. They are useful to inform the user about coins they can expect to receive soon,
 * and if you trust the sender of the transaction you can choose to assume they are in fact valid and will not
 * be double spent as an optimization.</p>
 *
 * <p>This is the same as {@link Wallet#receivePending(Transaction, java.util.List)} but allows you to override the
 * {@link Wallet#isPendingTransactionRelevant(Transaction)} sanity-check to keep track of transactions that are not
 * spendable or spend our coins. This can be useful when you want to keep track of transaction confidence on
 * arbitrary transactions. Note that transactions added in this way will still be relayed to peers and appear in
 * transaction lists like any other pending transaction (even when not relevant).</p>
 */
public void receivePending(Transaction tx, @Nullable List<Transaction> dependencies, boolean overrideIsRelevant) throws VerificationException {
    // Can run in a peer thread. This method will only be called if a prior call to isPendingTransactionRelevant
    // returned true, so we already know by this point that it sends coins to or from our wallet, or is a double
    // spend against one of our other pending transactions.
    lock.lock();
    try {
        tx.verify();
        // Ignore it if we already know about this transaction. Receiving a pending transaction never moves it
        // between pools.
        EnumSet<Pool> containingPools = getContainingPools(tx);
        if (!containingPools.equals(EnumSet.noneOf(Pool.class))) {
            log.debug("Received tx we already saw in a block or created ourselves: " + tx.getHashAsString());
            return;
        }
        // Repeat the check of relevancy here, even though the caller may have already done so - this is to avoid
        // race conditions where receivePending may be being called in parallel.
        if (!overrideIsRelevant && !isPendingTransactionRelevant(tx))
            return;
        if (isTransactionRisky(tx, dependencies) && !acceptRiskyTransactions) {
            // isTransactionRisky already logged the reason.
            riskDropped.put(tx.getHash(), tx);
            log.warn("There are now {} risk dropped transactions being kept in memory", riskDropped.size());
            return;
        }
        Coin valueSentToMe = tx.getValueSentToMe(this);
        Coin valueSentFromMe = tx.getValueSentFromMe(this);
        if (log.isInfoEnabled()) {
            log.info(String.format(Locale.US, "Received a pending transaction %s that spends %s from our own wallet," +
                    " and sends us %s", tx.getHashAsString(), valueSentFromMe.toFriendlyString(),
                    valueSentToMe.toFriendlyString()));
        }
        if (tx.getConfidence().getSource().equals(TransactionConfidence.Source.UNKNOWN)) {
            log.warn("Wallet received transaction with an unknown source. Consider tagging it!");
        }
        // If this tx spends any of our unspent outputs, mark them as spent now, then add to the pending pool. This
        // ensures that if some other client that has our keys broadcasts a spend we stay in sync. Also updates the
        // timestamp on the transaction and registers/runs event listeners.
        commitTx(tx);
    } finally {
        lock.unlock();
    }
    // maybeRotateKeys() will ignore pending transactions so we don't bother calling it here (see the comments
    // in that function for an explanation of why).
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:58,代码来源:Wallet.java


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