本文整理汇总了Java中com.google.bitcoin.wallet.WalletTransaction.Pool类的典型用法代码示例。如果您正苦于以下问题:Java Pool类的具体用法?Java Pool怎么用?Java Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pool类属于com.google.bitcoin.wallet.WalletTransaction包,在下文中一共展示了Pool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContainingPools
import com.google.bitcoin.wallet.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();
}
}
示例2: addWalletTransaction
import com.google.bitcoin.wallet.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;
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, Threading.SAME_THREAD);
}
示例3: sideChain
import com.google.bitcoin.wallet.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.getTransactions(true).size());
BigInteger v2 = toNanoCoins(0, 50);
sendMoneyToWallet(v2, AbstractBlockChain.NewBlockType.SIDE_CHAIN);
assertEquals(2, wallet.getTransactions(true).size());
assertEquals(v1, wallet.getBalance());
assertEquals(v1.add(v2), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
示例4: spendToSameWallet
import com.google.bitcoin.wallet.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.getTransactions(true).size());
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());
}
示例5: replayWhilstPending
import com.google.bitcoin.wallet.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));
}
示例6: getPoolSize
import com.google.bitcoin.wallet.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();
}
throw new RuntimeException("Unreachable");
} finally {
lock.unlock();
}
}
示例7: bounce
import com.google.bitcoin.wallet.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.getTransactions(true).size());
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());
}
示例8: getWalletTransactions
import com.google.bitcoin.wallet.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();
}
}
示例9: cleanupCommon
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
private Transaction cleanupCommon(Address destination) throws Exception {
receiveATransaction(wallet, myAddress);
BigInteger v2 = toNanoCoins(0, 50);
SendRequest req = SendRequest.to(destination, v2);
req.fee = toNanoCoins(0, 1);
wallet.completeTx(req);
Transaction t2 = req.tx;
// Broadcast the transaction and commit.
broadcastAndCommit(wallet, t2);
// At this point we have one pending and one spent
BigInteger v1 = toNanoCoins(0, 10);
Transaction t = sendMoneyToWallet(wallet, v1, myAddress, null);
Threading.waitForUserCode();
sendMoneyToWallet(wallet, t, null);
assertEquals("Wrong number of PENDING.4", 2, wallet.getPoolSize(Pool.PENDING));
assertEquals("Wrong number of UNSPENT.4", 0, wallet.getPoolSize(Pool.UNSPENT));
assertEquals("Wrong number of ALL.4", 3, wallet.getTransactions(true).size());
assertEquals(toNanoCoins(0, 59), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
// Now we have another incoming pending
return t;
}
示例10: getRecentTransactions
import com.google.bitcoin.wallet.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();
}
}
示例11: isConsistent_pools
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void isConsistent_pools() throws Exception {
// This test ensures that isConsistent catches transactions that are in incompatible pools.
Transaction tx = createFakeTx(params, Utils.toNanoCoins(1, 0), myAddress);
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, Utils.toNanoCoins(0, 5), someOtherGuy);
tx.addOutput(output);
wallet.receiveFromBlock(tx, null, BlockChain.NewBlockType.BEST_CHAIN, 0);
assertTrue(wallet.isConsistent());
wallet.addWalletTransaction(new WalletTransaction(Pool.PENDING, tx));
assertFalse(wallet.isConsistent());
}
示例12: cleanup
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void cleanup() throws Exception {
Address destination = new ECKey().toAddress(params);
Transaction t = cleanupCommon(destination);
// Consider the new pending as risky and remove it from the wallet
wallet.setRiskAnalyzer(new TestRiskAnalysis.Analyzer(t));
wallet.cleanup();
assertTrue(wallet.isConsistent());
assertEquals("Wrong number of PENDING.5", 1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals("Wrong number of UNSPENT.5", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals("Wrong number of ALL.5", 2, wallet.getTransactions(true).size());
assertEquals(toNanoCoins(0, 49), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
示例13: customTransactionSpending
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void customTransactionSpending() throws Exception {
// We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
BigInteger v1 = Utils.toNanoCoins(3, 0);
sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(v1, wallet.getBalance());
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals(1, wallet.getTransactions(true).size());
ECKey k2 = new ECKey();
Address a2 = k2.toAddress(params);
BigInteger v2 = toNanoCoins(0, 50);
BigInteger v3 = toNanoCoins(0, 75);
BigInteger v4 = toNanoCoins(1, 25);
Transaction t2 = new Transaction(params);
t2.addOutput(v2, a2);
t2.addOutput(v3, a2);
t2.addOutput(v4, a2);
SendRequest req = SendRequest.forTx(t2);
req.ensureMinRequiredFee = false;
wallet.completeTx(req);
// Do some basic sanity checks.
assertEquals(1, t2.getInputs().size());
assertEquals(myAddress, t2.getInputs().get(0).getScriptSig().getFromAddress(params));
assertEquals(TransactionConfidence.ConfidenceType.UNKNOWN, t2.getConfidence().getConfidenceType());
// We have NOT proven that the signature is correct!
wallet.commitTx(t2);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.SPENT));
assertEquals(2, wallet.getTransactions(true).size());
}
示例14: balance
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void balance() throws Exception {
// Receive 5 coins then half a coin.
BigInteger v1 = toNanoCoins(5, 0);
BigInteger v2 = toNanoCoins(0, 50);
BigInteger expected = toNanoCoins(5, 50);
assertEquals(0, wallet.getTransactions(true).size());
sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
sendMoneyToWallet(v2, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals(expected, wallet.getBalance());
// Now spend one coin.
BigInteger v3 = toNanoCoins(1, 0);
Transaction spend = wallet.createSend(new ECKey().toAddress(params), v3);
wallet.commitTx(spend);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
// Available and estimated balances should not be the same. We don't check the exact available balance here
// because it depends on the coin selection algorithm.
assertEquals(toNanoCoins(4, 50), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertFalse(wallet.getBalance(Wallet.BalanceType.AVAILABLE).equals(
wallet.getBalance(Wallet.BalanceType.ESTIMATED)));
// Now confirm the transaction by including it into a block.
StoredBlock b3 = createFakeBlock(blockStore, spend).storedBlock;
wallet.receiveFromBlock(spend, b3, BlockChain.NewBlockType.BEST_CHAIN, 0);
// Change is confirmed. We started with 5.50 so we should have 4.50 left.
BigInteger v4 = toNanoCoins(4, 50);
assertEquals(v4, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
}
示例15: isConsistent_spent
import com.google.bitcoin.wallet.WalletTransaction.Pool; //导入依赖的package包/类
@Test
public void isConsistent_spent() throws Exception {
// This test ensures that isConsistent catches transactions that are marked spent when
// they aren't.
Transaction tx = createFakeTx(params, Utils.toNanoCoins(1, 0), myAddress);
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, Utils.toNanoCoins(0, 5), someOtherGuy);
tx.addOutput(output);
assertTrue(wallet.isConsistent());
wallet.addWalletTransaction(new WalletTransaction(Pool.SPENT, tx));
assertFalse(wallet.isConsistent());
}