mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Make CMutableTransaction constructor explicit
Silently converting to a CMutableTransaction will drop all caches and should thus be done explicitly
This commit is contained in:
parent
f82e1c9482
commit
faab55fbb1
7 changed files with 12 additions and 12 deletions
|
@ -548,7 +548,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
|
||||||
// mergedTx will end up with all the signatures; it
|
// mergedTx will end up with all the signatures; it
|
||||||
// starts as a clone of the raw tx:
|
// starts as a clone of the raw tx:
|
||||||
CMutableTransaction mergedTx{tx};
|
CMutableTransaction mergedTx{tx};
|
||||||
const CTransaction txv{tx};
|
const CMutableTransaction txv{tx};
|
||||||
CCoinsView viewDummy;
|
CCoinsView viewDummy;
|
||||||
CCoinsViewCache view(&viewDummy);
|
CCoinsViewCache view(&viewDummy);
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ struct CMutableTransaction
|
||||||
uint32_t nLockTime;
|
uint32_t nLockTime;
|
||||||
|
|
||||||
CMutableTransaction();
|
CMutableTransaction();
|
||||||
CMutableTransaction(const CTransaction& tx);
|
explicit CMutableTransaction(const CTransaction& tx);
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline void Serialize(Stream& s) const {
|
inline void Serialize(Stream& s) const {
|
||||||
|
|
|
@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
|
||||||
if (InsecureRandRange(10) == 0 && coinbase_coins.size()) {
|
if (InsecureRandRange(10) == 0 && coinbase_coins.size()) {
|
||||||
auto utxod = FindRandomFrom(coinbase_coins);
|
auto utxod = FindRandomFrom(coinbase_coins);
|
||||||
// Reuse the exact same coinbase
|
// Reuse the exact same coinbase
|
||||||
tx = std::get<0>(utxod->second);
|
tx = CMutableTransaction{std::get<0>(utxod->second)};
|
||||||
// shouldn't be available for reconnection if it's been duplicated
|
// shouldn't be available for reconnection if it's been duplicated
|
||||||
disconnected_coins.erase(utxod->first);
|
disconnected_coins.erase(utxod->first);
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
|
||||||
// 1/20 times reconnect a previously disconnected tx
|
// 1/20 times reconnect a previously disconnected tx
|
||||||
if (randiter % 20 == 2 && disconnected_coins.size()) {
|
if (randiter % 20 == 2 && disconnected_coins.size()) {
|
||||||
auto utxod = FindRandomFrom(disconnected_coins);
|
auto utxod = FindRandomFrom(disconnected_coins);
|
||||||
tx = std::get<0>(utxod->second);
|
tx = CMutableTransaction{std::get<0>(utxod->second)};
|
||||||
prevout = tx.vin[0].prevout;
|
prevout = tx.vin[0].prevout;
|
||||||
if (!CTransaction(tx).IsCoinBase() && !utxoset.count(prevout)) {
|
if (!CTransaction(tx).IsCoinBase() && !utxoset.count(prevout)) {
|
||||||
disconnected_coins.erase(utxod->first);
|
disconnected_coins.erase(utxod->first);
|
||||||
|
|
|
@ -135,7 +135,7 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int n
|
||||||
return txCredit;
|
return txCredit;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CMutableTransaction& txCredit)
|
CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit)
|
||||||
{
|
{
|
||||||
CMutableTransaction txSpend;
|
CMutableTransaction txSpend;
|
||||||
txSpend.nVersion = 1;
|
txSpend.nVersion = 1;
|
||||||
|
@ -161,7 +161,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
||||||
flags |= SCRIPT_VERIFY_WITNESS;
|
flags |= SCRIPT_VERIFY_WITNESS;
|
||||||
}
|
}
|
||||||
ScriptError err;
|
ScriptError err;
|
||||||
CMutableTransaction txCredit = BuildCreditingTransaction(scriptPubKey, nValue);
|
const CTransaction txCredit{BuildCreditingTransaction(scriptPubKey, nValue)};
|
||||||
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, scriptWitness, txCredit);
|
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, scriptWitness, txCredit);
|
||||||
CMutableTransaction tx2 = tx;
|
CMutableTransaction tx2 = tx;
|
||||||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message);
|
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message);
|
||||||
|
@ -1071,7 +1071,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
|
||||||
CScript scriptPubKey12;
|
CScript scriptPubKey12;
|
||||||
scriptPubKey12 << OP_1 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
scriptPubKey12 << OP_1 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
|
const CTransaction txFrom12{BuildCreditingTransaction(scriptPubKey12)};
|
||||||
CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), CScriptWitness(), txFrom12);
|
CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), CScriptWitness(), txFrom12);
|
||||||
|
|
||||||
CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12);
|
CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12);
|
||||||
|
@ -1102,7 +1102,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
|
||||||
CScript scriptPubKey23;
|
CScript scriptPubKey23;
|
||||||
scriptPubKey23 << OP_2 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << ToByteVector(key3.GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
scriptPubKey23 << OP_2 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << ToByteVector(key3.GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
|
const CTransaction txFrom23{BuildCreditingTransaction(scriptPubKey23)};
|
||||||
CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), CScriptWitness(), txFrom23);
|
CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), CScriptWitness(), txFrom23);
|
||||||
|
|
||||||
std::vector<CKey> keys;
|
std::vector<CKey> keys;
|
||||||
|
|
|
@ -24,7 +24,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
|
||||||
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
|
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ToMemPool(CMutableTransaction& tx)
|
ToMemPool(const CMutableTransaction& tx)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,7 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin
|
||||||
// If the output is not large enough to pay the fee, fail.
|
// If the output is not large enough to pay the fee, fail.
|
||||||
CAmount nDelta = new_fee - old_fee;
|
CAmount nDelta = new_fee - old_fee;
|
||||||
assert(nDelta > 0);
|
assert(nDelta > 0);
|
||||||
mtx = *wtx.tx;
|
mtx = CMutableTransaction{*wtx.tx};
|
||||||
CTxOut* poutput = &(mtx.vout[nOutput]);
|
CTxOut* poutput = &(mtx.vout[nOutput]);
|
||||||
if (poutput->nValue < nDelta) {
|
if (poutput->nValue < nDelta) {
|
||||||
errors.push_back("Change output is too small to bump the fee");
|
errors.push_back("Change output is too small to bump the fee");
|
||||||
|
|
|
@ -2065,8 +2065,8 @@ bool CWalletTx::IsTrusted() const
|
||||||
|
|
||||||
bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
|
bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
|
||||||
{
|
{
|
||||||
CMutableTransaction tx1 = *this->tx;
|
CMutableTransaction tx1 {*this->tx};
|
||||||
CMutableTransaction tx2 = *_tx.tx;
|
CMutableTransaction tx2 {*_tx.tx};
|
||||||
for (auto& txin : tx1.vin) txin.scriptSig = CScript();
|
for (auto& txin : tx1.vin) txin.scriptSig = CScript();
|
||||||
for (auto& txin : tx2.vin) txin.scriptSig = CScript();
|
for (auto& txin : tx2.vin) txin.scriptSig = CScript();
|
||||||
return CTransaction(tx1) == CTransaction(tx2);
|
return CTransaction(tx1) == CTransaction(tx2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue