From 34c0677c453c409ef0a5b351959abdc176d3bacb Mon Sep 17 00:00:00 2001 From: Alan Cohen Date: Fri, 19 Dec 2014 16:20:05 -0800 Subject: [PATCH] [FEATURE] Add tests and support for ledger for requestBookOffers --- src/js/ripple/remote.js | 15 ++++++++++----- test/remote-test.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/js/ripple/remote.js b/src/js/ripple/remote.js index cfd08cc527..b702a26308 100644 --- a/src/js/ripple/remote.js +++ b/src/js/ripple/remote.js @@ -1476,10 +1476,12 @@ Remote.prototype.requestTxHistory = function(start, callback) { /** * Request book_offers * - * @param {Object} gets - * @param {Object} pays - * @param {String} taker - * @param [Function] calback + * @param {Object} options - taker_options or can be an options object with the following properties + * @param {Object} options.gets - taker_options + * @param {Object} options.pays - taker_pays + * @param {String} [options.taker] + * @param {String} [options.ledger] + * @param [Function] callback * @return {Request} */ @@ -1488,6 +1490,7 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) { if (gets.hasOwnProperty('gets') || gets.hasOwnProperty('taker_gets')) { var options = gets; + var ledger; // This would mutate the `lastArg` in `arguments` to be `null` and is // redundant. Once upon a time, some awkward code was written f(g, null, // null, cb) ... @@ -1495,6 +1498,7 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) { taker = options.taker; pays = options.pays || options.taker_pays; gets = options.gets || options.taker_gets; + ledger = options.ledger; } if (typeof lastArg === 'function') { @@ -1521,8 +1525,9 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) { request.message.taker = taker ? taker : UInt160.ACCOUNT_ONE; - request.callback(callback); + request.ledgerSelect(ledger); + request.callback(callback); return request; }; diff --git a/test/remote-test.js b/test/remote-test.js index b1da20bfaf..16683874eb 100644 --- a/test/remote-test.js +++ b/test/remote-test.js @@ -2,6 +2,8 @@ var assert = require('assert'); var Remote = require('ripple-lib').Remote; var Server = require('ripple-lib').Server; var Request = require('ripple-lib').Request; +var UInt160 = require('ripple-lib').UInt160; +var Currency = require('ripple-lib').Currency; var options, remote, callback, database, tx; @@ -434,6 +436,43 @@ describe('Remote', function () { assert(request.requested); }); + it('requestBookOffers, ledger', function() { + var callback = function() {}; + var remote = new Remote({ + servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ] + }); + var request = remote.requestBookOffers( + { + gets: { + currency: 'USD', + issuer: ADDRESS + }, + pays: { + currency: 'XRP' + }, + ledger: LEDGER_HASH + }, + callback + ); + + assert.deepEqual(request.message, { + command: 'book_offers', + id: undefined, + taker_gets: { + currency: Currency.from_human('USD').to_hex(), + issuer: ADDRESS + }, + taker_pays: { + currency: '0000000000000000000000000000000000000000' + }, + taker: UInt160.ACCOUNT_ONE, + ledger_hash: LEDGER_HASH + }); + + assert(request.requested); + }); + + it('create remote and get pending transactions', function() { before(function() { tx = [{