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


Java ConfidenceType类代码示例

本文整理汇总了Java中com.google.bitcoin.core.TransactionConfidence.ConfidenceType的典型用法代码示例。如果您正苦于以下问题:Java ConfidenceType类的具体用法?Java ConfidenceType怎么用?Java ConfidenceType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConfidenceType类属于com.google.bitcoin.core.TransactionConfidence包,在下文中一共展示了ConfidenceType类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTxDepthMap

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
private Map<String,Integer> getTxDepthMap()
{
    Map <String,Integer> map= new HashMap<String,Integer>();
    
    Set<Transaction> txs=getTransactions(true);

    for(Transaction tx : txs)
    {
        TransactionConfidence conf = tx.getConfidence();
        
        if (conf.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
        {
            map.put(tx.getHashAsString(), lastBlockSeenHeight-conf.getAppearedAtChainHeight());
        }
    }
    
    return map;
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:19,代码来源:Wallet.java

示例2: setTransactionBroadcaster

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
/**
 * <p>Specifies that the given {@link TransactionBroadcaster}, typically a {@link PeerGroup}, should be used for
 * sending transactions to the Bitcoin network by default. Some sendCoins methods let you specify a broadcaster
 * explicitly, in that case, they don't use this broadcaster. If null is specified then the wallet won't attempt
 * to broadcast transactions itself.</p>
 *
 * <p>You don't normally need to call this. A {@link PeerGroup} will automatically set itself as the wallets
 * broadcaster when you use {@link PeerGroup#addWallet(Wallet)}. A wallet can use the broadcaster when you ask
 * it to send money, but in future also at other times to implement various features that may require asynchronous
 * re-organisation of the wallet contents on the block chain. For instance, in future the wallet may choose to
 * optimise itself to reduce fees or improve privacy.</p>
 */
public void setTransactionBroadcaster(@Nullable com.google.bitcoin.core.TransactionBroadcaster broadcaster) {
    lock.lock();
    try {
        if (vTransactionBroadcaster == broadcaster)
            return;
        vTransactionBroadcaster = broadcaster;
        if (broadcaster == null)
            return;
        // Now use it to upload any pending transactions we have that are marked as not being seen by any peers yet.
        for (Transaction tx : pending.values()) {
            checkState(tx.getConfidence().getConfidenceType() == ConfidenceType.PENDING);
            // Re-broadcast even if it's marked as already seen for two reasons
            // 1) Old wallets may have transactions marked as broadcast by 1 peer when in reality the network
            //    never saw it, due to bugs.
            // 2) It can't really hurt.
            log.info("New broadcaster so uploading waiting tx {}", tx.getHash());
            broadcaster.broadcastTransaction(tx);
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:9cat,项目名称:templecoin-java,代码行数:35,代码来源:Wallet.java

示例3: setTransactionBroadcaster

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
/**
 * <p>Specifies that the given {@link TransactionBroadcaster}, typically a {@link PeerGroup}, should be used for
 * sending transactions to the Bitcoin network by default. Some sendCoins methods let you specify a broadcaster
 * explicitly, in that case, they don't use this broadcaster. If null is specified then the wallet won't attempt
 * to broadcast transactions itself.</p>
 *
 * <p>You don't normally need to call this. A {@link PeerGroup} will automatically set itself as the wallets
 * broadcaster when you use {@link PeerGroup#addWallet(Wallet)}. A wallet can use the broadcaster when you ask
 * it to send money, but in future also at other times to implement various features that may require asynchronous
 * re-organisation of the wallet contents on the block chain. For instance, in future the wallet may choose to
 * optimise itself to reduce fees or improve privacy.</p>
 */
public void setTransactionBroadcaster(@Nullable com.google.bitcoin.core.TransactionBroadcaster broadcaster) {
    lock.lock();
    try {
        if (vTransactionBroadcaster == broadcaster)
            return;
        vTransactionBroadcaster = broadcaster;
        if (broadcaster == null)
            return;
        // Now use it to upload any pending transactions we have that are marked as not being seen by any peers yet.
        for (Transaction tx : pending.values()) {
            checkState(tx.getConfidence().getConfidenceType() == ConfidenceType.PENDING);
            if (tx.getConfidence().numBroadcastPeers() == 0) {
                log.info("New broadcaster so uploading waiting tx {}", tx.getHash());
                broadcaster.broadcastTransaction(tx);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:33,代码来源:Wallet.java

示例4: isMature

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:13,代码来源:Transaction.java

示例5: setTransactionBroadcaster

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
/**
 * <p>Specifies that the given {@link TransactionBroadcaster}, typically a {@link PeerGroup}, should be used for
 * sending transactions to the Bitcoin network by default. Some sendCoins methods let you specify a broadcaster
 * explicitly, in that case, they don't use this broadcaster. If null is specified then the wallet won't attempt
 * to broadcast transactions itself.</p>
 *
 * <p>You don't normally need to call this. A {@link PeerGroup} will automatically set itself as the wallets
 * broadcaster when you use {@link PeerGroup#addWallet(Wallet)}. A wallet can use the broadcaster when you ask
 * it to send money, but in future also at other times to implement various features that may require asynchronous
 * re-organisation of the wallet contents on the block chain. For instance, in future the wallet may choose to
 * optimise itself to reduce fees or improve privacy.</p>
 */
public void setTransactionBroadcaster(@Nullable com.google.bitcoin.core.TransactionBroadcaster broadcaster) {
    Transaction[] toBroadcast = {};
    lock.lock();
    try {
        if (vTransactionBroadcaster == broadcaster)
            return;
        vTransactionBroadcaster = broadcaster;
        if (broadcaster == null)
            return;
        toBroadcast = pending.values().toArray(toBroadcast);
    } finally {
        lock.unlock();
    }
    // Now use it to upload any pending transactions we have that are marked as not being seen by any peers yet.
    // Don't hold the wallet lock whilst doing this, so if the broadcaster accesses the wallet at some point there
    // is no inversion.
    for (Transaction tx : toBroadcast) {
        checkState(tx.getConfidence().getConfidenceType() == ConfidenceType.PENDING);
        // Re-broadcast even if it's marked as already seen for two reasons
        // 1) Old wallets may have transactions marked as broadcast by 1 peer when in reality the network
        //    never saw it, due to bugs.
        // 2) It can't really hurt.
        log.info("New broadcaster so uploading waiting tx {}", tx.getHash());
        broadcaster.broadcastTransaction(tx);
    }
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:39,代码来源:Wallet.java

示例6: subtractDepthAndWorkDone

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
/**
 * Subtract the supplied depth and work done from the given transactions.
 */
private void subtractDepthAndWorkDone(int depthToSubtract, BigInteger workDoneToSubtract,
                                      Collection<Transaction> transactions) {
    for (Transaction tx : transactions) {
        if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
            tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract);
            tx.getConfidence().setWorkDone(tx.getConfidence().getWorkDone().subtract(workDoneToSubtract));
            confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
        }
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:14,代码来源:Wallet.java

示例7: testForking3

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
@Test
public void testForking3() throws Exception {
    // Check that we can handle our own spends being rolled back by a fork.
    Block b1 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
    chain.add(b1);
    assertEquals("50.00", Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    Address dest = new ECKey().toAddress(unitTestParams);
    Transaction spend = wallet.createSend(dest, Utils.toNanoCoins(10, 0));
    wallet.commitTx(spend);
    // Waiting for confirmation ... make it eligible for selection.
    assertEquals(BigInteger.ZERO, wallet.getBalance());
    spend.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{1, 2, 3, 4})));
    spend.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{5,6,7,8})));
    assertEquals(ConfidenceType.PENDING, spend.getConfidence().getConfidenceType());
    assertEquals(Utils.toNanoCoins(40, 0), wallet.getBalance());
    Block b2 = b1.createNextBlock(someOtherGuy);
    b2.addTransaction(spend);
    b2.solve();
    chain.add(roundtrip(b2));
    // We have 40 coins in change.
    assertEquals(ConfidenceType.BUILDING, spend.getConfidence().getConfidenceType());
    // genesis -> b1 (receive coins) -> b2 (spend coins)
    //                               \-> b3 -> b4
    Block b3 = b1.createNextBlock(someOtherGuy);
    Block b4 = b3.createNextBlock(someOtherGuy);
    chain.add(b3);
    chain.add(b4);
    // b4 causes a re-org that should make our spend go pending again.
    assertEquals(Utils.toNanoCoins(40, 0), wallet.getBalance());
    assertEquals(ConfidenceType.PENDING, spend.getConfidence().getConfidenceType());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:32,代码来源:ChainSplitTest.java

示例8: testForking4

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
@Test
public void testForking4() throws Exception {
    // Check that we can handle external spends on an inactive chain becoming active. An external spend is where
    // we see a transaction that spends our own coins but we did not broadcast it ourselves. This happens when
    // keys are being shared between wallets.
    Block b1 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
    chain.add(b1);
    assertEquals("50.00", Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    Address dest = new ECKey().toAddress(unitTestParams);
    Transaction spend = wallet.createSend(dest, Utils.toNanoCoins(50, 0));
    // We do NOT confirm the spend here. That means it's not considered to be pending because createSend is
    // stateless. For our purposes it is as if some other program with our keys created the tx.
    //
    // genesis -> b1 (receive 50) --> b2
    //                            \-> b3 (external spend) -> b4
    Block b2 = b1.createNextBlock(someOtherGuy);
    chain.add(b2);
    Block b3 = b1.createNextBlock(someOtherGuy);
    b3.addTransaction(spend);
    b3.solve();
    chain.add(roundtrip(b3));
    // The external spend is now pending.
    assertEquals(Utils.toNanoCoins(0, 0), wallet.getBalance());
    Transaction tx = wallet.getTransaction(spend.getHash());
    assertEquals(ConfidenceType.PENDING, tx.getConfidence().getConfidenceType());
    Block b4 = b3.createNextBlock(someOtherGuy);
    chain.add(b4);
    // The external spend is now active.
    assertEquals(Utils.toNanoCoins(0, 0), wallet.getBalance());
    assertEquals(ConfidenceType.BUILDING, tx.getConfidence().getConfidenceType());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:32,代码来源:ChainSplitTest.java

示例9: notifyNewBestBlock

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的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>
 */
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());
        // TODO: Clarify the code below.
        // Notify all the BUILDING transactions of the new block.
        // This is so that they can update their work done and 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
                // notify the tx confidence of work done twice, it'd result in miscounting.
                ignoreNextNewBlock.remove(tx.getHash());
            } else if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
                tx.getConfidence().notifyWorkDone(block.getHeader());
                confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
            }
        }

        informConfidenceListenersIfNotReorganizing();
        maybeQueueOnWalletChanged();
        // Coalesce writes to avoid throttling on disk access when catching up with the chain.
        saveLater();
    } finally {
        lock.unlock();
    }
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:44,代码来源:Wallet.java

示例10: onCoinsReceived

import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; //导入依赖的package包/类
@Override
public void onCoinsReceived(final Wallet wallet, final Transaction tx, final BigInteger prevBalance, final BigInteger newBalance)
{
	transactionsReceived.incrementAndGet();

	final int bestChainHeight = blockChain.getBestChainHeight();

	try
	{
		final Address from = WalletUtils.getFirstFromAddress(tx);
		final BigInteger amount = tx.getValue(wallet);
		final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType();

		handler.post(new Runnable()
		{
			@Override
			public void run()
			{
				final boolean isReceived = amount.signum() > 0;
				final boolean replaying = bestChainHeight < bestChainHeightEver;
				final boolean isReplayedTx = confidenceType == ConfidenceType.BUILDING && replaying;

				if (isReceived && !isReplayedTx)
					notifyCoinsReceived(from, amount);
			}
		});
	}
	catch (final ScriptException x)
	{
		throw new RuntimeException(x);
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:33,代码来源:BlockchainServiceImpl.java


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