forked from hiero-ledger/hiero-sdk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenTransfer.h
More file actions
171 lines (147 loc) · 5.41 KB
/
TokenTransfer.h
File metadata and controls
171 lines (147 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_SDK_CPP_TOKEN_TRANSFER_H_
#define HIERO_SDK_CPP_TOKEN_TRANSFER_H_
#include "AccountId.h"
#include "TokenId.h"
#include "hooks/FungibleHookCall.h"
#include <cstddef>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
namespace proto
{
class AccountAmount;
}
namespace Hiero
{
class Client;
}
namespace Hiero
{
/**
* A token ID and list of amounts representing the transferred out (negative) or into (positive) amounts, represented
* in the lowest denomination of the token.
*/
class TokenTransfer
{
public:
TokenTransfer() = default;
/**
* Construct with a token ID, account ID, amount, and approval.
*
* @param tokenId The ID of the token involved with this TokenTransfer.
* @param accountId The ID of the account to/from which the token is being transferred.
* @param amount The amount of the token being transferred.
* @param isApproved \c TRUE if this transfer is approved, otherwise \c FALSE.
*/
TokenTransfer(TokenId tokenId, AccountId accountId, int64_t amount, bool isApproved);
/**
* Construct with a token ID, account ID, amount, approval, and hook call.
*
* @param tokenId The ID of the token involved with this TokenTransfer.
* @param accountId The ID of the account to/from which the token is being transferred.
* @param amount The amount of the token being transferred.
* @param isApproved \c TRUE if this transfer is approved, otherwise \c FALSE.
* @param hookCall A hook call associated with this token transfer.
*/
TokenTransfer(TokenId tokenId,
AccountId accountId,
int64_t amount,
bool isApproved,
const FungibleHookCall& hookCall);
/**
* Construct with a token ID, account ID, amount, expected decimals of the token, and approval.
*
* @param tokenId The ID of the token involved with this TokenTransfer.
* @param accountId The ID of the account to/from which the token is being transferred.
* @param amount The amount of the token being transferred.
* @param isApproved \c TRUE if this transfer is approved, otherwise \c FALSE.
*/
TokenTransfer(TokenId tokenId, AccountId accountId, int64_t amount, uint32_t decimals, bool isApproved);
/**
* Construct a TokenTransfer object from an AccountAmount protobuf object, a TokenId object, and the number of
* expected decimals.
*
* @param proto The AccountAmount protobuf object from which to construct the TokenTransfer object.
* @param tokenId The ID of the token.
* @param decimals The number of expected decimals.
* @return The constructed TokenTransfer object.
*/
[[nodiscard]] static TokenTransfer fromProtobuf(const proto::AccountAmount& proto,
const TokenId& tokenId,
uint32_t expectedDecimals);
/**
* Construct a TokenTransfer object from a byte array.
*
* @param bytes The byte array from which to construct a TokenTransfer object.
* @return The constructed TokenTransfer object.
*/
[[nodiscard]] static TokenTransfer fromBytes(const std::vector<std::byte>& bytes);
/**
* Validate the checksums of the entities in this TokenTransfer.
*
* @param client The Client to use to validate the checksums.
* @throws BadEntityException If a checksum of one of the entities is not valid.
*/
void validateChecksums(const Client& client) const;
/**
* Compare this TokenTransfer to another TokenTransfer and determine if they represent the same TokenTransfer.
*
* @param other The other TokenTransfer with which to compare this TokenTransfer.
* @return \c TRUE if this TokenTransfer is the same as the input TokenTransfer, otherwise \c FALSE.
*/
[[nodiscard]] bool operator==(const TokenTransfer& other) const;
/**
* Construct an AccountAmount protobuf object from this TokenTransfer object.
*
* @return A pointer to the constructed AccountAmount protobuf object.
*/
[[nodiscard]] std::unique_ptr<proto::AccountAmount> toProtobuf() const;
/**
* Construct a representative byte array from this TokenTransfer object.
*
* @return The byte array representing this TokenTransfer object.
*/
[[nodiscard]] std::vector<std::byte> toBytes() const;
/**
* Construct a string representation of this TokenTransfer object.
*
* @return The string representation of this TokenTransfer object.
*/
[[nodiscard]] std::string toString() const;
/**
* Write this TokenTransfer to an output stream.
*
* @param os The output stream.
* @param transfer The TokenTransfer to print.
* @return The output stream with this TokenTransfer written to it.
*/
friend std::ostream& operator<<(std::ostream& os, const TokenTransfer& transfer);
/**
* The ID of the token being transferred.
*/
TokenId mTokenId;
/**
* The ID of the account to/from which the token is being transferred.
*/
AccountId mAccountId;
/**
* The amount of the token to transfer.
*/
int64_t mAmount = 0LL;
/**
* The expected decimals of the transfer amount.
*/
uint32_t mExpectedDecimals = 0U;
/**
* If \c TRUE then the transfer is expected to be an approved allowance.
*/
bool mIsApproval = false;
/**
* A hook call associated with this token transfer.
*/
FungibleHookCall mHookCall;
};
} // namespace Hiero
#endif // HIERO_SDK_CPP_TOKEN_TRANSFER_H_