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 <avalanche/proof.h> | |||||
#include <avalanche/proofid.h> | |||||
#include <pubkey.h> | |||||
#include <key.h> | #include <key.h> | ||||
namespace avalanche { | namespace avalanche { | ||||
DelegationBuilder::DelegationBuilder(const Proof &p) | DelegationBuilder::DelegationBuilder(const LimitedProofId <dProofId, | ||||
: limitedProofid(p.getLimitedId()), proofid(p.getId()), dgid(proofid) { | const CPubKey &proofMaster, | ||||
levels.push_back({p.getMaster(), {}}); | const DelegationId &delegationId) | ||||
} | : limitedProofid(ltdProofId), dgid(delegationId) { | ||||
levels.push_back({proofMaster, {}}); | |||||
bool DelegationBuilder::importDelegation(const Delegation &d) { | |||||
if (d.getProofId() != proofid) { | |||||
return false; | |||||
} | } | ||||
if (levels.size() > 1) { | DelegationBuilder::DelegationBuilder(const LimitedProofId <dProofId, | ||||
// We already imported a delegation | const CPubKey &proofMaster) | ||||
return false; | : DelegationBuilder(ltdProofId, proofMaster, | ||||
} | DelegationId(ltdProofId.computeProofId(proofMaster))) {} | ||||
if (!d.levels.size()) { | DelegationBuilder::DelegationBuilder(const Proof &p) | ||||
return true; | : DelegationBuilder(p.getLimitedId(), p.getMaster(), | ||||
} | DelegationId(p.getId())) {} | ||||
dgid = d.getId(); | DelegationBuilder::DelegationBuilder(const Delegation &dg) | ||||
for (auto &l : d.levels) { | : DelegationBuilder(dg.getLimitedProofId(), dg.getProofMaster(), | ||||
dg.getId()) { | |||||
for (auto &l : dg.levels) { | |||||
levels.back().sig = l.sig; | levels.back().sig = l.sig; | ||||
levels.push_back({l.pubkey, {}}); | levels.push_back({l.pubkey, {}}); | ||||
} | } | ||||
return true; | |||||
} | } | ||||
bool DelegationBuilder::addLevel(const CKey &delegatorKey, | bool DelegationBuilder::addLevel(const CKey &delegatorKey, | ||||
const CPubKey &delegatedPubKey) { | const CPubKey &delegatedPubKey) { | ||||
// 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 != delegatorKey.GetPubKey()) { | if (levels.back().pubkey != delegatorKey.GetPubKey()) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 26 Lines |