From 715cc37e62c43236740271ae320bf7b8142e6cad Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 12 Feb 2018 15:49:00 +0300 Subject: [PATCH] Refactor: use constant refs and `Ret` suffix --- src/governance-classes.cpp | 4 ++-- src/governance-classes.h | 5 +---- src/governance-object.cpp | 6 +++--- src/governance-object.h | 6 +++--- src/governance-vote.cpp | 6 +++--- src/governance-vote.h | 6 +++--- src/hdchain.cpp | 2 +- src/hdchain.h | 2 +- src/keepass.cpp | 26 +++++++++++++------------- src/keepass.h | 22 +++++++++++----------- src/masternode-sync.cpp | 2 +- src/masternode-sync.h | 2 +- src/masternode.cpp | 4 ++-- src/masternode.h | 4 ++-- src/masternodeconfig.cpp | 12 ++++++------ src/masternodeconfig.h | 6 +++--- src/messagesigner.cpp | 10 +++++----- src/messagesigner.h | 10 +++++----- src/netfulfilledman.cpp | 6 +++--- src/netfulfilledman.h | 6 +++--- src/spork.cpp | 6 +++--- src/spork.h | 6 +++--- src/wallet/wallet.cpp | 6 +++--- src/wallet/wallet.h | 24 ++++++++++++------------ 24 files changed, 93 insertions(+), 96 deletions(-) diff --git a/src/governance-classes.cpp b/src/governance-classes.cpp index 019a24a1c5d988..351d1befdbe669 100644 --- a/src/governance-classes.cpp +++ b/src/governance-classes.cpp @@ -20,7 +20,7 @@ CGovernanceTriggerManager triggerman; // SPLIT UP STRING BY DELIMITER // http://www.boost.org/doc/libs/1_58_0/doc/html/boost/algorithm/split_idp202406848.html -std::vector SplitBy(std::string strCommand, std::string strDelimit) +std::vector SplitBy(const std::string& strCommand, const std::string& strDelimit) { std::vector vParts; boost::split(vParts, strCommand, boost::is_any_of(strDelimit)); @@ -561,7 +561,7 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight) return nPaymentsLimit; } -void CSuperblock::ParsePaymentSchedule(std::string& strPaymentAddresses, std::string& strPaymentAmounts) +void CSuperblock::ParsePaymentSchedule(const std::string& strPaymentAddresses, const std::string& strPaymentAmounts) { // SPLIT UP ADDR/AMOUNT STRINGS AND PUT IN VECTORS diff --git a/src/governance-classes.h b/src/governance-classes.h index 69940faa98c016..8baa3d10c5e18d 100644 --- a/src/governance-classes.h +++ b/src/governance-classes.h @@ -28,9 +28,6 @@ typedef boost::shared_ptr CSuperblock_sptr; // DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES extern CGovernanceTriggerManager triggerman; -// SPLIT A STRING UP - USED FOR SUPERBLOCK PAYMENTS -std::vector SplitBy(std::string strCommand, std::string strDelimit); - /** * Trigger Mananger * @@ -153,7 +150,7 @@ class CSuperblock : public CGovernanceObject int nStatus; std::vector vecPayments; - void ParsePaymentSchedule(std::string& strPaymentAddresses, std::string& strPaymentAmounts); + void ParsePaymentSchedule(const std::string& strPaymentAddresses, const std::string& strPaymentAmounts); public: diff --git a/src/governance-object.cpp b/src/governance-object.cpp index d9c87ae7cf266d..bfbe69bddaf291 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -44,7 +44,7 @@ CGovernanceObject::CGovernanceObject() LoadData(); } -CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, int64_t nTimeIn, uint256 nCollateralHashIn, std::string strDataIn) +CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTimeIn, const uint256& nCollateralHashIn, const std::string& strDataIn) : cs(), nObjectType(GOVERNANCE_OBJECT_UNKNOWN), nHashParent(nHashParentIn), @@ -230,7 +230,7 @@ void CGovernanceObject::SetMasternodeVin(const COutPoint& outpoint) vinMasternode = CTxIn(outpoint); } -bool CGovernanceObject::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) +bool CGovernanceObject::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) { std::string strError; std::string strMessage = GetSignatureMessage(); @@ -254,7 +254,7 @@ bool CGovernanceObject::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) return true; } -bool CGovernanceObject::CheckSignature(CPubKey& pubKeyMasternode) +bool CGovernanceObject::CheckSignature(const CPubKey& pubKeyMasternode) { std::string strError; diff --git a/src/governance-object.h b/src/governance-object.h index c1696374766d22..79215dd4a86bfe 100644 --- a/src/governance-object.h +++ b/src/governance-object.h @@ -193,7 +193,7 @@ class CGovernanceObject public: CGovernanceObject(); - CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, int64_t nTime, uint256 nCollateralHashIn, std::string strDataIn); + CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTime, const uint256& nCollateralHashIn, const std::string& strDataIn); CGovernanceObject(const CGovernanceObject& other); @@ -256,8 +256,8 @@ class CGovernanceObject // Signature related functions void SetMasternodeVin(const COutPoint& outpoint); - bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); - bool CheckSignature(CPubKey& pubKeyMasternode); + bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); + bool CheckSignature(const CPubKey& pubKeyMasternode); std::string GetSignatureMessage() const; diff --git a/src/governance-vote.cpp b/src/governance-vote.cpp index 1a1c4489bcb217..03000eea48531c 100644 --- a/src/governance-vote.cpp +++ b/src/governance-vote.cpp @@ -147,7 +147,7 @@ std::string CGovernanceVoting::ConvertSignalToString(vote_signal_enum_t nSignal) } -vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(std::string strVoteOutcome) +vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(const std::string& strVoteOutcome) { vote_outcome_enum_t eVote = VOTE_OUTCOME_NONE; if(strVoteOutcome == "yes") { @@ -162,7 +162,7 @@ vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(std::string strVoteOut return eVote; } -vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(std::string strVoteSignal) +vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(const std::string& strVoteSignal) { vote_signal_enum_t eSignal = VOTE_SIGNAL_NONE; if(strVoteSignal == "funding") { @@ -238,7 +238,7 @@ void CGovernanceVote::Relay(CConnman& connman) const connman.RelayInv(inv, MIN_GOVERNANCE_PEER_PROTO_VERSION); } -bool CGovernanceVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) +bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) { // Choose coins to use CPubKey pubKeyCollateralAddress; diff --git a/src/governance-vote.h b/src/governance-vote.h index 53ccc2200d1672..d49e08425548ef 100644 --- a/src/governance-vote.h +++ b/src/governance-vote.h @@ -76,8 +76,8 @@ static const int MAX_SUPPORTED_VOTE_SIGNAL = VOTE_SIGNAL_ENDORSED; class CGovernanceVoting { public: - static vote_outcome_enum_t ConvertVoteOutcome(std::string strVoteOutcome); - static vote_signal_enum_t ConvertVoteSignal(std::string strVoteSignal); + static vote_outcome_enum_t ConvertVoteOutcome(const std::string& strVoteOutcome); + static vote_signal_enum_t ConvertVoteSignal(const std::string& strVoteSignal); static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome); static std::string ConvertSignalToString(vote_signal_enum_t nSignal); }; @@ -122,7 +122,7 @@ class CGovernanceVote void SetSignature(const std::vector& vchSigIn) { vchSig = vchSigIn; } - bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); + bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); bool IsValid(bool fSignatureCheck) const; void Relay(CConnman& connman) const; diff --git a/src/hdchain.cpp b/src/hdchain.cpp index 78cb7708a135d6..ce426e9e71516f 100644 --- a/src/hdchain.cpp +++ b/src/hdchain.cpp @@ -40,7 +40,7 @@ bool CHDChain::IsCrypted() const return fCrypted; } -void CHDChain::Debug(std::string strName) const +void CHDChain::Debug(const std::string& strName) const { DBG( std::cout << __func__ << ": ---" << strName << "---" << std::endl; diff --git a/src/hdchain.h b/src/hdchain.h index 65539dc1fc132a..d9dbffea938c6c 100644 --- a/src/hdchain.h +++ b/src/hdchain.h @@ -99,7 +99,7 @@ class CHDChain void SetCrypted(bool fCryptedIn); bool IsCrypted() const; - void Debug(std::string strName) const; + void Debug(const std::string& strName) const; bool SetMnemonic(const SecureVector& vchMnemonic, const SecureVector& vchMnemonicPassphrase, bool fUpdateID); bool SetMnemonic(const SecureString& ssMnemonic, const SecureString& ssMnemonicPassphrase, bool fUpdateID); diff --git a/src/keepass.cpp b/src/keepass.cpp index e4907992eddb04..6cb791a4299a40 100644 --- a/src/keepass.cpp +++ b/src/keepass.cpp @@ -123,12 +123,12 @@ void CKeePassIntegrator::init() } } -void CKeePassIntegrator::CKeePassRequest::addStrParameter(std::string strName, std::string strValue) +void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const std::string& strValue) { requestObj.push_back(Pair(strName, strValue)); } -void CKeePassIntegrator::CKeePassRequest::addStrParameter(std::string strName, SecureString sValue) +void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const SecureString& sValue) { std::string sCipherValue; @@ -156,7 +156,7 @@ void CKeePassIntegrator::CKeePassRequest::init() addStrParameter("RequestType", strType); } -void CKeePassIntegrator::CKeePassResponse::parseResponse(std::string strResponse) +void CKeePassIntegrator::CKeePassResponse::parseResponse(const std::string& strResponse) { UniValue responseValue; if(!responseValue.read(strResponse)) @@ -172,12 +172,12 @@ void CKeePassIntegrator::CKeePassResponse::parseResponse(std::string strResponse strIV = DecodeBase64(getStr("Nonce")); } -std::string CKeePassIntegrator::CKeePassResponse::getStr(std::string strName) +std::string CKeePassIntegrator::CKeePassResponse::getStr(const std::string& strName) { return responseObj[strName].get_str(); } -SecureString CKeePassIntegrator::CKeePassResponse::getSecureStr(std::string strName) +SecureString CKeePassIntegrator::CKeePassResponse::getSecureStr(const std::string& strName) { std::string strValueBase64Encrypted(responseObj[strName].get_str()); SecureString sValue; @@ -194,7 +194,7 @@ SecureString CKeePassIntegrator::CKeePassResponse::getSecureStr(std::string strN return sValue; } -SecureString CKeePassIntegrator::CKeePassResponse::decrypt(std::string strValueBase64Encrypted) +SecureString CKeePassIntegrator::CKeePassResponse::decrypt(const std::string& strValueBase64Encrypted) { std::string strValueEncrypted = DecodeBase64(strValueBase64Encrypted); SecureString sValue; @@ -287,7 +287,7 @@ static void http_request_done(struct evhttp_request *req, void *ctx) } // Send RPC message to KeePassHttp -void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatus, std::string& strResponse) +void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatusRet, std::string& strResponseRet) { // // Prepare communication // boost::asio::io_service io_service; @@ -403,7 +403,7 @@ void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatus, s // ReadHTTPMessage(response_stream, mapHeaders, strResponse, nProto, std::numeric_limits::max()); // LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- Processed body\n"); - nStatus = response.nStatus; + nStatusRet = response.nStatus; if (response.nStatus == 0) throw std::runtime_error("couldn't connect to server"); else if (response.nStatus >= 400 && response.nStatus != HTTP_BAD_REQUEST && response.nStatus != HTTP_NOT_FOUND && response.nStatus != HTTP_INTERNAL_SERVER_ERROR) @@ -419,7 +419,7 @@ void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatus, s if (reply.empty()) throw std::runtime_error("expected reply to have result, error and id properties"); - strResponse = valReply.get_str(); + strResponseRet = valReply.get_str(); } void CKeePassIntegrator::rpcTestAssociation(bool bTriggerUnlock) @@ -535,13 +535,13 @@ SecureString CKeePassIntegrator::generateKeePassKey() return sKeyBase64; } -void CKeePassIntegrator::rpcAssociate(std::string& strId, SecureString& sKeyBase64) +void CKeePassIntegrator::rpcAssociate(std::string& strIdRet, SecureString& sKeyBase64Ret) { sKey = generateRandomKey(KEEPASS_CRYPTO_KEY_SIZE); CKeePassRequest request(sKey, "associate"); - sKeyBase64 = EncodeBase64Secure(sKey); - request.addStrParameter("Key", std::string(&sKeyBase64[0], sKeyBase64.size())); + sKeyBase64Ret = EncodeBase64Secure(sKey); + request.addStrParameter("Key", std::string(&sKeyBase64Ret[0], sKeyBase64Ret.size())); int nStatus; std::string strResponse; @@ -570,7 +570,7 @@ void CKeePassIntegrator::rpcAssociate(std::string& strId, SecureString& sKeyBase } // If we got here, we were successful. Return the information - strId = response.getStr("Id"); + strIdRet = response.getStr("Id"); } // Retrieve wallet passphrase from KeePass diff --git a/src/keepass.h b/src/keepass.h index f728f25c442b8f..d94f6f5dc7dc22 100644 --- a/src/keepass.h +++ b/src/keepass.h @@ -42,11 +42,11 @@ class CKeePassIntegrator { void init(); public: - void addStrParameter(std::string strName, std::string strValue); // Regular - void addStrParameter(std::string strName, SecureString sValue); // Encrypt + void addStrParameter(const std::string& strName, const std::string& strValue); // Regular + void addStrParameter(const std::string& strName, const SecureString& sValue); // Encrypt std::string getJson(); - CKeePassRequest(SecureString sKey, std::string strType) + CKeePassRequest(const SecureString& sKey, const std::string& strType) { this->sKey = sKey; this->strType = strType; @@ -63,7 +63,7 @@ class CKeePassIntegrator { SecureString sPassword; public: - CKeePassEntry(SecureString sUuid, SecureString sName, SecureString sLogin, SecureString sPassword) : + CKeePassEntry(const SecureString& sUuid, const SecureString& sName, const SecureString& sLogin, const SecureString& sPassword) : sUuid(sUuid), sName(sName), sLogin(sLogin), sPassword(sPassword) { } @@ -93,11 +93,11 @@ class CKeePassIntegrator { std::string strIV; SecureString sKey; - void parseResponse(std::string strResponse); + void parseResponse(const std::string& strResponse); public: UniValue responseObj; - CKeePassResponse(SecureString sKey, std::string strResponse) { + CKeePassResponse(const SecureString& sKey, const std::string& strResponse) { this->sKey = sKey; parseResponse(strResponse); } @@ -106,17 +106,17 @@ class CKeePassIntegrator { return bSuccess; } - SecureString getSecureStr(std::string strName); - std::string getStr(std::string strName); + SecureString getSecureStr(const std::string& strName); + std::string getStr(const std::string& strName); std::vector getEntries(); - SecureString decrypt(std::string strValue); // DecodeBase64 and decrypt arbitrary string value + SecureString decrypt(const std::string& strValue); // DecodeBase64 and decrypt arbitrary string value }; static SecureString generateRandomKey(size_t nSize); static std::string constructHTTPPost(const std::string& strMsg, const std::map& mapRequestHeaders); - void doHTTPPost(const std::string& strRequest, int& nStatus, std::string& strResponse); + void doHTTPPost(const std::string& strRequest, int& nStatusRet, std::string& strResponseRet); void rpcTestAssociation(bool bTriggerUnlock); std::vector rpcGetLogins(); void rpcSetLogin(const SecureString& sWalletPass, const SecureString& sEntryId); @@ -125,7 +125,7 @@ class CKeePassIntegrator { CKeePassIntegrator(); void init(); static SecureString generateKeePassKey(); - void rpcAssociate(std::string& strId, SecureString& sKeyBase64); + void rpcAssociate(std::string& strIdRet, SecureString& sKeyBase64Ret); SecureString retrievePassphrase(); void updatePassphrase(const SecureString& sWalletPassphrase); diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 783efd44f45765..31271d2012ffa7 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -35,7 +35,7 @@ void CMasternodeSync::Reset() nTimeLastFailure = 0; } -void CMasternodeSync::BumpAssetLastTime(std::string strFuncName) +void CMasternodeSync::BumpAssetLastTime(const std::string& strFuncName) { if(IsSynced() || IsFailed()) return; nTimeLastBumped = GetTime(); diff --git a/src/masternode-sync.h b/src/masternode-sync.h index fb4ed17d3d1094..58d6626e4609d0 100644 --- a/src/masternode-sync.h +++ b/src/masternode-sync.h @@ -65,7 +65,7 @@ class CMasternodeSync int GetAssetID() { return nRequestedMasternodeAssets; } int GetAttempt() { return nRequestedMasternodeAttempt; } - void BumpAssetLastTime(std::string strFuncName); + void BumpAssetLastTime(const std::string& strFuncName); int64_t GetAssetStartTime() { return nTimeAssetSyncStarted; } std::string GetAssetName(); std::string GetSyncStatus(); diff --git a/src/masternode.cpp b/src/masternode.cpp index dddc9af60f30fb..804348d253dd18 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -338,7 +338,7 @@ void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScan } #ifdef ENABLE_WALLET -bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline) +bool CMasternodeBroadcast::Create(const std::string& strService, const std::string& strKeyMasternode, const std::string& strTxHash, const std::string& strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline) { COutPoint outpoint; CPubKey pubKeyCollateralAddressNew; @@ -672,7 +672,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste return true; } -bool CMasternodePing::CheckSignature(CPubKey& pubKeyMasternode, int &nDos) +bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos) { // TODO: add sentinel data std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); diff --git a/src/masternode.h b/src/masternode.h index fcfc07d9bb0e32..9048c850139786 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -78,7 +78,7 @@ class CMasternodePing bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; } bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); - bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos); + bool CheckSignature(const CPubKey& pubKeyMasternode, int &nDos); bool SimpleCheck(int& nDos); bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman); void Relay(CConnman& connman); @@ -349,7 +349,7 @@ class CMasternodeBroadcast : public CMasternode /// Create Masternode broadcast, needs to be relayed manually after that static bool Create(const COutPoint& outpoint, const CService& service, const CKey& keyCollateralAddressNew, const CPubKey& pubKeyCollateralAddressNew, const CKey& keyMasternodeNew, const CPubKey& pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet); - static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline = false); + static bool Create(const std::string& strService, const std::string& strKey, const std::string& strTxHash, const std::string& strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline = false); bool SimpleCheck(int& nDos); bool Update(CMasternode* pmn, int& nDos, CConnman& connman); diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp index 250036564913bd..31d4cacc12d4f5 100644 --- a/src/masternodeconfig.cpp +++ b/src/masternodeconfig.cpp @@ -9,12 +9,12 @@ CMasternodeConfig masternodeConfig; -void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { +void CMasternodeConfig::add(const std::string& alias, const std::string& ip, const std::string& privKey, const std::string& txHash, const std::string& outputIndex) { CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex); entries.push_back(cme); } -bool CMasternodeConfig::read(std::string& strErr) { +bool CMasternodeConfig::read(std::string& strErrRet) { int linenumber = 1; boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile(); boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile); @@ -48,7 +48,7 @@ bool CMasternodeConfig::read(std::string& strErr) { iss.str(line); iss.clear(); if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { - strErr = _("Could not parse masternode.conf") + "\n" + + strErrRet = _("Could not parse masternode.conf") + "\n" + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; streamConfig.close(); return false; @@ -59,7 +59,7 @@ bool CMasternodeConfig::read(std::string& strErr) { std::string hostname = ""; SplitHostPort(ip, port, hostname); if(port == 0 || hostname == "") { - strErr = _("Failed to parse host:port string") + "\n"+ + strErrRet = _("Failed to parse host:port string") + "\n"+ strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; streamConfig.close(); return false; @@ -67,7 +67,7 @@ bool CMasternodeConfig::read(std::string& strErr) { int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); if(Params().NetworkIDString() == CBaseChainParams::MAIN) { if(port != mainnetDefaultPort) { - strErr = _("Invalid port detected in masternode.conf") + "\n" + + strErrRet = _("Invalid port detected in masternode.conf") + "\n" + strprintf(_("Port: %d"), port) + "\n" + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + strprintf(_("(must be %d for mainnet)"), mainnetDefaultPort); @@ -75,7 +75,7 @@ bool CMasternodeConfig::read(std::string& strErr) { return false; } } else if(port == mainnetDefaultPort) { - strErr = _("Invalid port detected in masternode.conf") + "\n" + + strErrRet = _("Invalid port detected in masternode.conf") + "\n" + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + strprintf(_("(%d could be used only on mainnet)"), mainnetDefaultPort); streamConfig.close(); diff --git a/src/masternodeconfig.h b/src/masternodeconfig.h index 37d5d287325b8e..fb4a404b775a7e 100644 --- a/src/masternodeconfig.h +++ b/src/masternodeconfig.h @@ -25,7 +25,7 @@ class CMasternodeConfig std::string outputIndex; public: - CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { + CMasternodeEntry(const std::string& alias, const std::string& ip, const std::string& privKey, const std::string& txHash, const std::string& outputIndex) { this->alias = alias; this->ip = ip; this->privKey = privKey; @@ -79,8 +79,8 @@ class CMasternodeConfig } void clear(); - bool read(std::string& strErr); - void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); + bool read(std::string& strErrRet); + void add(const std::string& alias, const std::string& ip, const std::string& privKey, const std::string& txHash, const std::string& outputIndex); std::vector& getEntries() { return entries; diff --git a/src/messagesigner.cpp b/src/messagesigner.cpp index 96a67171154b2f..cb750b344ce0f9 100644 --- a/src/messagesigner.cpp +++ b/src/messagesigner.cpp @@ -10,7 +10,7 @@ #include "tinyformat.h" #include "utilstrencodings.h" -bool CMessageSigner::GetKeysFromSecret(const std::string strSecret, CKey& keyRet, CPubKey& pubkeyRet) +bool CMessageSigner::GetKeysFromSecret(const std::string& strSecret, CKey& keyRet, CPubKey& pubkeyRet) { CBitcoinSecret vchSecret; @@ -22,7 +22,7 @@ bool CMessageSigner::GetKeysFromSecret(const std::string strSecret, CKey& keyRet return true; } -bool CMessageSigner::SignMessage(const std::string strMessage, std::vector& vchSigRet, const CKey key) +bool CMessageSigner::SignMessage(const std::string& strMessage, std::vector& vchSigRet, const CKey& key) { CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; @@ -31,7 +31,7 @@ bool CMessageSigner::SignMessage(const std::string strMessage, std::vector& vchSig, const std::string strMessage, std::string& strErrorRet) +bool CMessageSigner::VerifyMessage(const CPubKey& pubkey, const std::vector& vchSig, const std::string& strMessage, std::string& strErrorRet) { CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; @@ -40,12 +40,12 @@ bool CMessageSigner::VerifyMessage(const CPubKey pubkey, const std::vector& vchSigRet) +bool CHashSigner::SignHash(const uint256& hash, const CKey& key, std::vector& vchSigRet) { return key.SignCompact(hash, vchSigRet); } -bool CHashSigner::VerifyHash(const uint256& hash, const CPubKey pubkey, const std::vector& vchSig, std::string& strErrorRet) +bool CHashSigner::VerifyHash(const uint256& hash, const CPubKey& pubkey, const std::vector& vchSig, std::string& strErrorRet) { CPubKey pubkeyFromSig; if(!pubkeyFromSig.RecoverCompact(hash, vchSig)) { diff --git a/src/messagesigner.h b/src/messagesigner.h index 32abd0d23e689e..bf4a9fe9d989e1 100644 --- a/src/messagesigner.h +++ b/src/messagesigner.h @@ -14,11 +14,11 @@ class CMessageSigner { public: /// Set the private/public key values, returns true if successful - static bool GetKeysFromSecret(const std::string strSecret, CKey& keyRet, CPubKey& pubkeyRet); + static bool GetKeysFromSecret(const std::string& strSecret, CKey& keyRet, CPubKey& pubkeyRet); /// Sign the message, returns true if successful - static bool SignMessage(const std::string strMessage, std::vector& vchSigRet, const CKey key); + static bool SignMessage(const std::string& strMessage, std::vector& vchSigRet, const CKey& key); /// Verify the message signature, returns true if succcessful - static bool VerifyMessage(const CPubKey pubkey, const std::vector& vchSig, const std::string strMessage, std::string& strErrorRet); + static bool VerifyMessage(const CPubKey& pubkey, const std::vector& vchSig, const std::string& strMessage, std::string& strErrorRet); }; /** Helper class for signing hashes and checking their signatures @@ -27,9 +27,9 @@ class CHashSigner { public: /// Sign the hash, returns true if successful - static bool SignHash(const uint256& hash, const CKey key, std::vector& vchSigRet); + static bool SignHash(const uint256& hash, const CKey& key, std::vector& vchSigRet); /// Verify the hash signature, returns true if succcessful - static bool VerifyHash(const uint256& hash, const CPubKey pubkey, const std::vector& vchSig, std::string& strErrorRet); + static bool VerifyHash(const uint256& hash, const CPubKey& pubkey, const std::vector& vchSig, std::string& strErrorRet); }; #endif diff --git a/src/netfulfilledman.cpp b/src/netfulfilledman.cpp index 0d6ac12f551017..6b4ce896a1c6ae 100644 --- a/src/netfulfilledman.cpp +++ b/src/netfulfilledman.cpp @@ -9,13 +9,13 @@ CNetFulfilledRequestManager netfulfilledman; -void CNetFulfilledRequestManager::AddFulfilledRequest(CAddress addr, std::string strRequest) +void CNetFulfilledRequestManager::AddFulfilledRequest(const CAddress& addr, const std::string& strRequest) { LOCK(cs_mapFulfilledRequests); mapFulfilledRequests[addr][strRequest] = GetTime() + Params().FulfilledRequestExpireTime(); } -bool CNetFulfilledRequestManager::HasFulfilledRequest(CAddress addr, std::string strRequest) +bool CNetFulfilledRequestManager::HasFulfilledRequest(const CAddress& addr, const std::string& strRequest) { LOCK(cs_mapFulfilledRequests); fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addr); @@ -25,7 +25,7 @@ bool CNetFulfilledRequestManager::HasFulfilledRequest(CAddress addr, std::string it->second[strRequest] > GetTime(); } -void CNetFulfilledRequestManager::RemoveFulfilledRequest(CAddress addr, std::string strRequest) +void CNetFulfilledRequestManager::RemoveFulfilledRequest(const CAddress& addr, const std::string& strRequest) { LOCK(cs_mapFulfilledRequests); fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addr); diff --git a/src/netfulfilledman.h b/src/netfulfilledman.h index bee88af7b4392e..cc5a261e0443d1 100644 --- a/src/netfulfilledman.h +++ b/src/netfulfilledman.h @@ -37,9 +37,9 @@ class CNetFulfilledRequestManager READWRITE(mapFulfilledRequests); } - void AddFulfilledRequest(CAddress addr, std::string strRequest); // expire after 1 hour by default - bool HasFulfilledRequest(CAddress addr, std::string strRequest); - void RemoveFulfilledRequest(CAddress addr, std::string strRequest); + void AddFulfilledRequest(const CAddress& addr, const std::string& strRequest); // expire after 1 hour by default + bool HasFulfilledRequest(const CAddress& addr, const std::string& strRequest); + void RemoveFulfilledRequest(const CAddress& addr, const std::string& strRequest); void CheckAndRemove(); void Clear(); diff --git a/src/spork.cpp b/src/spork.cpp index 890ab912e0fce5..108ae07d7d6643 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -169,7 +169,7 @@ int64_t CSporkManager::GetSporkValue(int nSporkID) } -int CSporkManager::GetSporkIDByName(std::string strName) +int CSporkManager::GetSporkIDByName(const std::string& strName) { if (strName == "SPORK_2_INSTANTSEND_ENABLED") return SPORK_2_INSTANTSEND_ENABLED; if (strName == "SPORK_3_INSTANTSEND_BLOCK_FILTERING") return SPORK_3_INSTANTSEND_BLOCK_FILTERING; @@ -203,7 +203,7 @@ std::string CSporkManager::GetSporkNameByID(int nSporkID) } } -bool CSporkManager::SetPrivKey(std::string strPrivKey) +bool CSporkManager::SetPrivKey(const std::string& strPrivKey) { CSporkMessage spork; @@ -219,7 +219,7 @@ bool CSporkManager::SetPrivKey(std::string strPrivKey) } } -bool CSporkMessage::Sign(std::string strSignKey) +bool CSporkMessage::Sign(const std::string& strSignKey) { CKey key; CPubKey pubkey; diff --git a/src/spork.h b/src/spork.h index f222460e23f66f..a4ddd86dcb7ecb 100644 --- a/src/spork.h +++ b/src/spork.h @@ -90,7 +90,7 @@ class CSporkMessage return ss.GetHash(); } - bool Sign(std::string strSignKey); + bool Sign(const std::string& strSignKey); bool CheckSignature(); void Relay(CConnman& connman); }; @@ -113,10 +113,10 @@ class CSporkManager bool IsSporkActive(int nSporkID); int64_t GetSporkValue(int nSporkID); - int GetSporkIDByName(std::string strName); + int GetSporkIDByName(const std::string& strName); std::string GetSporkNameByID(int nSporkID); - bool SetPrivKey(std::string strPrivKey); + bool SetPrivKey(const std::string& strPrivKey); }; #endif diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b7f8d3fd5d52b7..f1a021b68b3ee0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1961,7 +1961,7 @@ void CWallet::ReacceptWalletTransactions() } } -bool CWalletTx::RelayWalletTransaction(CConnman* connman, std::string strCommand) +bool CWalletTx::RelayWalletTransaction(CConnman* connman, const std::string& strCommand) { assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain() == 0) @@ -3210,7 +3210,7 @@ bool CWallet::GetCollateralTxDSIn(CTxDSIn& txdsinRet, CAmount& nValueRet) const return false; } -bool CWallet::GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash, std::string strOutputIndex) +bool CWallet::GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, const std::string& strTxHash, const std::string& strOutputIndex) { // wait for reindex and/or import to finish if (fImporting || fReindex) return false; @@ -3816,7 +3816,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt /** * Call after CreateTransaction unless you want to abort */ -bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state, std::string strCommand) +bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state, const std::string& strCommand) { { LOCK2(cs_main, cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6bc21322a9de4f..f432d4ac23494e 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -286,7 +286,7 @@ class CMerkleTx bool IsCoinBase() const { return tx->IsCoinBase(); } }; -/** +/** * A transaction with a bunch of additional info that only the owner cares about. * It includes any unrecorded transactions needed to link it back to the block chain. */ @@ -482,7 +482,7 @@ class CWalletTx : public CMerkleTx int64_t GetTxTime() const; int GetRequestCount() const; - bool RelayWalletTransaction(CConnman* connman, std::string strCommand="tx"); + bool RelayWalletTransaction(CConnman* connman, const std::string& strCommand="tx"); std::set GetConflicts() const; }; @@ -623,7 +623,7 @@ class CAccountingEntry }; -/** +/** * A CWallet is an extension of a keystore, which also maintains a set of transactions and balances, * and provides the ability to create new transactions. */ @@ -734,7 +734,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface SetNull(); } - CWallet(const std::string& strWalletFileIn) + CWallet(const std::string& strWalletFileIn) : strWalletFile(strWalletFileIn) { SetNull(); @@ -812,7 +812,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool SelectCoinsGrouppedByAddresses(std::vector& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true) const; /// Get 2500ABS output and keys which can be used for the Masternode - bool GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = ""); + bool GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, const std::string& strTxHash = "", const std::string& strOutputIndex = ""); /// Extract txin information and keys from output bool GetOutpointAndKeysFromOutput(const COutput& out, COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet); @@ -887,7 +887,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface void GetKeyBirthTimes(std::map &mapKeyBirth) const; - /** + /** * Increment the next transaction order id * @return next transaction order id */ @@ -935,7 +935,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface */ bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false); - bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state, std::string strCommand="tx"); + bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state, const std::string& strCommand="tx"); bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason); bool ConvertList(std::vector vecTxIn, std::vector& vecAmounts); @@ -1026,7 +1026,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface LOCK(cs_wallet); mapRequestCount[hash] = 0; }; - + unsigned int GetKeyPoolSize() { AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool @@ -1052,8 +1052,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface //! Verify the wallet database and perform salvage if required static bool Verify(); - - /** + + /** * Address book entry changed. * @note called with lock cs_wallet held. */ @@ -1062,7 +1062,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface const std::string &purpose, ChangeType status)> NotifyAddressBookChanged; - /** + /** * Wallet transaction added, removed or updated. * @note called with lock cs_wallet held. */ @@ -1144,7 +1144,7 @@ class CReserveKey : public CReserveScript }; -/** +/** * Account information. * Stored in wallet with key "acc"+string account name. */