aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-04-04 12:25:56 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-05-11 10:38:18 +0200
commitfaa921f78788be0f236c6b10ed3f92dcf148d1cb (patch)
treeff190b5831f15cdddf718e722659c51075b1c9c5
parentd2f6d2976f50e7944b1582f022c7ba8dfbc0bfa7 (diff)
downloadbitcoin-faa921f78788be0f236c6b10ed3f92dcf148d1cb.tar.xz
move-only: Add util/hash_type
Can be reviewed with --color-moved=dimmed-zebra
-rw-r--r--src/Makefile.am1
-rw-r--r--src/script/standard.h65
-rw-r--r--src/util/hash_type.h72
3 files changed, 74 insertions, 64 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 972a3e279b..2b389e4b0a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -246,6 +246,7 @@ BITCOIN_CORE_H = \
util/fees.h \
util/getuniquepath.h \
util/golombrice.h \
+ util/hash_type.h \
util/hasher.h \
util/macros.h \
util/message.h \
diff --git a/src/script/standard.h b/src/script/standard.h
index f2bf4a8af3..12ab9979a8 100644
--- a/src/script/standard.h
+++ b/src/script/standard.h
@@ -8,6 +8,7 @@
#include <script/interpreter.h>
#include <uint256.h>
+#include <util/hash_type.h>
#include <string>
#include <variant>
@@ -18,70 +19,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>
{
diff --git a/src/util/hash_type.h b/src/util/hash_type.h
new file mode 100644
index 0000000000..13b831cf19
--- /dev/null
+++ b/src/util/hash_type.h
@@ -0,0 +1,72 @@
+// Copyright (c) 2020-2021 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_UTIL_HASH_TYPE_H
+#define BITCOIN_UTIL_HASH_TYPE_H
+
+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(); }
+};
+
+#endif // BITCOIN_UTIL_HASH_TYPE_H