mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add AccountState::addJson. Make RPC call "accountinfo <account>" work
on non-local accounts and local account by account identifier.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "AccountState.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
@@ -22,3 +25,30 @@ std::vector<unsigned char> AccountState::getRaw() const
|
||||
s.add32(mAccountSeq);
|
||||
return s.getData();
|
||||
}
|
||||
|
||||
static bool isHex(char j)
|
||||
{
|
||||
if((j>='0') && (j<='9')) return true;
|
||||
if((j>='A') && (j<='F')) return true;
|
||||
if((j>='a') && (j<='f')) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AccountState::isHexAccountID(const std::string& acct)
|
||||
{
|
||||
if(acct.size()!=40) return false;
|
||||
for(int i=1; i<40; i++)
|
||||
if(!isHex(acct[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AccountState::addJson(Json::Value& val)
|
||||
{
|
||||
Json::Value as(Json::objectValue);
|
||||
as["Account"]=mAccountID.GetHex();
|
||||
as["Balance"]=boost::lexical_cast<std::string>(mBalance);
|
||||
as["SendSequence"]=mAccountSeq;
|
||||
if(!mValid) as["Invalid"]=true;
|
||||
NewcoinAddress nad(mAccountID);
|
||||
val[nad.GetString()]=as;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "json/value.h"
|
||||
|
||||
#include "types.h"
|
||||
#include "uint256.h"
|
||||
|
||||
@@ -48,8 +50,10 @@ public:
|
||||
assert(mAccountSeq!=0);
|
||||
mAccountSeq--;
|
||||
}
|
||||
static bool isHexAccountID(const std::string& acct);
|
||||
|
||||
std::vector<unsigned char> getRaw() const;
|
||||
void addJson(Json::Value& value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "Wallet.h"
|
||||
#include "Conversion.h"
|
||||
#include "LocalTransaction.h"
|
||||
#include "NewcoinAddress.h"
|
||||
#include "AccountState.h"
|
||||
|
||||
/*
|
||||
Just read from wire until the entire request is in.
|
||||
@@ -198,15 +200,36 @@ Json::Value RPCServer::doCreateFamily(Json::Value& params)
|
||||
|
||||
Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
||||
{ // accountinfo <family>:<number>
|
||||
// accountinfo <account>
|
||||
std::string acct;
|
||||
if(!extractString(acct, params, 0))
|
||||
return JSONRPCError(500, "Invalid account identifier");
|
||||
|
||||
LocalAccount::pointer account=theApp->getWallet().parseAccount(acct);
|
||||
if(!account)
|
||||
return JSONRPCError(500, "Account not found");
|
||||
if(account) return account->getJson();
|
||||
|
||||
return account->getJson();
|
||||
uint160 acctid;
|
||||
if(AccountState::isHexAccountID(acct)) acctid.SetHex(acct);
|
||||
else
|
||||
{
|
||||
NewcoinAddress ad(acct);
|
||||
if(ad.IsValid()) acctid=ad.GetHash160();
|
||||
}
|
||||
if(!acctid) return JSONRPCError(500, "Unable to parse account");
|
||||
|
||||
LocalAccount::pointer lac(theApp->getWallet().getLocalAccount(acctid));
|
||||
if(!!lac) return lac->getJson();
|
||||
|
||||
AccountState::pointer as=theApp->getMasterLedger().getCurrentLedger()->getAccountState(acctid);
|
||||
Json::Value ret(Json::objectValue);
|
||||
if(as)
|
||||
as->addJson(ret);
|
||||
else
|
||||
{
|
||||
NewcoinAddress ad(acctid);
|
||||
ret[ad.GetString()]="NotFound";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doNewAccount(Json::Value ¶ms)
|
||||
|
||||
@@ -43,6 +43,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
||||
Json::Value doConnect(Json::Value& params);
|
||||
Json::Value doTx(Json::Value& params);
|
||||
Json::Value doLedger(Json::Value& params);
|
||||
Json::Value doAccount(Json::Value& params);
|
||||
|
||||
// parses a string account name into a uint160
|
||||
// can be local or remote
|
||||
|
||||
Reference in New Issue
Block a user