本文整理汇总了Java中com.google.bitcoin.core.Wallet.SendRequest.to方法的典型用法代码示例。如果您正苦于以下问题:Java SendRequest.to方法的具体用法?Java SendRequest.to怎么用?Java SendRequest.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.bitcoin.core.Wallet.SendRequest
的用法示例。
在下文中一共展示了SendRequest.to方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
}
示例2: 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;
}
示例3: 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));
}
示例4: testCompleteTxWithExistingInputs
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void testCompleteTxWithExistingInputs() throws Exception {
// Tests calling completeTx with a SendRequest that already has a few inputs in it
// Make sure TestWithWallet isnt doing anything crazy.
assertEquals(0, wallet.getTransactions(true).size());
Address notMyAddr = new ECKey().toAddress(params);
// Generate a few outputs to us
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, notMyAddr), BigInteger.ONE, 1);
Transaction tx1 = createFakeTx(params, Utils.COIN, myAddress);
wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
Transaction tx2 = createFakeTx(params, Utils.COIN, myAddress); assertTrue(!tx1.getHash().equals(tx2.getHash()));
wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
Transaction tx3 = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 2);
SendRequest request1 = SendRequest.to(notMyAddr, CENT);
// If we just complete as-is, we will use one of the COIN outputs to get higher priority,
// resulting in a change output
wallet.completeTx(request1);
assertEquals(1, request1.tx.getInputs().size());
assertEquals(2, request1.tx.getOutputs().size());
assertEquals(CENT, request1.tx.getOutput(0).getValue());
assertEquals(Utils.COIN.subtract(CENT), request1.tx.getOutput(1).getValue());
// Now create an identical request2 and add an unsigned spend of the CENT output
SendRequest request2 = SendRequest.to(notMyAddr, CENT);
request2.tx.addInput(tx3.getOutput(0));
// Now completeTx will result in one input, one output
wallet.completeTx(request2);
assertEquals(1, request2.tx.getInputs().size());
assertEquals(1, request2.tx.getOutputs().size());
assertEquals(CENT, request2.tx.getOutput(0).getValue());
// Make sure it was properly signed
request2.tx.getInput(0).getScriptSig().correctlySpends(request2.tx, 0, tx3.getOutput(0).getScriptPubKey(), true);
// However, if there is no connected output, we will grab a COIN output anyway and add the CENT to fee
SendRequest request3 = SendRequest.to(notMyAddr, CENT);
request3.tx.addInput(new TransactionInput(params, request3.tx, new byte[]{}, new TransactionOutPoint(params, 0, tx3.getHash())));
// Now completeTx will result in two inputs, two outputs and a fee of a CENT
// Note that it is simply assumed that the inputs are correctly signed, though in fact the first is not
wallet.completeTx(request3);
assertEquals(2, request3.tx.getInputs().size());
assertEquals(2, request3.tx.getOutputs().size());
assertEquals(CENT, request3.tx.getOutput(0).getValue());
assertEquals(Utils.COIN.subtract(CENT), request3.tx.getOutput(1).getValue());
SendRequest request4 = SendRequest.to(notMyAddr, CENT);
request4.tx.addInput(tx3.getOutput(0));
// Now if we manually sign it, completeTx will not replace our signature
request4.tx.signInputs(SigHash.ALL, wallet);
byte[] scriptSig = request4.tx.getInput(0).getScriptBytes();
wallet.completeTx(request4);
assertEquals(1, request4.tx.getInputs().size());
assertEquals(1, request4.tx.getOutputs().size());
assertEquals(CENT, request4.tx.getOutput(0).getValue());
assertArrayEquals(scriptSig, request4.tx.getInput(0).getScriptBytes());
}
示例5: feePerKbCategoryJumpTest
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void feePerKbCategoryJumpTest() throws Exception {
// Simple test of boundary condition on fee per kb in category fee solver
// 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);
Transaction tx = createFakeTx(params, Utils.COIN, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
Transaction tx2 = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
Transaction tx3 = createFakeTx(params, BigInteger.ONE, myAddress);
wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 2);
// Create a transaction who's max size could be up to 1000 (if signatures were maximum size)
SendRequest request1 = SendRequest.to(notMyAddr, Utils.COIN.subtract(CENT.multiply(BigInteger.valueOf(17))));
for (int i = 0; i < 16; i++)
request1.tx.addOutput(CENT, notMyAddr);
request1.tx.addOutput(new TransactionOutput(params, request1.tx, CENT, new byte[16]));
request1.fee = BigInteger.ONE;
request1.feePerKb = BigInteger.ONE;
// We get a category 2 using COIN+CENT
// It spends COIN + 1(fee) and because its output is thus < CENT, we have to pay MIN_TX_FEE
// When it tries category 1, its too large and requires COIN + 2 (fee)
// This adds the next input, but still has a < CENT output which means it cant reach category 1
wallet.completeTx(request1);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request1.fee);
assertEquals(2, request1.tx.getInputs().size());
// We then add one more satoshi output to the wallet
Transaction tx4 = createFakeTx(params, BigInteger.ONE, myAddress);
wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 3);
// Create a transaction who's max size could be up to 1000 (if signatures were maximum size)
SendRequest request2 = SendRequest.to(notMyAddr, Utils.COIN.subtract(CENT.multiply(BigInteger.valueOf(17))));
for (int i = 0; i < 16; i++)
request2.tx.addOutput(CENT, notMyAddr);
request2.tx.addOutput(new TransactionOutput(params, request2.tx, CENT, new byte[16]));
request2.feePerKb = BigInteger.ONE;
// The process is the same as above, but now we can complete category 1 with one more input, and pay a fee of 2
wallet.completeTx(request2);
assertEquals(BigInteger.valueOf(2), request2.fee);
assertEquals(4, request2.tx.getInputs().size());
}
示例6: basicCategoryStepTest
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@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;
}
示例7: testCompleteTxWithExistingInputs
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void testCompleteTxWithExistingInputs() throws Exception {
// Tests calling completeTx with a SendRequest that already has a few inputs in it
// Make sure TestWithWallet isnt doing anything crazy.
assertEquals(0, wallet.getTransactions(true).size());
Address notMyAddr = new ECKey().toAddress(params);
// Generate a few outputs to us
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, notMyAddr), BigInteger.ONE, 1);
Transaction tx1 = createFakeTx(params, Utils.COIN, myAddress);
wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
Transaction tx2 = createFakeTx(params, Utils.COIN, myAddress); assertTrue(!tx1.getHash().equals(tx2.getHash()));
wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
Transaction tx3 = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 2);
SendRequest request1 = SendRequest.to(notMyAddr, CENT);
// If we just complete as-is, we will use one of the COIN outputs to get higher priority,
// resulting in a change output
assertNotNull(wallet.completeTx(request1));
assertEquals(1, request1.tx.getInputs().size());
assertEquals(2, request1.tx.getOutputs().size());
assertEquals(CENT, request1.tx.getOutput(0).getValue());
assertEquals(Utils.COIN.subtract(CENT), request1.tx.getOutput(1).getValue());
// Now create an identical request2 and add an unsigned spend of the CENT output
SendRequest request2 = SendRequest.to(notMyAddr, CENT);
request2.tx.addInput(tx3.getOutput(0));
// Now completeTx will result in one input, one output
assertTrue(wallet.completeTx(request2));
assertEquals(1, request2.tx.getInputs().size());
assertEquals(1, request2.tx.getOutputs().size());
assertEquals(CENT, request2.tx.getOutput(0).getValue());
// Make sure it was properly signed
request2.tx.getInput(0).getScriptSig().correctlySpends(request2.tx, 0, tx3.getOutput(0).getScriptPubKey(), true);
// However, if there is no connected output, we will grab a COIN output anyway and add the CENT to fee
SendRequest request3 = SendRequest.to(notMyAddr, CENT);
request3.tx.addInput(new TransactionInput(params, request3.tx, new byte[]{}, new TransactionOutPoint(params, 0, tx3.getHash())));
// Now completeTx will result in two inputs, two outputs and a fee of a CENT
// Note that it is simply assumed that the inputs are correctly signed, though in fact the first is not
assertTrue(wallet.completeTx(request3));
assertEquals(2, request3.tx.getInputs().size());
assertEquals(2, request3.tx.getOutputs().size());
assertEquals(CENT, request3.tx.getOutput(0).getValue());
assertEquals(Utils.COIN.subtract(CENT), request3.tx.getOutput(1).getValue());
SendRequest request4 = SendRequest.to(notMyAddr, CENT);
request4.tx.addInput(tx3.getOutput(0));
// Now if we manually sign it, completeTx will not replace our signature
request4.tx.signInputs(SigHash.ALL, wallet);
byte[] scriptSig = request4.tx.getInput(0).getScriptBytes();
assertTrue(wallet.completeTx(request4));
assertEquals(1, request4.tx.getInputs().size());
assertEquals(1, request4.tx.getOutputs().size());
assertEquals(CENT, request4.tx.getOutput(0).getValue());
assertArrayEquals(scriptSig, request4.tx.getInput(0).getScriptBytes());
}
示例8: basicCategoryStepTest
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@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;
}