Skip to content

Commit

Permalink
remove boost dependency from Dash-specific code (#2072)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nmarley authored and UdjinM6 committed Jul 12, 2018
1 parent 2c0d4c9 commit 8ee9333
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/governance-classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "script/standard.h"
#include "util.h"

#include <boost/shared_ptr.hpp>

class CSuperblock;
class CGovernanceTrigger;
class CGovernanceTriggerManager;
Expand All @@ -22,7 +20,7 @@ class CSuperblockManager;
static const int TRIGGER_UNKNOWN = -1;
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
extern CGovernanceTriggerManager triggerman;
Expand Down
5 changes: 3 additions & 2 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "util.h"

#include <univalue.h>
#include <string>

CGovernanceObject::CGovernanceObject():
cs(),
Expand Down Expand Up @@ -225,8 +226,8 @@ std::string CGovernanceObject::GetSignatureMessage() const
{
LOCK(cs);
std::string strMessage = nHashParent.ToString() + "|" +
boost::lexical_cast<std::string>(nRevision) + "|" +
boost::lexical_cast<std::string>(nTime) + "|" +
std::to_string(nRevision) + "|" +
std::to_string(nTime) + "|" +
GetDataAsHexString() + "|" +
masternodeOutpoint.ToStringShort() + "|" +
nCollateralHash.ToString();
Expand Down
16 changes: 7 additions & 9 deletions src/governance-vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "messagesigner.h"
#include "util.h"

#include <boost/lexical_cast.hpp>

std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
{
switch(nOutcome)
Expand Down Expand Up @@ -173,7 +171,7 @@ bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
} else {

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)) {
LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n");
Expand All @@ -199,9 +197,9 @@ bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
// could be a signature in old format
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::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either
Expand All @@ -211,9 +209,9 @@ bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const
}
} else {
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::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
Expand Down
2 changes: 0 additions & 2 deletions src/governance-vote.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "key.h"
#include "primitives/transaction.h"

#include <boost/lexical_cast.hpp>

class CGovernanceVote;
class CConnman;

Expand Down
8 changes: 4 additions & 4 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "spork.h"
#include "util.h"

#include <boost/lexical_cast.hpp>
#include <string>

/** Object for who's going to get paid on which blocks */
CMasternodePayments mnpayments;
Expand Down Expand Up @@ -455,7 +455,7 @@ bool CMasternodePaymentVote::Sign()
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);

if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
Expand Down Expand Up @@ -905,7 +905,7 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
// could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either
Expand All @@ -921,7 +921,7 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);

if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
Expand Down
20 changes: 10 additions & 10 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "wallet/wallet.h"
#endif // ENABLE_WALLET

#include <boost/lexical_cast.hpp>
#include <string>


CMasternode::CMasternode() :
Expand Down Expand Up @@ -640,9 +640,9 @@ bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress)
return false;
}
} 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() +
boost::lexical_cast<std::string>(nProtocolVersion);
std::to_string(nProtocolVersion);

if (!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) {
LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n");
Expand All @@ -668,9 +668,9 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const

if (!CHashSigner::VerifyHash(hash, pubKeyCollateralAddress, vchSig, strError)) {
// 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() +
boost::lexical_cast<std::string>(nProtocolVersion);
std::to_string(nProtocolVersion);

if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){
// nope, not in old format either
Expand All @@ -680,9 +680,9 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const
}
}
} 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() +
boost::lexical_cast<std::string>(nProtocolVersion);
std::to_string(nProtocolVersion);

if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){
LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError);
Expand Down Expand Up @@ -762,7 +762,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
}
} else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
boost::lexical_cast<std::string>(sigTime);
std::to_string(sigTime);

if (!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) {
LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n");
Expand All @@ -788,7 +788,7 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)

if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) {
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)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);
Expand All @@ -798,7 +798,7 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)
}
} else {
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)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);
Expand Down
18 changes: 9 additions & 9 deletions src/privatesend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "util.h"
#include "utilmoneystr.h"

#include <boost/lexical_cast.hpp>
#include <string>

bool CDarkSendEntry::AddScriptSig(const CTxIn& txin)
{
Expand Down Expand Up @@ -62,9 +62,9 @@ bool CDarksendQueue::Sign()
}
} else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() +
boost::lexical_cast<std::string>(nDenom) +
boost::lexical_cast<std::string>(nTime) +
boost::lexical_cast<std::string>(fReady);
std::to_string(nDenom) +
std::to_string(nTime) +
std::to_string(fReady);

if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed, %s\n", ToString());
Expand Down Expand Up @@ -94,9 +94,9 @@ bool CDarksendQueue::CheckSignature(const CPubKey& pubKeyMasternode) const
}
} else {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() +
boost::lexical_cast<std::string>(nDenom) +
boost::lexical_cast<std::string>(nTime) +
boost::lexical_cast<std::string>(fReady);
std::to_string(nDenom) +
std::to_string(nTime) +
std::to_string(fReady);

if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature: %s; error: %s\n", ToString(), strError);
Expand Down Expand Up @@ -141,7 +141,7 @@ bool CDarksendBroadcastTx::Sign()
return false;
}
} 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)) {
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
Expand Down Expand Up @@ -170,7 +170,7 @@ bool CDarksendBroadcastTx::CheckSignature(const CPubKey& pubKeyMasternode) const
return false;
}
} 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)) {
LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError);
Expand Down
6 changes: 3 additions & 3 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "net_processing.h"
#include "netmessagemaker.h"

#include <boost/lexical_cast.hpp>
#include <string>

CSporkManager sporkManager;

Expand Down Expand Up @@ -262,7 +262,7 @@ bool CSporkMessage::Sign(const CKey& key)
return false;
}
} 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)) {
LogPrintf("CSporkMessage::Sign -- SignMessage() failed\n");
Expand Down Expand Up @@ -292,7 +292,7 @@ bool CSporkMessage::CheckSignature(const CKeyID& pubKeyId) const
return false;
}
} 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)){
// Note: unlike for other messages we have to check for new format even with SPORK_6_NEW_SIGS
Expand Down

0 comments on commit 8ee9333

Please sign in to comment.