diff --git a/src/js/ripple/serializedtypes.js b/src/js/ripple/serializedtypes.js index 4a850ad1..e8f4a1a6 100644 --- a/src/js/ripple/serializedtypes.js +++ b/src/js/ripple/serializedtypes.js @@ -278,14 +278,14 @@ STHash160.id = 17; // Internal var STCurrency = new SerializedType({ - serialize: function (so, val) { + serialize: function (so, val, xrp_as_ascii) { var currency = val.to_json().toUpperCase(); if (!isCurrencyString(currency)) { throw new Error('Tried to serialize invalid/unimplemented currency type.'); } - if (currency === 'XRP') { + if (currency === 'XRP' && !xrp_as_ascii) { serialize_hex(so, UInt160.HEX_ZERO, true); } else { var currencyCode = currency.toUpperCase(); @@ -361,7 +361,7 @@ var STAmount = exports.Amount = new SerializedType({ if (!amount.is_native()) { // Currency (160-bit hash) var currency = amount.currency(); - STCurrency.serialize(so, currency); + STCurrency.serialize(so, currency, true); // Issuer (160-bit hash) so.append(amount.issuer().to_bytes()); diff --git a/test/serializedtypes-test.js b/test/serializedtypes-test.js index ac2a253b..48af1ea3 100644 --- a/test/serializedtypes-test.js +++ b/test/serializedtypes-test.js @@ -494,6 +494,17 @@ describe('Serialized types', function() { types.Amount.serialize(so, '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), '94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); }); + it('Serialize 15/XRP/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () { + // This actually appears in the ledger, so we need to be able to serialize + // Transaction #A2AD66C93C7B7277CD5AEB718A4E82D88C7099129948BC66A394EE38B34657A9 + var so = new SerializedObject(); + types.Amount.serialize(so, { + "value":"1000", + "currency":"XRP", + "issuer":"rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo" + }); + assert.strictEqual(so.to_hex(), 'D5438D7EA4C680000000000000000000000000005852500000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367'); + }); it('Parse 1 XRP', function () { var so = new SerializedObject('4000000000000001'); assert.strictEqual(types.Amount.parse(so).to_json(), '1');