From 799c44ca251d8f2df818f2e9cb264b183bad2494 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Fri, 1 Jun 2012 05:18:03 -0700 Subject: [PATCH] Let wallet_accounts also take master_seed. --- src/RPCServer.cpp | 83 ++++++++++++++++++++++++++++------------------- src/RPCServer.h | 1 + src/main.cpp | 1 + 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 81c8e63ece..f53458ad8f 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -876,7 +876,34 @@ Json::Value RPCServer::doValidatorCreate(Json::Value& params) { return obj; } -// wallet_accounts +Json::Value RPCServer::accounts(const uint256& uLedger, const NewcoinAddress& naMasterGenerator) +{ + Json::Value jsonAccounts(Json::objectValue); + + // YYY Don't want to leak to thin server that these accounts are related. + // YYY Would be best to alternate requests to servers and to cache results. + uint uIndex = 0; + + do { + NewcoinAddress naAccount; + + naAccount.setAccountPublic(naMasterGenerator, uIndex++); + + AccountState::pointer as = mNetOps->getAccountState(uLedger, naAccount); + if (as) + { + as->addJson(jsonAccounts); + } + else + { + uIndex = 0; + } + } while (uIndex); + + return jsonAccounts; +} + +// wallet_accounts Json::Value RPCServer::doWalletAccounts(Json::Value& params) { NewcoinAddress naSeed; @@ -900,36 +927,32 @@ Json::Value RPCServer::doWalletAccounts(Json::Value& params) NewcoinAddress naMasterGenerator; - Json::Value ret = getGenerator(uLedger, naSeed, naMasterGenerator); + // Try the seed as a master seed. + naMasterGenerator.setFamilyGenerator(naSeed); + + Json::Value jsonAccounts = accounts(uLedger, naMasterGenerator); + + if (jsonAccounts.empty()) + { + // No account via seed as master, try seed a regular. + Json::Value ret = getGenerator(uLedger, naSeed, naMasterGenerator); + + if (!ret.empty()) + return ret; + + ret["accounts"] = accounts(uLedger, naMasterGenerator); - if (!ret.empty()) return ret; + } + else + { + // Had accounts via seed as master, return them. + Json::Value ret(Json::objectValue); - Json::Value jsonAccounts(Json::objectValue); + ret["accounts"] = jsonAccounts; - // YYY Don't want to leak to thin server that these accounts are related. - // YYY Would be best to alternate requests to servers and to cache results. - uint uIndex = 0; - - do { - NewcoinAddress naAccount; - - naAccount.setAccountPublic(naMasterGenerator, uIndex++); - - AccountState::pointer as = mNetOps->getAccountState(uLedger, naAccount); - if (as) - { - as->addJson(jsonAccounts); - } - else - { - uIndex = 0; - } - } while (uIndex); - - ret["accounts"] = jsonAccounts; - - return ret; + return ret; + } } Json::Value RPCServer::doWalletAdd(Json::Value& params) @@ -1172,11 +1195,6 @@ Json::Value RPCServer::doWalletSeed(Json::Value& params) } } -Json::Value RPCServer::doWalletVerify(Json::Value& params) -{ - return "not implemented"; -} - void RPCServer::validatorsResponse(const boost::system::error_code& err, std::string strResponse) { std::cerr << "Fetch '" VALIDATORS_FILE_NAME "' complete." << std::endl; @@ -1331,7 +1349,6 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params if (command == "wallet_create") return doWalletCreate(params); if (command == "wallet_propose") return doWalletPropose(params); if (command == "wallet_seed") return doWalletSeed(params); - if (command == "wallet_verify") return doWalletVerify(params); // // Obsolete or need rewrite: diff --git a/src/RPCServer.h b/src/RPCServer.h index c0ba722079..33710e9b18 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -43,6 +43,7 @@ private: Json::Value authorize(const uint256& uLedger, const NewcoinAddress& naSeed, const NewcoinAddress& naSrcAccountID, NewcoinAddress& naAccountPublic, NewcoinAddress& naAccountPrivate, AccountState::pointer& asSrc); + Json::Value accounts(const uint256& uLedger, const NewcoinAddress& naMasterGenerator); Json::Value accountFromString(const uint256& uLedger, NewcoinAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex); diff --git a/src/main.cpp b/src/main.cpp index 4dbf455155..39cdf7a908 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,7 @@ void printHelp(const po::options_description& desc) cout << " unl_list" << endl; cout << " unl_reset" << endl; cout << " validation_create [||]" << endl; + cout << " wallet_accounts " << endl; cout << " wallet_claim [] []" << endl; cout << " wallet_seed [||]" << endl; cout << " wallet_propose" << endl;