mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
4a3e3af6e7
fa0074e2d82928016a43ca408717154a1c70a4db scripted-diff: Bump copyright headers (MarcoFalke) Pull request description: Needs to be done because no one has removed the years yet ACKs for top commit: practicalswift: ACK fa0074e2d82928016a43ca408717154a1c70a4db Tree-SHA512: 210e92acd7d400b556cf8259c3ec9967797420cfd19f0c2a4fa54cb2b3d32ad9ae27e771269201e7d554c0f4cd73a8b1c1a42c9f65d8685ca4d52e5134b071a3
75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <uint256.h>
|
|
|
|
#include <util/strencodings.h>
|
|
|
|
template <unsigned int BITS>
|
|
std::string base_blob<BITS>::GetHex() const
|
|
{
|
|
uint8_t m_data_rev[WIDTH];
|
|
for (int i = 0; i < WIDTH; ++i) {
|
|
m_data_rev[i] = m_data[WIDTH - 1 - i];
|
|
}
|
|
return HexStr(m_data_rev);
|
|
}
|
|
|
|
template <unsigned int BITS>
|
|
void base_blob<BITS>::SetHex(const char* psz)
|
|
{
|
|
std::fill(m_data.begin(), m_data.end(), 0);
|
|
|
|
// skip leading spaces
|
|
while (IsSpace(*psz))
|
|
psz++;
|
|
|
|
// skip 0x
|
|
if (psz[0] == '0' && ToLower((unsigned char)psz[1]) == 'x')
|
|
psz += 2;
|
|
|
|
// hex string to uint
|
|
size_t digits = 0;
|
|
while (::HexDigit(psz[digits]) != -1)
|
|
digits++;
|
|
unsigned char* p1 = m_data.data();
|
|
unsigned char* pend = p1 + WIDTH;
|
|
while (digits > 0 && p1 < pend) {
|
|
*p1 = ::HexDigit(psz[--digits]);
|
|
if (digits > 0) {
|
|
*p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4);
|
|
p1++;
|
|
}
|
|
}
|
|
}
|
|
|
|
template <unsigned int BITS>
|
|
void base_blob<BITS>::SetHex(const std::string& str)
|
|
{
|
|
SetHex(str.c_str());
|
|
}
|
|
|
|
template <unsigned int BITS>
|
|
std::string base_blob<BITS>::ToString() const
|
|
{
|
|
return (GetHex());
|
|
}
|
|
|
|
// Explicit instantiations for base_blob<160>
|
|
template std::string base_blob<160>::GetHex() const;
|
|
template std::string base_blob<160>::ToString() const;
|
|
template void base_blob<160>::SetHex(const char*);
|
|
template void base_blob<160>::SetHex(const std::string&);
|
|
|
|
// Explicit instantiations for base_blob<256>
|
|
template std::string base_blob<256>::GetHex() const;
|
|
template std::string base_blob<256>::ToString() const;
|
|
template void base_blob<256>::SetHex(const char*);
|
|
template void base_blob<256>::SetHex(const std::string&);
|
|
|
|
const uint256 uint256::ZERO(0);
|
|
const uint256 uint256::ONE(1);
|
|
const uint256 uint256::TWO(2);
|