From 761121eba21bce8f49db3b81d969b09b99992d98 Mon Sep 17 00:00:00 2001 From: Nathan Nichols Date: Wed, 10 Mar 2021 16:53:27 -0600 Subject: [PATCH] fix: Order HopObject (#122) * fix: orders HopObject fields correctly --- .../ripple-binary-codec/src/types/path-set.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/ripple-binary-codec/src/types/path-set.ts b/packages/ripple-binary-codec/src/types/path-set.ts index b4b94d08..9b4ffbfd 100644 --- a/packages/ripple-binary-codec/src/types/path-set.ts +++ b/packages/ripple-binary-codec/src/types/path-set.ts @@ -117,17 +117,30 @@ class Hop extends SerializedType { const hopParser = new BinaryParser(this.bytes.toString("hex")); const type = hopParser.readUInt8(); - const result: HopObject = {}; + let account, currency, issuer; if (type & TYPE_ACCOUNT) { - result.account = (AccountID.fromParser(hopParser) as AccountID).toJSON(); + account = (AccountID.fromParser(hopParser) as AccountID).toJSON(); } if (type & TYPE_CURRENCY) { - result.currency = (Currency.fromParser(hopParser) as Currency).toJSON(); + currency = (Currency.fromParser(hopParser) as Currency).toJSON(); } if (type & TYPE_ISSUER) { - result.issuer = (AccountID.fromParser(hopParser) as AccountID).toJSON(); + issuer = (AccountID.fromParser(hopParser) as AccountID).toJSON(); + } + + const result: HopObject = {}; + if (account) { + result.account = account; + } + + if (issuer) { + result.issuer = issuer; + } + + if (currency) { + result.currency = currency; } return result;