mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
[wallet] Construct CWalletTx objects in CommitTransaction
Construct CWalletTx objects in CWallet::CommitTransaction, instead of having callers do it. This ensures CWalletTx objects are constructed in a uniform way and all fields are set. This also makes it possible to avoid confusing and wasteful CWalletTx copies in https://github.com/bitcoin/bitcoin/pull/9381 There is no change in behavior.
This commit is contained in:
@@ -624,23 +624,23 @@ public:
|
||||
|
||||
CWalletTx& AddTx(CRecipient recipient)
|
||||
{
|
||||
CWalletTx wtx;
|
||||
CTransactionRef tx;
|
||||
CReserveKey reservekey(wallet.get());
|
||||
CAmount fee;
|
||||
int changePos = -1;
|
||||
std::string error;
|
||||
CCoinControl dummy;
|
||||
BOOST_CHECK(wallet->CreateTransaction({recipient}, wtx, reservekey, fee, changePos, error, dummy));
|
||||
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, reservekey, fee, changePos, error, dummy));
|
||||
CValidationState state;
|
||||
BOOST_CHECK(wallet->CommitTransaction(wtx, reservekey, nullptr, state));
|
||||
BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, {}, reservekey, nullptr, state));
|
||||
CMutableTransaction blocktx;
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
blocktx = CMutableTransaction(*wallet->mapWallet.at(wtx.GetHash()).tx);
|
||||
blocktx = CMutableTransaction(*wallet->mapWallet.at(tx->GetHash()).tx);
|
||||
}
|
||||
CreateAndProcessBlock({CMutableTransaction(blocktx)}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
LOCK(wallet->cs_wallet);
|
||||
auto it = wallet->mapWallet.find(wtx.GetHash());
|
||||
auto it = wallet->mapWallet.find(tx->GetHash());
|
||||
BOOST_CHECK(it != wallet->mapWallet.end());
|
||||
it->second.SetMerkleBranch(chainActive.Tip(), 1);
|
||||
return it->second;
|
||||
|
||||
Reference in New Issue
Block a user