mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge #20588: Remove unused and confusing CTransaction constructor
fac39c1983
wallet: document that tx in CreateTransaction is purely an out-param (MarcoFalke)faac31521b
Remove unused and confusing CTransaction constructor (MarcoFalke) Pull request description: The constructor is confusing and dangerous (as explained in the TODO), fix that by removing it. ACKs for top commit: laanwj: Code review ACKfac39c1983
promag: Code review ACKfac39c1983
. theStack: Code review ACKfac39c1983
Tree-SHA512: e0c8cffce8d8ee0166b8e1cbfe85ed0657611e26e2af0d69fde70eceaa5d75cbde3eb489af0428fe4fc431360b4c791fb1cc21b8dee7d4c7a4f17df00836229d
This commit is contained in:
commit
ade38b6ee8
6 changed files with 7 additions and 12 deletions
|
@ -77,8 +77,6 @@ uint256 CTransaction::ComputeWitnessHash() const
|
|||
return SerializeHash(*this, SER_GETHASH, 0);
|
||||
}
|
||||
|
||||
/* 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), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
|
||||
CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
|
||||
|
||||
|
|
|
@ -287,12 +287,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 <typename Stream>
|
||||
inline void Serialize(Stream& s) const {
|
||||
|
@ -393,7 +390,6 @@ struct CMutableTransaction
|
|||
};
|
||||
|
||||
typedef std::shared_ptr<const CTransaction> CTransactionRef;
|
||||
static inline CTransactionRef MakeTransactionRef() { return std::make_shared<const CTransaction>(); }
|
||||
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
|
||||
|
||||
/** A generic txid reference (txid or wtxid). */
|
||||
|
|
|
@ -29,7 +29,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(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<unsigned int>();
|
||||
const CAmount amount = ConsumeMoney(fuzzed_data_provider);
|
||||
const bool store = fuzzed_data_provider.ConsumeBool();
|
||||
|
|
|
@ -42,7 +42,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
return CTransaction(deserialize, ds);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
valid_tx = false;
|
||||
return CTransaction();
|
||||
return CTransaction{CMutableTransaction{}};
|
||||
}
|
||||
}();
|
||||
bool valid_mutable_tx = true;
|
||||
|
|
|
@ -215,7 +215,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;
|
||||
|
|
|
@ -3113,13 +3113,14 @@ bool CWallet::CreateTransaction(
|
|||
bool sign)
|
||||
{
|
||||
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);
|
||||
// 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
|
||||
if (CreateTransactionInternal(vecSend, tx2, nFeeRet2, nChangePosInOut2, error2, tmp_cc, fee_calc_out, sign)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue