• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SendRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: spendUnconfirmedChange

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
private void spendUnconfirmedChange(Wallet wallet, Transaction t2, KeyParameter aesKey) throws Exception {
    BigInteger v3 = toNanoCoins(0, 49);
    assertEquals(v3, wallet.getBalance());
    Wallet.SendRequest req = Wallet.SendRequest.to(new ECKey().toAddress(params), toNanoCoins(0, 48));
    req.aesKey = aesKey;
    Address a = req.changeAddress = new ECKey().toAddress(params);
    req.ensureMinRequiredFee = false;
    wallet.completeTx(req);
    Transaction t3 = req.tx;
    assertEquals(a, t3.getOutput(1).getScriptPubKey().getToAddress(params));
    assertNotNull(t3);
    wallet.commitTx(t3);
    assertTrue(wallet.isConsistent());
    // t2 and t3 gets confirmed in the same block.
    BlockPair bp = createFakeBlock(blockStore, t2, t3);
    wallet.receiveFromBlock(t2, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
    wallet.receiveFromBlock(t3, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
    wallet.notifyNewBestBlock(bp.storedBlock);
    assertTrue(wallet.isConsistent());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:21,代码来源:WalletTest.java


示例2: testCategory2WithChange

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
@Test
public void testCategory2WithChange() throws Exception {
    // Specifically target case 2 with significant change

    // Make sure TestWithWallet isnt doing anything crazy.
    assertEquals(0, wallet.getTransactions(true).size());

    Address notMyAddr = new ECKey().toAddress(params);

    // Generate a ton of small outputs
    StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, notMyAddr), BigInteger.ONE, 1);
    int i = 0;
    while (i <= CENT.divide(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(BigInteger.TEN)).longValue()) {
        Transaction tx = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(BigInteger.TEN), myAddress, notMyAddr);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // The selector will choose 2 with MIN_TX_FEE fee
    SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(BigInteger.ONE));
    wallet.completeTx(request1);
    assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request1.fee);
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs
    assertEquals(2, request1.tx.getOutputs().size()); // and gotten change back
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:26,代码来源:WalletTest.java


示例3: SendBitcoinConfirmPanel

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
public SendBitcoinConfirmPanel(BitcoinController bitcoinController, MultiBitFrame mainFrame, MultiBitDialog sendBitcoinConfirmDialog, SendRequest sendRequest, String assetAmount, String assetDescription, AssetValidator validator) {
       super();
       this.bitcoinController = bitcoinController;
       this.controller = this.bitcoinController;
       this.mainFrame = mainFrame;
       this.sendBitcoinConfirmDialog = sendBitcoinConfirmDialog;
       this.sendRequest = sendRequest;

setAssetAmountLabel(assetAmount);
setAssetDescription(assetDescription);
setAssetValidator(validator);
setIsAsset(true);

       thisPanel = this;

       initUI();

       cancelButton.requestFocusInWindow();
       applyComponentOrientation(ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

       this.bitcoinController.registerWalletBusyListener(this);
   }
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:23,代码来源:SendBitcoinConfirmPanel.java


示例4: SendAssetConfirmDialog

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
/**
    * Creates a new {@link SendBitcoinConfirmDialog}.
    */
   public SendAssetConfirmDialog(BitcoinController bitcoinController, MultiBitFrame mainFrame, SendRequest sendRequest, int assetId, BigInteger assetAmountRawUnits, AssetValidator validator) {
       super(mainFrame, bitcoinController.getLocaliser().getString("sendAssetConfirmView.title"));
       this.bitcoinController = bitcoinController;
       this.controller = this.bitcoinController;
       this.mainFrame = mainFrame;
       this.sendRequest = sendRequest;

// Pass in asset related info
// Would be better if we had a single data structure we could reference (not wallet prefs)
this.assetId = assetId;
this.assetAmountRawUnits = assetAmountRawUnits;
this.validator = validator;

       ImageIcon imageIcon = ImageLoader.createImageIcon(ImageLoader.MULTIBIT_ICON_FILE);
       if (imageIcon != null) {
           setIconImage(imageIcon.getImage());
       }
       
       initUI();
       
       sendBitcoinConfirmPanel.getCancelButton().requestFocusInWindow();
       applyComponentOrientation(ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));
   }
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:27,代码来源:SendAssetConfirmDialog.java


