From b2580ec17879daa324af9ac2f85b4309730a7169 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Mon, 11 Nov 2013 11:49:52 -0800 Subject: [PATCH] Disambiguate PathSets with XRP vs XRP IOUs. XRP IOUs are no longer valid, however they do exist in the network's historical transactions, so the serialization and deserialization need to be able to handle them. --- src/js/ripple/serializedtypes.js | 7 ++- test/serializedtypes-test.js | 96 +++++++++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 11 deletions(-) diff --git a/src/js/ripple/serializedtypes.js b/src/js/ripple/serializedtypes.js index e8f4a1a6..de9150e6 100644 --- a/src/js/ripple/serializedtypes.js +++ b/src/js/ripple/serializedtypes.js @@ -482,7 +482,7 @@ var STPathSet = exports.PathSet = new SerializedType({ if (entry.currency) { var currency = Currency.from_json(entry.currency); - STCurrency.serialize(so, currency); + STCurrency.serialize(so, currency, entry.non_native); } if (entry.issuer) { @@ -532,7 +532,10 @@ var STPathSet = exports.PathSet = new SerializedType({ } if (tag_byte & this.typeCurrency) { //console.log('entry.currency'); - entry.currency = STCurrency.parse(so) + entry.currency = STCurrency.parse(so); + if (entry.currency === "XRP") { + entry.non_native = !entry.currency.is_native(); + } } if (tag_byte & this.typeIssuer) { //console.log('entry.issuer'); diff --git a/test/serializedtypes-test.js b/test/serializedtypes-test.js index 48af1ea3..6300af0d 100644 --- a/test/serializedtypes-test.js +++ b/test/serializedtypes-test.js @@ -564,6 +564,84 @@ describe('Serialized types', function() { }]]); assert.strictEqual(so.to_hex(), '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); //TODO: Check this independently }); + it('Serialize path through XRP', function () { + // Appears in the history + // TX #0CBB429C456ED999CC691DFCC8E62E8C8C7E9522C2BEA967FED0D7E2A9B28D13 + // Note that XRP IOUs are no longer allowed, so this functionality is + // for historic transactions only. + var so = new SerializedObject(); + types.PathSet.serialize(so, [[ { + account: 123, + currency: 'USD', + issuer: 789 + }], + [{ + currency: "XRP" + }, + { + account: 987, + currency: 'EUR', + issuer: 321 + }]]); + assert.strictEqual(so.to_hex(), '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF1000000000000000000000000000000000000000003100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); + }); + it('Serialize path through XRP IOUs', function () { + // Appears in the history + // TX #0CBB429C456ED999CC691DFCC8E62E8C8C7E9522C2BEA967FED0D7E2A9B28D13 + // Note that XRP IOUs are no longer allowed, so this functionality is + // for historic transactions only. + var so = new SerializedObject(); + types.PathSet.serialize(so, [ + [{ + "account": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K", + "currency": "BTC", + "issuer": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K" + }, { + "account": "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo", + "currency": "BTC", + "issuer": "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo" + }, { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "currency": "BTC", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, { + "currency": "USD", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }], + [{ + "account": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K", + "currency": "BTC", + "issuer": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K" + }, { + "account": "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo", + "currency": "BTC", + "issuer": "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo" + }, { + "account": "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi", + "currency": "BTC", + "issuer": "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi" + }, { + "currency": "USD", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }], + [{ + "account": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K", + "currency": "BTC", + "issuer": "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K" + }, { + "account": "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn", + "currency": "BTC", + "issuer": "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn" + }, { + "currency": "XRP", + "non_native": true + }, { + "currency": "USD", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }] + ]); + assert.strictEqual(so.to_hex(), '31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367310A20B3C85F482532A9578DBB3950B85CA06594D100000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D13000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F33673115036E2D3F5437A83E5AC3CAEE34FF2C21DEB618000000000000000000000000425443000000000015036E2D3F5437A83E5AC3CAEE34FF2C21DEB6183000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C13157180C769B66D942EE69E6DCC940CA48D82337AD000000000000000000000000425443000000000057180C769B66D942EE69E6DCC940CA48D82337AD1000000000000000000000000058525000000000003000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D100'); + }); it('Parse single empty path [[]]', function () { var so = new SerializedObject('00'); var parsed_path = types.PathSet.parse(so) @@ -573,15 +651,15 @@ describe('Serialized types', function() { var so = new SerializedObject('31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); var parsed_path = types.PathSet.parse(so); - var comp =[ [ { account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrpYnYCNYf' } ], - [ { account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', - currency: 'BTC', - issuer: 'rrrrrrrrrrrrrrrrrrrpYnYCNYf' }, - { account: 'rrrrrrrrrrrrrrrrrrrpvQsW3V3', - currency: 'EUR', - issuer: 'rrrrrrrrrrrrrrrrrrrdHRtqg2' } ] ]; + var comp = [ [ { account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrpYnYCNYf' } ], + [ { account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', + currency: 'BTC', + issuer: 'rrrrrrrrrrrrrrrrrrrpYnYCNYf' }, + { account: 'rrrrrrrrrrrrrrrrrrrpvQsW3V3', + currency: 'EUR', + issuer: 'rrrrrrrrrrrrrrrrrrrdHRtqg2' } ] ]; assert.deepEqual(SerializedObject.jsonify_structure(parsed_path, ""), comp); }); });