mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Remove unused (and broken) functionality in SpanReader
This removes the ability to set an offset in the SpanReader constructor,
as the current code is broken. All call sites use pos=0, so it is actually
unused. If future call sites need it, SpanReader{a, b, c, d} is equivalent
to SpanReader{a, b, c.subspan(d)}.
It also removes the ability to deserialize from SpanReader directly from
the constructor. This too is unused, and can be more idiomatically
simulated using (SpanReader{a, b, c} >> x >> y >> z) instead of
SpanReader{a, b, c, x, y, z}.
This commit is contained in:
@@ -82,7 +82,7 @@ FUZZ_TARGET(golomb_rice)
|
||||
|
||||
std::vector<uint64_t> decoded_deltas;
|
||||
{
|
||||
SpanReader stream{SER_NETWORK, 0, golomb_rice_data, 0};
|
||||
SpanReader stream{SER_NETWORK, 0, golomb_rice_data};
|
||||
BitStreamReader<SpanReader> bitreader{stream};
|
||||
const uint32_t n = static_cast<uint32_t>(ReadCompactSize(stream));
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
@@ -94,7 +94,7 @@ FUZZ_TARGET(golomb_rice)
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider, 1024);
|
||||
SpanReader stream{SER_NETWORK, 0, random_bytes, 0};
|
||||
SpanReader stream{SER_NETWORK, 0, random_bytes};
|
||||
uint32_t n;
|
||||
try {
|
||||
n = static_cast<uint32_t>(ReadCompactSize(stream));
|
||||
|
||||
@@ -54,7 +54,7 @@ CMutableTransaction TxFromHex(const std::string& str)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
try {
|
||||
SpanReader{SER_DISK, SERIALIZE_TRANSACTION_NO_WITNESS, CheckedParseHex(str), 0} >> tx;
|
||||
SpanReader{SER_DISK, SERIALIZE_TRANSACTION_NO_WITNESS, CheckedParseHex(str)} >> tx;
|
||||
} catch (const std::ios_base::failure&) {
|
||||
throw std::runtime_error("Tx deserialization failure");
|
||||
}
|
||||
@@ -68,7 +68,7 @@ std::vector<CTxOut> TxOutsFromJSON(const UniValue& univalue)
|
||||
for (size_t i = 0; i < univalue.size(); ++i) {
|
||||
CTxOut txout;
|
||||
try {
|
||||
SpanReader{SER_DISK, 0, CheckedParseHex(univalue[i].get_str()), 0} >> txout;
|
||||
SpanReader{SER_DISK, 0, CheckedParseHex(univalue[i].get_str())} >> txout;
|
||||
} catch (const std::ios_base::failure&) {
|
||||
throw std::runtime_error("Prevout invalid format");
|
||||
}
|
||||
|
||||
@@ -1473,7 +1473,7 @@ BOOST_AUTO_TEST_CASE(script_HasValidOps)
|
||||
static CMutableTransaction TxFromHex(const std::string& str)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
SpanReader{SER_DISK, SERIALIZE_TRANSACTION_NO_WITNESS, ParseHex(str), 0} >> tx;
|
||||
SpanReader{SER_DISK, SERIALIZE_TRANSACTION_NO_WITNESS, ParseHex(str)} >> tx;
|
||||
return tx;
|
||||
}
|
||||
|
||||
@@ -1483,7 +1483,7 @@ static std::vector<CTxOut> TxOutsFromJSON(const UniValue& univalue)
|
||||
std::vector<CTxOut> prevouts;
|
||||
for (size_t i = 0; i < univalue.size(); ++i) {
|
||||
CTxOut txout;
|
||||
SpanReader{SER_DISK, 0, ParseHex(univalue[i].get_str()), 0} >> txout;
|
||||
SpanReader{SER_DISK, 0, ParseHex(univalue[i].get_str())} >> txout;
|
||||
prevouts.push_back(std::move(txout));
|
||||
}
|
||||
return prevouts;
|
||||
@@ -1754,7 +1754,7 @@ BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors)
|
||||
for (const auto& vec : vectors.getValues()) {
|
||||
auto txhex = ParseHex(vec["given"]["rawUnsignedTx"].get_str());
|
||||
CMutableTransaction tx;
|
||||
SpanReader{SER_NETWORK, PROTOCOL_VERSION, txhex, 0} >> tx;
|
||||
SpanReader{SER_NETWORK, PROTOCOL_VERSION, txhex} >> tx;
|
||||
std::vector<CTxOut> utxos;
|
||||
for (const auto& utxo_spent : vec["given"]["utxosSpent"].getValues()) {
|
||||
auto script_bytes = ParseHex(utxo_spent["scriptPubKey"].get_str());
|
||||
|
||||
@@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
|
||||
{
|
||||
std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};
|
||||
|
||||
SpanReader reader{SER_NETWORK, INIT_PROTO_VERSION, vch, 0};
|
||||
SpanReader reader{SER_NETWORK, INIT_PROTO_VERSION, vch};
|
||||
BOOST_CHECK_EQUAL(reader.size(), 6U);
|
||||
BOOST_CHECK(!reader.empty());
|
||||
|
||||
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
|
||||
BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);
|
||||
|
||||
// Read a 4 bytes as a signed int from the beginning of the buffer.
|
||||
SpanReader new_reader{SER_NETWORK, INIT_PROTO_VERSION, vch, 0};
|
||||
SpanReader new_reader{SER_NETWORK, INIT_PROTO_VERSION, vch};
|
||||
new_reader >> d;
|
||||
BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256
|
||||
BOOST_CHECK_EQUAL(new_reader.size(), 2U);
|
||||
@@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
|
||||
BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue)
|
||||
{
|
||||
std::vector<uint8_t> data{0x82, 0xa7, 0x31};
|
||||
SpanReader reader{SER_NETWORK, INIT_PROTO_VERSION, data, /* pos= */ 0};
|
||||
SpanReader reader{SER_NETWORK, INIT_PROTO_VERSION, data};
|
||||
uint32_t varint = 0;
|
||||
// Deserialize into r-value
|
||||
reader >> VARINT(varint);
|
||||
|
||||
Reference in New Issue
Block a user