@@ -85,7 +85,7 @@ Data Transaction::serialize() const {
85
85
(transaction_type == TransactionType::NFTokenCreateOffer)) {
86
86
encodeType (FieldType::amount, 1 , data);
87
87
append (data,
88
- (currency_amount.currency .size () > 0 ) ?
88
+ (! currency_amount.currency .empty () ) ?
89
89
serializeCurrencyAmount (currency_amount) :
90
90
serializeAmount (amount));
91
91
} else if (transaction_type == TransactionType::TrustSet) {
@@ -257,17 +257,7 @@ Data Transaction::serializeCurrencyAmount(const CurrencyAmount& currency_amount)
257
257
// https://xrpl.org/serialization.html#amount-fields
258
258
auto data = Data ();
259
259
encode64BE (amount_cast.value , data);
260
-
261
- // ISO-4217 currency code
262
- encodeZeros (1 , data); // type code (0x00)
263
- encodeZeros (11 , data); // reserved
264
- if (currency_amount.currency .size () == 3 ) {
265
- data.insert (data.end (), currency_amount.currency .begin (), currency_amount.currency .end ());
266
- } else {
267
- encodeZeros (3 , data); // none
268
- }
269
-
270
- encodeZeros (5 , data); // reserved
260
+ serializeCurrencyCode (data, currency_amount.currency );
271
261
data.insert (data.end (), currency_amount.issuer .begin (), currency_amount.issuer .end ());
272
262
return data;
273
263
}
@@ -278,4 +268,24 @@ Data Transaction::serializeAddress(Address address) {
278
268
return data;
279
269
}
280
270
271
+ void Transaction::serializeCurrencyCode (Data& out, const std::string& currency_code) {
272
+ if (currency_code.size () == 40 ) {
273
+ auto code_bytes = parse_hex (currency_code);
274
+ out.insert (out.end (), code_bytes.begin (), code_bytes.end ());
275
+ return ;
276
+ }
277
+
278
+ // Standard ISO-4217 currency code
279
+ encodeZeros (1 , out); // type code (0x00)
280
+ encodeZeros (11 , out); // reserved
281
+
282
+ if (currency_code.size () == 3 ) {
283
+ out.insert (out.end (), currency_code.begin (), currency_code.end ());
284
+ } else {
285
+ encodeZeros (3 , out); // none
286
+ }
287
+
288
+ encodeZeros (5 , out); // reserved
289
+ }
290
+
281
291
} // namespace TW::Ripple
0 commit comments