Minor nit: Allow CBlock.ToString() to take an optional "verbose" arg.

Also in the deserializer, we print the number of junk bytes left at the
end if there are junk bytes.
This commit is contained in:
Calin Culianu 2024-06-26 21:21:26 +03:00
parent 89bcc47222
commit be56dd204f
No known key found for this signature in database
GPG key ID: 21810A542031C02C
3 changed files with 5 additions and 4 deletions

View file

@ -102,7 +102,8 @@ namespace BTC
bitcoin::GenericVectorReader<QByteArray> vr(bitcoin::SER_NETWORK, version, bytes, pos);
thing.Unserialize(vr);
if (throwIfJunkAtEnd && !vr.empty())
throw std::ios_base::failure("Got unprocessed bytes at the end when deserializeing a bitcoin object");
throw std::ios_base::failure(strprintf("Got %u unprocessed bytes at the end when deserializeing a bitcoin object",
vr.size()));
}
/// Convenience for above. Create an instance of object and deserialize to it
template <typename BitcoinObject>

View file

@ -16,7 +16,7 @@ uint256 CBlockHeader::GetHash() const {
return SerializeHash(*this);
}
std::string CBlock::ToString() const {
std::string CBlock::ToString(bool fVerbose) const {
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, "
"hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, "
@ -24,7 +24,7 @@ std::string CBlock::ToString() const {
GetHash().ToString(), nVersion, hashPrevBlock.ToString(),
hashMerkleRoot.ToString(), nTime, nBits, nNonce, vtx.size());
for (const auto &tx : vtx) {
s << " " << tx->ToString() << "\n";
s << " " << tx->ToString(fVerbose) << "\n";
}
return s.str();
}

View file

@ -109,7 +109,7 @@ public:
return block;
}
std::string ToString() const;
std::string ToString(bool fVerbose = false) const;
};
/**