Finish 'info' RPC call.

This commit is contained in:
JoelKatz
2012-01-01 07:45:34 -08:00
parent a24e7a4c27
commit 82a88671dd
3 changed files with 53 additions and 30 deletions

View File

@@ -3,6 +3,7 @@
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include "json/value.h"
#include "json/reader.h"
@@ -230,8 +231,9 @@ Json::Value RPCServer::doInfo(Json::Value &params)
}
return ret;
}
else if(paramCount==1)
{
if(paramCount>2) return JSONRPCError(500, "Invalid parameters");
uint160 family;
if(Wallet::isHexFamily(fParam))
family.SetHex(fParam);
@@ -252,12 +254,25 @@ Json::Value RPCServer::doInfo(Json::Value &params)
obj["Comment"]=comment;
obj["PublicGenerator"]=pubKey;
obj["Locked"]=isLocked ? "true" : "false";
return obj;
}
else if(paramCount==2)
if(paramCount==2)
{
Json::Value keyNum=params[1u];
if(keyNum.isString()) keyNum=Json::Value(boost::lexical_cast<int>(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)

View File

@@ -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<int, LocalAccountEntry::pointer>::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<uint160, LocalAccountFamily::pointer>::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<uint160, LocalAccount::pointer>::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<uint160, LocalAccountFamily::pointer>::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<uint160, LocalAccountFamily::pointer>::iterator fit=families.find(familyName);

View File

@@ -90,7 +90,7 @@ public:
std::map<int, LocalAccountEntry::pointer>& 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);