diff --git a/RPCServer.cpp b/RPCServer.cpp index e2c04fb56d..a58e30e6b3 100644 --- a/RPCServer.cpp +++ b/RPCServer.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "json/value.h" #include "json/reader.h" @@ -230,34 +231,48 @@ Json::Value RPCServer::doInfo(Json::Value ¶ms) } return ret; } - else if(paramCount==1) - { - uint160 family; - if(Wallet::isHexFamily(fParam)) - family.SetHex(fParam); - else if(Wallet::isHexPublicKey(fParam)) - family=theApp->getWallet().findFamilyPK(fParam); - else - family=theApp->getWallet().findFamilySN(fParam); - if(!family) return JSONRPCError(500, "No such family"); + + if(paramCount>2) return JSONRPCError(500, "Invalid parameters"); + + uint160 family; + if(Wallet::isHexFamily(fParam)) + family.SetHex(fParam); + else if(Wallet::isHexPublicKey(fParam)) + family=theApp->getWallet().findFamilyPK(fParam); + else + family=theApp->getWallet().findFamilySN(fParam); + if(!family) return JSONRPCError(500, "No such family"); - std::string name, comment, pubKey; - bool isLocked; - if(!theApp->getWallet().getFullFamilyInfo(family, name, comment, pubKey, isLocked)) - return JSONRPCError(500, "Family not found"); - Json::Value obj(Json::objectValue); - obj["FamilyIdentifier"]=family.GetHex(); - obj["ShortName"]=name; - if(!comment.empty()) - obj["Comment"]=comment; - obj["PublicGenerator"]=pubKey; - obj["Locked"]=isLocked ? "true" : "false"; - return obj; - } - else if(paramCount==2) + std::string name, comment, pubKey; + bool isLocked; + if(!theApp->getWallet().getFullFamilyInfo(family, name, comment, pubKey, isLocked)) + return JSONRPCError(500, "Family not found"); + Json::Value obj(Json::objectValue); + obj["FamilyIdentifier"]=family.GetHex(); + obj["ShortName"]=name; + if(!comment.empty()) + obj["Comment"]=comment; + obj["PublicGenerator"]=pubKey; + obj["Locked"]=isLocked ? "true" : "false"; + + if(paramCount==2) { + Json::Value keyNum=params[1u]; + if(keyNum.isString()) keyNum=Json::Value(boost::lexical_cast(keyNum.asString())); + if(keyNum.isConvertibleTo(Json::intValue)) + { + uint160 k=theApp->getWallet().peekKey(family, keyNum.asInt()); + if(!!k) + { + Json::Value key(Json::objectValue); + key["Number"]=keyNum.asInt(); + key["Address"]=NewcoinAddress(k).GetString(); + obj["Account"]=key; + } + } } - else return JSONRPCError(500, "Invalid parameters"); + + return obj; } Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params) diff --git a/Wallet.cpp b/Wallet.cpp index fb2f2c1d39..56dc071666 100644 --- a/Wallet.cpp +++ b/Wallet.cpp @@ -28,12 +28,12 @@ void LocalAccountEntry::unlock(const BIGNUM* rootPrivKey) std::string LocalAccountEntry::getAccountName() const { - return mPublicKey->GetAddress().GetString(); + return mPublicKey->GetAddress().GetString(); } std::string LocalAccountEntry::getLocalAccountName() const { - return NewcoinAddress(mAccountFamily).GetString() + ":" + boost::lexical_cast(mAccountSeq); + return NewcoinAddress(mAccountFamily).GetString() + ":" + boost::lexical_cast(mAccountSeq); } LocalAccountFamily::LocalAccountFamily(const uint160& family, const EC_GROUP* group, const EC_POINT* pubKey) : @@ -49,7 +49,7 @@ LocalAccountFamily::~LocalAccountFamily() if(mRootPubKey!=NULL) EC_POINT_free(mRootPubKey); } -uint160 LocalAccountFamily::getAccount(int seq) +uint160 LocalAccountFamily::getAccount(int seq, bool keep) { std::map::iterator ait=mAccounts.find(seq); if(ait!=mAccounts.end()) return ait->second->getAccountID(); @@ -425,7 +425,7 @@ LocalAccount::pointer Wallet::getLocalAccount(const uint160& family, int seq) { std::map::iterator fit=families.find(family); if(fit==families.end()) return LocalAccount::pointer(); - uint160 acct=fit->second->getAccount(seq); + uint160 acct=fit->second->getAccount(seq, true); std::map::iterator ait=accounts.find(acct); if(ait!=accounts.end()) return ait->second; @@ -435,6 +435,13 @@ LocalAccount::pointer Wallet::getLocalAccount(const uint160& family, int seq) return lac; } +uint160 Wallet::peekKey(const uint160& family, int seq) +{ + std::map::iterator fit=families.find(family); + if(fit==families.end()) return uint160(); + return fit->second->getAccount(seq, false); +} + void Wallet::delFamily(const uint160& familyName) { std::map::iterator fit=families.find(familyName); diff --git a/Wallet.h b/Wallet.h index 9d3d8ba9c4..19192e01cd 100644 --- a/Wallet.h +++ b/Wallet.h @@ -90,7 +90,7 @@ public: std::map& getAcctMap() { return mAccounts; } LocalAccountEntry::pointer get(int seq); - uint160 getAccount(int seq); + uint160 getAccount(int seq, bool keep); std::string getPubKeyHex() const; // The text name of the public key std::string getShortName() const { return mName; } @@ -165,6 +165,7 @@ public: LocalAccount::pointer getLocalAccount(const uint160& famBase, int seq); LocalAccount::pointer getLocalAccount(const uint160& acctID); + uint160 peekKey(const uint160& family, int seq); std::string getPubKeyHex(const uint160& famBase); std::string getShortName(const uint160& famBase); bool getFamilyInfo(const uint160& family, std::string& name, std::string& comment);