aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-03-28 15:39:25 -0400
committerAndrew Chow <achow101-github@achow101.com>2022-07-29 11:07:29 -0400
commit8a105ecd1aeff15f84c3883e2762bf71ad59d920 (patch)
tree5f2155df9b5e970daa41109b9dd46088b01eac72 /src/wallet/spend.cpp
parent5871b5b5ab57a0caf9b7514eb162c491c83281d5 (diff)
downloadbitcoin-8a105ecd1aeff15f84c3883e2762bf71ad59d920.tar.xz
wallet: Use CalculateMaximumSignedInputSize to indicate solvability
In AvailableCoins, we need to know whether we can solve for an output. This was done by using IsSolvable, which just calls ProduceSignature and produces a dummy signature. However, we already do that in order to get the size of the input by using CalculateMaximumSignedInputSize. As this function returns -1 if ProduceSignature fails, we can just remove the use of IsSolvable and check that input_bytes is not -1 to determine the solvability of an output.
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r--src/wallet/spend.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index c00a2cd023..cacefffe35 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -213,7 +213,10 @@ CoinsResult AvailableCoins(const CWallet& wallet,
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(output.scriptPubKey);
- bool solvable = provider ? IsSolvable(*provider, output.scriptPubKey) : false;
+ int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl);
+ // Because CalculateMaximumSignedInputSize just uses ProduceSignature and makes a dummy signature,
+ // it is safe to assume that this input is solvable if input_bytes is greater -1.
+ bool solvable = input_bytes > -1;
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
// Filter by spendable outputs only
@@ -243,7 +246,6 @@ CoinsResult AvailableCoins(const CWallet& wallet,
type = Solver(output.scriptPubKey, return_values_unused);
}
- int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl);
COutput coin(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
switch (type) {
case TxoutType::WITNESS_UNKNOWN: