Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/delegationbuilder.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/delegationbuilder.h> | #include <avalanche/delegationbuilder.h> | ||||
#include <key.h> | #include <key.h> | ||||
namespace avalanche { | namespace avalanche { | ||||
DelegationBuilder::DelegationBuilder(const Proof &p) | DelegationBuilder::DelegationBuilder(const Proof &p) | ||||
: proofid(p.getId()), dgid(proofid) { | : proofid(p.getId()), dgid(proofid) { | ||||
levels.push_back({p.getMaster(), {}}); | levels.push_back({p.getMaster(), {}}); | ||||
} | } | ||||
bool DelegationBuilder::importDelegation(const Delegation &d) { | |||||
if (d.getProofId() != proofid) { | |||||
return false; | |||||
} | |||||
if (levels.size() > 1) { | |||||
// We already imported a delegation | |||||
return false; | |||||
} | |||||
if (!d.levels.size()) { | |||||
return true; | |||||
} | |||||
dgid = d.getId(); | |||||
for (auto &l : d.levels) { | |||||
levels.back().sig = l.sig; | |||||
levels.push_back({l.pubkey, {}}); | |||||
} | |||||
return true; | |||||
} | |||||
bool DelegationBuilder::addLevel(const CKey &key, const CPubKey &master) { | bool DelegationBuilder::addLevel(const CKey &key, const CPubKey &master) { | ||||
// Ensures that the private key provided is the one we need. | // Ensures that the private key provided is the one we need. | ||||
if (levels.back().pubkey != key.GetPubKey()) { | if (levels.back().pubkey != key.GetPubKey()) { | ||||
return false; | return false; | ||||
} | } | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << dgid; | ss << dgid; | ||||
Show All 22 Lines |