remove boost dependency from Dash-specific code (#2072)

* replace boost casts in dash-specific code

Specifically for spork.cpp : this should be temporary until all spork
sigs are based on hash and not string serialization format, after which
I expect the old signatures (else branch) should go away altogether. But
I still think it's worth it to get pieces of the boost dependency
removed, and this is an easy win, and could be merged now or in a patch
release w/o issue.

* replace boost::shared_ptr w/std::shared_ptr
This commit is contained in:
Nathan Marley 2018-07-12 16:02:20 +07:00 committed by UdjinM6
parent 2c0d4c9d77
commit 8ee9333bc2
8 changed files with 37 additions and 42 deletions

View File

@ -12,8 +12,6 @@
#include "script/standard.h" #include "script/standard.h"
#include "util.h" #include "util.h"
#include <boost/shared_ptr.hpp>
class CSuperblock; class CSuperblock;
class CGovernanceTrigger; class CGovernanceTrigger;
class CGovernanceTriggerManager; class CGovernanceTriggerManager;
@ -22,7 +20,7 @@ class CSuperblockManager;
static const int TRIGGER_UNKNOWN = -1; static const int TRIGGER_UNKNOWN = -1;
static const int TRIGGER_SUPERBLOCK = 1000; static const int TRIGGER_SUPERBLOCK = 1000;
typedef boost::shared_ptr<CSuperblock> CSuperblock_sptr; typedef std::shared_ptr<CSuperblock> CSuperblock_sptr;
// DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES // DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES
extern CGovernanceTriggerManager triggerman; extern CGovernanceTriggerManager triggerman;

View File

@ -15,6 +15,7 @@
#include "util.h" #include "util.h"
#include <univalue.h> #include <univalue.h>
#include <string>
CGovernanceObject::CGovernanceObject(): CGovernanceObject::CGovernanceObject():
cs(), cs(),
@ -225,8 +226,8 @@ std::string CGovernanceObject::GetSignatureMessage() const
{ {
LOCK(cs); LOCK(cs);
std::string strMessage = nHashParent.ToString() + "|" + std::string strMessage = nHashParent.ToString() + "|" +
boost::lexical_cast<std::string>(nRevision) + "|" + std::to_string(nRevision) + "|" +
boost::lexical_cast<std::string>(nTime) + "|" + std::to_string(nTime) + "|" +
GetDataAsHexString() + "|" + GetDataAsHexString() + "|" +
masternodeOutpoint.ToStringShort() + "|" + masternodeOutpoint.ToStringShort() + "|" +
nCollateralHash.ToString(); nCollateralHash.ToString();

View File

@ -9,8 +9,6 @@
#include "messagesigner.h" #include "messagesigner.h"
#include "util.h" #include "util.h"
#include <boost/lexical_cast.hpp>
std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome) std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
{ {
switch(nOutcome) switch(nOutcome)
@ -173,7 +171,7 @@ bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
} else { } else {
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" + std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime); std::to_string(nVoteSignal) + "|" + std::to_string(nVoteOutcome) + "|" + std::to_string(nTime);
if(!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) {
LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n"); LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n");
@ -199,9 +197,9 @@ bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
// could be a signature in old format // could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" + std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
boost::lexical_cast<std::string>(nVoteSignal) + "|" + std::to_string(nVoteSignal) + "|" +
boost::lexical_cast<std::string>(nVoteOutcome) + "|" + std::to_string(nVoteOutcome) + "|" +
boost::lexical_cast<std::string>(nTime); std::to_string(nTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
@ -211,9 +209,9 @@ bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const
} }
} else { } else {
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" + std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
boost::lexical_cast<std::string>(nVoteSignal) + "|" + std::to_string(nVoteSignal) + "|" +
boost::lexical_cast<std::string>(nVoteOutcome) + "|" + std::to_string(nVoteOutcome) + "|" +
boost::lexical_cast<std::string>(nTime); std::to_string(nTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError); LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);

View File

@ -8,8 +8,6 @@
#include "key.h" #include "key.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
#include <boost/lexical_cast.hpp>
class CGovernanceVote; class CGovernanceVote;
class CConnman; class CConnman;

View File

@ -14,7 +14,7 @@
#include "spork.h" #include "spork.h"
#include "util.h" #include "util.h"
#include <boost/lexical_cast.hpp> #include <string>
/** Object for who's going to get paid on which blocks */ /** Object for who's going to get paid on which blocks */
CMasternodePayments mnpayments; CMasternodePayments mnpayments;
@ -455,7 +455,7 @@ bool CMasternodePaymentVote::Sign()
} }
} else { } else {
std::string strMessage = masternodeOutpoint.ToStringShort() + std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
@ -905,7 +905,7 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
// could be a signature in old format // could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() + std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
@ -921,7 +921,7 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
} }
} else { } else {
std::string strMessage = masternodeOutpoint.ToStringShort() + std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {

View File

@ -18,7 +18,7 @@
#include "wallet/wallet.h" #include "wallet/wallet.h"
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
#include <boost/lexical_cast.hpp> #include <string>
CMasternode::CMasternode() : CMasternode::CMasternode() :
@ -640,9 +640,9 @@ bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress)
return false; return false;
} }
} else { } else {
std::string strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() +
boost::lexical_cast<std::string>(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) { if (!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) {
LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n"); LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n");
@ -668,9 +668,9 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const
if (!CHashSigner::VerifyHash(hash, pubKeyCollateralAddress, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, pubKeyCollateralAddress, vchSig, strError)) {
// maybe it's in old format // maybe it's in old format
std::string strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() +
boost::lexical_cast<std::string>(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){
// nope, not in old format either // nope, not in old format either
@ -680,9 +680,9 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const
} }
} }
} else { } else {
std::string strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() +
boost::lexical_cast<std::string>(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){
LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError); LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError);
@ -762,7 +762,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
} }
} else { } else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
boost::lexical_cast<std::string>(sigTime); std::to_string(sigTime);
if (!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) { if (!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) {
LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n"); LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n");
@ -788,7 +788,7 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
boost::lexical_cast<std::string>(sigTime); std::to_string(sigTime);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError); LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);
@ -798,7 +798,7 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)
} }
} else { } else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
boost::lexical_cast<std::string>(sigTime); std::to_string(sigTime);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError); LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);

