Skip to content

Commit faa921f

Browse files
author
MarcoFalke
committed
move-only: Add util/hash_type
Can be reviewed with --color-moved=dimmed-zebra
1 parent d2f6d29 commit faa921f

File tree

3 files changed

+74
-64
lines changed

3 files changed

+74
-64
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ BITCOIN_CORE_H = \
246246
util/fees.h \
247247
util/getuniquepath.h \
248248
util/golombrice.h \
249+
util/hash_type.h \
249250
util/hasher.h \
250251
util/macros.h \
251252
util/message.h \

src/script/standard.h

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <script/interpreter.h>
1010
#include <uint256.h>
11+
#include <util/hash_type.h>
1112

1213
#include <string>
1314
#include <variant>
@@ -18,70 +19,6 @@ class CKeyID;
1819
class CScript;
1920
struct ScriptHash;
2021

21-
template<typename HashType>
22-
class BaseHash
23-
{
24-
protected:
25-
HashType m_hash;
26-
27-
public:
28-
BaseHash() : m_hash() {}
29-
explicit BaseHash(const HashType& in) : m_hash(in) {}
30-
31-
unsigned char* begin()
32-
{
33-
return m_hash.begin();
34-
}
35-
36-
const unsigned char* begin() const
37-
{
38-
return m_hash.begin();
39-
}
40-
41-
unsigned char* end()
42-
{
43-
return m_hash.end();
44-
}
45-
46-
const unsigned char* end() const
47-
{
48-
return m_hash.end();
49-
}
50-
51-
operator std::vector<unsigned char>() const
52-
{
53-
return std::vector<unsigned char>{m_hash.begin(), m_hash.end()};
54-
}
55-
56-
std::string ToString() const
57-
{
58-
return m_hash.ToString();
59-
}
60-
61-
bool operator==(const BaseHash<HashType>& other) const noexcept
62-
{
63-
return m_hash == other.m_hash;
64-
}
65-
66-
bool operator!=(const BaseHash<HashType>& other) const noexcept
67-
{
68-
return !(m_hash == other.m_hash);
69-
}
70-
71-
bool operator<(const BaseHash<HashType>& other) const noexcept
72-
{
73-
return m_hash < other.m_hash;
74-
}
75-
76-
size_t size() const
77-
{
78-
return m_hash.size();
79-
}
80-
81-
unsigned char* data() { return m_hash.data(); }
82-
const unsigned char* data() const { return m_hash.data(); }
83-
};
84-
8522
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
8623
class CScriptID : public BaseHash<uint160>
8724
{

src/util/hash_type.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2020-2021 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_UTIL_HASH_TYPE_H
6+
#define BITCOIN_UTIL_HASH_TYPE_H
7+
8+
template <typename HashType>
9+
class BaseHash
10+
{
11+
protected:
12+
HashType m_hash;
13+
14+
public:
15+
BaseHash() : m_hash() {}
16+
explicit BaseHash(const HashType& in) : m_hash(in) {}
17+
18+
unsigned char* begin()
19+
{
20+
return m_hash.begin();
21+
}
22+
23+
const unsigned char* begin() const
24+
{
25+
return m_hash.begin();
26+
}
27+
28+
unsigned char* end()
29+
{
30+
return m_hash.end();
31+
}
32+
33+
const unsigned char* end() const
34+
{
35+
return m_hash.end();
36+
}
37+
38+
operator std::vector<unsigned char>() const
39+
{
40+
return std::vector<unsigned char>{m_hash.begin(), m_hash.end()};
41+
}
42+
43+
std::string ToString() const
44+
{
45+
return m_hash.ToString();
46+
}
47+
48+
bool operator==(const BaseHash<HashType>& other) const noexcept
49+
{
50+
return m_hash == other.m_hash;
51+
}
52+
53+
bool operator!=(const BaseHash<HashType>& other) const noexcept
54+
{
55+
return !(m_hash == other.m_hash);
56+
}
57+
58+
bool operator<(const BaseHash<HashType>& other) const noexcept
59+
{
60+
return m_hash < other.m_hash;
61+
}
62+
63+
size_t size() const
64+
{
65+
return m_hash.size();
66+
}
67+
68+
unsigned char* data() { return m_hash.data(); }
69+
const unsigned char* data() const { return m_hash.data(); }
70+
};
71+
72+
#endif // BITCOIN_UTIL_HASH_TYPE_H

0 commit comments

Comments
 (0)