From 3fff14cdd26be01c22a84b7080aa2a482c85d80a Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 7 Mar 2013 11:38:51 +0100 Subject: [PATCH 1/4] JS: Fix for multiple Account instances (which caused multiple subscriptions.) --- src/js/account.js | 2 ++ src/js/remote.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/js/account.js b/src/js/account.js index 59eb95c91..2e1121e5d 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -1,5 +1,7 @@ // Routines for working with an account. // +// You should not instantiate this class yourself, instead use Remote#account. +// // Events: // wallet_clean : True, iff the wallet has been updated. // wallet_dirty : True, iff the wallet needs to be updated. diff --git a/src/js/remote.js b/src/js/remote.js index fa9e4ba51..75622411a 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -1111,11 +1111,17 @@ Remote.prototype.request_owner_count = function (account, current) { }; Remote.prototype.account = function (accountId) { - var account = new Account(this, accountId); + accountId = UInt160.json_rewrite(accountId); - if (!account.is_valid()) return account; + if (!this._accounts[accountId]) { + var account = new Account(this, accountId); - return this._accounts[account.to_json()] = account; + if (!account.is_valid()) return account; + + this._accounts[accountId] = account; + } + + return this._accounts[accountId]; }; Remote.prototype.book = function (currency_out, issuer_out, @@ -1130,7 +1136,7 @@ Remote.prototype.book = function (currency_out, issuer_out, // Return the next account sequence if possible. // <-- undefined or Sequence Remote.prototype.account_seq = function (account, advance) { - var account = UInt160.json_rewrite(account); + account = UInt160.json_rewrite(account); var account_info = this.accounts[account]; var seq; From ef10a41f63e544f136a1d1f4f02250da85b90ea1 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Thu, 7 Mar 2013 03:34:03 -0800 Subject: [PATCH 2/4] Increment ripple-lib version 0.7.3 --- package.json | 2 +- src/cpp/ripple/PeerDoor.h | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index bf860e737..1cbd65733 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ripple-lib", - "version": "0.7.1", + "version": "0.7.2", "description": "Ripple JavaScript client library", "files": [ diff --git a/src/cpp/ripple/PeerDoor.h b/src/cpp/ripple/PeerDoor.h index 5f03c5914..a6146e411 100644 --- a/src/cpp/ripple/PeerDoor.h +++ b/src/cpp/ripple/PeerDoor.h @@ -1,9 +1,6 @@ #ifndef __PEERDOOR__ #define __PEERDOOR__ -#include -#include - #include #include From 9121cfd567665fab1ff4f66f5cb08398357e76da Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Thu, 7 Mar 2013 03:39:17 -0800 Subject: [PATCH 3/4] Change RPCs to use account instead of ident. --- src/cpp/ripple/RPCHandler.cpp | 10 +++++----- src/js/remote.js | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 28b54a322..412853584 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -559,7 +559,7 @@ Json::Value RPCHandler::accountFromString(Ledger::ref lrLedger, RippleAddress& n } // { -// ident : , +// account: , // account_index : // optional // strict: // true, only allow public keys and addresses. false, default. // ledger_hash : @@ -573,10 +573,10 @@ Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest) if (!lpLedger) return jvResult; - if (!jvRequest.isMember("ident")) + if (!jvRequest.isMember("account") && !jvRequest.isMember("ident")) return rpcError(rpcINVALID_PARAMS); - std::string strIdent = jvRequest["ident"].asString(); + std::string strIdent = jvRequest.isMember("account") ? jvRequest["account"].asString() : jvRequest["ident"].asString(); bool bIndex; int iIndex = jvRequest.isMember("account_index") ? jvRequest["account_index"].asUInt() : 0; bool bStrict = jvRequest.isMember("strict") && jvRequest["strict"].asBool(); @@ -742,10 +742,10 @@ Json::Value RPCHandler::doNicknameInfo(Json::Value params) // XXX This would be better if it took the ledger. Json::Value RPCHandler::doOwnerInfo(Json::Value jvRequest) { - if (!jvRequest.isMember("ident")) + if (!jvRequest.isMember("account") && !jvRequest.isMember("ident")) return rpcError(rpcINVALID_PARAMS); - std::string strIdent = jvRequest["ident"].asString(); + std::string strIdent = jvRequest.isMember("account") ? jvRequest["account"].asString() : jvRequest["ident"].asString(); bool bIndex; int iIndex = jvRequest.isMember("account_index") ? jvRequest["account_index"].asUInt() : 0; RippleAddress raAccount; diff --git a/src/js/remote.js b/src/js/remote.js index 75622411a..2ce9d15da 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -890,7 +890,8 @@ Remote.prototype.request_tx = function (hash) { Remote.prototype.request_account_info = function (accountID) { var request = new Request(this, 'account_info'); - request.message.ident = UInt160.json_rewrite(accountID); + request.message.ident = UInt160.json_rewrite(accountID); // DEPRECATED + request.message.account = UInt160.json_rewrite(accountID); return request; }; From 3a7491c6d98b7bfb5d24bc08729e44357d6f539e Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 7 Mar 2013 16:05:11 +0100 Subject: [PATCH 4/4] JS: Feed server entropy into SJCL's entropy pool. --- src/js/remote.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/remote.js b/src/js/remote.js index 2ce9d15da..9b6bd4b5d 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -26,6 +26,7 @@ var OrderBook = require('./orderbook').OrderBook; var utils = require('./utils'); var config = require('./config'); +var sjcl = require('../../build/sjcl'); // Request events emitted: // 'success' : Request successful. @@ -1031,8 +1032,13 @@ Remote.prototype._server_subscribe = function () { self._stand_alone = !!message.stand_alone; self._testnet = !!message.testnet; - if (message.random) + if ("string" === typeof message.random) { + var rand = message.random.match(/[0-9A-F]{8}/ig); + while (rand && rand.length) + sjcl.random.addEntropy(parseInt(rand.pop(), 16)); + self.emit('random', utils.hexToArray(message.random)); + } if (message.ledger_hash && message.ledger_index) { self._ledger_time = message.ledger_time;