Merge pull request #8159 from ethereum/fixedhash-cleanup

Remove some rarely used features of FixedHash
This commit is contained in:
chriseth 2020-01-16 19:01:20 +01:00 committed by GitHub
commit 53106011eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 19 deletions

View File

@ -63,9 +63,6 @@ public:
/// Convert from the corresponding arithmetic type. /// Convert from the corresponding arithmetic type.
FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); } FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); }
/// Convert from unsigned
explicit FixedHash(unsigned _u) { toBigEndian(_u, m_data); }
/// Explicitly construct, copying from a byte array. /// Explicitly construct, copying from a byte array.
explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
@ -78,17 +75,12 @@ public:
/// Convert to arithmetic type. /// Convert to arithmetic type.
operator Arith() const { return fromBigEndian<Arith>(m_data); } operator Arith() const { return fromBigEndian<Arith>(m_data); }
/// @returns true iff this is the empty hash.
explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](uint8_t _b) { return _b != 0; }); }
// The obvious comparison operators. // The obvious comparison operators.
bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; } bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; }
bool operator!=(FixedHash const& _c) const { return m_data != _c.m_data; } bool operator!=(FixedHash const& _c) const { return m_data != _c.m_data; }
/// Required to sort objects of this type or use them as map keys. /// Required to sort objects of this type or use them as map keys.
bool operator<(FixedHash const& _c) const { for (unsigned i = 0; i < N; ++i) if (m_data[i] < _c.m_data[i]) return true; else if (m_data[i] > _c.m_data[i]) return false; return false; } bool operator<(FixedHash const& _c) const { for (unsigned i = 0; i < N; ++i) if (m_data[i] < _c.m_data[i]) return true; else if (m_data[i] > _c.m_data[i]) return false; return false; }
FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; }
/// @returns a particular byte from the hash. /// @returns a particular byte from the hash.
uint8_t& operator[](unsigned _i) { return m_data[_i]; } uint8_t& operator[](unsigned _i) { return m_data[_i]; }
/// @returns a particular byte from the hash. /// @returns a particular byte from the hash.
@ -112,12 +104,6 @@ public:
/// @returns a copy of the object's data as a byte vector. /// @returns a copy of the object's data as a byte vector.
bytes asBytes() const { return bytes(data(), data() + N); } bytes asBytes() const { return bytes(data(), data() + N); }
/// @returns a mutable reference to the object's data as an STL array.
std::array<uint8_t, N>& asArray() { return m_data; }
/// @returns a constant reference to the object's data as an STL array.
std::array<uint8_t, N> const& asArray() const { return m_data; }
/// Returns the index of the first bit set to one, or size() * 8 if no bits are set. /// Returns the index of the first bit set to one, or size() * 8 if no bits are set.
inline unsigned firstBitSet() const inline unsigned firstBitSet() const
{ {
@ -134,8 +120,6 @@ public:
return ret; return ret;
} }
void clear() { m_data.fill(0); }
private: private:
std::array<uint8_t, N> m_data; ///< The binary data. std::array<uint8_t, N> m_data; ///< The binary data.
}; };

View File

@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(reserve)
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee + 1, encodeDyn(name[1])) == encodeArgs()); BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee + 1, encodeDyn(name[1])) == encodeArgs());
BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[1])) == encodeArgs(h256(account(0), h256::AlignRight))); BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[1])) == encodeArgs(h256(account(0), h256::AlignRight)));
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee - 1, encodeDyn(name[2])) == encodeArgs()); BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee - 1, encodeDyn(name[2])) == encodeArgs());
BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[2])) == encodeArgs(h256(0))); BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[2])) == encodeArgs(h256{}));
} }
BOOST_AUTO_TEST_CASE(double_reserve) BOOST_AUTO_TEST_CASE(double_reserve)

View File

@ -465,7 +465,7 @@ BOOST_AUTO_TEST_CASE(creation)
deployWallet(200); deployWallet(200);
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(m_sender, h256::AlignRight)) == encodeArgs(true)); BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(m_sender, h256::AlignRight)) == encodeArgs(true));
bool v2 = solidity::test::Options::get().useABIEncoderV2; bool v2 = solidity::test::Options::get().useABIEncoderV2;
BOOST_REQUIRE(callContractFunction("isOwner(address)", ~h256(m_sender, h256::AlignRight)) == (v2 ? encodeArgs() : encodeArgs(false))); BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(~0)) == (v2 ? encodeArgs() : encodeArgs(false)));
} }
BOOST_AUTO_TEST_CASE(add_owners) BOOST_AUTO_TEST_CASE(add_owners)

View File

@ -60,7 +60,7 @@ void InterpreterState::dumpTraceAndState(ostream& _out) const
_out << " " << std::uppercase << std::hex << std::setw(4) << offset << ": " << h256(value).hex() << endl; _out << " " << std::uppercase << std::hex << std::setw(4) << offset << ": " << h256(value).hex() << endl;
_out << "Storage dump:" << endl; _out << "Storage dump:" << endl;
for (auto const& slot: storage) for (auto const& slot: storage)
if (slot.second != h256(0)) if (slot.second != h256{})
_out << " " << slot.first.hex() << ": " << slot.second.hex() << endl; _out << " " << slot.first.hex() << ": " << slot.second.hex() << endl;
} }