Skip to content

Commit

Permalink
Masternode: proper copy-assignment for CMasternode/CmasternodePing
Browse files Browse the repository at this point in the history
Also remove unneeded swap func in SignedMessage
  • Loading branch information
random-zebra committed Dec 20, 2020
1 parent 2e6aeed commit e28259d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
55 changes: 14 additions & 41 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions src/messagesigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

1 change: 0 additions & 1 deletion src/messagesigner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CSignedMessage
{
protected:
std::vector<unsigned char> vchSig;
void swap(CSignedMessage& first, CSignedMessage& second); // Swap two messages

public:
int nMessVersion;
Expand Down

0 comments on commit e28259d

Please sign in to comment.