diff --git a/src/js/ripple/remote.js b/src/js/ripple/remote.js index bf7cba37..8a271acc 100644 --- a/src/js/ripple/remote.js +++ b/src/js/ripple/remote.js @@ -34,6 +34,7 @@ var SerializedObject = require('./serializedobject').SerializedObject; var RippleError = require('./rippleerror').RippleError; var utils = require('./utils'); var sjcl = require('./utils').sjcl; +var hashprefixes = require('./hashprefixes'); var config = require('./config'); var log = require('./log').internal.sub('remote'); @@ -1451,12 +1452,19 @@ Remote.prototype.requestAccountTx = function(options, callback) { */ Remote.parseBinaryTransaction = function(transaction) { - var tx = { validated: transaction.validated }; - tx.meta = new SerializedObject(transaction.meta).to_json(); - tx.tx = new SerializedObject(transaction.tx_blob).to_json(); - tx.tx.ledger_index = transaction.ledger_index; - tx.tx.hash = Transaction.from_json(tx.tx).hash(); - return tx; + var tx_obj = new SerializedObject(transaction.tx_blob); + var meta = new SerializedObject(transaction.meta); + + var tx_result = { + validated: transaction.validated, + ledger_index: transaction.ledger_index + }; + + tx_result.meta = meta.to_json(); + tx_result.tx = tx_obj.to_json(); + tx_result.tx.hash = tx_obj.hash(hashprefixes.HASH_TX_ID).to_hex(); + + return tx_result; }; /** diff --git a/test/fixtures/binary-transaction.json b/test/fixtures/binary-transaction.json new file mode 100644 index 00000000..c2798741 --- /dev/null +++ b/test/fixtures/binary-transaction.json @@ -0,0 +1,131 @@ +{ + "binary": { + "ledger_index": 10983428, + "meta": "201C00000000F8E311006F561C0662854F6571DD28392C1AF031757BDF2BC0E62C190ABE0BC22C46A2E443FDE824000263F550107B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE0064400000032A0D8DB065D4838D7EA4C6800000000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D1811473DFB1F8FDE93B1E301897694F0DDE56516BDC40E1E1E51100645642EE066C2D6E683C6FDC95C3C0EF88B3D7C10E31E9D98060F517F18AD98217DFE722000000005842EE066C2D6E683C6FDC95C3C0EF88B3D7C10E31E9D98060F517F18AD98217DF821473DFB1F8FDE93B1E301897694F0DDE56516BDC40E1E1E4110064567B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F400E72200000000365F04CE166242F400587B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F40001110000000000000000000000000000000000000000021100000000000000000000000000000000000000000311000000000000000000000000425443000000000004110A20B3C85F482532A9578DBB3950B85CA06594D1E1E1E3110064567B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE00E8365F04D40AEE52AE00587B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE000311000000000000000000000000425443000000000004110A20B3C85F482532A9578DBB3950B85CA06594D1E1E1E411006F56CDD61BD2DF2ADF53D0C05C171E2C8D48337BFE63868497BC30C5DCF2D0A03AFFE7220000000024000263E72500A79550330000000000000000340000000000000000550F60460F66E991AE6D77C50435E7FF8915453D411B6E43B38AC6410113B06CDC50107B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F400644000000326266D2065D4838D7EA4C6800000000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D1811473DFB1F8FDE93B1E301897694F0DDE56516BDC40E1E1E51100612500A7974E55329262FE69DD4F191AF0CE075489E7B7BDD273EC5528531D8184E1A73E76B7D356E0A052DA53A0D6F6C16422D206D4E38862ED7A13AE90ED0EF5ED09353C2A7A94E624000263F56240000005F01B0F39E1E7220000000024000263F62D000000096240000005F01AE829811473DFB1F8FDE93B1E301897694F0DDE56516BDC40E1E1F1031000", + "tx_blob": "120007228000000024000263F52019000263E764400000032A0D8DB065D4838D7EA4C6800000000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D1684000000000002710732103CDF7533BF6B6DE8C1AEFC1F2F776F8EDAE08D88C6E1F9B69535D9CDDF3071029744630440220153DDCA438981E498EF3AF383845F74B2CC20602FD1E20546A067C68D026DE6502207E4ECB4A23FFBC274CE0C2D08131F26FDDB6240B2A701C8E49410E0F18595053811473DFB1F8FDE93B1E301897694F0DDE56516BDC40", + "validated": true + }, + "parsed": { + "validated": true, + "ledger_index": 10983428, + "meta": { + "TransactionIndex": 0, + "AffectedNodes": [ + { + "CreatedNode": { + "LedgerEntryType": "Offer", + "LedgerIndex": "1C0662854F6571DD28392C1AF031757BDF2BC0E62C190ABE0BC22C46A2E443FD", + "NewFields": { + "Sequence": 156661, + "BookDirectory": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE00", + "TakerPays": "13590433200", + "TakerGets": { + "value": "1", + "currency": "BTC", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "Account": "rBZgggUbdV7wHF1d7BRu1BLsxQqKHX3SN4" + } + } + }, + { + "ModifiedNode": { + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "42EE066C2D6E683C6FDC95C3C0EF88B3D7C10E31E9D98060F517F18AD98217DF", + "FinalFields": { + "Flags": 0, + "RootIndex": "42EE066C2D6E683C6FDC95C3C0EF88B3D7C10E31E9D98060F517F18AD98217DF", + "Owner": "rBZgggUbdV7wHF1d7BRu1BLsxQqKHX3SN4" + } + } + }, + { + "DeletedNode": { + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F400", + "FinalFields": { + "Flags": 0, + "ExchangeRate": "5F04CE166242F400", + "RootIndex": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F400", + "TakerPaysCurrency": "0000000000000000000000000000000000000000", + "TakerPaysIssuer": "0000000000000000000000000000000000000000", + "TakerGetsCurrency": "0000000000000000000000004254430000000000", + "TakerGetsIssuer": "0A20B3C85F482532A9578DBB3950B85CA06594D1" + } + } + }, + { + "CreatedNode": { + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE00", + "NewFields": { + "ExchangeRate": "5F04D40AEE52AE00", + "RootIndex": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04D40AEE52AE00", + "TakerGetsCurrency": "0000000000000000000000004254430000000000", + "TakerGetsIssuer": "0A20B3C85F482532A9578DBB3950B85CA06594D1" + } + } + }, + { + "DeletedNode": { + "LedgerEntryType": "Offer", + "LedgerIndex": "CDD61BD2DF2ADF53D0C05C171E2C8D48337BFE63868497BC30C5DCF2D0A03AFF", + "FinalFields": { + "Flags": 0, + "Sequence": 156647, + "PreviousTxnLgrSeq": 10982736, + "BookNode": "0", + "OwnerNode": "0", + "PreviousTxnID": "0F60460F66E991AE6D77C50435E7FF8915453D411B6E43B38AC6410113B06CDC", + "BookDirectory": "7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F04CE166242F400", + "TakerPays": "13524954400", + "TakerGets": { + "value": "1", + "currency": "BTC", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "Account": "rBZgggUbdV7wHF1d7BRu1BLsxQqKHX3SN4" + } + } + }, + { + "ModifiedNode": { + "LedgerEntryType": "AccountRoot", + "PreviousTxnLgrSeq": 10983246, + "PreviousTxnID": "329262FE69DD4F191AF0CE075489E7B7BDD273EC5528531D8184E1A73E76B7D3", + "LedgerIndex": "E0A052DA53A0D6F6C16422D206D4E38862ED7A13AE90ED0EF5ED09353C2A7A94", + "PreviousFields": { + "Sequence": 156661, + "Balance": "25503141689" + }, + "FinalFields": { + "Flags": 0, + "Sequence": 156662, + "OwnerCount": 9, + "Balance": "25503131689", + "Account": "rBZgggUbdV7wHF1d7BRu1BLsxQqKHX3SN4" + } + } + } + ], + "TransactionResult": "tesSUCCESS" + }, + "tx": { + "TransactionType": "OfferCreate", + "Flags": 2147483648, + "Sequence": 156661, + "OfferSequence": 156647, + "TakerPays": "13590433200", + "TakerGets": { + "value": "1", + "currency": "BTC", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "Fee": "10000", + "SigningPubKey": "03CDF7533BF6B6DE8C1AEFC1F2F776F8EDAE08D88C6E1F9B69535D9CDDF3071029", + "TxnSignature": "30440220153DDCA438981E498EF3AF383845F74B2CC20602FD1E20546A067C68D026DE6502207E4ECB4A23FFBC274CE0C2D08131F26FDDB6240B2A701C8E49410E0F18595053", + "Account": "rBZgggUbdV7wHF1d7BRu1BLsxQqKHX3SN4", + "hash": "3CC8ED34260911194E8E30543D70A6DF04D3DABC746A546DAED32D22496B478C" + } + } +} diff --git a/test/remote-test.js b/test/remote-test.js index 9631269b..297f0907 100644 --- a/test/remote-test.js +++ b/test/remote-test.js @@ -79,28 +79,28 @@ describe('Remote', function () { it('remote server initialization - url object - invalid host', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ { host: '+', port: 443, secure: true } ] - }); - }, Error); + var remote = new Remote({ + servers: [ { host: '+', port: 443, secure: true } ] + }); + }, Error); }); it('remote server initialization - url object - invalid port', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ { host: 's-west.ripple.com', port: null, secure: true } ] - }); - }, TypeError); + var remote = new Remote({ + servers: [ { host: 's-west.ripple.com', port: null, secure: true } ] + }); + }, TypeError); }); it('remote server initialization - url object - port out of range', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ { host: 's-west.ripple.com', port: 65537, secure: true } ] - }); - }, Error); + var remote = new Remote({ + servers: [ { host: 's-west.ripple.com', port: 65537, secure: true } ] + }); + }, Error); }); it('remote server initialization - url string', function() { @@ -124,30 +124,30 @@ describe('Remote', function () { it('remote server initialization - url string - invalid host', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ 'ws://+:443' ] - }); - }, Error + var remote = new Remote({ + servers: [ 'ws://+:443' ] + }); + }, Error ); }); it('remote server initialization - url string - invalid port', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ 'ws://s-west.ripple.com:null' ] - }); - }, Error + var remote = new Remote({ + servers: [ 'ws://s-west.ripple.com:null' ] + }); + }, Error ); }); it('remote server initialization - url string - port out of range', function() { assert.throws( function() { - var remote = new Remote({ - servers: [ 'ws://s-west.ripple.com:65537:' ] - }); - }, Error + var remote = new Remote({ + servers: [ 'ws://s-west.ripple.com:65537:' ] + }); + }, Error ); }); @@ -179,92 +179,6 @@ describe('Remote', function () { assert.strictEqual((new Remote()).max_fee, 1e6); }); - describe('request constructors', function () { - beforeEach(function () { - callback = function () {} - remote = new Remote(options); - }); - - it('requesting a ledger', function () { - var request = remote.request_ledger(null, {}, callback); - assert(request instanceof Request); - }); - - it('requesting server info', function () { - var request = remote.request_server_info(null, {}, callback); - assert(request instanceof Request); - }) - - it('requesting peers', function () { - var request = remote.request_peers(null, {}, callback); - assert(request instanceof Request); - }); - - it('requesting a connection', function () { - var request = remote.request_connect(null, {}, callback); - assert(request instanceof Request); - }); - - it('making a unique node list add request', function () { - var request = remote.request_unl_add(null, {}, callback); - assert(request instanceof Request); - }); - - it('making a unique node list request', function () { - var request = remote.request_unl_list(null, {}, callback); - assert(request instanceof Request); - }); - - it('making a unique node list delete request', function () { - var request = remote.request_unl_delete(null, {}, callback); - assert(request instanceof Request); - }); - - it('request account currencies with ledger index', function() { - var request = remote.requestAccountCurrencies({account: ADDRESS}); - assert.strictEqual(request.message.command, 'account_currencies'); - assert.strictEqual(request.message.account, ADDRESS); - }); - - it('request account info with ledger index', function() { - var request = remote.requestAccountInfo({account: ADDRESS, ledger: 9592219}); - assert.strictEqual(request.message.command, 'account_info'); - assert.strictEqual(request.message.account, ADDRESS); - assert.strictEqual(request.message.ledger_index, 9592219); - }); - it('request account info with ledger hash', function() { - var request = remote.requestAccountInfo({account: ADDRESS, ledger: LEDGER_HASH}); - assert.strictEqual(request.message.command, 'account_info'); - assert.strictEqual(request.message.account, ADDRESS); - assert.strictEqual(request.message.ledger_hash, LEDGER_HASH); - }); - it('request account info with ledger identifier', function() { - var request = remote.requestAccountInfo({account: ADDRESS, ledger: 'validated'}); - assert.strictEqual(request.message.command, 'account_info'); - assert.strictEqual(request.message.account, ADDRESS); - assert.strictEqual(request.message.ledger_index, 'validated'); - }); - - it('request account balance with ledger index', function() { - var request = remote.requestAccountBalance(ADDRESS, 9592219); - assert.strictEqual(request.message.command, 'ledger_entry'); - assert.strictEqual(request.message.account_root, ADDRESS); - assert.strictEqual(request.message.ledger_index, 9592219); - }); - it('request account balance with ledger hash', function() { - var request = remote.requestAccountBalance(ADDRESS, LEDGER_HASH); - assert.strictEqual(request.message.command, 'ledger_entry'); - assert.strictEqual(request.message.account_root, ADDRESS); - assert.strictEqual(request.message.ledger_hash, LEDGER_HASH); - }); - it('request account balance with ledger identifier', function() { - var request = remote.requestAccountBalance(ADDRESS, 'validated'); - assert.strictEqual(request.message.command, 'ledger_entry'); - assert.strictEqual(request.message.account_root, ADDRESS); - assert.strictEqual(request.message.ledger_index, 'validated'); - }); - }); - it('pagingAccountRequest', function() { var request = Remote.accountRequest('account_lines', {account: ADDRESS}); assert.deepEqual(request.message, { @@ -527,26 +441,26 @@ describe('Remote', function () { Paths : [ [ { - account : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - currency : "USD", - issuer : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - type : 49, - type_hex : "0000000000000031" - }, - { - currency : "LTC", - issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - type : 48, - type_hex : "0000000000000030" - }, - { - account : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - currency : "LTC", - issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - type : 49, - type_hex : "0000000000000031" - } - ] + account : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + currency : "USD", + issuer : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + type : 49, + type_hex : "0000000000000031" + }, + { + currency : "LTC", + issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + type : 48, + type_hex : "0000000000000030" + }, + { + account : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + currency : "LTC", + issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + type : 49, + type_hex : "0000000000000031" + } + ] ], SendMax : { currency : "USD", @@ -597,4 +511,96 @@ describe('Remote', function () { }) }) + + it('Remote.parseBinaryTransaction()', function() { + var binaryTransaction = require('./fixtures/binary-transaction.json'); + var parsed = Remote.parseBinaryTransaction(binaryTransaction.binary); + assert.deepEqual(parsed, binaryTransaction.parsed); + }); + + describe('request constructors', function () { + beforeEach(function () { + callback = function () {} + remote = new Remote(options); + }); + + it('requesting a ledger', function () { + var request = remote.request_ledger(null, {}, callback); + assert(request instanceof Request); + }); + + it('requesting server info', function () { + var request = remote.request_server_info(null, {}, callback); + assert(request instanceof Request); + }) + + it('requesting peers', function () { + var request = remote.request_peers(null, {}, callback); + assert(request instanceof Request); + }); + + it('requesting a connection', function () { + var request = remote.request_connect(null, {}, callback); + assert(request instanceof Request); + }); + + it('making a unique node list add request', function () { + var request = remote.request_unl_add(null, {}, callback); + assert(request instanceof Request); + }); + + it('making a unique node list request', function () { + var request = remote.request_unl_list(null, {}, callback); + assert(request instanceof Request); + }); + + it('making a unique node list delete request', function () { + var request = remote.request_unl_delete(null, {}, callback); + assert(request instanceof Request); + }); + + it('request account currencies with ledger index', function() { + var request = remote.requestAccountCurrencies({account: ADDRESS}); + assert.strictEqual(request.message.command, 'account_currencies'); + assert.strictEqual(request.message.account, ADDRESS); + }); + + it('request account info with ledger index', function() { + var request = remote.requestAccountInfo({account: ADDRESS, ledger: 9592219}); + assert.strictEqual(request.message.command, 'account_info'); + assert.strictEqual(request.message.account, ADDRESS); + assert.strictEqual(request.message.ledger_index, 9592219); + }); + it('request account info with ledger hash', function() { + var request = remote.requestAccountInfo({account: ADDRESS, ledger: LEDGER_HASH}); + assert.strictEqual(request.message.command, 'account_info'); + assert.strictEqual(request.message.account, ADDRESS); + assert.strictEqual(request.message.ledger_hash, LEDGER_HASH); + }); + it('request account info with ledger identifier', function() { + var request = remote.requestAccountInfo({account: ADDRESS, ledger: 'validated'}); + assert.strictEqual(request.message.command, 'account_info'); + assert.strictEqual(request.message.account, ADDRESS); + assert.strictEqual(request.message.ledger_index, 'validated'); + }); + + it('request account balance with ledger index', function() { + var request = remote.requestAccountBalance(ADDRESS, 9592219); + assert.strictEqual(request.message.command, 'ledger_entry'); + assert.strictEqual(request.message.account_root, ADDRESS); + assert.strictEqual(request.message.ledger_index, 9592219); + }); + it('request account balance with ledger hash', function() { + var request = remote.requestAccountBalance(ADDRESS, LEDGER_HASH); + assert.strictEqual(request.message.command, 'ledger_entry'); + assert.strictEqual(request.message.account_root, ADDRESS); + assert.strictEqual(request.message.ledger_hash, LEDGER_HASH); + }); + it('request account balance with ledger identifier', function() { + var request = remote.requestAccountBalance(ADDRESS, 'validated'); + assert.strictEqual(request.message.command, 'ledger_entry'); + assert.strictEqual(request.message.account_root, ADDRESS); + assert.strictEqual(request.message.ledger_index, 'validated'); + }); + }); });