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


Java SendRequest.DEFAULT_FEE_PER_KB属性代码示例

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


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

示例1: basicCategoryStepTest

@Test
public void basicCategoryStepTest() throws Exception {
    // Creates spends that step through the possible fee solver categories
    SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
    // 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).longValue()) {
        Transaction tx = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // Create a spend that will throw away change (category 3 type 2 in which the change causes fee which is worth more than change)
    SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request1);
    assertEquals(BigInteger.ONE, request1.fee);
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs

    // Give us one more input...
    Transaction tx1 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx1.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    SendRequest request2 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request2);
    assertEquals(BigInteger.ONE, request2.fee);
    assertEquals(request2.tx.getInputs().size(), i - 1); // We should have spent all inputs - 1

    // Give us one more input...
    Transaction tx2 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx2.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    // but that also could have been category 2 if it wanted
    SendRequest request3 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request3);
    assertEquals(BigInteger.ONE, request3.fee);
    assertEquals(request3.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    //
    SendRequest request4 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(BigInteger.valueOf(request3.tx.bitcoinSerialize().length));
    wallet.completeTx(request4);
    assertEquals(BigInteger.ONE, request4.fee);
    assertEquals(request4.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    // Give us a few more inputs...
    while (wallet.getBalance().compareTo(CENT.shiftLeft(1)) < 0) {
        Transaction tx3 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx3.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // ...that is just slightly less than is needed for category 1
    SendRequest request5 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request5);
    assertEquals(BigInteger.ONE, request5.fee);
    assertEquals(1, request5.tx.getOutputs().size()); // We should have no change output

    // Give us one more input...
    Transaction tx4 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx4.getInput(0).setSequenceNumber(i); // Keep every transaction unique
    wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... that puts us in category 1 (no fee!)
    SendRequest request6 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request6);
    assertEquals(BigInteger.ZERO, request6.fee);
    assertEquals(2, request6.tx.getOutputs().size()); // We should have a change output

    SendRequest.DEFAULT_FEE_PER_KB = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:80,代码来源:WalletTest.java

示例2: basicCategoryStepTest

@Test
public void basicCategoryStepTest() throws Exception {
    // Creates spends that step through the possible fee solver categories
    SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
    // 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).longValue()) {
        Transaction tx = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // Create a spend that will throw away change (category 3 type 2 in which the change causes fee which is worth more than change)
    SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request1);
    assertEquals(BigInteger.ONE, request1.fee);
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs

    // Give us one more input...
    Transaction tx1 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx1.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    SendRequest request2 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request2);
    assertEquals(BigInteger.ONE, request2.fee);
    assertEquals(request2.tx.getInputs().size(), i - 1); // We should have spent all inputs - 1

    // Give us one more input...
    Transaction tx2 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx2.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    // but that also could have been category 2 if it wanted
    SendRequest request3 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request3);
    assertEquals(BigInteger.ONE, request3.fee);
    assertEquals(request3.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    //
    SendRequest request4 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(BigInteger.valueOf(request3.tx.bitcoinSerialize().length));
    wallet.completeTx(request4);
    assertEquals(BigInteger.ONE, request4.fee);
    assertEquals(request4.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    // Give us a few more inputs...
    while (wallet.getBalance().compareTo(CENT.shiftLeft(1)) < 0) {
        Transaction tx3 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx3.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // ...that is just slightly less than is needed for category 1
    SendRequest request5 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request5);
    assertEquals(BigInteger.ONE, request5.fee);
    assertEquals(1, request5.tx.getOutputs().size()); // We should have no change output

    // Give us one more input...
    Transaction tx4 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx4.getInput(0).setSequenceNumber(i); // Keep every transaction unique
    wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... that puts us in category 1 (no fee!)
    SendRequest request6 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    wallet.completeTx(request6);

    assertEquals(BigInteger.ZERO, request6.fee);
    assertEquals(2, request6.tx.getOutputs().size()); // We should have a change output

    SendRequest.DEFAULT_FEE_PER_KB = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:81,代码来源:WalletTest.java

示例3: basicCategoryStepTest

@Test
public void basicCategoryStepTest() throws Exception {
    // Creates spends that step through the possible fee solver categories
    SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
    // 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).longValue()) {
        Transaction tx = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // Create a spend that will throw away change (category 3 type 2 in which the change causes fee which is worth more than change)
    SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    assertTrue(wallet.completeTx(request1));
    assertEquals(BigInteger.ONE, request1.fee);
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs

    // Give us one more input...
    Transaction tx1 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx1.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    SendRequest request2 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    assertTrue(wallet.completeTx(request2));
    assertEquals(BigInteger.ONE, request2.fee);
    assertEquals(request2.tx.getInputs().size(), i - 1); // We should have spent all inputs - 1

    // Give us one more input...
    Transaction tx2 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx2.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
    wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
    // but that also could have been category 2 if it wanted
    SendRequest request3 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    assertTrue(wallet.completeTx(request3));
    assertEquals(BigInteger.ONE, request3.fee);
    assertEquals(request3.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    //
    SendRequest request4 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(BigInteger.valueOf(request3.tx.bitcoinSerialize().length));
    assertTrue(wallet.completeTx(request4));
    assertEquals(BigInteger.ONE, request4.fee);
    assertEquals(request4.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2

    // Give us a few more inputs...
    while (wallet.getBalance().compareTo(CENT.shiftLeft(1)) < 0) {
        Transaction tx3 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
        tx3.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // ...that is just slightly less than is needed for category 1
    SendRequest request5 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    assertTrue(wallet.completeTx(request5));
    assertEquals(BigInteger.ONE, request5.fee);
    assertEquals(1, request5.tx.getOutputs().size()); // We should have no change output

    // Give us one more input...
    Transaction tx4 = createFakeTxWithChangeAddress(params, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, myAddress, notMyAddr);
    tx4.getInput(0).setSequenceNumber(i); // Keep every transaction unique
    wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);

    // ... that puts us in category 1 (no fee!)
    SendRequest request6 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE));
    assertTrue(wallet.completeTx(request6));
    assertEquals(BigInteger.ZERO, request6.fee);
    assertEquals(2, request6.tx.getOutputs().size()); // We should have a change output

    SendRequest.DEFAULT_FEE_PER_KB = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:80,代码来源:WalletTest.java


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