forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate and enforce DIP4 masternodes merkle root in CbTx
Also add "coinbase_payload" field to block templates
- Loading branch information
Showing
10 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2017 The Dash Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "simplifiedmns.h" | ||
#include "specialtx.h" | ||
#include "deterministicmns.h" | ||
|
||
#include "validation.h" | ||
#include "univalue.h" | ||
#include "consensus/merkle.h" | ||
|
||
CSimplifiedMNListEntry::CSimplifiedMNListEntry(const CDeterministicMN& dmn) : | ||
proRegTxHash(dmn.proTxHash), | ||
service(dmn.pdmnState->addr), | ||
keyIDOperator(dmn.pdmnState->keyIDOperator), | ||
keyIDVoting(dmn.pdmnState->keyIDVoting), | ||
isValid(dmn.pdmnState->nPoSeBanHeight == -1) | ||
{ | ||
} | ||
|
||
uint256 CSimplifiedMNListEntry::CalcHash() const | ||
{ | ||
CHashWriter hw(SER_GETHASH, CLIENT_VERSION); | ||
hw << *this; | ||
return hw.GetHash(); | ||
} | ||
|
||
std::string CSimplifiedMNListEntry::ToString() const | ||
{ | ||
return strprintf("CSimplifiedMNListEntry(proRegTxHash=%s, service=%s, keyIDOperator=%s, keyIDVoting=%s, isValie=%d)", | ||
proRegTxHash.ToString(), service.ToString(false), keyIDOperator.ToString(), keyIDVoting.ToString(), isValid); | ||
} | ||
|
||
void CSimplifiedMNListEntry::ToJson(UniValue& obj) const | ||
{ | ||
obj.clear(); | ||
obj.setObject(); | ||
obj.push_back(Pair("proRegTxHash", proRegTxHash.ToString())); | ||
obj.push_back(Pair("service", service.ToString(false))); | ||
obj.push_back(Pair("keyIDOperator", keyIDOperator.ToString())); | ||
obj.push_back(Pair("keyIDVoting", keyIDOperator.ToString())); | ||
obj.push_back(Pair("isValid", isValid)); | ||
} | ||
|
||
CSimplifiedMNList::CSimplifiedMNList(const CDeterministicMNList& dmnList) | ||
{ | ||
mnList.reserve(dmnList.all_count()); | ||
|
||
for (const auto& dmn : dmnList.all_range()) { | ||
mnList.emplace_back(*dmn); | ||
} | ||
|
||
std::sort(mnList.begin(), mnList.end(), [&](const CSimplifiedMNListEntry& a, const CSimplifiedMNListEntry& b) { | ||
return a.proRegTxHash.Compare(b.proRegTxHash) < 0; | ||
}); | ||
} | ||
|
||
uint256 CSimplifiedMNList::CalcMerkleRoot(bool *pmutated) const | ||
{ | ||
std::vector<uint256> leaves; | ||
leaves.reserve(mnList.size()); | ||
for (const auto& e : mnList) { | ||
leaves.emplace_back(e.CalcHash()); | ||
} | ||
return ComputeMerkleRoot(leaves, pmutated); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2017 The Dash Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef DASH_SIMPLIFIEDMNS_H | ||
#define DASH_SIMPLIFIEDMNS_H | ||
|
||
#include "serialize.h" | ||
#include "pubkey.h" | ||
#include "netaddress.h" | ||
|
||
class UniValue; | ||
class CDeterministicMNList; | ||
class CDeterministicMN; | ||
|
||
class CSimplifiedMNListEntry | ||
{ | ||
public: | ||
uint256 proRegTxHash; | ||
CService service; | ||
CKeyID keyIDOperator; | ||
CKeyID keyIDVoting; | ||
bool isValid; | ||
|
||
public: | ||
CSimplifiedMNListEntry() {} | ||
CSimplifiedMNListEntry(const CDeterministicMN& dmn); | ||
|
||
public: | ||
ADD_SERIALIZE_METHODS; | ||
|
||
template <typename Stream, typename Operation> | ||
inline void SerializationOp(Stream& s, Operation ser_action) | ||
{ | ||
READWRITE(proRegTxHash); | ||
READWRITE(service); | ||
READWRITE(keyIDOperator); | ||
READWRITE(keyIDVoting); | ||
READWRITE(isValid); | ||
} | ||
|
||
public: | ||
uint256 CalcHash() const; | ||
|
||
std::string ToString() const; | ||
void ToJson(UniValue& obj) const; | ||
}; | ||
|
||
class CSimplifiedMNList | ||
{ | ||
public: | ||
std::vector<CSimplifiedMNListEntry> mnList; | ||
|
||
public: | ||
CSimplifiedMNList() {} | ||
CSimplifiedMNList(const CDeterministicMNList& dmnList); | ||
|
||
uint256 CalcMerkleRoot(bool *pmutated = NULL) const; | ||
}; | ||
|
||
#endif//DASH_SIMPLIFIEDMNS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters