coins,refactor: Migrate Coin#fCoinBase to bool

This commit is contained in:
Lőrinc 2024-12-09 13:25:25 +01:00
parent 35000e34cf
commit 5658c51871
6 changed files with 10 additions and 10 deletions

View file

@ -36,7 +36,7 @@ public:
CTxOut out; CTxOut out;
//! whether containing transaction was a coinbase //! whether containing transaction was a coinbase
unsigned int fCoinBase : 1; bool fCoinBase : 1;
//! at which height this containing transaction was included in the active block chain //! at which height this containing transaction was included in the active block chain
uint32_t nHeight : 31; uint32_t nHeight : 31;

View file

@ -219,7 +219,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true); ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);
UniValue p(UniValue::VOBJ); UniValue p(UniValue::VOBJ);
p.pushKV("generated", bool(prev_coin.fCoinBase)); p.pushKV("generated", prev_coin.IsCoinBase());
p.pushKV("height", uint64_t(prev_coin.nHeight)); p.pushKV("height", uint64_t(prev_coin.nHeight));
p.pushKV("value", ValueFromAmount(prev_txout.nValue)); p.pushKV("value", ValueFromAmount(prev_txout.nValue));
p.pushKV("scriptPubKey", std::move(o_script_pub_key)); p.pushKV("scriptPubKey", std::move(o_script_pub_key));

View file

@ -1160,7 +1160,7 @@ static RPCHelpMan gettxout()
UniValue o(UniValue::VOBJ); UniValue o(UniValue::VOBJ);
ScriptToUniv(coin->out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true); ScriptToUniv(coin->out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
ret.pushKV("scriptPubKey", std::move(o)); ret.pushKV("scriptPubKey", std::move(o));
ret.pushKV("coinbase", (bool)coin->fCoinBase); ret.pushKV("coinbase", coin->IsCoinBase());
return ret; return ret;
}, },

View file

@ -514,7 +514,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
DataStream ss1{"97f23c835800816115944e077fe7c803cfa57f29b36bf87c1d35"_hex}; DataStream ss1{"97f23c835800816115944e077fe7c803cfa57f29b36bf87c1d35"_hex};
Coin cc1; Coin cc1;
ss1 >> cc1; ss1 >> cc1;
BOOST_CHECK_EQUAL(cc1.fCoinBase, false); BOOST_CHECK_EQUAL(cc1.IsCoinBase(), false);
BOOST_CHECK_EQUAL(cc1.nHeight, 203998U); BOOST_CHECK_EQUAL(cc1.nHeight, 203998U);
BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000}); BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000});
BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("816115944e077fe7c803cfa57f29b36bf87c1d35"_hex_u8))))); BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("816115944e077fe7c803cfa57f29b36bf87c1d35"_hex_u8)))));
@ -523,7 +523,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
DataStream ss2{"8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex}; DataStream ss2{"8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex};
Coin cc2; Coin cc2;
ss2 >> cc2; ss2 >> cc2;
BOOST_CHECK_EQUAL(cc2.fCoinBase, true); BOOST_CHECK_EQUAL(cc2.IsCoinBase(), true);
BOOST_CHECK_EQUAL(cc2.nHeight, 120891U); BOOST_CHECK_EQUAL(cc2.nHeight, 120891U);
BOOST_CHECK_EQUAL(cc2.out.nValue, 110397); BOOST_CHECK_EQUAL(cc2.out.nValue, 110397);
BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex_u8))))); BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex_u8)))));
@ -532,7 +532,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
DataStream ss3{"000006"_hex}; DataStream ss3{"000006"_hex};
Coin cc3; Coin cc3;
ss3 >> cc3; ss3 >> cc3;
BOOST_CHECK_EQUAL(cc3.fCoinBase, false); BOOST_CHECK_EQUAL(cc3.IsCoinBase(), false);
BOOST_CHECK_EQUAL(cc3.nHeight, 0U); BOOST_CHECK_EQUAL(cc3.nHeight, 0U);
BOOST_CHECK_EQUAL(cc3.out.nValue, 0); BOOST_CHECK_EQUAL(cc3.out.nValue, 0);
BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U); BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U);
@ -870,7 +870,7 @@ Coin MakeCoin()
Coin coin; Coin coin;
coin.out.nValue = m_rng.rand32(); coin.out.nValue = m_rng.rand32();
coin.nHeight = m_rng.randrange(4096); coin.nHeight = m_rng.randrange(4096);
coin.fCoinBase = 0; coin.fCoinBase = false;
return coin; return coin;
} }

View file

@ -104,7 +104,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
outfile << coinbase->GetHash(); outfile << coinbase->GetHash();
WriteCompactSize(outfile, 1); // number of coins for the hash WriteCompactSize(outfile, 1); // number of coins for the hash
WriteCompactSize(outfile, 0); // index of coin WriteCompactSize(outfile, 0); // index of coin
outfile << Coin(coinbase->vout[0], height, /*fCoinBaseIn=*/1); outfile << Coin(coinbase->vout[0], height, /*fCoinBaseIn=*/true);
height++; height++;
} }
} }
@ -116,7 +116,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
outfile << coinbase->GetHash(); outfile << coinbase->GetHash();
WriteCompactSize(outfile, 1); // number of coins for the hash WriteCompactSize(outfile, 1); // number of coins for the hash
WriteCompactSize(outfile, 999); // index of coin WriteCompactSize(outfile, 999); // index of coin
outfile << Coin{coinbase->vout[0], /*nHeightIn=*/999, /*fCoinBaseIn=*/0}; outfile << Coin{coinbase->vout[0], /*nHeightIn=*/999, /*fCoinBaseIn=*/false};
} }
} }

View file

@ -2332,7 +2332,7 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn
COutPoint out(hash, o); COutPoint out(hash, o);
Coin coin; Coin coin;
bool is_spent = view.SpendCoin(out, &coin); bool is_spent = view.SpendCoin(out, &coin);
if (!is_spent || tx.vout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.fCoinBase) { if (!is_spent || tx.vout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.IsCoinBase()) {
if (!is_bip30_exception) { if (!is_bip30_exception) {
fClean = false; // transaction output mismatch fClean = false; // transaction output mismatch
} }