Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/delegation.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin 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 <avalanche/delegation.h> | #include <avalanche/delegation.h> | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <streams.h> | |||||
#include <util/strencodings.h> | |||||
#include <util/translation.h> | |||||
namespace avalanche { | namespace avalanche { | ||||
bool Delegation::FromHex(Delegation &dg, const std::string &dgHex, | |||||
bilingual_str &errorOut) { | |||||
if (!IsHex(dgHex)) { | |||||
errorOut = _("Delegation must be an hexadecimal string."); | |||||
return false; | |||||
} | |||||
CDataStream ss(ParseHex(dgHex), SER_NETWORK, PROTOCOL_VERSION); | |||||
try { | |||||
ss >> dg; | |||||
} catch (std::exception &e) { | |||||
errorOut = strprintf(_("Delegation has invalid format: %s"), e.what()); | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
template <typename L, typename F> | template <typename L, typename F> | ||||
static bool reduceLevels(uint256 &hash, const std::vector<L> &levels, F f) { | static bool reduceLevels(uint256 &hash, const std::vector<L> &levels, F f) { | ||||
for (const auto &l : levels) { | for (const auto &l : levels) { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << hash; | ss << hash; | ||||
ss << l.pubkey; | ss << l.pubkey; | ||||
hash = ss.GetHash(); | hash = ss.GetHash(); | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |