@@ -22,7 +22,9 @@ Data Transaction::serialize() const {
2222
2323    auto  data = Data ();
2424
25-     // / field must be sorted by field type then by field name
25+     // / fields must be sorted by field type code then by field code (key)
26+     //  https://xrpl.org/serialization.html#canonical-field-order
27+ 
2628    // / "type"
2729    encodeType (FieldType::int16, 2 , data);
2830    encode16BE (uint16_t (transaction_type), data);
@@ -36,17 +38,37 @@ Data Transaction::serialize() const {
3638    encode32BE (sequence, data);
3739
3840    // / "destinationTag"
39-     if  ((transaction_type == TransactionType::payment) && encode_tag) {
41+     if  (((transaction_type == TransactionType::payment) || 
42+          (transaction_type == TransactionType::EscrowCreate)) && encode_tag) {
4043        encodeType (FieldType::int32, 14 , data);
4144        encode32BE (static_cast <uint32_t >(destination_tag), data);
4245    }
4346
47+     // / "OfferSequence"
48+     if  ((transaction_type == TransactionType::EscrowCancel) || 
49+         (transaction_type == TransactionType::EscrowFinish)) {
50+         encodeType (FieldType::int32, 25 , data);
51+         encode32BE (offer_sequence, data);
52+     }
53+ 
4454    // / "lastLedgerSequence"
4555    if  (last_ledger_sequence > 0 ) {
4656        encodeType (FieldType::int32, 27 , data);
4757        encode32BE (last_ledger_sequence, data);
4858    }
4959
60+     // / "CancelAfter"
61+     if  ((transaction_type == TransactionType::EscrowCreate) && cancel_after > 0 ) {
62+         encodeType (FieldType::int32, 36 , data);
63+         encode32BE (static_cast <uint32_t >(cancel_after), data);
64+     }
65+ 
66+     // / "FinishAfter"
67+     if  ((transaction_type == TransactionType::EscrowCreate) && finish_after > 0 ) {
68+         encodeType (FieldType::int32, 37 , data);
69+         encode32BE (static_cast <uint32_t >(finish_after), data);
70+     }
71+ 
5072    // / "NFTokenId"
5173    if  ((transaction_type == TransactionType::NFTokenCreateOffer) ||
5274        (transaction_type == TransactionType::NFTokenBurn)) {
@@ -71,6 +93,9 @@ Data Transaction::serialize() const {
7193    } else  if  (transaction_type == TransactionType::TrustSet) {
7294        encodeType (FieldType::amount, 3 , data);
7395        append (data, serializeCurrencyAmount (limit_amount));
96+     } else  if  (transaction_type == TransactionType::EscrowCreate) {
97+         encodeType (FieldType::amount, 1 , data);
98+         append (data, serializeAmount (amount));
7499    }
75100
76101    // / "fee"
@@ -82,23 +107,45 @@ Data Transaction::serialize() const {
82107        encodeType (FieldType::vl, 3 , data);
83108        encodeBytes (pub_key, data);
84109    }
110+ 
85111    // / "txnSignature"
86112    if  (!signature.empty ()) {
87113        encodeType (FieldType::vl, 4 , data);
88114        encodeBytes (signature, data);
89115    }
90116
117+     // / "Fulfillment"
118+     if  ((transaction_type == TransactionType::EscrowFinish) && !fulfillment.empty ()) {
119+         encodeType (FieldType::vl, 16 , data);
120+         encodeBytes (fulfillment, data);
121+     }
122+ 
123+     // / "Condition"
124+     if  (((transaction_type == TransactionType::EscrowCreate) ||
125+          (transaction_type == TransactionType::EscrowFinish)) && !condition.empty ()) {
126+         encodeType (FieldType::vl, 17 , data);
127+         encodeBytes (condition, data);
128+     }
129+ 
91130    // / "account"
92131    encodeType (FieldType::account, 1 , data);
93132    encodeBytes (serializeAddress (account), data);
94133
95134    // / "destination"
96135    if  ((transaction_type == TransactionType::payment) ||
97-         (transaction_type == TransactionType::NFTokenCreateOffer)) {
136+         (transaction_type == TransactionType::NFTokenCreateOffer) ||
137+         (transaction_type == TransactionType::EscrowCreate)) {
98138        encodeType (FieldType::account, 3 , data);
99139        encodeBytes (destination, data);
100140    }
101141
142+     // / "Owner"
143+     if  ((transaction_type == TransactionType::EscrowCancel) ||
144+         (transaction_type == TransactionType::EscrowFinish)) {
145+         encodeType (FieldType::account, 2 , data);
146+         encodeBytes (owner, data);
147+     }
148+ 
102149    // / "NFTokenOffers"
103150    if  (transaction_type == TransactionType::NFTokenCancelOffer) {
104151        //  only support one offer
0 commit comments