Merge ee9befe8b4 into merged_master (Bitcoin PR bitcoin/bitcoin#21584)

This commit is contained in:
Andrew Poelstra 2021-07-09 21:14:15 +00:00
commit 1fd44e5dfc
10 changed files with 130 additions and 123 deletions

View file

@ -8,6 +8,7 @@
#include <script/interpreter.h>
#include <uint256.h>
#include <util/hash_type.h>
#include <string>
#include <variant>
@ -20,70 +21,6 @@ class CKeyID;
class CScript;
struct ScriptHash;
template<typename HashType>
class BaseHash
{
protected:
HashType m_hash;
public:
BaseHash() : m_hash() {}
explicit BaseHash(const HashType& in) : m_hash(in) {}
unsigned char* begin()
{
return m_hash.begin();
}
const unsigned char* begin() const
{
return m_hash.begin();
}
unsigned char* end()
{
return m_hash.end();
}
const unsigned char* end() const
{
return m_hash.end();
}
operator std::vector<unsigned char>() const
{
return std::vector<unsigned char>{m_hash.begin(), m_hash.end()};
}
std::string ToString() const
{
return m_hash.ToString();
}
bool operator==(const BaseHash<HashType>& other) const noexcept
{
return m_hash == other.m_hash;
}
bool operator!=(const BaseHash<HashType>& other) const noexcept
{
return !(m_hash == other.m_hash);
}
bool operator<(const BaseHash<HashType>& other) const noexcept
{
return m_hash < other.m_hash;
}
size_t size() const
{
return m_hash.size();
}
unsigned char* data() { return m_hash.data(); }
const unsigned char* data() const { return m_hash.data(); }
};
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
class CScriptID : public BaseHash<uint160>
{