mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
Finish 'info' RPC call.
This commit is contained in:
@@ -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,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<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)
|
||||
|
||||
15
Wallet.cpp
15
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<std::string>(mAccountSeq);
|
||||
return NewcoinAddress(mAccountFamily).GetString() + ":" + boost::lexical_cast<std::string>(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<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);
|
||||
|
||||
3
Wallet.h
3
Wallet.h
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user