mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
WalletTool: extract creation of SendRequest
to private method
This is a step towards an immutable `SendRequest`.
This commit is contained in:
parent
8ce4dbaff7
commit
7d00afc7a0
1 changed files with 28 additions and 14 deletions
|
@ -656,26 +656,22 @@ public class WalletTool implements Callable<Integer> {
|
|||
return;
|
||||
}
|
||||
}
|
||||
SendRequest req = SendRequest.forTx(tx);
|
||||
if (coinSelector != null) {
|
||||
req.coinSelector = coinSelector;
|
||||
req.recipientsPayFees = true;
|
||||
}
|
||||
if (tx.getOutputs().size() == 1 && tx.getOutput(0).getValue().equals(balance)) {
|
||||
boolean emptyWallet = tx.getOutputs().size() == 1 && tx.getOutput(0).getValue().equals(balance);
|
||||
if (emptyWallet) {
|
||||
log.info("Emptying out wallet, recipient may get less than what you expect");
|
||||
req.emptyWallet = true;
|
||||
}
|
||||
if (feePerVkb != null)
|
||||
req.setFeePerVkb(feePerVkb);
|
||||
if (allowUnconfirmed) {
|
||||
req.allowUnconfirmed();
|
||||
}
|
||||
|
||||
AesKey aesKey;
|
||||
if (password != null) {
|
||||
req.aesKey = passwordToKey(true);
|
||||
if (req.aesKey == null)
|
||||
aesKey = passwordToKey(true);
|
||||
if (aesKey == null)
|
||||
return; // Error message already printed.
|
||||
} else {
|
||||
aesKey = null;
|
||||
}
|
||||
|
||||
SendRequest req = buildSendRequest(tx, emptyWallet, allowUnconfirmed, coinSelector, feePerVkb, aesKey);
|
||||
|
||||
try {
|
||||
wallet.completeTx(req);
|
||||
} catch (InsufficientMoneyException e) {
|
||||
|
@ -723,6 +719,24 @@ public class WalletTool implements Callable<Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
// "Atomically" create a SendRequest. In the future SendRequest may be immutable and this method will be updated
|
||||
private SendRequest buildSendRequest(Transaction tx, boolean emptyWallet, boolean allowUnconfirmed, @Nullable CoinSelector coinSelector, @Nullable Coin feePerVkb, @Nullable AesKey aesKey) {
|
||||
SendRequest req = SendRequest.forTx(tx);
|
||||
req.emptyWallet = emptyWallet;
|
||||
if (coinSelector != null) {
|
||||
req.coinSelector = coinSelector;
|
||||
req.recipientsPayFees = true;
|
||||
}
|
||||
if (allowUnconfirmed) {
|
||||
// Note that this will overwrite the CoinSelector set above
|
||||
req.allowUnconfirmed();
|
||||
}
|
||||
if (feePerVkb != null)
|
||||
req.setFeePerVkb(feePerVkb);
|
||||
req.aesKey = aesKey;
|
||||
return req;
|
||||
}
|
||||
|
||||
static class OutputSpec {
|
||||
public final Coin value;
|
||||
public final Address addr;
|
||||
|
|
Loading…
Add table
Reference in a new issue