|
|
|
|
@@ -29,8 +29,8 @@
|
|
|
|
|
Just read from wire until the entire request is in.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
RPCServer::RPCServer(boost::asio::io_service& io_service)
|
|
|
|
|
: mSocket(io_service)
|
|
|
|
|
RPCServer::RPCServer(boost::asio::io_service& io_service , NetworkOPs* nopNetwork)
|
|
|
|
|
: mNetOps(nopNetwork), mSocket(io_service)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -173,7 +173,7 @@ bool RPCServer::extractString(std::string& param, const Json::Value& params, int
|
|
|
|
|
// Given a seed and a source account get the public and private key for authorizing transactions for the account.
|
|
|
|
|
Json::Value RPCServer::authorize(const NewcoinAddress& naSeed, const NewcoinAddress& naSrcAccountID,
|
|
|
|
|
NewcoinAddress& naAccountPublic, NewcoinAddress& naAccountPrivate,
|
|
|
|
|
SerializedLedgerEntry::pointer& sleSrc)
|
|
|
|
|
SLE::pointer& sleSrc)
|
|
|
|
|
{
|
|
|
|
|
Ledger::pointer ledger = theApp->getMasterLedger().getCurrentLedger();
|
|
|
|
|
LedgerStateParms qry = lepNONE;
|
|
|
|
|
@@ -198,7 +198,7 @@ Json::Value RPCServer::authorize(const NewcoinAddress& naSeed, const NewcoinAddr
|
|
|
|
|
na0Private.setAccountPrivate(naGenerator, naSeed, 0);
|
|
|
|
|
|
|
|
|
|
qry = lepNONE;
|
|
|
|
|
SerializedLedgerEntry::pointer sleGen = ledger->getGenerator(qry, na0Public.getAccountID());
|
|
|
|
|
SLE::pointer sleGen = ledger->getGenerator(qry, na0Public.getAccountID());
|
|
|
|
|
|
|
|
|
|
if (!sleGen)
|
|
|
|
|
{
|
|
|
|
|
@@ -246,30 +246,15 @@ Json::Value RPCServer::authorize(const NewcoinAddress& naSeed, const NewcoinAddr
|
|
|
|
|
return Json::Value(Json::objectValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// account_info <account>|<nickname>|<account_public_key>
|
|
|
|
|
// account_info <seed>|<pass_phrase>|<key> [<index>]
|
|
|
|
|
Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
// <-- bIndex: true if iIndex > 0 and used the index.
|
|
|
|
|
Json::Value RPCServer::accountFromString(NewcoinAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex)
|
|
|
|
|
{
|
|
|
|
|
if (params.size() < 1 || params.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
return "invalid params";
|
|
|
|
|
}
|
|
|
|
|
else if (!theApp->getOPs().available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::string strIdent = params[0u].asString();
|
|
|
|
|
bool bIndex = 2 == params.size();
|
|
|
|
|
int iIndex = bIndex ? boost::lexical_cast<int>(params[1u].asString()) : 0;
|
|
|
|
|
|
|
|
|
|
NewcoinAddress naAccount;
|
|
|
|
|
NewcoinAddress naSeed;
|
|
|
|
|
|
|
|
|
|
if (!bIndex && (naAccount.setAccountPublic(strIdent) || naAccount.setAccountID(strIdent)))
|
|
|
|
|
if (naAccount.setAccountPublic(strIdent) || naAccount.setAccountID(strIdent))
|
|
|
|
|
{
|
|
|
|
|
// Got the account.
|
|
|
|
|
nothing();
|
|
|
|
|
bIndex = false;
|
|
|
|
|
}
|
|
|
|
|
// Must be a seed.
|
|
|
|
|
else if (!naSeed.setFamilySeedGeneric(strIdent))
|
|
|
|
|
@@ -293,7 +278,7 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
|
|
|
|
|
Ledger::pointer ledger = theApp->getMasterLedger().getCurrentLedger();
|
|
|
|
|
LedgerStateParms qry = lepNONE;
|
|
|
|
|
SerializedLedgerEntry::pointer sleGen = ledger->getGenerator(qry, naRegular0Public.getAccountID());
|
|
|
|
|
SLE::pointer sleGen = ledger->getGenerator(qry, naRegular0Public.getAccountID());
|
|
|
|
|
if (!sleGen)
|
|
|
|
|
{
|
|
|
|
|
// Didn't find a generator map, assume it is a master generator.
|
|
|
|
|
@@ -312,15 +297,43 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
naGenerator.setFamilyGenerator(vucMasterGenerator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bIndex = true;
|
|
|
|
|
bIndex = !iIndex;
|
|
|
|
|
|
|
|
|
|
naAccount.setAccountPublic(naGenerator, iIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get info on account.
|
|
|
|
|
Json::Value ret(Json::objectValue);
|
|
|
|
|
return Json::Value(Json::objectValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccountState::pointer as=theApp->getMasterLedger().getCurrentLedger()->getAccountState(naAccount);
|
|
|
|
|
// account_info <account>|<nickname>|<account_public_key>
|
|
|
|
|
// account_info <seed>|<pass_phrase>|<key> [<index>]
|
|
|
|
|
Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
{
|
|
|
|
|
if (params.size() < 1 || params.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
return "invalid params";
|
|
|
|
|
}
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::string strIdent = params[0u].asString();
|
|
|
|
|
bool bIndex;
|
|
|
|
|
int iIndex = 2 == params.size()? boost::lexical_cast<int>(params[1u].asString()) : 0;
|
|
|
|
|
NewcoinAddress naAccount;
|
|
|
|
|
|
|
|
|
|
Json::Value ret;
|
|
|
|
|
|
|
|
|
|
ret = accountFromString(naAccount, bIndex, strIdent, iIndex);
|
|
|
|
|
|
|
|
|
|
if (!ret.empty())
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
// Get info on account.
|
|
|
|
|
ret = Json::Value(Json::objectValue);
|
|
|
|
|
|
|
|
|
|
AccountState::pointer as=mNetOps->getAccountState(naAccount);
|
|
|
|
|
if (as)
|
|
|
|
|
{
|
|
|
|
|
as->addJson(ret);
|
|
|
|
|
@@ -329,7 +342,6 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
{
|
|
|
|
|
ret["account"] = naAccount.humanAccountID();
|
|
|
|
|
ret["status"] = "NotFound";
|
|
|
|
|
ret["bIndex"] = bIndex;
|
|
|
|
|
if (bIndex)
|
|
|
|
|
ret["index"] = iIndex;
|
|
|
|
|
}
|
|
|
|
|
@@ -338,6 +350,100 @@ Json::Value RPCServer::doAccountInfo(Json::Value ¶ms)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// account_lines <account>|<nickname>|<account_public_key> [<index>]
|
|
|
|
|
Json::Value RPCServer::doAccountLines(Json::Value ¶ms)
|
|
|
|
|
{
|
|
|
|
|
if (params.size() < 1 || params.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
return "invalid params";
|
|
|
|
|
}
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::string strIdent = params[0u].asString();
|
|
|
|
|
bool bIndex;
|
|
|
|
|
int iIndex = 2 == params.size()? boost::lexical_cast<int>(params[1u].asString()) : 0;
|
|
|
|
|
NewcoinAddress naAccount;
|
|
|
|
|
|
|
|
|
|
Json::Value ret;
|
|
|
|
|
|
|
|
|
|
ret = accountFromString(naAccount, bIndex, strIdent, iIndex);
|
|
|
|
|
|
|
|
|
|
if (!ret.empty())
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
// SHAMap::pointer smAccounts = theApp->getMasterLedger().getCurrentLedger()->peekAccountStateMap();
|
|
|
|
|
|
|
|
|
|
// Get info on account.
|
|
|
|
|
ret = Json::Value(Json::objectValue);
|
|
|
|
|
|
|
|
|
|
ret["account"] = naAccount.humanAccountID();
|
|
|
|
|
if (bIndex)
|
|
|
|
|
ret["index"] = iIndex;
|
|
|
|
|
|
|
|
|
|
AccountState::pointer as = mNetOps->getAccountState(naAccount);
|
|
|
|
|
if (as)
|
|
|
|
|
{
|
|
|
|
|
ret["account"] = naAccount.humanAccountID();
|
|
|
|
|
|
|
|
|
|
// We access a committed ledger and need not worry about changes.
|
|
|
|
|
uint64 uDirLineNodeFirst;
|
|
|
|
|
uint64 uDirLineNodeLast;
|
|
|
|
|
|
|
|
|
|
if (!mNetOps->getDirLineInfo(naAccount, uDirLineNodeFirst, uDirLineNodeLast))
|
|
|
|
|
{
|
|
|
|
|
ret["lines"] = Json::Value(Json::objectValue);
|
|
|
|
|
}
|
|
|
|
|
else if (uDirLineNodeFirst)
|
|
|
|
|
{
|
|
|
|
|
Json::Value jsonLines = Json::Value(Json::objectValue);
|
|
|
|
|
|
|
|
|
|
for (; uDirLineNodeFirst <= uDirLineNodeLast; uDirLineNodeFirst++)
|
|
|
|
|
{
|
|
|
|
|
std::vector<uint256> vuRippleNodes = mNetOps->getDirLineNode(uDirLineNodeFirst);
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(uint256& uNode, vuRippleNodes)
|
|
|
|
|
{
|
|
|
|
|
NewcoinAddress naAccountPeer;
|
|
|
|
|
uint64 uBalance = 0;
|
|
|
|
|
// uint160 uCurrency;
|
|
|
|
|
STAmount saLimit;
|
|
|
|
|
STAmount saLimitPeer;
|
|
|
|
|
#if 0
|
|
|
|
|
RippleState::pointer rsLine = mNetOps->getRippleState(uNode);
|
|
|
|
|
|
|
|
|
|
rsLine->setViewAccount(naAccount);
|
|
|
|
|
rsLine->getAccountPeer(naAccountPeer);
|
|
|
|
|
// ->getBalance(iBalance);
|
|
|
|
|
// ->getCurrency(uCurrency);
|
|
|
|
|
rsLine->getLimit(saLimit)
|
|
|
|
|
rsLine->getLimitPeer(saPeerLimit);
|
|
|
|
|
#endif
|
|
|
|
|
Json::Value jPeer = Json::Value(Json::objectValue);
|
|
|
|
|
|
|
|
|
|
jPeer["balance"] = Json::Value::UInt(uBalance); // XXX Raw number.
|
|
|
|
|
jPeer["limit"] = Json::Value::UInt(saLimit.getValue());
|
|
|
|
|
jPeer["limit_peer"] = Json::Value::UInt(saLimitPeer.getValue());
|
|
|
|
|
|
|
|
|
|
ret[naAccountPeer.humanAccountID()] = jPeer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret["lines"] = jsonLines;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ret["status"] = "NotFound";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json::Value RPCServer::doConnect(Json::Value& params)
|
|
|
|
|
{
|
|
|
|
|
// connect <ip> [port]
|
|
|
|
|
@@ -403,14 +509,14 @@ Json::Value RPCServer::doCreditSet(Json::Value& params)
|
|
|
|
|
{
|
|
|
|
|
return JSONRPCError(500, "bad src amount/currency");
|
|
|
|
|
}
|
|
|
|
|
else if (!theApp->getOPs().available()) {
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NewcoinAddress naAccountPublic;
|
|
|
|
|
NewcoinAddress naAccountPrivate;
|
|
|
|
|
SerializedLedgerEntry::pointer sleSrc;
|
|
|
|
|
SLE::pointer sleSrc;
|
|
|
|
|
Json::Value obj = authorize(naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, sleSrc);
|
|
|
|
|
|
|
|
|
|
if (!obj.empty())
|
|
|
|
|
@@ -434,7 +540,7 @@ Json::Value RPCServer::doCreditSet(Json::Value& params)
|
|
|
|
|
saLimitAmount,
|
|
|
|
|
uAcceptRate);
|
|
|
|
|
|
|
|
|
|
(void) theApp->getOPs().processTransaction(trans);
|
|
|
|
|
(void) mNetOps->processTransaction(trans);
|
|
|
|
|
|
|
|
|
|
obj["transaction"] = trans->getSTransaction()->getJson(0);
|
|
|
|
|
obj["status"] = trans->getStatus();
|
|
|
|
|
@@ -490,14 +596,14 @@ Json::Value RPCServer::doSend(Json::Value& params)
|
|
|
|
|
{
|
|
|
|
|
return JSONRPCError(500, "bad src amount/currency");
|
|
|
|
|
}
|
|
|
|
|
else if (!theApp->getOPs().available()) {
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NewcoinAddress naAccountPublic;
|
|
|
|
|
NewcoinAddress naAccountPrivate;
|
|
|
|
|
SerializedLedgerEntry::pointer sleSrc;
|
|
|
|
|
SLE::pointer sleSrc;
|
|
|
|
|
Json::Value obj = authorize(naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, sleSrc);
|
|
|
|
|
|
|
|
|
|
if (!obj.empty())
|
|
|
|
|
@@ -530,7 +636,7 @@ Json::Value RPCServer::doSend(Json::Value& params)
|
|
|
|
|
saSrcAmount,
|
|
|
|
|
spPaths);
|
|
|
|
|
|
|
|
|
|
(void) theApp->getOPs().processTransaction(trans);
|
|
|
|
|
(void) mNetOps->processTransaction(trans);
|
|
|
|
|
|
|
|
|
|
obj["transaction"] = trans->getSTransaction()->getJson(0);
|
|
|
|
|
obj["status"] = trans->getStatus();
|
|
|
|
|
@@ -580,14 +686,14 @@ Json::Value RPCServer::doTransitSet(Json::Value& params)
|
|
|
|
|
{
|
|
|
|
|
return JSONRPCError(500, "source account id needed");
|
|
|
|
|
}
|
|
|
|
|
else if (!theApp->getOPs().available()) {
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NewcoinAddress naAccountPublic;
|
|
|
|
|
NewcoinAddress naAccountPrivate;
|
|
|
|
|
SerializedLedgerEntry::pointer sleSrc;
|
|
|
|
|
SLE::pointer sleSrc;
|
|
|
|
|
Json::Value obj = authorize(naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, sleSrc);
|
|
|
|
|
|
|
|
|
|
if (!obj.empty())
|
|
|
|
|
@@ -617,7 +723,7 @@ Json::Value RPCServer::doTransitSet(Json::Value& params)
|
|
|
|
|
uTransitStart,
|
|
|
|
|
uTransitExpire);
|
|
|
|
|
|
|
|
|
|
(void) theApp->getOPs().processTransaction(trans);
|
|
|
|
|
(void) mNetOps->processTransaction(trans);
|
|
|
|
|
|
|
|
|
|
obj["transaction"] = trans->getSTransaction()->getJson(0);
|
|
|
|
|
obj["status"] = trans->getStatus();
|
|
|
|
|
@@ -843,7 +949,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
|
|
|
|
|
naRegular0Public.getAccountPublic(),
|
|
|
|
|
vucGeneratorSig);
|
|
|
|
|
|
|
|
|
|
(void) theApp->getOPs().processTransaction(trns);
|
|
|
|
|
(void) mNetOps->processTransaction(trns);
|
|
|
|
|
|
|
|
|
|
Json::Value obj(Json::objectValue);
|
|
|
|
|
|
|
|
|
|
@@ -891,11 +997,11 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|
|
|
|
{
|
|
|
|
|
return "create account id needed";
|
|
|
|
|
}
|
|
|
|
|
else if (!theApp->getOPs().available()) {
|
|
|
|
|
else if (!mNetOps->available()) {
|
|
|
|
|
// We require access to the paying account's sequence number and key information.
|
|
|
|
|
return JSONRPCError(503, "network not available");
|
|
|
|
|
}
|
|
|
|
|
else if (theApp->getMasterLedger().getCurrentLedger()->getAccountState(naDstAccountID))
|
|
|
|
|
else if (mNetOps->getAccountState(naDstAccountID))
|
|
|
|
|
{
|
|
|
|
|
return "account already exists";
|
|
|
|
|
}
|
|
|
|
|
@@ -906,7 +1012,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|
|
|
|
|
|
|
|
|
NewcoinAddress naAccountPublic;
|
|
|
|
|
NewcoinAddress naAccountPrivate;
|
|
|
|
|
SerializedLedgerEntry::pointer sleSrc;
|
|
|
|
|
SLE::pointer sleSrc;
|
|
|
|
|
Json::Value obj = authorize(naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, sleSrc);
|
|
|
|
|
|
|
|
|
|
STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
|
|
|
|
|
@@ -931,7 +1037,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|
|
|
|
naDstAccountID,
|
|
|
|
|
saInitialFunds); // Initial funds in XNC.
|
|
|
|
|
|
|
|
|
|
(void) theApp->getOPs().processTransaction(trans);
|
|
|
|
|
(void) mNetOps->processTransaction(trans);
|
|
|
|
|
|
|
|
|
|
obj["transaction"] = trans->getSTransaction()->getJson(0);
|
|
|
|
|
obj["status"] = trans->getStatus();
|
|
|
|
|
@@ -1139,6 +1245,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
|
|
|
|
|
std::cerr << "RPC:" << command << std::endl;
|
|
|
|
|
|
|
|
|
|
if (command == "account_info") return doAccountInfo(params);
|
|
|
|
|
if (command == "account_lines") return doAccountLines(params);
|
|
|
|
|
if (command == "connect") return doConnect(params);
|
|
|
|
|
if (command == "credit_set") return doCreditSet(params);
|
|
|
|
|
if (command == "peers") return doPeers(params);
|
|
|
|
|
|