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


Java Pool类代码示例

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


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

示例1: getContainingPools

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
EnumSet<Pool> getContainingPools(Transaction tx) {
    lock.lock();
    try {
        EnumSet<Pool> result = EnumSet.noneOf(Pool.class);
        Sha256Hash txHash = tx.getHash();
        if (unspent.containsKey(txHash)) {
            result.add(Pool.UNSPENT);
        }
        if (spent.containsKey(txHash)) {
            result.add(Pool.SPENT);
        }
        if (pending.containsKey(txHash)) {
            result.add(Pool.PENDING);
        }
        if (dead.containsKey(txHash)) {
            result.add(Pool.DEAD);
        }
        return result;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:23,代码来源:Wallet.java

示例2: getPoolSize

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
int getPoolSize(WalletTransaction.Pool pool) {
    lock.lock();
    try {
        switch (pool) {
            case UNSPENT:
                return unspent.size();
            case SPENT:
                return spent.size();
            case PENDING:
                return pending.size();
            case DEAD:
                return dead.size();
            case ALL:
                return unspent.size() + spent.size() + pending.size() + dead.size();
        }
        throw new RuntimeException("Unreachable");
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:21,代码来源:Wallet.java

示例3: sideChain

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void sideChain() throws Exception {
    // The wallet receives a coin on the main chain, then on a side chain. Balance is equal to both added together
    // as we assume the side chain tx is pending and will be included shortly.
    BigInteger v1 = Utils.toNanoCoins(1, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals(v1, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.ALL));

    BigInteger v2 = toNanoCoins(0, 50);
    sendMoneyToWallet(v2, AbstractBlockChain.NewBlockType.SIDE_CHAIN);
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.ALL));
    assertEquals(v1, wallet.getBalance());
    assertEquals(v1.add(v2), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:17,代码来源:WalletTest.java

示例4: bounce

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void bounce() throws Exception {
    // This test covers bug 64 (False double spends). Check that if we create a spend and it's immediately sent
    // back to us, this isn't considered as a double spend.
    BigInteger coin1 = Utils.toNanoCoins(1, 0);
    sendMoneyToWallet(coin1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // Send half to some other guy. Sending only half then waiting for a confirm is important to ensure the tx is
    // in the unspent pool, not pending or spent.
    BigInteger coinHalf = Utils.toNanoCoins(0, 50);
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.ALL));
    Address someOtherGuy = new ECKey().toAddress(params);
    Transaction outbound1 = wallet.createSend(someOtherGuy, coinHalf);
    wallet.commitTx(outbound1);
    sendMoneyToWallet(outbound1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // That other guy gives us the coins right back.
    Transaction inbound2 = new Transaction(params);
    inbound2.addOutput(new TransactionOutput(params, inbound2, coinHalf, myAddress));
    inbound2.addInput(outbound1.getOutputs().get(0));
    sendMoneyToWallet(inbound2, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals(coin1, wallet.getBalance());
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:23,代码来源:WalletTest.java

示例5: spendToSameWallet

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void spendToSameWallet() throws Exception {
    // Test that a spend to the same wallet is dealt with correctly.
    // It should appear in the wallet and confirm.
    // This is a bit of a silly thing to do in the real world as all it does is burn a fee but it is perfectly valid.
    BigInteger coin1 = Utils.toNanoCoins(1, 0);
    BigInteger coinHalf = Utils.toNanoCoins(0, 50);
    // Start by giving us 1 coin.
    sendMoneyToWallet(coin1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // Send half to ourselves. We should then have a balance available to spend of zero.
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.ALL));
    Transaction outbound1 = wallet.createSend(myAddress, coinHalf);
    wallet.commitTx(outbound1);
    // We should have a zero available balance before the next block.
    assertEquals(BigInteger.ZERO, wallet.getBalance());
    sendMoneyToWallet(outbound1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // We should have a balance of 1 BTC after the block is received.
    assertEquals(coin1, wallet.getBalance());
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:21,代码来源:WalletTest.java

示例6: replayWhilstPending

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void replayWhilstPending() throws Exception {
    // Check that if a pending transaction spends outputs of chain-included transactions, we mark them as spent.
    // See bug 345. This can happen if there is a pending transaction floating around and then you replay the
    // chain without emptying the memory pool (or refilling it from a peer).
    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction tx1 = createFakeTx(params, value, myAddress);
    Transaction tx2 = new Transaction(params);
    tx2.addInput(tx1.getOutput(0));
    tx2.addOutput(Utils.toNanoCoins(0, 9), new ECKey());
    // Add a change address to ensure this tx is relevant.
    tx2.addOutput(Utils.toNanoCoins(0, 1), wallet.getChangeAddress());
    wallet.receivePending(tx2, null);
    BlockPair bp = createFakeBlock(blockStore, tx1);
    wallet.receiveFromBlock(tx1, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
    wallet.notifyNewBestBlock(bp.storedBlock);
    assertEquals(BigInteger.ZERO, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(Pool.SPENT));
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:22,代码来源:WalletTest.java

示例7: PaymentChannel

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
public PaymentChannel(PaymentChannelGroup parentGroup, Transaction setupTransaction,
		Transaction refundTransaction, BigInteger peerMinDeposit, BigInteger minDeposit,
		BigInteger peerContribution, BigInteger contribution, BigInteger initialFee, BigInteger feeStep,
		int maxLifetime, int locktimeStep, int commitDepth) {
	this.parentGroup = parentGroup;
	this.setupTransaction = setupTransaction;
	this.refundTransaction = refundTransaction;
	this.lastSentTransaction = refundTransaction;
	this.pendingTransaction = null;
	this.commitDepth = commitDepth;
	this.minDeposit = minDeposit;
	this.peerMinDeposit = peerMinDeposit;
	this.contribution = contribution;
	this.peerContribution = peerContribution;
	this.initialFee = initialFee;
	this.feeStep = feeStep;
	this.locktimeStep = locktimeStep;
	this.iAmInitiator = false;
	getParentPeer().wallet().addWalletTransaction(
			new WalletTransaction(Pool.PENDING, setupTransaction));
	this.state = State.SETUP;
}
 
开发者ID:aakselrod,项目名称:libtxchain-java,代码行数:23,代码来源:PaymentChannel.java

示例8: expire

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
void expire() {
	getParentPeer().wallet().addWalletTransaction(
			new WalletTransaction(WalletTransaction.Pool.PENDING, this.refundTransaction));
	getParentPeer().peerGroup().broadcastTransaction(this.refundTransaction);
	this.redeemTransaction = new Transaction(getParentPeer().params());
	this.redeemTransaction.addOutput(
			this.refundTransaction.getOutput(this.iAmInitiator ? 0 : 1).getValue().subtract(this.initialFee),
			getParentPeerKey().toAddress(getParentPeer().params()));
	this.redeemTransaction.addInput(this.refundTransaction.getOutput(this.iAmInitiator ? 0 : 1));
	this.redeemTransaction.getInput(0).setScriptSig(
			new ScriptBuilder()
			.data(this.redeemTransaction.calculateSignature(0, getParentPeerKey(), null,
					this.refundTransaction.getOutput(this.iAmInitiator ? 0 : 1).getScriptBytes(), SigHash.ALL,
						false)
					.encodeToBitcoin())
			.data(this.committedPreImage)
			.build());
	getParentPeer().wallet().addWalletTransaction(
			new WalletTransaction(WalletTransaction.Pool.PENDING, this.redeemTransaction));
	getParentPeer().peerGroup().broadcastTransaction(this.redeemTransaction);
	this.state = State.CLOSING;
}
 
开发者ID:aakselrod,项目名称:libtxchain-java,代码行数:23,代码来源:PaymentChannel.java

示例9: addWalletTransaction

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的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.isLocked());
    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;
    case PENDING_INACTIVE:
        checkState(pending.put(tx.getHash(), tx) == null);
        break;
    default:
        throw new RuntimeException("Unknown wallet transaction type " + pool);
    }
    // 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(txConfidenceListener);
}
 
开发者ID:praus,项目名称:multicoinj,代码行数:29,代码来源:Wallet.java

示例10: receiveAPendingTransaction

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
private void receiveAPendingTransaction(Wallet wallet, Address toAddress) throws Exception {
    BigInteger v1 = Utils.toNanoCoins(1, 0);
    final ListenableFuture<BigInteger> availFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.AVAILABLE);
    final ListenableFuture<BigInteger> estimatedFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.ESTIMATED);
    assertFalse(availFuture.isDone());
    assertFalse(estimatedFuture.isDone());
    Transaction t1 = sendMoneyToWallet(wallet, v1, toAddress, null);
    final ListenableFuture<Transaction> depthFuture = t1.getConfidence().getDepthFuture(1);
    assertFalse(depthFuture.isDone());
    assertEquals(BigInteger.ZERO, wallet.getBalance());
    assertEquals(v1, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
    assertFalse(availFuture.isDone());
    assertTrue(estimatedFuture.isDone());
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    sendMoneyToWallet(wallet, t1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals("Incorrect confirmed tx balance", v1, wallet.getBalance());
    assertEquals("Incorrect confirmed tx PENDING pool size", 0, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals("Incorrect confirmed tx UNSPENT pool size", 1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals("Incorrect confirmed tx ALL pool size", 1, wallet.getPoolSize(WalletTransaction.Pool.ALL));
    assertTrue(availFuture.isDone());
    assertTrue(estimatedFuture.isDone());
    assertTrue(depthFuture.isDone());
}
 
开发者ID:praus,项目名称:multicoinj,代码行数:25,代码来源:WalletTest.java

示例11: replayWhilstPending

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void replayWhilstPending() throws Exception {
    // Check that if a pending transaction spends outputs of chain-included transactions, we mark them as spent.
    // See bug 345. This can happen if there is a pending transaction floating around and then you replay the
    // chain without emptying the memory pool (or refilling it from a peer).
    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction tx1 = createFakeTx(params, value, myAddress);
    Transaction tx2 = new Transaction(params);
    tx2.addInput(tx1.getOutput(0));
    tx2.addOutput(Utils.toNanoCoins(0, 9), new ECKey());
    // Add a change address to ensure this tx is relevant.
    tx2.addOutput(Utils.toNanoCoins(0, 1), wallet.getChangeAddress());
    wallet.receivePending(tx2, null);
    BlockPair bp = createFakeBlock(blockStore, tx1);
    wallet.receiveFromBlock(tx1, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    wallet.notifyNewBestBlock(bp.storedBlock);
    assertEquals(BigInteger.ZERO, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(Pool.SPENT));
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
}
 
开发者ID:praus,项目名称:multicoinj,代码行数:22,代码来源:WalletTest.java

示例12: isPendingTransactionRelevant

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
/**
 * This method is used by a {@link Peer} to find out if a transaction that has been announced is interesting,
 * that is, whether we should bother downloading its dependencies and exploring the transaction to decide how
 * risky it is. If this method returns true then {@link Wallet#receivePending(Transaction, java.util.List)}
 * will soon be called with the transactions dependencies as well.
 */
public boolean isPendingTransactionRelevant(Transaction tx) throws ScriptException {
    lock.lock();
    try {
        // 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 false;
        }

        // We only care about transactions that:
        //   - Send us coins
        //   - Spend our coins
        if (!isTransactionRelevant(tx)) {
            log.debug("Received tx that isn't relevant to this wallet, discarding.");
            return false;
        }

        if (isTransactionRisky(tx, null) && !acceptRiskyTransactions) {
            log.warn("Received transaction {} with a lock time of {}, but not configured to accept these, discarding",
                    tx.getHashAsString(), tx.getLockTime());
            return false;
        }
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:36,代码来源:Wallet.java

示例13: getWalletTransactions

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
/**
 * Returns a set of all WalletTransactions in the wallet.
 */
public Iterable<WalletTransaction> getWalletTransactions() {
    lock.lock();
    try {
        Set<WalletTransaction> all = new HashSet<WalletTransaction>();
        addWalletTransactionsToSet(all, Pool.UNSPENT, unspent.values());
        addWalletTransactionsToSet(all, Pool.SPENT, spent.values());
        addWalletTransactionsToSet(all, Pool.DEAD, dead.values());
        addWalletTransactionsToSet(all, Pool.PENDING, pending.values());
        return all;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:17,代码来源:Wallet.java

示例14: addWalletTransaction

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的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;
    case PENDING_INACTIVE:
        checkState(pending.put(tx.getHash(), tx) == null);
        break;
    default:
        throw new RuntimeException("Unknown wallet transaction type " + pool);
    }
    // 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(txConfidenceListener);
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:30,代码来源:Wallet.java

示例15: getRecentTransactions

import com.google.bitcoin.core.WalletTransaction.Pool; //导入依赖的package包/类
/**
 * Returns an list of N transactions, ordered by increasing age. Transactions on side chains are not included.
 * Dead transactions (overridden by double spends) are optionally included. <p>
 * <p/>
 * Note: the current implementation is O(num transactions in wallet). Regardless of how many transactions are
 * requested, the cost is always the same. In future, requesting smaller numbers of transactions may be faster
 * depending on how the wallet is implemented (eg if backed by a database).
 */
public List<Transaction> getRecentTransactions(int numTransactions, boolean includeDead) {
    lock.lock();
    try {
        checkArgument(numTransactions >= 0);
        // Firstly, put all transactions into an array.
        int size = getPoolSize(Pool.UNSPENT) +
                getPoolSize(Pool.SPENT) +
                getPoolSize(Pool.PENDING);
        if (numTransactions > size || numTransactions == 0) {
            numTransactions = size;
        }
        ArrayList<Transaction> all = new ArrayList<Transaction>(getTransactions(includeDead));
        // Order by date.
        Collections.sort(all, Collections.reverseOrder(new Comparator<Transaction>() {
            public int compare(Transaction t1, Transaction t2) {
                return t1.getUpdateTime().compareTo(t2.getUpdateTime());
            }
        }));
        if (numTransactions == all.size()) {
            return all;
        } else {
            all.subList(numTransactions, all.size()).clear();
            return all;
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:37,代码来源:Wallet.java


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