diff --git a/src/js/index.js b/src/js/index.js index 4ff2b374d..b603d6a53 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -3,6 +3,8 @@ exports.Amount = require('./amount').Amount; exports.UInt160 = require('./amount').UInt160; exports.Seed = require('./amount').Seed; +exports.utils = require('./utils'); + // Important: We do not guarantee any specific version of SJCL or for any // specific features to be included. The version and configuration may change at // any time without warning. diff --git a/src/js/orderbook.js b/src/js/orderbook.js index c78674e07..00ac29b23 100644 --- a/src/js/orderbook.js +++ b/src/js/orderbook.js @@ -32,7 +32,7 @@ var OrderBook = function (remote, if (OrderBook.subscribe_events.indexOf(type) !== -1) { if (!self._subs && 'open' === self._remote._online_state) { self._remote.request_subscribe() - .books([self.to_json()]) + .books([self.to_json()], true) .request(); } self._subs += 1; @@ -54,7 +54,7 @@ var OrderBook = function (remote, this._remote.on('connect', function () { if (self._subs) { self._remote.request_subscribe() - .books([self.to_json()]) + .books([self.to_json()], true) .request(); } }); diff --git a/src/js/remote.js b/src/js/remote.js index 2f99748b2..fed025256 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -203,7 +203,7 @@ Request.prototype.rt_accounts = function (accounts) { return this.accounts(accounts, true); }; -Request.prototype.books = function (books) { +Request.prototype.books = function (books, state) { var procBooks = []; for (var i = 0, l = books.length; i < l; i++) { @@ -221,6 +221,8 @@ Request.prototype.books = function (books) { json["IssuerIn"] = UInt160.json_rewrite(book["IssuerIn"]); } + if (state || book["StateNow"]) json["StateNow"] = true; + procBooks.push(json); } this.message.books = procBooks; diff --git a/src/js/serializedtypes.js b/src/js/serializedtypes.js index 93009a9fb..a3a2808d8 100644 --- a/src/js/serializedtypes.js +++ b/src/js/serializedtypes.js @@ -243,17 +243,25 @@ var STAccount = exports.Account = new SerializedType({ }); var STPathSet = exports.PathSet = new SerializedType({ + typeBoundary: 0xff, + typeEnd: 0x00, + typeAccount: 0x01, + typeCurrency: 0x10, + typeIssuer: 0x20, serialize: function (so, val) { // XXX for (var i = 0, l = val.length; i < l; i++) { + // Boundary + if (i) STInt8.serialize(so, this.typeBoundary); + for (var j = 0, l2 = val[i].length; j < l2; j++) { var entry = val[i][j]; var type = 0; - if (entry.account) type |= 0x01; - if (entry.currency) type |= 0x10; - if (entry.issuer) type |= 0x20; + if (entry.account) type |= this.typeAccount; + if (entry.currency) type |= this.typeCurrency; + if (entry.issuer) type |= this.typeIssuer; STInt8.serialize(so, type); @@ -268,10 +276,8 @@ var STPathSet = exports.PathSet = new SerializedType({ so.append(UInt160.from_json(entry.issuer).to_bytes()); } } - - if (j < l2) STInt8.serialize(so, 0xff); } - STInt8.serialize(so, 0x00); + STInt8.serialize(so, this.typeEnd); }, parse: function (so) { // XXX diff --git a/src/js/utils.js b/src/js/utils.js index d1779faf9..462f3f286 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -97,6 +97,15 @@ var assert = function (assertion, msg) { } }; +/** + * Convert a ripple epoch to a JavaScript timestamp. + * + * JavaScript timestamps are unix epoch in milliseconds. + */ +var toTimestamp = function (rpepoch) { + return (rpepoch + 0x386D4380) * 1000; +}; + exports.trace = trace; exports.arraySet = arraySet; exports.hexToString = hexToString; @@ -106,5 +115,6 @@ exports.stringToHex = stringToHex; exports.chunkString = chunkString; exports.logObject = logObject; exports.assert = assert; +exports.toTimestamp = toTimestamp; // vim:sw=2:sts=2:ts=8:et