Remove unused CDataStream

pull/28451/head
MarcoFalke 8 months ago
parent fa7eb4f5c3
commit fae00fe9c2
No known key found for this signature in database

@ -23,7 +23,7 @@ struct TestBlockAndIndex {
TestBlockAndIndex()
{
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
DataStream stream{benchmark::data::block413567};
std::byte a{0};
stream.write({&a, 1}); // Prevent compaction

@ -546,7 +546,7 @@ bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base6
bool DecodeRawPSBT(PartiallySignedTransaction& psbt, Span<const std::byte> tx_data, std::string& error)
{
CDataStream ss_data(tx_data, SER_NETWORK, PROTOCOL_VERSION);
DataStream ss_data{tx_data};
try {
ss_data >> psbt;
if (!ss_data.empty()) {

@ -279,42 +279,6 @@ public:
}
};
class CDataStream : public DataStream
{
private:
int nType;
int nVersion;
public:
explicit CDataStream(int nTypeIn, int nVersionIn)
: nType{nTypeIn},
nVersion{nVersionIn} {}
explicit CDataStream(Span<const uint8_t> sp, int type, int version) : CDataStream{AsBytes(sp), type, version} {}
explicit CDataStream(Span<const value_type> sp, int nTypeIn, int nVersionIn)
: DataStream{sp},
nType{nTypeIn},
nVersion{nVersionIn} {}
int GetType() const { return nType; }
void SetVersion(int n) { nVersion = n; }
int GetVersion() const { return nVersion; }
template <typename T>
CDataStream& operator<<(const T& obj)
{
::Serialize(*this, obj);
return *this;
}
template <typename T>
CDataStream& operator>>(T&& obj)
{
::Unserialize(*this, obj);
return *this;
}
};
template <typename IStream>
class BitStreamReader
{

File diff suppressed because one or more lines are too long

@ -82,7 +82,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
SetMockTime(mock_time);
// fuzzed_data_provider is fully consumed after this call, don't use it
CDataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>(), SER_NETWORK, PROTOCOL_VERSION};
DataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>()};
try {
g_setup->m_node.peerman->ProcessMessage(p2p_node, random_message_type, random_bytes_data_stream,
GetTime<std::chrono::microseconds>(), std::atomic<bool>{false});

@ -254,7 +254,7 @@ std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider, b
good_data = false;
return;
}
CDataStream data_stream{SER_NETWORK, PROTOCOL_VERSION};
DataStream data_stream{};
data_stream << TX_WITH_WITNESS(*opt_block);
r = HexStr(data_stream);
},
@ -288,7 +288,7 @@ std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider, b
good_data = false;
return;
}
CDataStream data_stream{SER_NETWORK, PROTOCOL_VERSION};
DataStream data_stream{};
data_stream << *opt_psbt;
r = EncodeBase64(data_stream);
},

@ -36,14 +36,13 @@ FUZZ_TARGET(script_sign, .init = initialize_script_sign)
const std::vector<uint8_t> key = ConsumeRandomLengthByteVector(fuzzed_data_provider, 128);
{
DataStream stream{ConsumeDataStream(fuzzed_data_provider)};
CDataStream random_data_stream{stream, SER_NETWORK, INIT_PROTO_VERSION}; // temporary copy, to be removed along with the version flag SERIALIZE_TRANSACTION_NO_WITNESS
DataStream random_data_stream{ConsumeDataStream(fuzzed_data_provider)};
std::map<CPubKey, KeyOriginInfo> hd_keypaths;
try {
DeserializeHDKeypaths(random_data_stream, key, hd_keypaths);
} catch (const std::ios_base::failure&) {
}
CDataStream serialized{SER_NETWORK, PROTOCOL_VERSION};
DataStream serialized{};
SerializeHDKeypaths(serialized, hd_keypaths, CompactSizeWriter(fuzzed_data_provider.ConsumeIntegral<uint8_t>()));
}
@ -60,7 +59,7 @@ FUZZ_TARGET(script_sign, .init = initialize_script_sign)
}
hd_keypaths[*pub_key] = *key_origin_info;
}
CDataStream serialized{SER_NETWORK, PROTOCOL_VERSION};
DataStream serialized{};
try {
SerializeHDKeypaths(serialized, hd_keypaths, CompactSizeWriter(fuzzed_data_provider.ConsumeIntegral<uint8_t>()));
} catch (const std::ios_base::failure&) {

@ -118,7 +118,7 @@ template <typename T>
[[nodiscard]] inline std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
{
const std::vector<uint8_t> buffer = ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length);
CDataStream ds{buffer, SER_NETWORK, INIT_PROTO_VERSION};
DataStream ds{buffer};
T obj;
try {
ds >> obj;

@ -858,13 +858,13 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
const auto msg_version =
NetMsg::Make(NetMsgType::VERSION, PROTOCOL_VERSION, services, time, services, CAddress::V1_NETWORK(peer_us));
CDataStream msg_version_stream{msg_version.data, SER_NETWORK, PROTOCOL_VERSION};
DataStream msg_version_stream{msg_version.data};
m_node.peerman->ProcessMessage(
peer, NetMsgType::VERSION, msg_version_stream, time_received_dummy, interrupt_dummy);
const auto msg_verack = NetMsg::Make(NetMsgType::VERACK);
CDataStream msg_verack_stream{msg_verack.data, SER_NETWORK, PROTOCOL_VERSION};
DataStream msg_verack_stream{msg_verack.data};
// Will set peer.fSuccessfullyConnected to true (necessary in SendMessages()).
m_node.peerman->ProcessMessage(

File diff suppressed because one or more lines are too long

@ -32,12 +32,16 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
m_wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
// Create prevtxs and add to wallet
CDataStream s_prev_tx1(ParseHex("0200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f7965000000"), SER_NETWORK, PROTOCOL_VERSION);
DataStream s_prev_tx1{
ParseHex("0200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f7965000000"),
};
CTransactionRef prev_tx1;
s_prev_tx1 >> TX_WITH_WITNESS(prev_tx1);
m_wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(prev_tx1->GetHash()), std::forward_as_tuple(prev_tx1, TxStateInactive{}));
CDataStream s_prev_tx2(ParseHex("0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000"), SER_NETWORK, PROTOCOL_VERSION);
DataStream s_prev_tx2{
ParseHex("0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000"),
};
CTransactionRef prev_tx2;
s_prev_tx2 >> TX_WITH_WITNESS(prev_tx2);
m_wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(prev_tx2->GetHash()), std::forward_as_tuple(prev_tx2, TxStateInactive{}));
@ -49,7 +53,9 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
// Call FillPSBT
PartiallySignedTransaction psbtx;
CDataStream ssData(ParseHex("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000"), SER_NETWORK, PROTOCOL_VERSION);
DataStream ssData{
ParseHex("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000"),
};
ssData >> psbtx;
// Fill transaction with our data

@ -17,11 +17,11 @@ BOOST_FIXTURE_TEST_SUITE(walletdb_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(walletdb_readkeyvalue)
{
/**
* When ReadKeyValue() reads from either a "key" or "wkey" it first reads the CDataStream steam into a
* When ReadKeyValue() reads from either a "key" or "wkey" it first reads the DataStream into a
* CPrivKey or CWalletKey respectively and then reads a hash of the pubkey and privkey into a uint256.
* Wallets from 0.8 or before do not store the pubkey/privkey hash, trying to read the hash from old
* wallets throws an exception, for backwards compatibility this read is wrapped in a try block to
* silently fail. The test here makes sure the type of exception thrown from CDataStream::read()
* silently fail. The test here makes sure the type of exception thrown from DataStream::read()
* matches the type we expect, otherwise we need to update the "key"/"wkey" exception type caught.
*/
DataStream ssValue{};

@ -104,7 +104,7 @@ bool HasAnyRecordOfType(WalletDatabase& db, const std::string& key)
template<typename... Args>
SerializeData MakeSerializeData(const Args&... args)
{
CDataStream s(0, 0);
DataStream s{};
SerializeMany(s, args...);
return {s.begin(), s.end()};
}

Loading…
Cancel
Save