本文整理汇总了Java中org.bitcoinj.core.Transaction.getValueSentToMe方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.getValueSentToMe方法的具体用法?Java Transaction.getValueSentToMe怎么用?Java Transaction.getValueSentToMe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.Transaction
的用法示例。
在下文中一共展示了Transaction.getValueSentToMe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: coinsRecevied
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/** When coins are received this will report information; used as an event listener.
* @author Francis Fasola
* @param wallet The wallet receiving the coins.
* @param tx The transaction sending the coins.
* @param prevBalance The previous balance of the wallet.
* @param newBalance The new balance of the wallet. */
private void coinsRecevied(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
Coin value = tx.getValueSentToMe(wallet);
JOptionPane.showMessageDialog(null, "Coins receive.\nHASH: " + tx.getHashAsString() +
"\nRECEIVED: " + tx.getValue(wallet) + "\nPREVIOUS BALANCE: " +
prevBalance.value + " NEW BALANCE: " + newBalance.value +
"VERSION: " + tx.getVersion() + "Received transaction for " +
value.toFriendlyString() + ": " + tx);
}
示例2: 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).
}