Changeset View
Changeset View
Standalone View
Standalone View
src/uint256.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
template <unsigned int BITS> | template <unsigned int BITS> | ||||
base_blob<BITS>::base_blob(const std::vector<uint8_t> &vch) { | base_blob<BITS>::base_blob(const std::vector<uint8_t> &vch) { | ||||
assert(vch.size() == sizeof(m_data)); | assert(vch.size() == sizeof(m_data)); | ||||
memcpy(m_data, vch.data(), sizeof(m_data)); | memcpy(m_data, vch.data(), sizeof(m_data)); | ||||
} | } | ||||
template <unsigned int BITS> std::string base_blob<BITS>::GetHex() const { | template <unsigned int BITS> std::string base_blob<BITS>::GetHex() const { | ||||
return HexStr( | uint8_t m_data_rev[WIDTH]; | ||||
std::reverse_iterator<const uint8_t *>(m_data + sizeof(m_data)), | for (int i = 0; i < WIDTH; ++i) { | ||||
std::reverse_iterator<const uint8_t *>(m_data)); | 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) { | template <unsigned int BITS> void base_blob<BITS>::SetHex(const char *psz) { | ||||
memset(m_data, 0, sizeof(m_data)); | memset(m_data, 0, sizeof(m_data)); | ||||
// skip leading spaces | // skip leading spaces | ||||
while (IsSpace(*psz)) { | while (IsSpace(*psz)) { | ||||
psz++; | psz++; | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |