mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
Wallet: use getInputSum()
in completeTx()
, separately warn about null
values
Note that this changes behavior slightly. We are now warning on inputs with null value and skipping inputs with no value in the sum. Previously we were checking for non-null getConnectedOutput(). I reviewed the code and whenever getConnectedOutput() is non-null, getValue() should also be non-null. There might be cases where we have a value and no connected output, but in those cases I think we should use the value.
This commit is contained in:
parent
9f76385c9d
commit
15a9086122
1 changed files with 8 additions and 6 deletions
|
@ -4540,13 +4540,15 @@ public class Wallet extends BaseTaggableObject
|
|||
log.info("Completing send tx with {} outputs totalling {} and a fee of {}/vkB", req.tx.getOutputs().size(),
|
||||
req.tx.getOutputSum().toFriendlyString(), req.feePerKb.toFriendlyString());
|
||||
|
||||
// Warn if there are unconnected inputs whose value we do not know
|
||||
// TODO: Consider throwing if there are inputs that we don't have a value for
|
||||
if (req.tx.getInputs().stream()
|
||||
.map(TransactionInput::getValue)
|
||||
.anyMatch(Objects::isNull))
|
||||
log.warn("SendRequest transaction already has inputs but we don't know how much they are worth - they will be added to fee.");
|
||||
|
||||
// If any inputs have already been added, we don't need to get their value from wallet
|
||||
Coin totalInput = Coin.ZERO;
|
||||
for (TransactionInput input : req.tx.getInputs())
|
||||
if (input.getConnectedOutput() != null)
|
||||
totalInput = totalInput.add(input.getConnectedOutput().getValue());
|
||||
else
|
||||
log.warn("SendRequest transaction already has inputs but we don't know how much they are worth - they will be added to fee.");
|
||||
Coin totalInput = req.tx.getInputSum();
|
||||
// Calculate the amount of value we need to import.
|
||||
Coin valueNeeded = req.tx.getOutputSum().subtract(totalInput);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue