Skip to content

Commit 3a7c351

Browse files
committed
feat: token transfer operator == adition
Signed-off-by: Egbaiyelo <moteniolaegbaiyelo@trentu.ca>
1 parent 98f9995 commit 3a7c351

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/sdk/main/include/TokenTransfer.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ class TokenTransfer
9797
*/
9898
void validateChecksums(const Client& client) const;
9999

100+
/**
101+
* Compare this TokenTransfer instance to another TokenTransfer instance and determine if they represent the same pending TokenTransfer.
102+
*
103+
* @param other The other TokenTransfer with which to compare this TokenTransfer.
104+
* @return \c TRUE if this TokenTransfer is the same as the input TokenTransfer, otherwise \c FALSE.
105+
*/
106+
friend bool operator==(const TokenTransfer&, const TokenTransfer&);
107+
100108
/**
101109
* Construct an AccountAmount protobuf object from this TokenTransfer object.
102110
*
@@ -158,6 +166,15 @@ class TokenTransfer
158166
FungibleHookCall mHookCall;
159167
};
160168

169+
// Adding nodiscard attribute to == operator
170+
/**
171+
* Compare this TokenTransfer instance to another TokenTransfer instance and determine if they represent the same pending TokenTransfer.
172+
*
173+
* @param other The other TokenTransfer with which to compare this TokenTransfer.
174+
* @return \c TRUE if this TokenTransfer is the same as the input TokenTransfer, otherwise \c FALSE.
175+
*/
176+
[[nodiscard]] bool operator==(const TokenTransfer&, const TokenTransfer&);
177+
161178
} // namespace Hiero
162179

163180
#endif // HIERO_SDK_CPP_TOKEN_TRANSFER_H_

src/sdk/main/src/TokenTransfer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void TokenTransfer::validateChecksums(const Client& client) const
7878
mAccountId.validateChecksum(client);
7979
}
8080

81+
bool operator==(const TokenTransfer& lhs, const TokenTransfer& rhs) {
82+
return (lhs.mTokenId == rhs.mTokenId) && (lhs.mAccountId == rhs.mAccountId) && (lhs.mAmount == rhs.mAmount) && (lhs.mIsApproval == rhs.mIsApproval) && (lhs.mExpectedDecimals == rhs.mExpectedDecimals);
83+
}
84+
8185
//-----
8286
std::unique_ptr<proto::AccountAmount> TokenTransfer::toProtobuf() const
8387
{

src/sdk/tests/unit/TokenTransferUnitTests.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: Apache-2.0
1+
// SPDX-License-Identifier: Apache-2.0
22
#include "TokenTransfer.h"
33

44
#include "AccountId.h"
@@ -114,3 +114,27 @@ TEST_F(TokenTransferUnitTests, ToProtobuf)
114114
EXPECT_EQ(proto->amount(), getTestAmount());
115115
EXPECT_EQ(proto->is_approval(), getTestIsApproval());
116116
}
117+
118+
//-----
119+
TEST_F(TokenTransferUnitTests, OperatorEqualsFt)
120+
{
121+
// Given
122+
// Defaults
123+
TokenTransfer defaultTokenL;
124+
TokenTransfer defaultTokenR;
125+
// Identical
126+
TokenTransfer equalTokenL(
127+
getTestTokenId(), getTestAccountId(), getTestAmount(), getTestExpectedDecimals(), getTestIsApproval());
128+
TokenTransfer equalTokenR(
129+
getTestTokenId(), getTestAccountId(), getTestAmount(), getTestExpectedDecimals(), getTestIsApproval());
130+
// Different
131+
TokenTransfer diffTokenL(
132+
getTestTokenId(), getTestAccountId(), getTestAmount(), getTestExpectedDecimals(), true);
133+
TokenTransfer diffTokenR(
134+
getTestTokenId(), getTestAccountId(), getTestAmount(), getTestExpectedDecimals(), false);
135+
136+
// Then
137+
EXPECT_TRUE(defaultTokenL == defaultTokenR);
138+
EXPECT_TRUE(equalTokenL == equalTokenR);
139+
EXPECT_TRUE(diffTokenL == diffTokenR);
140+
}

0 commit comments

Comments
 (0)