diff --git a/src/avalanche/delegationbuilder.cpp b/src/avalanche/delegationbuilder.cpp index 5dbf55fca..abb10889b 100644 --- a/src/avalanche/delegationbuilder.cpp +++ b/src/avalanche/delegationbuilder.cpp @@ -1,68 +1,69 @@ // Copyright (c) 2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include namespace avalanche { DelegationBuilder::DelegationBuilder(const Proof &p) : proofid(p.getId()), dgid(proofid) { 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 &delegatorKey, + const CPubKey &delegatedPubKey) { // Ensures that the private key provided is the one we need. - if (levels.back().pubkey != key.GetPubKey()) { + if (levels.back().pubkey != delegatorKey.GetPubKey()) { return false; } CHashWriter ss(SER_GETHASH, 0); ss << dgid; - ss << master; + ss << delegatedPubKey; auto hash = ss.GetHash(); - if (!key.SignSchnorr(hash, levels.back().sig)) { + if (!delegatorKey.SignSchnorr(hash, levels.back().sig)) { return false; } dgid = DelegationId(hash); - levels.push_back({master, {}}); + levels.push_back({delegatedPubKey, {}}); return true; } Delegation DelegationBuilder::build() const { std::vector dglvls; for (size_t i = 1; i < levels.size(); i++) { dglvls.push_back({levels[i].pubkey, levels[i - 1].sig}); } return Delegation(proofid, dgid, std::move(dglvls)); } } // namespace avalanche diff --git a/src/avalanche/delegationbuilder.h b/src/avalanche/delegationbuilder.h index 7a1fb2fd4..b84a8c693 100644 --- a/src/avalanche/delegationbuilder.h +++ b/src/avalanche/delegationbuilder.h @@ -1,38 +1,38 @@ // Copyright (c) 2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_AVALANCHE_DELEGATIONBUILDER_H #define BITCOIN_AVALANCHE_DELEGATIONBUILDER_H #include #include #include #include class CKey; namespace avalanche { class Proof; class DelegationBuilder { ProofId proofid; DelegationId dgid; std::vector levels; public: explicit DelegationBuilder(const Proof &p); bool importDelegation(const Delegation &d); - bool addLevel(const CKey &key, const CPubKey &newMaster); + bool addLevel(const CKey &delegatorKey, const CPubKey &delegatedPubKey); Delegation build() const; }; } // namespace avalanche #endif // BITCOIN_AVALANCHE_DELEGATIONBUILDER_H