Skip to content

Commit a4af324

Browse files
committed
Use CWallet::SignTransaction in CreateTransaction and signrawtransactionwithwallet
Instead of duplicating signing code, just use the function we already have.
1 parent f37de92 commit a4af324

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,23 +3329,15 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
33293329
// Parse the prevtxs array
33303330
ParsePrevouts(request.params[1], nullptr, coins);
33313331

3332-
std::set<std::shared_ptr<SigningProvider>> providers;
3333-
for (const std::pair<COutPoint, Coin> coin_pair : coins) {
3334-
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(coin_pair.second.out.scriptPubKey);
3335-
if (provider) {
3336-
providers.insert(std::move(provider));
3337-
}
3338-
}
3339-
if (providers.size() == 0) {
3340-
// When there are no available providers, use a dummy SigningProvider so we can check if the tx is complete
3341-
providers.insert(std::make_shared<SigningProvider>());
3342-
}
3332+
int nHashType = ParseSighashString(request.params[2]);
33433333

3334+
// Script verification errors
3335+
std::map<int, std::string> input_errors;
3336+
3337+
bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
33443338
UniValue result(UniValue::VOBJ);
3345-
for (std::shared_ptr<SigningProvider> provider : providers) {
3346-
SignTransaction(mtx, provider.get(), coins, request.params[2], result);
3347-
}
3348-
return result;
3339+
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
3340+
return result;
33493341
}
33503342

33513343
static UniValue bumpfee(const JSONRPCRequest& request)

src/wallet/wallet.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,25 +2923,9 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
29232923
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
29242924
}
29252925

2926-
if (sign)
2927-
{
2928-
int nIn = 0;
2929-
for (const auto& coin : selected_coins)
2930-
{
2931-
const CScript& scriptPubKey = coin.txout.scriptPubKey;
2932-
SignatureData sigdata;
2933-
2934-
std::unique_ptr<SigningProvider> provider = GetSigningProvider(scriptPubKey);
2935-
if (!provider || !ProduceSignature(*provider, MutableTransactionSignatureCreator(&txNew, nIn, coin.txout.nValue, SIGHASH_ALL), scriptPubKey, sigdata))
2936-
{
2937-
strFailReason = _("Signing transaction failed").translated;
2938-
return false;
2939-
} else {
2940-
UpdateInput(txNew.vin.at(nIn), sigdata);
2941-
}
2942-
2943-
nIn++;
2944-
}
2926+
if (sign && !SignTransaction(txNew)) {
2927+
strFailReason = _("Signing transaction failed").translated;
2928+
return false;
29452929
}
29462930

29472931
// Return the constructed transaction data.

0 commit comments

Comments
 (0)