View File

@ -19,7 +19,7 @@
#include "util.h" #include "util.h"
#include "utilmoneystr.h" #include "utilmoneystr.h"
#include <boost/lexical_cast.hpp> #include <string>
bool CDarkSendEntry::AddScriptSig(const CTxIn& txin) bool CDarkSendEntry::AddScriptSig(const CTxIn& txin)
{ {
@ -62,9 +62,9 @@ bool CDarksendQueue::Sign()
} }
} else { } else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() +
boost::lexical_cast<std::string>(nDenom) + std::to_string(nDenom) +
boost::lexical_cast<std::string>(nTime) + std::to_string(nTime) +
boost::lexical_cast<std::string>(fReady); std::to_string(fReady);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed, %s\n", ToString()); LogPrintf("CDarksendQueue::Sign -- SignMessage() failed, %s\n", ToString());
@ -94,9 +94,9 @@ bool CDarksendQueue::CheckSignature(const CPubKey& pubKeyMasternode) const
} }
} else { } else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() +
boost::lexical_cast<std::string>(nDenom) + std::to_string(nDenom) +
boost::lexical_cast<std::string>(nTime) + std::to_string(nTime) +
boost::lexical_cast<std::string>(fReady); std::to_string(fReady);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature: %s; error: %s\n", ToString(), strError); LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature: %s; error: %s\n", ToString(), strError);
@ -141,7 +141,7 @@ bool CDarksendBroadcastTx::Sign()
return false; return false;
} }
} else { } else {
std::string strMessage = tx->GetHash().ToString() + boost::lexical_cast<std::string>(sigTime); std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n"); LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
@ -170,7 +170,7 @@ bool CDarksendBroadcastTx::CheckSignature(const CPubKey& pubKeyMasternode) const
return false; return false;
} }
} else { } else {
std::string strMessage = tx->GetHash().ToString() + boost::lexical_cast<std::string>(sigTime); std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError); LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError);

View File

@ -11,7 +11,7 @@
#include "net_processing.h" #include "net_processing.h"
#include "netmessagemaker.h" #include "netmessagemaker.h"
#include <boost/lexical_cast.hpp> #include <string>
CSporkManager sporkManager; CSporkManager sporkManager;
@ -262,7 +262,7 @@ bool CSporkMessage::Sign(const CKey& key)
return false; return false;
} }
} else { } else {
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned); std::string strMessage = std::to_string(nSporkID) + std::to_string(nValue) + std::to_string(nTimeSigned);
if(!CMessageSigner::SignMessage(strMessage, vchSig, key)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
LogPrintf("CSporkMessage::Sign -- SignMessage() failed\n"); LogPrintf("CSporkMessage::Sign -- SignMessage() failed\n");
@ -292,7 +292,7 @@ bool CSporkMessage::CheckSignature(const CKeyID& pubKeyId) const
return false; return false;
} }
} else { } else {
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned); std::string strMessage = std::to_string(nSporkID) + std::to_string(nValue) + std::to_string(nTimeSigned);
if (!CMessageSigner::VerifyMessage(pubKeyId, vchSig, strMessage, strError)){ if (!CMessageSigner::VerifyMessage(pubKeyId, vchSig, strMessage, strError)){
// Note: unlike for other messages we have to check for new format even with SPORK_6_NEW_SIGS // Note: unlike for other messages we have to check for new format even with SPORK_6_NEW_SIGS