aboutsummaryrefslogtreecommitdiff
path: root/src/arith_uint256.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-12-19 13:07:07 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-01-05 15:45:36 +0100
commit6bd0dc2a845b4d17d5ffabbdadda80d47d6c2dc3 (patch)
tree0a9d27e397e15c0e7bcbe8f3eff95c5285a2d7ba /src/arith_uint256.cpp
parent30007fda76aa7ba4e4090f7a16298874a7722926 (diff)
downloadbitcoin-6bd0dc2a845b4d17d5ffabbdadda80d47d6c2dc3.tar.xz
arith_uint256: remove initialization from byte vector
Remove initialization from vector (as this is only used in the tests). Also implement SetHex and GetHex in terms of uint256, to avoid duplicate code as well as avoid endianness issues (as they work in term of bytes).
Diffstat (limited to 'src/arith_uint256.cpp')
-rw-r--r--src/arith_uint256.cpp39
1 files changed, 2 insertions, 37 deletions
diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp
index 11df3b05c0..1243823da5 100644
--- a/src/arith_uint256.cpp
+++ b/src/arith_uint256.cpp
@@ -18,14 +18,6 @@ base_uint<BITS>::base_uint(const std::string& str)
}
template <unsigned int BITS>
-base_uint<BITS>::base_uint(const std::vector<unsigned char>& vch)
-{
- if (vch.size() != sizeof(pn))
- throw uint_error("Converting vector of wrong size to base_uint");
- memcpy(pn, &vch[0], sizeof(pn));
-}
-
-template <unsigned int BITS>
base_uint<BITS>& base_uint<BITS>::operator<<=(unsigned int shift)
{
base_uint<BITS> a(*this);
@@ -154,39 +146,13 @@ double base_uint<BITS>::getdouble() const
template <unsigned int BITS>
std::string base_uint<BITS>::GetHex() const
{
- char psz[sizeof(pn) * 2 + 1];
- for (unsigned int i = 0; i < sizeof(pn); i++)
- sprintf(psz + i * 2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]);
- return std::string(psz, psz + sizeof(pn) * 2);
+ return ArithToUint256(*this).GetHex();
}
template <unsigned int BITS>
void base_uint<BITS>::SetHex(const char* psz)
{
- memset(pn, 0, sizeof(pn));
-
- // skip leading spaces
- while (isspace(*psz))
- psz++;
-
- // skip 0x
- if (psz[0] == '0' && tolower(psz[1]) == 'x')
- psz += 2;
-
- // hex string to uint
- const char* pbegin = psz;
- while (::HexDigit(*psz) != -1)
- psz++;
- psz--;
- unsigned char* p1 = (unsigned char*)pn;
- unsigned char* pend = p1 + WIDTH * 4;
- while (psz >= pbegin && p1 < pend) {
- *p1 = ::HexDigit(*psz--);
- if (psz >= pbegin) {
- *p1 |= ((unsigned char)::HexDigit(*psz--) << 4);
- p1++;
- }
- }
+ *this = UintToArith256(uint256S(psz));
}
template <unsigned int BITS>
@@ -218,7 +184,6 @@ unsigned int base_uint<BITS>::bits() const
// Explicit instantiations for base_uint<256>
template base_uint<256>::base_uint(const std::string&);
-template base_uint<256>::base_uint(const std::vector<unsigned char>&);
template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);