aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorSjors Provoost <[email protected]>2019-10-23 15:21:50 +0200
committerSjors Provoost <[email protected]>2020-02-04 11:20:25 +0100
commit92bcd70808b9cac56b184903aa6d37baf9641b37 (patch)
tree0faa43d78dc9851c88308ef0c5a5943b9379fe32 /src/wallet/wallet.cpp
parent[wallet] CreateTransaction: simplify change address check (diff)
downloaddiscoin-92bcd70808b9cac56b184903aa6d37baf9641b37.tar.xz
discoin-92bcd70808b9cac56b184903aa6d37baf9641b37.zip
[wallet] allow transaction without change if keypool is empty
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 8e20f48ae..5b4781bea 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2629,13 +2629,14 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
// rediscover unknown transactions that were written with keys of ours to recover
// post-backup change.
- // Reserve a new key pair from key pool
+ // Reserve a new key pair from key pool. If it fails, provide a dummy
+ // destination in case we don't need change.
CTxDestination dest;
if (!reservedest.GetReservedDestination(dest, true)) {
- strFailReason = _("Can't generate a change-address key. Please call keypoolrefill first.").translated;
- return false;
+ strFailReason = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.").translated;
}
scriptChange = GetScriptForDestination(dest);
+ assert(!dest.empty() || scriptChange.empty());
}
CTxOut change_prototype_txout(0, scriptChange);
coin_selection_params.change_output_size = GetSerializeSize(change_prototype_txout);
@@ -2851,6 +2852,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
coin_selection_params.use_bnb = false;
continue;
}
+
+ // Give up if change keypool ran out and we failed to find a solution without change:
+ if (scriptChange.empty() && nChangePosInOut != -1) {
+ return false;
+ }
}
// Shuffle selected coins and fill in final vin