WalletTool: simplify coinSelector lambdas

This commit is contained in:
Sean Gilligan 2023-09-06 10:55:12 -07:00 committed by Andreas Schildbach
parent 853aeebd81
commit e186ef9c84

View file

@ -445,8 +445,7 @@ public class WalletTool implements Callable<Integer> {
final Address validSelectAddr = selectAddr; final Address validSelectAddr = selectAddr;
coinSelector = CoinSelector.fromPredicate(candidate -> { coinSelector = CoinSelector.fromPredicate(candidate -> {
try { try {
Address candidateAddr = candidate.getScriptPubKey().getToAddress(net); return candidate.getScriptPubKey().getToAddress(net).equals(validSelectAddr);
return validSelectAddr.equals(candidateAddr);
} catch (ScriptException x) { } catch (ScriptException x) {
return false; return false;
} }
@ -456,11 +455,9 @@ public class WalletTool implements Callable<Integer> {
String[] parts = selectOutputStr.split(":", 2); String[] parts = selectOutputStr.split(":", 2);
Sha256Hash selectTransactionHash = Sha256Hash.wrap(parts[0]); Sha256Hash selectTransactionHash = Sha256Hash.wrap(parts[0]);
int selectIndex = Integer.parseInt(parts[1]); int selectIndex = Integer.parseInt(parts[1]);
coinSelector = CoinSelector.fromPredicate(candidate -> { coinSelector = CoinSelector.fromPredicate(candidate ->
int candidateIndex = candidate.getIndex(); candidate.getIndex() == selectIndex && candidate.getParentTransactionHash().equals(selectTransactionHash)
Sha256Hash candidateTransactionHash = candidate.getParentTransactionHash(); );
return selectIndex == candidateIndex && selectTransactionHash.equals(candidateTransactionHash);
});
} }
send(coinSelector, outputsStr, feePerVkb, lockTimeStr, allowUnconfirmed); send(coinSelector, outputsStr, feePerVkb, lockTimeStr, allowUnconfirmed);
} else if (paymentRequestLocationStr != null) { } else if (paymentRequestLocationStr != null) {