Skip to content

Commit b96d24c

Browse files
authored
fix: always include amount in transaction payloads (#202)
1 parent 09714c5 commit b96d24c

5 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/include/cpp-crypto/interfaces/constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ constexpr size_t WIF_STRING_LEN = 52U;
7676
constexpr auto KEY_ASSET_LABEL = "asset";
7777
const auto KEY_ASSET_SIZE = strlen(KEY_ASSET_LABEL);
7878

79+
constexpr auto KEY_AMOUNT_LABEL = "amount";
80+
const auto KEY_AMOUNT_SIZE = strlen(KEY_AMOUNT_LABEL);
81+
7982
////////////////////////////////////////////////////////////////////////////////
8083
// Misc
8184
constexpr uint8_t BASE_10 = 10U;

src/transactions/mapping/json.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ static auto getCommonJsonCapacity(
7474
KEY_TIMESTAMP_SIZE + UINT32_MAX_CHARS;
7575
}
7676

77+
// Amount
78+
if (transactionVersion == TRANSACTION_VERSION_TYPE_2) {
79+
commonCapacity += JSON_OBJECT_SIZE(1) +
80+
KEY_AMOUNT_SIZE + UINT64_MAX_CHARS;
81+
}
82+
7783
// Vendorfield
7884
if (map.find(KEY_VENDORFIELD_LABEL) != map.end()) {
7985
commonCapacity += JSON_OBJECT_SIZE(1) +
@@ -244,6 +250,12 @@ static void mapCommonJson(DynamicJsonDocument &jsonDoc,
244250
// Fee
245251
jsonDoc[KEY_FEE_LABEL] = map.at(KEY_FEE_LABEL);
246252

253+
// Amount
254+
jsonDoc[KEY_AMOUNT_LABEL] = map.find(KEY_AMOUNT_LABEL) == map.end() &&
255+
transactionVersion == TRANSACTION_VERSION_TYPE_2
256+
? "0"
257+
: map.at(KEY_AMOUNT_LABEL);
258+
247259
// VendorField
248260
if (map.find(KEY_VENDORFIELD_LABEL) != map.end()) {
249261
jsonDoc[KEY_VENDORFIELD_LABEL] = map.at(KEY_VENDORFIELD_LABEL);

src/transactions/types/multi_payment.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ const auto KEY_AMOUNTS_SIZE = strlen(KEY_AMOUNTS_LABEL);
175175
constexpr auto KEY_ADDRESSES_LABEL = "addresses";
176176
const auto KEY_ADDRESSES_SIZE = strlen(KEY_ADDRESSES_LABEL);
177177

178-
constexpr auto KEY_AMOUNT_LABEL = "amount";
179-
const auto KEY_AMOUNT_SIZE = strlen(KEY_AMOUNT_LABEL);
180-
181178
constexpr auto KEY_RECIPIENT_ID_LABEL = "recipientId";
182179
const auto KEY_RECIPIENT_ID_SIZE = strlen(KEY_RECIPIENT_ID_LABEL);
183180

0 commit comments

Comments
 (0)