Skip to content

Commit

Permalink
Refactor: use constant refs and Ret suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored and CryptoCentric committed Mar 2, 2019
1 parent ac390a5 commit 715cc37
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 96 deletions.
4 changes: 2 additions & 2 deletions src/governance-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> SplitBy(std::string strCommand, std::string strDelimit)
std::vector<std::string> SplitBy(const std::string& strCommand, const std::string& strDelimit)
{
std::vector<std::string> vParts;
boost::split(vParts, strCommand, boost::is_any_of(strDelimit));
Expand Down Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/governance-classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ typedef boost::shared_ptr<CSuperblock> CSuperblock_sptr;
// DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES
extern CGovernanceTriggerManager triggerman;

// SPLIT A STRING UP - USED FOR SUPERBLOCK PAYMENTS
std::vector<std::string> SplitBy(std::string strCommand, std::string strDelimit);

/**
* Trigger Mananger
*
Expand Down Expand Up @@ -153,7 +150,7 @@ class CSuperblock : public CGovernanceObject
int nStatus;
std::vector<CGovernancePayment> vecPayments;

void ParsePaymentSchedule(std::string& strPaymentAddresses, std::string& strPaymentAmounts);
void ParsePaymentSchedule(const std::string& strPaymentAddresses, const std::string& strPaymentAmounts);

public:

Expand Down
6 changes: 3 additions & 3 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/governance-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/governance-vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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") {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/governance-vote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -122,7 +122,7 @@ class CGovernanceVote

void SetSignature(const std::vector<unsigned char>& 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;

Expand Down
2 changes: 1 addition & 1 deletion src/hdchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/hdchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions src/keepass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -403,7 +403,7 @@ void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatus, s
// ReadHTTPMessage(response_stream, mapHeaders, strResponse, nProto, std::numeric_limits<size_t>::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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/keepass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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<CKeePassEntry> 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<std::string,std::string>& 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<CKeePassEntry> rpcGetLogins();
void rpcSetLogin(const SecureString& sWalletPass, const SecureString& sEntryId);
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/masternode-sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string>(sigTime);
Expand Down
4 changes: 2 additions & 2 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 715cc37

Please sign in to comment.