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


Java Threading.waitForUserCode方法代码示例

本文整理汇总了Java中org.bitcoinj.utils.Threading.waitForUserCode方法的典型用法代码示例。如果您正苦于以下问题:Java Threading.waitForUserCode方法的具体用法?Java Threading.waitForUserCode怎么用?Java Threading.waitForUserCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.utils.Threading的用法示例。


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

示例1: cleanupCommon

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
private Transaction cleanupCommon(Address destination) throws Exception {
    receiveATransaction(wallet, myAddress);

    Coin v2 = valueOf(0, 50);
    SendRequest req = SendRequest.to(destination, v2);
    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

    Coin v1 = valueOf(0, 10);
    Transaction t = sendMoneyToWallet(null, v1, myAddress);
    Threading.waitForUserCode();
    sendMoneyToWallet(null, t);
    assertEquals("Wrong number of PENDING", 2, wallet.getPoolSize(Pool.PENDING));
    assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(Pool.UNSPENT));
    assertEquals("Wrong number of ALL", 3, wallet.getTransactions(true).size());
    assertEquals(valueOf(0, 60), wallet.getBalance(Wallet.BalanceType.ESTIMATED));

    // Now we have another incoming pending
    return t;
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:27,代码来源:WalletTest.java

示例2: receiveATransactionAmount

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
private void receiveATransactionAmount(Wallet wallet, Address toAddress, Coin amount) {
    final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE);
    final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED);
    assertFalse(availFuture.isDone());
    assertFalse(estimatedFuture.isDone());
    // Send some pending coins to the wallet.
    Transaction t1 = sendMoneyToWallet(wallet, null, amount, toAddress);
    Threading.waitForUserCode();
    final ListenableFuture<TransactionConfidence> depthFuture = t1.getConfidence().getDepthFuture(1);
    assertFalse(depthFuture.isDone());
    assertEquals(ZERO, wallet.getBalance());
    assertEquals(amount, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
    assertFalse(availFuture.isDone());
    // Our estimated balance has reached the requested level.
    assertTrue(estimatedFuture.isDone());
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
    // Confirm the coins.
    sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
    assertEquals("Incorrect confirmed tx balance", amount, wallet.getBalance());
    assertEquals("Incorrect confirmed tx PENDING pool size", 0, wallet.getPoolSize(Pool.PENDING));
    assertEquals("Incorrect confirmed tx UNSPENT pool size", 1, wallet.getPoolSize(Pool.UNSPENT));
    assertEquals("Incorrect confirmed tx ALL pool size", 1, wallet.getTransactions(true).size());
    Threading.waitForUserCode();
    assertTrue(availFuture.isDone());
    assertTrue(estimatedFuture.isDone());
    assertTrue(depthFuture.isDone());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:29,代码来源:WalletTest.java

示例3: fourPeers

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Test
public void fourPeers() throws Exception {
    InboundMessageQueuer[] channels = { connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
    Transaction tx = new Transaction(params);
    TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx);
    ListenableFuture<Transaction> future = broadcast.broadcast();
    assertFalse(future.isDone());
    // We expect two peers to receive a tx message, and at least one of the others must announce for the future to
    // complete successfully.
    Message[] messages = {
            (Message) outbound(channels[0]),
            (Message) outbound(channels[1]),
            (Message) outbound(channels[2]),
            (Message) outbound(channels[3])
    };
    // 0 and 3 are randomly selected to receive the broadcast.
    assertEquals(tx, messages[0]);
    assertEquals(tx, messages[3]);
    assertNull(messages[1]);
    assertNull(messages[2]);
    Threading.waitForUserCode();
    assertFalse(future.isDone());
    inbound(channels[1], InventoryMessage.with(tx));
    pingAndWait(channels[1]);
    Threading.waitForUserCode();
    assertTrue(future.isDone());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:28,代码来源:TransactionBroadcastTest.java

示例4: cleanupCommon

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
private Transaction cleanupCommon(Address destination) throws Exception {
    receiveATransaction(wallet, myAddress);

    Coin v2 = valueOf(0, 50);
    SendRequest req = SendRequest.to(destination, v2);
    req.fee = CENT;
    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

    Coin v1 = valueOf(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(valueOf(0, 59), wallet.getBalance(Wallet.BalanceType.ESTIMATED));

    // Now we have another incoming pending
    return t;
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:28,代码来源:WalletTest.java

示例5: receiveATransactionAmount

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
private void receiveATransactionAmount(Wallet wallet, Address toAddress, Coin amount) {
    final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE);
    final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED);
    assertFalse(availFuture.isDone());
    assertFalse(estimatedFuture.isDone());
    // Send some pending coins to the wallet.
    Transaction t1 = sendMoneyToWallet(wallet, amount, toAddress, null);
    Threading.waitForUserCode();
    final ListenableFuture<Transaction> depthFuture = t1.getConfidence().getDepthFuture(1);
    assertFalse(depthFuture.isDone());
    assertEquals(ZERO, wallet.getBalance());
    assertEquals(amount, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
    assertFalse(availFuture.isDone());
    // Our estimated balance has reached the requested level.
    assertTrue(estimatedFuture.isDone());
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
    // Confirm the coins.
    sendMoneyToWallet(wallet, t1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals("Incorrect confirmed tx balance", amount, wallet.getBalance());
    assertEquals("Incorrect confirmed tx PENDING pool size", 0, wallet.getPoolSize(Pool.PENDING));
    assertEquals("Incorrect confirmed tx UNSPENT pool size", 1, wallet.getPoolSize(Pool.UNSPENT));
    assertEquals("Incorrect confirmed tx ALL pool size", 1, wallet.getTransactions(true).size());
    Threading.waitForUserCode();
    assertTrue(availFuture.isDone());
    assertTrue(estimatedFuture.isDone());
    assertTrue(depthFuture.isDone());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:29,代码来源:WalletTest.java

示例6: listener

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Test
public void listener() throws Exception {
    peerGroup.startAsync();
    peerGroup.awaitRunning();
    peerGroup.addEventListener(listener);

    // Create a couple of peers.
    InboundMessageQueuer p1 = connectPeer(1);
    InboundMessageQueuer p2 = connectPeer(2);
    connectedPeers.take();
    connectedPeers.take();

    pingAndWait(p1);
    pingAndWait(p2);
    Threading.waitForUserCode();
    assertEquals(0, disconnectedPeers.size());

    p1.close();
    disconnectedPeers.take();
    assertEquals(0, disconnectedPeers.size());
    p2.close();
    disconnectedPeers.take();
    assertEquals(0, disconnectedPeers.size());

    assertTrue(peerGroup.removeEventListener(listener));
    assertFalse(peerGroup.removeEventListener(listener));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:28,代码来源:PeerGroupTest.java

示例7: receiveATransaction

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
private void receiveATransaction(Wallet wallet, Address toAddress) throws Exception {
    Coin v1 = COIN;
    final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.AVAILABLE);
    final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.ESTIMATED);
    assertFalse(availFuture.isDone());
    assertFalse(estimatedFuture.isDone());
    // Send some pending coins to the wallet.
    Transaction t1 = sendMoneyToWallet(wallet, v1, toAddress, null);
    Threading.waitForUserCode();
    final ListenableFuture<Transaction> depthFuture = t1.getConfidence().getDepthFuture(1);
    assertFalse(depthFuture.isDone());
    assertEquals(ZERO, wallet.getBalance());
    assertEquals(v1, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
    assertFalse(availFuture.isDone());
    // Our estimated balance has reached the requested level.
    assertTrue(estimatedFuture.isDone());
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    // Confirm the coins.
    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.getTransactions(true).size());
    Threading.waitForUserCode();
    assertTrue(availFuture.isDone());
    assertTrue(estimatedFuture.isDone());
    assertTrue(depthFuture.isDone());
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:30,代码来源:WalletTest.java

示例8: recursiveDependencyDownload_depthLimited

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Test
public void recursiveDependencyDownload_depthLimited() throws Exception {
    peer.setDownloadTxDependencies(1); // Depth limit
    connect();

    // Make some fake transactions in the following graph:
    //   t1 -> t2 -> t3 -> [t4]
    // The ones in brackets are assumed to be in the chain and are represented only by hashes.
    Sha256Hash t4hash = Sha256Hash.wrap("2b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
    Transaction t3 = new Transaction(PARAMS);
    t3.addInput(new TransactionInput(PARAMS, t3, new byte[]{}, new TransactionOutPoint(PARAMS, 0, t4hash)));
    t3.addOutput(COIN, new ECKey());
    t3 = FakeTxBuilder.roundTripTransaction(PARAMS, t3);
    Transaction t2 = new Transaction(PARAMS);
    t2.addInput(t3.getOutput(0));
    t2.addOutput(COIN, new ECKey());
    t2 = FakeTxBuilder.roundTripTransaction(PARAMS, t2);
    Transaction t1 = new Transaction(PARAMS);
    t1.addInput(t2.getOutput(0));
    t1.addOutput(COIN, new ECKey());
    t1 = FakeTxBuilder.roundTripTransaction(PARAMS, t1);

    // Announce the first one. Wait for it to be downloaded.
    InventoryMessage inv = new InventoryMessage(PARAMS);
    inv.addTransaction(t1);
    inbound(writeTarget, inv);
    GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
    Threading.waitForUserCode();
    assertEquals(t1.getHash(), getdata.getItems().get(0).hash);
    inbound(writeTarget, t1);
    pingAndWait(writeTarget);
    // We want its dependencies so ask for them.
    ListenableFuture<List<Transaction>> futures = peer.downloadDependencies(t1);
    assertFalse(futures.isDone());
    // level 1
    getdata = (GetDataMessage) outbound(writeTarget);
    assertEquals(1, getdata.getItems().size());
    assertEquals(t2.getHash(), getdata.getItems().get(0).hash);
    inbound(writeTarget, t2);
    // no level 2
    getdata = (GetDataMessage) outbound(writeTarget);
    assertNull(getdata);

    // That's it, now double check what we've got
    pingAndWait(writeTarget);
    assertTrue(futures.isDone());
    List<Transaction> results = futures.get();
    assertEquals(1, results.size());
    assertTrue(results.contains(t2));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:51,代码来源:PeerTest.java

示例9: testAppearedAtChainHeightDepthAndWorkDone

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
    // Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.

    BlockChain chain = new BlockChain(PARAMS, myWallet, new MemoryBlockStore(PARAMS));

    final ArrayList<Transaction> txns = new ArrayList<Transaction>(2);
    myWallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            txns.add(tx);
        }
    });

    // Start by building two blocks on top of the genesis block.
    Block b1 = PARAMS.getGenesisBlock().createNextBlock(myAddress);
    BigInteger work1 = b1.getWork();
    assertTrue(work1.signum() > 0);

    Block b2 = b1.createNextBlock(myAddress);
    BigInteger work2 = b2.getWork();
    assertTrue(work2.signum() > 0);

    assertTrue(chain.add(b1));
    assertTrue(chain.add(b2));

    // We now have the following chain:
    //     genesis -> b1 -> b2

    // Check the transaction confidence levels are correct before wallet roundtrip.
    Threading.waitForUserCode();
    assertEquals(2, txns.size());

    TransactionConfidence confidence0 = txns.get(0).getConfidence();
    TransactionConfidence confidence1 = txns.get(1).getConfidence();

    assertEquals(1, confidence0.getAppearedAtChainHeight());
    assertEquals(2, confidence1.getAppearedAtChainHeight());

    assertEquals(2, confidence0.getDepthInBlocks());
    assertEquals(1, confidence1.getDepthInBlocks());

    // Roundtrip the wallet and check it has stored the depth and workDone.
    Wallet rebornWallet = roundTrip(myWallet);

    Set<Transaction> rebornTxns = rebornWallet.getTransactions(false);
    assertEquals(2, rebornTxns.size());

    // The transactions are not guaranteed to be in the same order so sort them to be in chain height order if required.
    Iterator<Transaction> it = rebornTxns.iterator();
    Transaction txA = it.next();
    Transaction txB = it.next();

    Transaction rebornTx0, rebornTx1;
     if (txA.getConfidence().getAppearedAtChainHeight() == 1) {
        rebornTx0 = txA;
        rebornTx1 = txB;
    } else {
        rebornTx0 = txB;
        rebornTx1 = txA;
    }

    TransactionConfidence rebornConfidence0 = rebornTx0.getConfidence();
    TransactionConfidence rebornConfidence1 = rebornTx1.getConfidence();

    assertEquals(1, rebornConfidence0.getAppearedAtChainHeight());
    assertEquals(2, rebornConfidence1.getAppearedAtChainHeight());

    assertEquals(2, rebornConfidence0.getDepthInBlocks());
    assertEquals(1, rebornConfidence1.getDepthInBlocks());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:72,代码来源:WalletProtobufSerializerTest.java

示例10: testAppearedAtChainHeightDepthAndWorkDone

import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
    // Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.

    BlockChain chain = new BlockChain(params, myWallet, new MemoryBlockStore(params));

    final ArrayList<Transaction> txns = new ArrayList<Transaction>(2);
    myWallet.addEventListener(new AbstractWalletEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            txns.add(tx);
        }
    });

    // Start by building two blocks on top of the genesis block.
    Block b1 = params.getGenesisBlock().createNextBlock(myAddress);
    BigInteger work1 = b1.getWork();
    assertTrue(work1.signum() > 0);

    Block b2 = b1.createNextBlock(myAddress);
    BigInteger work2 = b2.getWork();
    assertTrue(work2.signum() > 0);

    assertTrue(chain.add(b1));
    assertTrue(chain.add(b2));

    // We now have the following chain:
    //     genesis -> b1 -> b2

    // Check the transaction confidence levels are correct before wallet roundtrip.
    Threading.waitForUserCode();
    assertEquals(2, txns.size());

    TransactionConfidence confidence0 = txns.get(0).getConfidence();
    TransactionConfidence confidence1 = txns.get(1).getConfidence();

    assertEquals(1, confidence0.getAppearedAtChainHeight());
    assertEquals(2, confidence1.getAppearedAtChainHeight());

    assertEquals(2, confidence0.getDepthInBlocks());
    assertEquals(1, confidence1.getDepthInBlocks());

    // Roundtrip the wallet and check it has stored the depth and workDone.
    Wallet rebornWallet = roundTrip(myWallet);

    Set<Transaction> rebornTxns = rebornWallet.getTransactions(false);
    assertEquals(2, rebornTxns.size());

    // The transactions are not guaranteed to be in the same order so sort them to be in chain height order if required.
    Iterator<Transaction> it = rebornTxns.iterator();
    Transaction txA = it.next();
    Transaction txB = it.next();

    Transaction rebornTx0, rebornTx1;
     if (txA.getConfidence().getAppearedAtChainHeight() == 1) {
        rebornTx0 = txA;
        rebornTx1 = txB;
    } else {
        rebornTx0 = txB;
        rebornTx1 = txA;
    }

    TransactionConfidence rebornConfidence0 = rebornTx0.getConfidence();
    TransactionConfidence rebornConfidence1 = rebornTx1.getConfidence();

    assertEquals(1, rebornConfidence0.getAppearedAtChainHeight());
    assertEquals(2, rebornConfidence1.getAppearedAtChainHeight());

    assertEquals(2, rebornConfidence0.getDepthInBlocks());
    assertEquals(1, rebornConfidence1.getDepthInBlocks());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:72,代码来源:WalletProtobufSerializerTest.java


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