Skip to content

Commit 8a105ec

Browse files
committed
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.
1 parent 5871b5b commit 8a105ec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/wallet/spend.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ CoinsResult AvailableCoins(const CWallet& wallet,
213213

214214
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(output.scriptPubKey);
215215

216-
bool solvable = provider ? IsSolvable(*provider, output.scriptPubKey) : false;
216+
int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl);
217+
// Because CalculateMaximumSignedInputSize just uses ProduceSignature and makes a dummy signature,
218+
// it is safe to assume that this input is solvable if input_bytes is greater -1.
219+
bool solvable = input_bytes > -1;
217220
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
218221

219222
// Filter by spendable outputs only
@@ -243,7 +246,6 @@ CoinsResult AvailableCoins(const CWallet& wallet,
243246
type = Solver(output.scriptPubKey, return_values_unused);
244247
}
245248

246-
int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl);
247249
COutput coin(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
248250
switch (type) {
249251
case TxoutType::WITNESS_UNKNOWN:

0 commit comments

Comments
 (0)