mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-26 15:15:49 +00:00
[FEATURE] Add tests and support for ledger for requestBookOffers
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 = [{
|
||||
|
||||
Reference in New Issue
Block a user