mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-21 17:42:37 +02:00
Use CWallet::SignTransaction in CreateTransaction and signrawtransactionwithwallet
Instead of duplicating signing code, just use the function we already have.
This commit is contained in:
parent
f37de92744
commit
a4af324d15
@ -3329,23 +3329,15 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
|
|||||||
// Parse the prevtxs array
|
// Parse the prevtxs array
|
||||||
ParsePrevouts(request.params[1], nullptr, coins);
|
ParsePrevouts(request.params[1], nullptr, coins);
|
||||||
|
|
||||||
std::set<std::shared_ptr<SigningProvider>> providers;
|
int nHashType = ParseSighashString(request.params[2]);
|
||||||
for (const std::pair<COutPoint, Coin> coin_pair : coins) {
|
|
||||||
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(coin_pair.second.out.scriptPubKey);
|
|
||||||
if (provider) {
|
|
||||||
providers.insert(std::move(provider));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (providers.size() == 0) {
|
|
||||||
// When there are no available providers, use a dummy SigningProvider so we can check if the tx is complete
|
|
||||||
providers.insert(std::make_shared<SigningProvider>());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Script verification errors
|
||||||
|
std::map<int, std::string> input_errors;
|
||||||
|
|
||||||
|
bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
for (std::shared_ptr<SigningProvider> provider : providers) {
|
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
|
||||||
SignTransaction(mtx, provider.get(), coins, request.params[2], result);
|
return result;
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue bumpfee(const JSONRPCRequest& request)
|
static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
|
@ -2923,25 +2923,9 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
|
|||||||
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
|
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sign)
|
if (sign && !SignTransaction(txNew)) {
|
||||||
{
|
strFailReason = _("Signing transaction failed").translated;
|
||||||
int nIn = 0;
|
return false;
|
||||||
for (const auto& coin : selected_coins)
|
|
||||||
{
|
|
||||||
const CScript& scriptPubKey = coin.txout.scriptPubKey;
|
|
||||||
SignatureData sigdata;
|
|
||||||
|
|
||||||
std::unique_ptr<SigningProvider> provider = GetSigningProvider(scriptPubKey);
|
|
||||||
if (!provider || !ProduceSignature(*provider, MutableTransactionSignatureCreator(&txNew, nIn, coin.txout.nValue, SIGHASH_ALL), scriptPubKey, sigdata))
|
|
||||||
{
|
|
||||||
strFailReason = _("Signing transaction failed").translated;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
UpdateInput(txNew.vin.at(nIn), sigdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
nIn++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the constructed transaction data.
|
// Return the constructed transaction data.
|
||||||
|
Loading…
Reference in New Issue
Block a user