mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Helper function to parse families. Code to issue new accounts.
This commit is contained in:
@@ -151,6 +151,18 @@ bool RPCServer::extractString(std::string& param, const Json::Value& params, int
|
||||
return true;
|
||||
}
|
||||
|
||||
uint160 RPCServer::parseFamily(const std::string& fParam)
|
||||
{
|
||||
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);
|
||||
return family;
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doCreateFamily(Json::Value& params)
|
||||
{
|
||||
// createfamily <hexPrivateKey>
|
||||
@@ -206,6 +218,7 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
||||
return JSONRPCError(500, "Account not found");
|
||||
|
||||
Json::Value ret(Json::objectValue);
|
||||
ret["Family"]=account->getFamilyName();
|
||||
ret["ShortName"]=account->getShortName();
|
||||
ret["FullName"]=account->getFullName();
|
||||
ret["AccountID"]=NewcoinAddress(account->getAddress()).GetString();
|
||||
@@ -214,8 +227,25 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doNewAccount(Json::Value ¶ms)
|
||||
{ // newaccount <family>
|
||||
return "Not yet";
|
||||
{ // newaccount <family> [<name>]
|
||||
std::string fParam;
|
||||
if(!extractString(fParam, params, 0))
|
||||
return JSONRPCError(500, "Family required");
|
||||
|
||||
uint160 family = parseFamily(fParam);
|
||||
if(!family) return JSONRPCError(500, "No such family");
|
||||
|
||||
LocalAccount::pointer account(theApp->getWallet().getNewLocalAccount(family));
|
||||
if(!account)
|
||||
return JSONRPCError(500, "Family not found");
|
||||
|
||||
Json::Value ret(Json::objectValue);
|
||||
ret["Family"]=account->getFamilyName();
|
||||
ret["ShortName"]=account->getShortName();
|
||||
ret["FullName"]=account->getFullName();
|
||||
ret["AccountID"]=NewcoinAddress(account->getAddress()).GetString();
|
||||
ret["Issued"]=Json::Value(account->isIssued());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doLock(Json::Value ¶ms)
|
||||
@@ -263,13 +293,7 @@ Json::Value RPCServer::doFamilyInfo(Json::Value ¶ms)
|
||||
std::string fParam;
|
||||
extractString(fParam, params, 0);
|
||||
|
||||
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);
|
||||
uint160 family=parseFamily(fParam);
|
||||
if(!family) return JSONRPCError(500, "No such family");
|
||||
|
||||
std::string name, comment, pubGen;
|
||||
|
||||
@@ -31,6 +31,8 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
||||
int getParamCount(const Json::Value& params);
|
||||
bool extractString(std::string& param, const Json::Value& params, int index);
|
||||
|
||||
uint160 parseFamily(const std::string& family);
|
||||
|
||||
Json::Value doCreateFamily(Json::Value& params);
|
||||
Json::Value doFamilyInfo(Json::Value& params);
|
||||
Json::Value doAccountInfo(Json::Value& params);
|
||||
|
||||
23
Wallet.cpp
23
Wallet.cpp
@@ -350,6 +350,11 @@ std::string LocalAccount::getFullName() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string LocalAccount::getFamilyName() const
|
||||
{
|
||||
return mFamily->getShortName();
|
||||
}
|
||||
|
||||
bool LocalAccount::isIssued() const
|
||||
{
|
||||
return mSeq < mFamily->getSeq();
|
||||
@@ -471,6 +476,24 @@ std::string Wallet::getShortName(const uint160& famBase)
|
||||
return fit->second->getShortName();
|
||||
}
|
||||
|
||||
LocalAccount::pointer Wallet::getNewLocalAccount(const uint160& family)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
std::map<uint160, LocalAccountFamily::pointer>::iterator fit=mFamilies.find(family);
|
||||
if(fit==mFamilies.end()) return LocalAccount::pointer();
|
||||
|
||||
uint32 seq=fit->second->getSeq();
|
||||
uint160 acct=fit->second->getAccount(seq, true);
|
||||
fit->second->setSeq(seq+1); // FIXME: writeout new seq
|
||||
|
||||
std::map<uint160, LocalAccount::pointer>::iterator ait=mAccounts.find(acct);
|
||||
if(ait!=mAccounts.end()) return ait->second;
|
||||
|
||||
LocalAccount::pointer lac(new LocalAccount(fit->second, seq));
|
||||
mAccounts.insert(std::make_pair(acct, lac));
|
||||
return lac;
|
||||
}
|
||||
|
||||
LocalAccount::pointer Wallet::getLocalAccount(const uint160& family, int seq)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
2
Wallet.h
2
Wallet.h
@@ -121,6 +121,7 @@ public:
|
||||
|
||||
std::string getShortName() const;
|
||||
std::string getFullName() const;
|
||||
std::string getFamilyName() const;
|
||||
bool isIssued() const;
|
||||
|
||||
bool signRaw(Serializer::pointer);
|
||||
@@ -173,6 +174,7 @@ public:
|
||||
|
||||
LocalAccount::pointer getLocalAccount(const uint160& famBase, int seq);
|
||||
LocalAccount::pointer getLocalAccount(const uint160& acctID);
|
||||
LocalAccount::pointer getNewLocalAccount(const uint160& family);
|
||||
uint160 peekKey(const uint160& family, int seq);
|
||||
std::string getPubGenHex(const uint160& famBase);
|
||||
std::string getShortName(const uint160& famBase);
|
||||
|
||||
Reference in New Issue
Block a user