From e28259d6e881864bd628f1479a42afe87d51fe68 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sun, 20 Dec 2020 15:27:43 +0100 Subject: [PATCH] Masternode: proper copy-assignment for CMasternode/CmasternodePing Also remove unneeded swap func in SignedMessage --- src/masternode.h | 55 +++++++++++-------------------------------- src/messagesigner.cpp | 11 --------- src/messagesigner.h | 1 - 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/src/masternode.h b/src/masternode.h index 3d242a775d2fb..29636901ba62c 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -71,25 +71,7 @@ class CMasternodePing : public CSignedMessage bool CheckAndUpdate(int& nDos, bool fRequireAvailable = true, bool fCheckSigTimeOnly = false); void Relay(); - void swap(CMasternodePing& first, CMasternodePing& second) // nothrow - { - CSignedMessage::swap(first, second); - - // enable ADL (not necessary in our case, but good practice) - using std::swap; - - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.vin, second.vin); - swap(first.blockHash, second.blockHash); - swap(first.sigTime, second.sigTime); - } - - CMasternodePing& operator=(CMasternodePing from) - { - swap(*this, from); - return *this; - } + CMasternodePing& operator=(const CMasternodePing& other) = default; friend bool operator==(const CMasternodePing& a, const CMasternodePing& b) { @@ -142,31 +124,22 @@ class CMasternode : public CSignedMessage void SetLastPing(const CMasternodePing& _lastPing) { WITH_LOCK(cs, lastPing = _lastPing;); } - void swap(CMasternode& first, CMasternode& second) // nothrow - { - CSignedMessage::swap(first, second); - - // enable ADL (not necessary in our case, but good practice) - using std::swap; - - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.vin, second.vin); - swap(first.addr, second.addr); - swap(first.pubKeyCollateralAddress, second.pubKeyCollateralAddress); - swap(first.pubKeyMasternode, second.pubKeyMasternode); - swap(first.sigTime, second.sigTime); - swap(first.lastPing, second.lastPing); - swap(first.protocolVersion, second.protocolVersion); - swap(first.nScanningErrorCount, second.nScanningErrorCount); - swap(first.nLastScanningErrorBlockHeight, second.nLastScanningErrorBlockHeight); - } - - CMasternode& operator=(CMasternode from) + CMasternode& operator=(const CMasternode& other) { - swap(*this, from); + nMessVersion = other.nMessVersion; + vchSig = other.vchSig; + vin = other.vin; + addr = other.addr; + pubKeyCollateralAddress = other.pubKeyCollateralAddress; + pubKeyMasternode = other.pubKeyMasternode; + sigTime = other.sigTime; + lastPing = other.lastPing; + protocolVersion = other.protocolVersion; + nScanningErrorCount = other.nScanningErrorCount; + nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight; return *this; } + friend bool operator==(const CMasternode& a, const CMasternode& b) { return a.vin == b.vin; diff --git a/src/messagesigner.cpp b/src/messagesigner.cpp index 0b2315d1f03ca..0c42afff9ff7a 100644 --- a/src/messagesigner.cpp +++ b/src/messagesigner.cpp @@ -144,14 +144,3 @@ std::string CSignedMessage::GetSignatureBase64() const return EncodeBase64(&vchSig[0], vchSig.size()); } -void CSignedMessage::swap(CSignedMessage& first, CSignedMessage& second) // nothrow -{ - // enable ADL (not necessary in our case, but good practice) - using std::swap; - - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.vchSig, second.vchSig); - swap(first.nMessVersion, second.nMessVersion); -} - diff --git a/src/messagesigner.h b/src/messagesigner.h index 647a74379f037..5e3acdf0c501a 100644 --- a/src/messagesigner.h +++ b/src/messagesigner.h @@ -50,7 +50,6 @@ class CSignedMessage { protected: std::vector vchSig; - void swap(CSignedMessage& first, CSignedMessage& second); // Swap two messages public: int nMessVersion;