mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SendRequest req = SendRequest.forTx(tx);
|
boolean emptyWallet = tx.getOutputs().size() == 1 && tx.getOutput(0).getValue().equals(balance);
|
||||||
if (coinSelector != null) {
|
if (emptyWallet) {
|
||||||
req.coinSelector = coinSelector;
|
|
||||||
req.recipientsPayFees = true;
|
|
||||||
}
|
|
||||||
if (tx.getOutputs().size() == 1 && tx.getOutput(0).getValue().equals(balance)) {
|
|
||||||
log.info("Emptying out wallet, recipient may get less than what you expect");
|
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) {
|
if (password != null) {
|
||||||
req.aesKey = passwordToKey(true);
|
aesKey = passwordToKey(true);
|
||||||
if (req.aesKey == null)
|
if (aesKey == null)
|
||||||
return; // Error message already printed.
|
return; // Error message already printed.
|
||||||
|
} else {
|
||||||
|
aesKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendRequest req = buildSendRequest(tx, emptyWallet, allowUnconfirmed, coinSelector, feePerVkb, aesKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wallet.completeTx(req);
|
wallet.completeTx(req);
|
||||||
} catch (InsufficientMoneyException e) {
|
} 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 {
|
static class OutputSpec {
|
||||||
public final Coin value;
|
public final Coin value;
|
||||||
public final Address addr;
|
public final Address addr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue