Skip to content

Commit d42acb6

Browse files
authored
chore(transactions): use explicit size vs strlen for labels [arduino] (#219)
1 parent 02a888d commit d42acb6

11 files changed

Lines changed: 70 additions & 70 deletions

File tree

src/interfaces/constants.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define ARK_INTERFACES_CONSTANTS_H
1212

1313
#include <cstddef>
14-
#include <cstring>
1514

1615
#include "utils/platform.h"
1716

@@ -73,11 +72,11 @@ constexpr size_t WIF_STRING_LEN = 52U;
7372
////////////////////////////////////////////////////////////////////////////////
7473
////////////////////////////////////////////////////////////////////////////////
7574
// Map/Json Constants
76-
constexpr auto KEY_ASSET_LABEL = "asset";
77-
const auto KEY_ASSET_SIZE = strlen(KEY_ASSET_LABEL);
75+
constexpr auto KEY_ASSET_LABEL = "asset";
76+
constexpr size_t KEY_ASSET_SIZE = 5;
7877

79-
constexpr auto KEY_AMOUNT_LABEL = "amount";
80-
const auto KEY_AMOUNT_SIZE = strlen(KEY_AMOUNT_LABEL);
78+
constexpr auto KEY_AMOUNT_LABEL = "amount";
79+
constexpr size_t KEY_AMOUNT_SIZE = 6;
8180

8281
////////////////////////////////////////////////////////////////////////////////
8382
// Misc

src/transactions/mapping/labels.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef ARK_TRANSACTIONS_MAPPING_LABELS_HPP
1111
#define ARK_TRANSACTIONS_MAPPING_LABELS_HPP
1212

13-
#include <string>
13+
#include <cstddef>
1414

1515
namespace Ark {
1616
namespace Crypto {
@@ -19,40 +19,40 @@ namespace transactions { // NOLINT
1919
////////////////////////////////////////////////////////////////////////////////
2020
// Mapping Label Constants
2121
constexpr auto KEY_VERSION_LABEL = "version";
22-
const auto KEY_VERSION_SIZE = strlen(KEY_VERSION_LABEL);
22+
constexpr size_t KEY_VERSION_SIZE = 7;
2323

2424
constexpr auto KEY_NETWORK_LABEL = "network";
25-
const auto KEY_NETWORK_SIZE = strlen(KEY_NETWORK_LABEL);
25+
constexpr size_t KEY_NETWORK_SIZE = 7;
2626

2727
constexpr auto KEY_TYPEGROUP_LABEL = "typeGroup";
28-
const auto KEY_TYPEGROUP_SIZE = strlen(KEY_TYPEGROUP_LABEL);
28+
constexpr size_t KEY_TYPEGROUP_SIZE = 8;
2929

3030
constexpr auto KEY_TYPE_LABEL = "type";
31-
const auto KEY_TYPE_SIZE = strlen(KEY_TYPE_LABEL);
31+
constexpr size_t KEY_TYPE_SIZE = 4;
3232

3333
constexpr auto KEY_NONCE_LABEL = "nonce";
34-
const auto KEY_NONCE_SIZE = strlen(KEY_NONCE_LABEL);
34+
constexpr size_t KEY_NONCE_SIZE = 5;
3535

3636
constexpr auto KEY_TIMESTAMP_LABEL = "timestamp";
37-
const auto KEY_TIMESTAMP_SIZE = strlen(KEY_TIMESTAMP_LABEL);
37+
constexpr size_t KEY_TIMESTAMP_SIZE = 9;
3838

3939
constexpr auto KEY_SENDER_PUBLICKEY_LABEL = "senderPublicKey";
40-
const auto KEY_SENDER_PUBLICKEY_SIZE = strlen(KEY_SENDER_PUBLICKEY_LABEL);
40+
constexpr size_t KEY_SENDER_PUBLICKEY_SIZE = 15;
4141

4242
constexpr auto KEY_FEE_LABEL = "fee";
43-
const auto KEY_FEE_SIZE = strlen(KEY_FEE_LABEL);
43+
constexpr size_t KEY_FEE_SIZE = 3;
4444

4545
constexpr auto KEY_VENDORFIELD_LABEL = "vendorField";
46-
const auto KEY_VENDORFIELD_SIZE = strlen(KEY_VENDORFIELD_LABEL);
46+
constexpr size_t KEY_VENDORFIELD_SIZE = 11;
4747

4848
constexpr auto KEY_SIGNATURE_LABEL = "signature";
49-
const auto KEY_SIGNATURE_SIZE = strlen(KEY_SIGNATURE_LABEL);
49+
constexpr size_t KEY_SIGNATURE_SIZE = 9;
5050

5151
constexpr auto KEY_SECOND_SIGNATURE_LABEL = "secondSignature";
52-
const auto KEY_SECOND_SIGNATURE_SIZE = strlen(KEY_SECOND_SIGNATURE_LABEL);
52+
constexpr size_t KEY_SECOND_SIGNATURE_SIZE = 15;
5353

5454
constexpr auto KEY_ID_LABEL = "id";
55-
const auto KEY_ID_SIZE = strlen(KEY_ID_LABEL);
55+
constexpr size_t KEY_ID_SIZE = 2;
5656

5757
} // namespace transactions
5858
} // namespace Crypto

src/transactions/types/delegate_registration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "transactions/types/delegate_registration.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
15-
#include <string>
1616

1717
#include "utils/json.h"
1818
#include "utils/str.hpp"
@@ -92,10 +92,10 @@ auto DelegateRegistration::Serialize(const DelegateRegistration &registration,
9292
////////////////////////////////////////////////////////////////////////////////
9393
// Map/Json Constants
9494
constexpr auto OBJECT_DELEGATE_LABEL = "delegate";
95-
const auto KEY_DELEGATE_SIZE = strlen(OBJECT_DELEGATE_LABEL);
95+
constexpr size_t KEY_DELEGATE_SIZE = 8;
9696

9797
constexpr auto KEY_USERNAME_LABEL = "username";
98-
const auto KEY_USERNAME_SIZE = strlen(KEY_USERNAME_LABEL);
98+
constexpr size_t KEY_USERNAME_SIZE = 8;
9999

100100
////////////////////////////////////////////////////////////////////////////////
101101
// Add Delegate Registration Asset data to a Transaction Map.

src/transactions/types/htlc_claim.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "transactions/types/htlc_claim.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
15-
#include <string>
1616

1717
#include "interfaces/constants.h"
1818

@@ -82,14 +82,14 @@ auto HtlcClaim::Serialize(const HtlcClaim &claim, uint8_t *buffer) -> size_t {
8282
////////////////////////////////////////////////////////////////////////////////
8383
////////////////////////////////////////////////////////////////////////////////
8484
// Map/Json Constants
85-
constexpr auto OBJECT_HTLC_CLAIM_LABEL = "claim";
86-
const auto OBJECT_HTLC_CLAIM_SIZE = strlen(OBJECT_HTLC_CLAIM_LABEL);
85+
constexpr auto OBJECT_HTLC_CLAIM_LABEL = "claim";
86+
constexpr size_t OBJECT_HTLC_CLAIM_SIZE = 5;
8787

88-
constexpr auto KEY_CLAIM_TX_ID_LABEL = "lockTransactionId";
89-
const auto KEY_CLAIM_TX_ID_SIZE = strlen(KEY_CLAIM_TX_ID_LABEL);
88+
constexpr auto KEY_CLAIM_TX_ID_LABEL = "lockTransactionId";
89+
constexpr size_t KEY_CLAIM_TX_ID_SIZE = 17;
9090

91-
constexpr auto KEY_CLAIM_SECRET_LABEL = "unlockSecret";
92-
const auto KEY_CLAIM_SECRET_SIZE = strlen(KEY_CLAIM_SECRET_LABEL);
91+
constexpr auto KEY_CLAIM_SECRET_LABEL = "unlockSecret";
92+
constexpr size_t KEY_CLAIM_SECRET_SIZE = 11;
9393

9494
////////////////////////////////////////////////////////////////////////////////
9595
// Add Htlc Claim Asset data to a Transaction Map.

src/transactions/types/htlc_lock.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "transactions/types/htlc_lock.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
1516
#include <string>
@@ -146,26 +147,26 @@ auto HtlcLock::Serialize(const HtlcLock &lock, uint8_t *buffer) -> size_t {
146147
////////////////////////////////////////////////////////////////////////////////
147148
////////////////////////////////////////////////////////////////////////////////
148149
// Map/Json Constants
149-
constexpr auto OBJECT_HTLC_LOCK_LABEL = "lock";
150-
const auto OBJECT_HTLC_LOCK_SIZE = strlen(OBJECT_HTLC_LOCK_LABEL) - 1U;
150+
constexpr auto OBJECT_HTLC_LOCK_LABEL = "lock";
151+
constexpr size_t OBJECT_HTLC_LOCK_SIZE = 4;
151152

152-
constexpr auto OBJECT_HTLC_LOCK_TYPE_LABEL = "type";
153-
const auto OBJECT_HTLC_LOCK_VALUE_LABEL = "value";
153+
constexpr auto OBJECT_HTLC_LOCK_TYPE_LABEL = "type";
154+
constexpr auto OBJECT_HTLC_LOCK_VALUE_LABEL = "value";
154155

155-
constexpr auto KEY_AMOUNT_LABEL = "amount";
156-
const auto KEY_AMOUNT_SIZE = strlen(KEY_AMOUNT_LABEL);
156+
constexpr auto KEY_AMOUNT_LABEL = "amount";
157+
constexpr size_t KEY_AMOUNT_SIZE = 6;
157158

158-
constexpr auto KEY_SECRET_HASH_LABEL = "secretHash";
159-
const auto KEY_SECRET_HASH_SIZE = strlen(KEY_SECRET_HASH_LABEL);
159+
constexpr auto KEY_SECRET_HASH_LABEL = "secretHash";
160+
constexpr size_t KEY_SECRET_HASH_SIZE = 10;
160161

161-
constexpr auto KEY_EXPIRATION_TYPE_LABEL = "expirationType";
162-
const auto KEY_EXPIRATION_TYPE_SIZE = strlen(KEY_EXPIRATION_TYPE_LABEL);
162+
constexpr auto KEY_EXPIRATION_TYPE_LABEL = "expirationType";
163+
constexpr size_t KEY_EXPIRATION_TYPE_SIZE = 14;
163164

164-
constexpr auto KEY_EXPIRATION_LABEL = "expiration";
165-
const auto KEY_EXPIRATION_SIZE = strlen(KEY_EXPIRATION_LABEL);
165+
constexpr auto KEY_EXPIRATION_LABEL = "expiration";
166+
constexpr size_t KEY_EXPIRATION_SIZE = 10;
166167

167-
constexpr auto KEY_RECIPIENT_ID_LABEL = "recipientId";
168-
const auto KEY_RECIPIENT_ID_SIZE = strlen(KEY_RECIPIENT_ID_LABEL);
168+
constexpr auto KEY_RECIPIENT_ID_LABEL = "recipientId";
169+
constexpr size_t KEY_RECIPIENT_ID_SIZE = 11;
169170

170171
////////////////////////////////////////////////////////////////////////////////
171172
// Add Htlc Lock Asset data to a Transaction Map.

src/transactions/types/htlc_refund.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "transactions/types/htlc_refund.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
15-
#include <string>
1616

1717
#include "interfaces/constants.h"
1818

@@ -70,11 +70,11 @@ auto HtlcRefund::Serialize(const HtlcRefund &refund, uint8_t *buffer)
7070
////////////////////////////////////////////////////////////////////////////////
7171
////////////////////////////////////////////////////////////////////////////////
7272
// Map/Json Constants
73-
constexpr auto OBJECT_HTLC_REFUND_LABEL = "refund";
74-
const auto OBJECT_HTLC_REFUND_SIZE = strlen(OBJECT_HTLC_REFUND_LABEL);
73+
constexpr auto OBJECT_HTLC_REFUND_LABEL = "refund";
74+
constexpr size_t OBJECT_HTLC_REFUND_SIZE = 6;
7575

76-
constexpr auto KEY_REFUND_TX_ID_LABEL = "lockTransactionId";
77-
const auto KEY_REFUND_TX_ID_SIZE = strlen(KEY_REFUND_TX_ID_LABEL);
76+
constexpr auto KEY_REFUND_TX_ID_LABEL = "lockTransactionId";
77+
constexpr size_t KEY_REFUND_TX_ID_SIZE = 17;
7878

7979
constexpr auto HTLC_JSON_OBJECT_SIZE = 1U;
8080

src/transactions/types/ipfs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "transactions/types/ipfs.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
15-
#include <string>
1616

1717
#include "interfaces/constants.h"
1818

@@ -84,7 +84,7 @@ auto Ipfs::Serialize(const Ipfs &ipfs, uint8_t *buffer) -> size_t {
8484
////////////////////////////////////////////////////////////////////////////////
8585
// Map/Json Constants
8686
constexpr auto KEY_IPFS_LABEL = "ipfs";
87-
const auto KEY_IPFS_SIZE = strlen(KEY_IPFS_LABEL);
87+
constexpr size_t KEY_IPFS_SIZE = 4;
8888

8989
////////////////////////////////////////////////////////////////////////////////
9090
// Add Ipfs Asset data to a Transaction Map.

src/transactions/types/multi_payment.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <algorithm>
1313
#include <array>
14+
#include <cstddef>
1415
#include <cstdint>
1516
#include <map>
1617
#include <numeric> // std::accumulate
@@ -164,19 +165,19 @@ auto MultiPayment::Serialize(const MultiPayment &payments,
164165
////////////////////////////////////////////////////////////////////////////////
165166
////////////////////////////////////////////////////////////////////////////////
166167
// Map/Json Constants
167-
constexpr auto KEY_PAYMENTS_LABEL = "payments";
168-
const auto KEY_PAYMENTS_SIZE = strlen(KEY_PAYMENTS_LABEL);
168+
constexpr auto KEY_PAYMENTS_LABEL = "payments";
169+
constexpr size_t KEY_PAYMENTS_SIZE = 8;
169170

170-
const auto KEY_N_PAYMENTS_SIZE = strlen(KEY_N_PAYMENTS_LABEL);
171+
constexpr size_t KEY_N_PAYMENTS_SIZE = 9;
171172

172-
constexpr auto KEY_AMOUNTS_LABEL = "amounts";
173-
const auto KEY_AMOUNTS_SIZE = strlen(KEY_AMOUNTS_LABEL);
173+
constexpr auto KEY_AMOUNTS_LABEL = "amounts";
174+
constexpr size_t KEY_AMOUNTS_SIZE = 7;
174175

175-
constexpr auto KEY_ADDRESSES_LABEL = "addresses";
176-
const auto KEY_ADDRESSES_SIZE = strlen(KEY_ADDRESSES_LABEL);
176+
constexpr auto KEY_ADDRESSES_LABEL = "addresses";
177+
constexpr size_t KEY_ADDRESSES_SIZE = 9;
177178

178179
constexpr auto KEY_RECIPIENT_ID_LABEL = "recipientId";
179-
const auto KEY_RECIPIENT_ID_SIZE = strlen(KEY_RECIPIENT_ID_LABEL);
180+
constexpr size_t KEY_RECIPIENT_ID_SIZE = 11;
180181

181182
constexpr auto MULTIPAYMENT_JSON_OBJECT_SIZE = 2U;
182183

src/transactions/types/second_signature.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "transactions/types/second_signature.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
1415
#include <map>
15-
#include <string>
1616

1717
#include "interfaces/constants.h"
1818

@@ -75,10 +75,10 @@ auto SecondSignature::Serialize(const SecondSignature &registration,
7575
////////////////////////////////////////////////////////////////////////////////
7676
// Map/Json Constants
7777
constexpr auto KEY_SIGNATURE_LABEL = "signature";
78-
const auto KEY_SIGNATURE_SIZE = strlen(KEY_SIGNATURE_LABEL);
78+
constexpr size_t KEY_SIGNATURE_SIZE = 9;
7979

8080
constexpr auto KEY_PUBLICKEY_LABEL = "publicKey";
81-
const auto KEY_PUBLICKEY_SIZE = strlen(KEY_PUBLICKEY_LABEL);
81+
constexpr size_t KEY_PUBLICKEY_SIZE = 9;
8282

8383
////////////////////////////////////////////////////////////////////////////////
8484
// Add SecondSignature Asset data to a Transaction Map.

src/transactions/types/transfer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
#include "transactions/types/transfer.hpp"
1111

1212
#include <algorithm>
13+
#include <cstddef>
1314
#include <cstdint>
14-
#include <cstring>
1515
#include <map>
16-
#include <string>
1716

1817
#include "interfaces/constants.h"
1918

@@ -97,13 +96,13 @@ auto Transfer::Serialize(const Transfer &transfer, uint8_t *buffer) -> size_t {
9796
////////////////////////////////////////////////////////////////////////////////
9897
// Map/Json Constants
9998
constexpr auto KEY_AMOUNT_LABEL = "amount";
100-
const auto KEY_AMOUNT_SIZE = strlen(KEY_AMOUNT_LABEL);
99+
constexpr size_t KEY_AMOUNT_SIZE = 6;
101100

102101
constexpr auto KEY_EXPIRATION_LABEL = "expiration";
103-
const auto KEY_EXPIRATION_SIZE = strlen(KEY_EXPIRATION_LABEL);
102+
constexpr size_t KEY_EXPIRATION_SIZE = 10;
104103

105104
constexpr auto KEY_RECIPIENT_ID_LABEL = "recipientId";
106-
const auto KEY_RECIPIENT_ID_SIZE = strlen(KEY_RECIPIENT_ID_LABEL);
105+
constexpr size_t KEY_RECIPIENT_ID_SIZE = 11;
107106

108107
////////////////////////////////////////////////////////////////////////////////
109108
// Add Transfer Asset data to a Transaction Map.

0 commit comments

Comments
 (0)