mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
[TASK] Allow limit option in remote.requestBookOffers
This commit is contained in:
@@ -1258,7 +1258,7 @@ Remote.accountRequest = function(type, options, callback) {
|
|||||||
request.message.peer = UInt160.json_rewrite(peer);
|
request.message.peer = UInt160.json_rewrite(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNaN(Number(limit))) {
|
if (!isNaN(limit)) {
|
||||||
limit = Number(limit);
|
limit = Number(limit);
|
||||||
|
|
||||||
// max for 32-bit unsigned int is 4294967295
|
// max for 32-bit unsigned int is 4294967295
|
||||||
@@ -1481,16 +1481,18 @@ Remote.prototype.requestTxHistory = function(start, callback) {
|
|||||||
* @param {Object} options.pays - taker_pays with issuer and currency
|
* @param {Object} options.pays - taker_pays with issuer and currency
|
||||||
* @param {String} [options.taker]
|
* @param {String} [options.taker]
|
||||||
* @param {String} [options.ledger]
|
* @param {String} [options.ledger]
|
||||||
|
* @param {String|Number} [options.limit]
|
||||||
* @param [Function] callback
|
* @param [Function] callback
|
||||||
* @return {Request}
|
* @return {Request}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
|
Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
|
||||||
|
var ledger;
|
||||||
|
var limit;
|
||||||
var lastArg = arguments[arguments.length - 1];
|
var lastArg = arguments[arguments.length - 1];
|
||||||
|
|
||||||
if (gets.hasOwnProperty('gets') || gets.hasOwnProperty('taker_gets')) {
|
if (gets.hasOwnProperty('gets') || gets.hasOwnProperty('taker_gets')) {
|
||||||
var options = gets;
|
var options = gets;
|
||||||
var ledger;
|
|
||||||
// This would mutate the `lastArg` in `arguments` to be `null` and is
|
// 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,
|
// redundant. Once upon a time, some awkward code was written f(g, null,
|
||||||
// null, cb) ...
|
// null, cb) ...
|
||||||
@@ -1499,6 +1501,7 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
|
|||||||
pays = options.pays || options.taker_pays;
|
pays = options.pays || options.taker_pays;
|
||||||
gets = options.gets || options.taker_gets;
|
gets = options.gets || options.taker_gets;
|
||||||
ledger = options.ledger;
|
ledger = options.ledger;
|
||||||
|
limit = options.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof lastArg === 'function') {
|
if (typeof lastArg === 'function') {
|
||||||
@@ -1524,9 +1527,25 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.message.taker = taker ? taker : UInt160.ACCOUNT_ONE;
|
request.message.taker = taker ? taker : UInt160.ACCOUNT_ONE;
|
||||||
|
|
||||||
request.ledgerSelect(ledger);
|
request.ledgerSelect(ledger);
|
||||||
|
|
||||||
|
if (!isNaN(limit)) {
|
||||||
|
limit = Number(limit);
|
||||||
|
|
||||||
|
// max for 32-bit unsigned int is 4294967295
|
||||||
|
// we'll clamp to 1e9
|
||||||
|
if (limit > 1e9) {
|
||||||
|
limit = 1e9;
|
||||||
|
}
|
||||||
|
// min for 32-bit unsigned int is 0
|
||||||
|
// we'll clamp to 0
|
||||||
|
if (limit < 0) {
|
||||||
|
limit = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.message.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(callback);
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ describe('Remote', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('requestAccountLines, account and callback', function() {
|
it('requestAccountLines, account and callback', function() {
|
||||||
var callback = function() {};
|
function callback() {}
|
||||||
var remote = new Remote({
|
var remote = new Remote({
|
||||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||||
});
|
});
|
||||||
@@ -354,7 +354,7 @@ describe('Remote', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('requestAccountLines, ledger, peer', function() {
|
it('requestAccountLines, ledger, peer', function() {
|
||||||
var callback = function() {};
|
function callback() {}
|
||||||
var remote = new Remote({
|
var remote = new Remote({
|
||||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||||
});
|
});
|
||||||
@@ -379,7 +379,7 @@ describe('Remote', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('requestAccountLines, ledger, peer, limit and marker', function() {
|
it('requestAccountLines, ledger, peer, limit and marker', function() {
|
||||||
var callback = function() {};
|
function callback() {}
|
||||||
var remote = new Remote({
|
var remote = new Remote({
|
||||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||||
});
|
});
|
||||||
@@ -408,7 +408,7 @@ describe('Remote', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('requestAccountOffers, ledger, peer, limit and marker', function() {
|
it('requestAccountOffers, ledger, peer, limit and marker', function() {
|
||||||
var callback = function() {};
|
function callback() {}
|
||||||
var remote = new Remote({
|
var remote = new Remote({
|
||||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||||
});
|
});
|
||||||
@@ -437,7 +437,7 @@ describe('Remote', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('requestBookOffers, ledger', function() {
|
it('requestBookOffers, ledger', function() {
|
||||||
var callback = function() {};
|
function callback() {}
|
||||||
var remote = new Remote({
|
var remote = new Remote({
|
||||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||||
});
|
});
|
||||||
@@ -472,6 +472,44 @@ describe('Remote', function () {
|
|||||||
assert(request.requested);
|
assert(request.requested);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('requestBookOffers, ledger and limit', function() {
|
||||||
|
function callback() {}
|
||||||
|
|
||||||
|
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,
|
||||||
|
limit: 10
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(request.message, {
|
||||||
|
command: 'book_offers',
|
||||||
|
id: undefined,
|
||||||
|
taker_gets: {
|
||||||
|
currency: Currency.from_human('USD').to_hex(),
|
||||||
|
issuer: ADDRESS
|
||||||
|
},
|
||||||
|
taker_pays: {
|
||||||
|
currency: Currency.from_human('XRP').to_hex()
|
||||||
|
},
|
||||||
|
taker: UInt160.ACCOUNT_ONE,
|
||||||
|
ledger_hash: LEDGER_HASH,
|
||||||
|
limit: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(request.requested);
|
||||||
|
});
|
||||||
|
|
||||||
it('create remote and get pending transactions', function() {
|
it('create remote and get pending transactions', function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user