Skip to content

Commit a4f4f89

Browse files
Replace uint256 specific implementations of base_uint::GetHex() and base_uint::SetHex() with proper ones that don't depend on uint256 and replace template methods instantiations of base_uint with template class instantiation
1 parent 807169e commit a4f4f89

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/arith_uint256.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,21 @@ double base_uint<BITS>::getdouble() const
146146
template <unsigned int BITS>
147147
std::string base_uint<BITS>::GetHex() const
148148
{
149-
return ArithToUint256(*this).GetHex();
149+
base_blob<BITS> b;
150+
for (int x = 0; x < this->WIDTH; ++x) {
151+
WriteLE32(b.begin() + x*4, this->pn[x]);
152+
}
153+
return b.GetHex();
150154
}
151155

152156
template <unsigned int BITS>
153157
void base_uint<BITS>::SetHex(const char* psz)
154158
{
155-
*this = UintToArith256(uint256S(psz));
159+
base_blob<BITS> b;
160+
b.SetHex(psz);
161+
for (int x = 0; x < this->WIDTH; ++x) {
162+
this->pn[x] = ReadLE32(b.begin() + x*4);
163+
}
156164
}
157165

158166
template <unsigned int BITS>
@@ -164,7 +172,7 @@ void base_uint<BITS>::SetHex(const std::string& str)
164172
template <unsigned int BITS>
165173
std::string base_uint<BITS>::ToString() const
166174
{
167-
return (GetHex());
175+
return GetHex();
168176
}
169177

170178
template <unsigned int BITS>
@@ -183,20 +191,7 @@ unsigned int base_uint<BITS>::bits() const
183191
}
184192

185193
// Explicit instantiations for base_uint<256>
186-
template base_uint<256>::base_uint(const std::string&);
187-
template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
188-
template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
189-
template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);
190-
template base_uint<256>& base_uint<256>::operator*=(const base_uint<256>& b);
191-
template base_uint<256>& base_uint<256>::operator/=(const base_uint<256>& b);
192-
template int base_uint<256>::CompareTo(const base_uint<256>&) const;
193-
template bool base_uint<256>::EqualTo(uint64_t) const;
194-
template double base_uint<256>::getdouble() const;
195-
template std::string base_uint<256>::GetHex() const;
196-
template std::string base_uint<256>::ToString() const;
197-
template void base_uint<256>::SetHex(const char*);
198-
template void base_uint<256>::SetHex(const std::string&);
199-
template unsigned int base_uint<256>::bits() const;
194+
template class base_uint<256>;
200195

201196
// This implementation directly uses shifts instead of going
202197
// through an intermediate MPI representation.

src/arith_uint256.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,6 @@ class arith_uint256 : public base_uint<256> {
284284
uint256 ArithToUint256(const arith_uint256 &);
285285
arith_uint256 UintToArith256(const uint256 &);
286286

287+
extern template class base_uint<256>;
288+
287289
#endif // BITCOIN_ARITH_UINT256_H

0 commit comments

Comments
 (0)