diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index f8ee759524..5eda8eac95 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -116,8 +116,6 @@ uint256 CTransaction::GetWitnessOnlyHash() const return ComputeFastMerkleRoot(leaves); } -/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */ -CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), hash{}, m_witness_hash{} {} CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), witness(tx.witness), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {} CTransaction::CTransaction(CMutableTransaction&& tx) : diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index d15ea944f7..9b922ba091 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -506,12 +506,9 @@ private: uint256 ComputeWitnessHash() const; public: - /** Construct a CTransaction that qualifies as IsNull() */ - CTransaction(); - /** Convert a CMutableTransaction into a CTransaction. */ - explicit CTransaction(const CMutableTransaction &tx); - CTransaction(CMutableTransaction &&tx); + explicit CTransaction(const CMutableTransaction& tx); + CTransaction(CMutableTransaction&& tx); template inline void Serialize(Stream& s) const { @@ -606,7 +603,6 @@ struct CMutableTransaction }; typedef std::shared_ptr CTransactionRef; -static inline CTransactionRef MakeTransactionRef() { return std::make_shared(); } template static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared(std::forward(txIn)); } /** A generic txid reference (txid or wtxid). */ diff --git a/src/test/fuzz/script_sigcache.cpp b/src/test/fuzz/script_sigcache.cpp index 87af71897b..d67654bde3 100644 --- a/src/test/fuzz/script_sigcache.cpp +++ b/src/test/fuzz/script_sigcache.cpp @@ -29,7 +29,7 @@ void test_one_input(const std::vector& buffer) FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); const std::optional mutable_transaction = ConsumeDeserializable(fuzzed_data_provider); - const CTransaction tx = mutable_transaction ? CTransaction{*mutable_transaction} : CTransaction{}; + const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}}; const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral(); const CAmount amount = ConsumeMoney(fuzzed_data_provider); const bool store = fuzzed_data_provider.ConsumeBool(); diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp index b164c1030a..82274fb275 100644 --- a/src/test/fuzz/transaction.cpp +++ b/src/test/fuzz/transaction.cpp @@ -44,7 +44,7 @@ void test_one_input(const std::vector& buffer) return CTransaction(mtx); } catch (const std::ios_base::failure&) { valid_tx = false; - return CTransaction(); + return CTransaction{CMutableTransaction{}}; } }(); bool valid_mutable_tx = true; diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp index 607ba3fffd..042c282cb9 100644 --- a/src/wallet/feebumper.cpp +++ b/src/wallet/feebumper.cpp @@ -232,7 +232,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo // We cannot source new unconfirmed inputs(bip125 rule 2) new_coin_control.m_min_depth = 1; - CTransactionRef tx_new = MakeTransactionRef(); + CTransactionRef tx_new; CAmount fee_ret; int change_pos_in_out = -1; // No requested location for change bilingual_str fail_reason; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e78c9e4444..dffa7aac48 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5868,8 +5868,8 @@ static RPCHelpMan sendtomainchain() extern UniValue signrawtransaction(const JSONRPCRequest& request); extern UniValue sendrawtransaction(const JSONRPCRequest& request); -template -static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef, T_tx& tx_aux, T_merkle_block& merkleBlock) +template +static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef, T_merkle_block& merkleBlock) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -5990,17 +5990,15 @@ static RPCHelpMan createrawpegin() UniValue ret(UniValue::VOBJ); if (Params().GetConsensus().ParentChainHasPow()) { Sidechain::Bitcoin::CTransactionRef txBTCRef; - Sidechain::Bitcoin::CTransaction tx_aux; Sidechain::Bitcoin::CMerkleBlock merkleBlock; - ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock); + ret = createrawpegin(request, txBTCRef, merkleBlock); if (!CheckParentProofOfWork(merkleBlock.header.GetHash(), merkleBlock.header.nBits, Params().GetConsensus())) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof"); } } else { CTransactionRef txBTCRef; - CTransaction tx_aux; CMerkleBlock merkleBlock; - ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock); + ret = createrawpegin(request, txBTCRef, merkleBlock); if (!CheckProofSignedParent(merkleBlock.header, Params().GetConsensus())) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof"); } @@ -6455,7 +6453,7 @@ static CTransactionRef SendGenerationTransaction(const CScript& asset_script, co FeeCalculation fee_calc_out; CCoinControl dummy_control; BlindDetails blind_details; - CTransactionRef tx_ref(MakeTransactionRef()); + CTransactionRef tx_ref; if (!pwallet->CreateTransaction(vecSend, tx_ref, nFeeRequired, nChangePosRet, error, dummy_control, fee_calc_out, true, &blind_details, issuance_details)) { throw JSONRPCError(RPC_WALLET_ERROR, error.original); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f9dcceed68..c853a554d6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4003,13 +4003,14 @@ bool CWallet::CreateTransaction( const IssuanceDetails* issuance_details) { int nChangePosIn = nChangePosInOut; - CTransactionRef tx2 = tx; + Assert(!tx); // tx is an out-param. TODO change the return type from bool to tx (or nullptr) bool res = CreateTransactionInternal(vecSend, tx, nFeeRet, nChangePosInOut, error, coin_control, fee_calc_out, sign, blind_details, issuance_details); // try with avoidpartialspends unless it's enabled already if (res && nFeeRet > 0 /* 0 means non-functional fee rate estimation */ && m_max_aps_fee > -1 && !coin_control.m_avoid_partial_spends) { CCoinControl tmp_cc = coin_control; tmp_cc.m_avoid_partial_spends = true; CAmount nFeeRet2; + CTransactionRef tx2; int nChangePosInOut2 = nChangePosIn; bilingual_str error2; // fired and forgotten; if an error occurs, we discard the results BlindDetails blind_details2;