示例5: testCategory2WithChange

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
@Test
public void testCategory2WithChange() throws Exception {
    // Specifically target case 2 with significant change

    // Make sure TestWithWallet isnt doing anything crazy.
    assertEquals(0, wallet.getTransactions(true).size());

    Address notMyAddr = new ECKey().toAddress(params);

    // Generate a ton of small outputs
    StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, notMyAddr), BigInteger.ONE, 1);
    int i = 0;
    while (i <= CENT.divide(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(BigInteger.TEN)).longValue()) {
        Transaction tx = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(BigInteger.TEN), myAddress, notMyAddr);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // The selector will choose 2 with MIN_TX_FEE fee
    SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(BigInteger.ONE));
    assertTrue(wallet.completeTx(request1));
    assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request1.fee);
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs
    assertEquals(2, request1.tx.getOutputs().size()); // and gotten change back
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:26,代码来源:WalletTest.java


示例6: cleanupCommon

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


示例7: spendOutputFromPendingTransaction

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的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,项目名称:myriadcoinj,代码行数:40,代码来源:WalletTest.java


示例8: customTransactionSpending

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的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: respectMaxStandardSize

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void respectMaxStandardSize() throws Exception {
    // Check that we won't create txns > 100kb. Average tx size is ~220 bytes so this would have to be enormous.
    sendMoneyToWallet(Utils.toNanoCoins(100, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
    Transaction tx = new Transaction(params);
    byte[] bits = new byte[20];
    new Random().nextBytes(bits);
    BigInteger v = Utils.toNanoCoins(0, 1);
    // 3100 outputs to a random address.
    for (int i = 0; i < 3100; i++) {
        tx.addOutput(v, new Address(params, bits));
    }
    Wallet.SendRequest req = Wallet.SendRequest.forTx(tx);
    wallet.completeTx(req);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:16,代码来源:WalletTest.java


示例10: testEmptyRandomWallet

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
@Test
public void testEmptyRandomWallet() throws Exception {
    // Add a random set of outputs
    StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, new ECKey().toAddress(params)), BigInteger.ONE, 1);
    Random rng = new Random();
    for (int i = 0; i < rng.nextInt(100) + 1; i++) {
        Transaction tx = createFakeTx(params, BigInteger.valueOf(rng.nextInt((int) Utils.COIN.longValue())), myAddress);
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }
    SendRequest request = SendRequest.emptyWallet(new ECKey().toAddress(params));
    wallet.completeTx(request);
    wallet.commitTx(request.tx);
    assertEquals(BigInteger.ZERO, wallet.getBalance());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:15,代码来源:WalletTest.java


示例11: completeTxPartiallySigned

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Test
public void completeTxPartiallySigned() throws Exception {
    // Check the wallet will write dummy scriptSigs for inputs that we have only pubkeys for without the privkey.
    ECKey priv = new ECKey();
    ECKey pub = new ECKey(null, priv.getPubKey());
    wallet.addKey(pub);
    ECKey priv2 = new ECKey();
    wallet.addKey(priv2);
    // Send three transactions, with one being an address type and the other being a raw CHECKSIG type pubkey only,
    // and the final one being a key we do have. We expect the first two inputs to be dummy values and the last
    // to be signed correctly.
    Transaction t1 = sendMoneyToWallet(wallet, Utils.CENT, pub.toAddress(params), AbstractBlockChain.NewBlockType.BEST_CHAIN);
    Transaction t2 = sendMoneyToWallet(wallet, Utils.CENT, pub, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    Transaction t3 = sendMoneyToWallet(wallet, Utils.CENT, priv2, AbstractBlockChain.NewBlockType.BEST_CHAIN);

    ECKey dest = new ECKey();
    Wallet.SendRequest req = Wallet.SendRequest.emptyWallet(dest.toAddress(params));
    wallet.completeTx(req);
    byte[] dummySig = TransactionSignature.dummy().encodeToBitcoin();
    // Selected inputs can be in any order.
    for (int i = 0; i < req.tx.getInputs().size(); i++) {
        TransactionInput input = req.tx.getInput(i);
        if (input.getConnectedOutput().getParentTransaction().equals(t1)) {
            assertArrayEquals(dummySig, input.getScriptSig().getChunks().get(0).data);
        } else if (input.getConnectedOutput().getParentTransaction().equals(t2)) {
            assertArrayEquals(dummySig, input.getScriptSig().getChunks().get(0).data);
        } else if (input.getConnectedOutput().getParentTransaction().equals(t3)) {
            input.getScriptSig().correctlySpends(req.tx, i, t3.getOutput(0).getScriptPubKey(), true);
        }
    }
    assertTrue(TransactionSignature.isEncodingCanonical(dummySig));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:34,代码来源:WalletTest.java


示例12: cleanupFailsDueToSpend

import com.google.bitcoin.core.Wallet.SendRequest; //导入依赖的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:cannabiscoindev,项目名称:cannabiscoinj,代码行数:33,代码来源:WalletTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AtomicLongMap类代码示例发布时间:2022-05-21
下一篇:
Java HttpSessionRequiredException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap