本文整理汇总了Java中org.bitcoinj.core.TransactionOutput.isMineOrWatched方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionOutput.isMineOrWatched方法的具体用法?Java TransactionOutput.isMineOrWatched怎么用?Java TransactionOutput.isMineOrWatched使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.TransactionOutput
的用法示例。
在下文中一共展示了TransactionOutput.isMineOrWatched方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isTxConsistent
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@VisibleForTesting
boolean isTxConsistent(final Transaction tx, final boolean isSpent) {
boolean isActuallySpent = true;
for (TransactionOutput o : tx.getOutputs()) {
if (o.isAvailableForSpending()) {
if (o.isMineOrWatched(this)) isActuallySpent = false;
if (o.getSpentBy() != null) {
log.error("isAvailableForSpending != spentBy");
return false;
}
} else {
if (o.getSpentBy() == null) {
log.error("isAvailableForSpending != spentBy");
return false;
}
}
}
return isActuallySpent == isSpent;
}
示例2: sentToAddressOfTx
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
private String sentToAddressOfTx(TransactionWrapper txWrapper) {
// positive amount (for our wallet) = incoming tx
boolean isIncoming = txWrapper.getAmount().isPositive();
List<TransactionOutput> outputs = txWrapper.getTransaction().getOutputs();
// due to space limitations we only display if we have a common 2 outputs tx
if (outputs.size() <= 2) {
for (TransactionOutput o : outputs) {
// ignore:
// tx to me, output not, i.e. change to sender
// tx from me, output mine, i.e. change to me
boolean cont = (isIncoming && !o.isMineOrWatched(walletServiceBinder.getWallet()))
|| (!isIncoming && o.isMineOrWatched(walletServiceBinder.getWallet()));
if (cont) {
continue;
}
Address addr = o.getScriptPubKey().getToAddress(appConfig.getNetworkParameters());
return addr.toBase58();
}
}
return null;
}
示例3: addWalletTransaction
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
/**
* Adds the given transaction to the given pools and registers a confidence change listener on it.
*/
private void addWalletTransaction(Pool pool, Transaction tx) {
checkState(lock.isHeldByCurrentThread());
transactions.put(tx.getHash(), tx);
switch (pool) {
case UNSPENT:
checkState(unspent.put(tx.getHash(), tx) == null);
break;
case SPENT:
checkState(spent.put(tx.getHash(), tx) == null);
break;
case PENDING:
checkState(pending.put(tx.getHash(), tx) == null);
break;
case DEAD:
checkState(dead.put(tx.getHash(), tx) == null);
break;
default:
throw new RuntimeException("Unknown wallet transaction type " + pool);
}
if (pool == Pool.UNSPENT || pool == Pool.PENDING) {
for (TransactionOutput output : tx.getOutputs()) {
if (output.isAvailableForSpending() && output.isMineOrWatched(this))
myUnspents.add(output);
}
}
// This is safe even if the listener has been added before, as TransactionConfidence ignores duplicate
// registration requests. That makes the code in the wallet simpler.
tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener);
}
示例4: updateV1toV2
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
private static void updateV1toV2(Wallet wallet) {
checkState(wallet.getVersion() < 2, "Can update only from version < 2");
wallet.setVersion(2);
for (WalletAccount walletAccount : wallet.getAllAccounts()) {
if (walletAccount instanceof WalletPocketHD) {
WalletPocketHD account = (WalletPocketHD) walletAccount;
// Force resync
account.addressesStatus.clear();
// Gather hashes to trim them later
Set<Sha256Hash> txHashes = new HashSet<>(account.rawTransactions.size());
// Reconstruct UTXO set
for (BitTransaction tx : account.rawTransactions.values()) {
txHashes.add(tx.getHash());
for (TransactionOutput txo : tx.getOutputs()) {
if (txo.isAvailableForSpending() && txo.isMineOrWatched(account)) {
OutPointOutput utxo = new OutPointOutput(tx, txo.getIndex());
if (tx.getConfidenceType() == BUILDING) {
utxo.setAppearedAtChainHeight(tx.getAppearedAtChainHeight());
utxo.setDepthInBlocks(tx.getDepthInBlocks());
}
account.unspentOutputs.put(utxo.getOutPoint(), utxo);
}
}
}
// Trim transactions
for (Sha256Hash txHash : txHashes) {
account.trimTransactionIfNeeded(txHash);
}
}
}
}
示例5: processTxFromBestChain
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
/**
* Handle when a transaction becomes newly active on the best chain, either due to receiving a new block or a
* re-org. Places the tx into the right pool, handles coinbase transactions, handles double-spends and so on.
*/
private void processTxFromBestChain(Transaction tx, boolean forceAddToPool) throws VerificationException {
checkState(lock.isHeldByCurrentThread());
checkState(!pending.containsKey(tx.getHash()));
// This TX may spend our existing outputs even though it was not pending. This can happen in unit
// tests, if keys are moved between wallets, if we're catching up to the chain given only a set of keys,
// or if a dead coinbase transaction has moved back onto the main chain.
boolean isDeadCoinbase = tx.isCoinBase() && dead.containsKey(tx.getHash());
if (isDeadCoinbase) {
// There is a dead coinbase tx being received on the best chain. A coinbase tx is made dead when it moves
// to a side chain but it can be switched back on a reorg and resurrected back to spent or unspent.
// So take it out of the dead pool. Note that we don't resurrect dependent transactions here, even though
// we could. Bitcoin Core nodes on the network have deleted the dependent transactions from their mempools
// entirely by this point. We could and maybe should rebroadcast them so the network remembers and tries
// to confirm them again. But this is a deeply unusual edge case that due to the maturity rule should never
// happen in practice, thus for simplicities sake we ignore it here.
log.info(" coinbase tx <-dead: confidence {}", tx.getHashAsString(),
tx.getConfidence().getConfidenceType().name());
dead.remove(tx.getHash());
}
// Update tx and other unspent/pending transactions by connecting inputs/outputs.
updateForSpends(tx, true);
// Now make sure it ends up in the right pool. Also, handle the case where this TX is double-spending
// against our pending transactions. Note that a tx may double spend our pending transactions and also send
// us money/spend our money.
boolean hasOutputsToMe = tx.getValueSentToMe(this).signum() > 0;
boolean hasOutputsFromMe = false;
if (hasOutputsToMe) {
// Needs to go into either unspent or spent (if the outputs were already spent by a pending tx).
if (tx.isEveryOwnedOutputSpent(this)) {
log.info(" tx {} ->spent (by pending)", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
} else {
log.info(" tx {} ->unspent", tx.getHashAsString());
addWalletTransaction(Pool.UNSPENT, tx);
}
} else if (tx.getValueSentFromMe(this).signum() > 0) {
hasOutputsFromMe = true;
// Didn't send us any money, but did spend some. Keep it around for record keeping purposes.
log.info(" tx {} ->spent", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
} else if (forceAddToPool) {
// Was manually added to pending, so we should keep it to notify the user of confidence information
log.info(" tx {} ->spent (manually added)", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
}
// Kill txns in conflict with this tx
Set<Transaction> doubleSpendTxns = findDoubleSpendsAgainst(tx, pending);
if (!doubleSpendTxns.isEmpty()) {
// no need to addTransactionsDependingOn(doubleSpendTxns) because killTxns() already kills dependencies;
killTxns(doubleSpendTxns, tx);
}
if (!hasOutputsToMe
&& !hasOutputsFromMe
&& !forceAddToPool
&& !findDoubleSpendsAgainst(tx, transactions).isEmpty())
{
// disconnect irrelevant inputs (otherwise might cause protobuf serialization issue)
for (TransactionInput input : tx.getInputs()) {
TransactionOutput output = input.getConnectedOutput();
if (output != null && !output.isMineOrWatched(this)) {
input.disconnect();
}
}
}
}
示例6: getUnspentOutputs
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
Map<TrimmedOutPoint, OutPointOutput> getUnspentOutputs(boolean includeUnsafe) {
lock.lock();
try {
// The confirmed UTXO set
Map<TrimmedOutPoint, OutPointOutput> utxoSet = Maps.newHashMap(unspentOutputs);
Set<TrimmedOutPoint> spentTxo = new HashSet<>();
Set<TrimmedOutPoint> txSpendingTxo = new HashSet<>();
// The unconfirmed UTXO set originating from transactions the wallet sends
for (BitTransaction tx : pending.values()) {
if (includeUnsafe || tx.getSource() == Source.SELF) {
boolean isDoubleSpending = false;
txSpendingTxo.clear();
// Remove any unspent outputs that this transaction spends
for (TransactionInput txi : tx.getInputs()) {
TrimmedOutPoint outPoint = TrimmedOutPoint.get(txi);
// Check if another transaction
if (spentTxo.contains(outPoint)) {
log.warn("Transaction {} double-spends outpoint {}:{}",
tx.getHash(), outPoint.getHash(), outPoint.getIndex());
isDoubleSpending = true;
break;
}
txSpendingTxo.add(outPoint);
}
if (isDoubleSpending) continue;
spentTxo.addAll(txSpendingTxo);
List<TransactionOutput> outputs = tx.getOutputs();
for (int i = 0; i < outputs.size(); i++) {
TransactionOutput output = outputs.get(i);
if (output.isMineOrWatched(this)) {
OutPointOutput outPointOutput = new OutPointOutput(tx, i);
utxoSet.put(outPointOutput.getOutPoint(), outPointOutput);
}
}
}
}
// Remove any outputs that are spent
for (TrimmedOutPoint spent : spentTxo) {
utxoSet.remove(spent);
}
return utxoSet;
} finally {
lock.unlock();
}
}