本文整理汇总了Java中com.google.bitcoin.core.Wallet.SendRequest.emptyWallet方法的典型用法代码示例。如果您正苦于以下问题:Java SendRequest.emptyWallet方法的具体用法?Java SendRequest.emptyWallet怎么用?Java SendRequest.emptyWallet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.bitcoin.core.Wallet.SendRequest
的用法示例。
在下文中一共展示了SendRequest.emptyWallet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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));
assertTrue(wallet.completeTx(request));
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
}
示例3: testEmptyWallet
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void testEmptyWallet() throws Exception {
Address outputKey = new ECKey().toAddress(params);
// Add exactly 0.01
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
Transaction tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
SendRequest request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add 1 confirmed cent and 1 unconfirmed cent. Verify only one cent is emptied because of the coin selection
// policies that are in use by default.
block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
tx = createFakeTx(params, CENT, myAddress);
wallet.receivePending(tx, null);
request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add just under 0.01
StoredBlock block2 = new StoredBlock(block.getHeader().createNextBlock(outputKey), BigInteger.ONE, 2);
tx = createFakeTx(params, CENT.subtract(BigInteger.ONE), myAddress);
wallet.receiveFromBlock(tx, block2, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT.subtract(BigInteger.ONE).subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), request.tx.getOutput(0).getValue());
// Add an unsendable value
StoredBlock block3 = new StoredBlock(block2.getHeader().createNextBlock(outputKey), BigInteger.ONE, 3);
BigInteger outputValue = Transaction.MIN_NONDUST_OUTPUT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE);
tx = createFakeTx(params, outputValue, myAddress);
wallet.receiveFromBlock(tx, block3, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
try {
wallet.completeTx(request);
fail();
} catch (InsufficientMoneyException.CouldNotAdjustDownwards e) {}
request.ensureMinRequiredFee = false;
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(outputValue, request.tx.getOutput(0).getValue());
}
示例4: testEmptyWallet
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void testEmptyWallet() throws Exception {
Address outputKey = new ECKey().toAddress(params);
// Add exactly 0.01
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
Transaction tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
SendRequest request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add 1 confirmed cent and 1 unconfirmed cent. Verify only one cent is emptied because of the coin selection
// policies that are in use by default.
block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
tx = createFakeTx(params, CENT, myAddress);
wallet.receivePending(tx, null);
request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add just under 0.01
StoredBlock block2 = new StoredBlock(block.getHeader().createNextBlock(outputKey), BigInteger.ONE, 2);
tx = createFakeTx(params, CENT.subtract(BigInteger.ONE), myAddress);
wallet.receiveFromBlock(tx, block2, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT.subtract(BigInteger.ONE).subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), request.tx.getOutput(0).getValue());
// Add an unsendable value
StoredBlock block3 = new StoredBlock(block2.getHeader().createNextBlock(outputKey), BigInteger.ONE, 3);
BigInteger outputValue = Transaction.MIN_NONDUST_OUTPUT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE);
tx = createFakeTx(params, outputValue, myAddress);
wallet.receiveFromBlock(tx, block3, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
try {
wallet.completeTx(request);
fail();
} catch (InsufficientMoneyException.CouldNotAdjustDownwards e) {}
request.ensureMinRequiredFee = false;
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(outputValue, request.tx.getOutput(0).getValue());
}
示例5: testEmptyWallet
import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void testEmptyWallet() throws Exception {
Address outputKey = new ECKey().toAddress(params);
// Add exactly 0.01
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
Transaction tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
SendRequest request = SendRequest.emptyWallet(outputKey);
assertTrue(wallet.completeTx(request));
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add 1 confirmed cent and 1 unconfirmed cent. Verify only one cent is emptied because of the coin selection
// policies that are in use by default.
block = new StoredBlock(makeSolvedTestBlock(blockStore, outputKey), BigInteger.ONE, 1);
tx = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
tx = createFakeTx(params, CENT, myAddress);
wallet.receivePending(tx, null);
request = SendRequest.emptyWallet(outputKey);
assertTrue(wallet.completeTx(request));
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT, request.tx.getOutput(0).getValue());
// Add just under 0.01
StoredBlock block2 = new StoredBlock(block.getHeader().createNextBlock(outputKey), BigInteger.ONE, 2);
tx = createFakeTx(params, CENT.subtract(BigInteger.ONE), myAddress);
wallet.receiveFromBlock(tx, block2, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
assertTrue(wallet.completeTx(request));
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(CENT.subtract(BigInteger.ONE).subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), request.tx.getOutput(0).getValue());
// Add an unsendable value
StoredBlock block3 = new StoredBlock(block2.getHeader().createNextBlock(outputKey), BigInteger.ONE, 3);
BigInteger outputValue = Transaction.MIN_NONDUST_OUTPUT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(BigInteger.ONE);
tx = createFakeTx(params, outputValue, myAddress);
wallet.receiveFromBlock(tx, block3, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
assertFalse(wallet.completeTx(request));
request.ensureMinRequiredFee = false;
assertTrue(wallet.completeTx(request));
wallet.commitTx(request.tx);
assertEquals(BigInteger.ZERO, wallet.getBalance());
assertEquals(outputValue, request.tx.getOutput(0).getValue());
}