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


Java WalletTransaction类代码示例

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


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

示例1: sideChain

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:17,代码来源:WalletTest.java

示例2: bounce

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:23,代码来源:WalletTest.java

示例3: spendToSameWallet

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:21,代码来源:WalletTest.java

示例4: getProtoPool

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的package包/类
private static Protos.Transaction.Pool getProtoPool(WalletTransaction wtx) {
    switch (wtx.getPool()) {
        case UNSPENT: return Protos.Transaction.Pool.UNSPENT;
        case SPENT: return Protos.Transaction.Pool.SPENT;
        case DEAD: return Protos.Transaction.Pool.DEAD;
        case PENDING: return Protos.Transaction.Pool.PENDING;
        default:
            throw new RuntimeException("Unreachable");
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:11,代码来源:WalletProtobufSerializer.java

示例5: cleanup

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:16,代码来源:WalletTest.java

示例6: cleanupFailsDueToSpend

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的package包/类
@Test
public void cleanupFailsDueToSpend() throws Exception {
    Address destination = new ECKey().toAddress(params);
    Transaction t = cleanupCommon(destination);

    // Now we have another incoming pending.  Spend everything.
    BigInteger v3 = toNanoCoins(0, 58);
    SendRequest req = SendRequest.to(destination, v3);

    // Force selection of the incoming coin so that we can spend it
    req.coinSelector = new TestCoinSelector();

    req.fee = toNanoCoins(0, 1);
    wallet.completeTx(req);
    wallet.commitTx(req.tx);

    assertEquals("Wrong number of PENDING.5", 3, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals("Wrong number of UNSPENT.5", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals("Wrong number of ALL.5", 4, wallet.getTransactions(true).size());

    // Consider the new pending as risky and try to remove it from the wallet
    wallet.setRiskAnalyzer(new TestRiskAnalysis.Analyzer(t));

    wallet.cleanup();
    assertTrue(wallet.isConsistent());

    // The removal should have failed
    assertEquals("Wrong number of PENDING.5", 3, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals("Wrong number of UNSPENT.5", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals("Wrong number of ALL.5", 4, wallet.getTransactions(true).size());
    assertEquals(toNanoCoins(0, 0), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:33,代码来源:WalletTest.java

示例7: receiveATransaction

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的package包/类
private void receiveATransaction(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());
    // 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(BigInteger.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:HashEngineering,项目名称:megacoinj,代码行数:30,代码来源:WalletTest.java

示例8: customTransactionSpending

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:35,代码来源:WalletTest.java

示例9: balance

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:34,代码来源:WalletTest.java

示例10: isConsistent_pools

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:15,代码来源:WalletTest.java

示例11: isConsistent_spent

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的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());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:14,代码来源:WalletTest.java

示例12: spendOutputFromPendingTransaction

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的package包/类
@Test
public void spendOutputFromPendingTransaction() 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(1, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // First create our current transaction
    ECKey k2 = new ECKey();
    wallet.addKey(k2);
    BigInteger v2 = toNanoCoins(0, 50);
    Transaction t2 = new Transaction(params);
    TransactionOutput o2 = new TransactionOutput(params, t2, v2, k2.toAddress(params));
    t2.addOutput(o2);
    SendRequest req = SendRequest.forTx(t2);
    req.ensureMinRequiredFee = false;
    wallet.completeTx(req);

    // Commit t2, so it is placed in the pending pool
    wallet.commitTx(t2);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(2, wallet.getTransactions(true).size());

    // Now try to the spend the output.
    ECKey k3 = new ECKey();
    BigInteger v3 = toNanoCoins(0, 25);
    Transaction t3 = new Transaction(params);
    t3.addOutput(v3, k3.toAddress(params));
    t3.addInput(o2);
    t3.signInputs(SigHash.ALL, wallet);

    // Commit t3, so the coins from the pending t2 are spent
    wallet.commitTx(t3);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(3, wallet.getTransactions(true).size());

    // Now the output of t2 must not be available for spending
    assertFalse(o2.isAvailableForSpending());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:40,代码来源:WalletTest.java

示例13: getTransactions

import com.google.bitcoin.wallet.WalletTransaction; //导入依赖的package包/类
public Iterable<WalletTransaction> getTransactions() {
    if (mHDReceiver == null)
        return null;

    if (mState != State.READY)
        return null;

    return mKit.wallet().getWalletTransactions();
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:10,代码来源:WalletService.java


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