Refactor NetworkOps and RPC to specify account_index and ledgers better.

This commit is contained in:
Arthur Britto
2012-12-05 18:02:41 -08:00
parent 01f1e6c337
commit 5b68f2a15d
7 changed files with 184 additions and 168 deletions

View File

@@ -71,7 +71,7 @@ Json::Value RPCParser::parseAccountInfo(const Json::Value& jvParams)
return rpcError(rpcACT_MALFORMED); return rpcError(rpcACT_MALFORMED);
jvRequest["ident"] = strIdent; jvRequest["ident"] = strIdent;
jvRequest["index"] = iIndex; jvRequest["account_index"] = iIndex;
return jvRequest; return jvRequest;
} }
@@ -233,7 +233,7 @@ Json::Value RPCParser::parseAccountItems(const Json::Value& jvParams)
jvRequest["account"] = strIdent; jvRequest["account"] = strIdent;
if (bIndex) if (bIndex)
jvRequest["index"] = iIndex; jvRequest["account_index"] = iIndex;
return jvRequest; return jvRequest;
} }

View File

@@ -774,12 +774,14 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
if ( (parms & lepCREATE) == 0 ) if ( (parms & lepCREATE) == 0 )
{ {
parms = lepMISSING; parms = lepMISSING;
cLog(lsDEBUG) << "getASNode: MISSING";
return SLE::pointer(); return SLE::pointer();
} }
parms = parms | lepCREATED | lepOKAY; parms = parms | lepCREATED | lepOKAY;
SLE::pointer sle=boost::make_shared<SLE>(let, nodeID); SLE::pointer sle=boost::make_shared<SLE>(let, nodeID);
cLog(lsDEBUG) << "getASNode: CREATED";
return sle; return sle;
} }
@@ -788,12 +790,14 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
if (sle->getType() != let) if (sle->getType() != let)
{ // maybe it's a currency or something { // maybe it's a currency or something
cLog(lsDEBUG) << "getASNode: WRONG TYPE";
parms = parms | lepWRONGTYPE; parms = parms | lepWRONGTYPE;
return SLE::pointer(); return SLE::pointer();
} }
parms = parms | lepOKAY; parms = parms | lepOKAY;
cLog(lsDEBUG) << "getASNode: FOUND";
return sle; return sle;
} }

View File

@@ -268,6 +268,7 @@ Transaction::pointer NetworkOPs::findTransactionByID(const uint256& transactionI
return Transaction::load(transactionID); return Transaction::load(transactionID);
} }
#if 0
int NetworkOPs::findTransactionsBySource(const uint256& uLedger, std::list<Transaction::pointer>& txns, int NetworkOPs::findTransactionsBySource(const uint256& uLedger, std::list<Transaction::pointer>& txns,
const RippleAddress& sourceAccount, uint32 minSeq, uint32 maxSeq) const RippleAddress& sourceAccount, uint32 minSeq, uint32 maxSeq)
{ {
@@ -289,6 +290,7 @@ int NetworkOPs::findTransactionsBySource(const uint256& uLedger, std::list<Trans
} }
return count; return count;
} }
#endif
int NetworkOPs::findTransactionsByDestination(std::list<Transaction::pointer>& txns, int NetworkOPs::findTransactionsByDestination(std::list<Transaction::pointer>& txns,
const RippleAddress& destinationAccount, uint32 startLedgerSeq, uint32 endLedgerSeq, int maxTransactions) const RippleAddress& destinationAccount, uint32 startLedgerSeq, uint32 endLedgerSeq, int maxTransactions)
@@ -301,20 +303,19 @@ int NetworkOPs::findTransactionsByDestination(std::list<Transaction::pointer>& t
// Account functions // Account functions
// //
AccountState::pointer NetworkOPs::getAccountState(const uint256& uLedger, const RippleAddress& accountID) AccountState::pointer NetworkOPs::getAccountState(Ledger::ref lrLedger, const RippleAddress& accountID)
{ {
return mLedgerMaster->getLedgerByHash(uLedger)->getAccountState(accountID); return lrLedger->getAccountState(accountID);
} }
SLE::pointer NetworkOPs::getGenerator(const uint256& uLedger, const uint160& uGeneratorID) SLE::pointer NetworkOPs::getGenerator(Ledger::ref lrLedger, const uint160& uGeneratorID)
{ {
LedgerStateParms qry = lepNONE; LedgerStateParms qry = lepNONE;
Ledger::pointer ledger = mLedgerMaster->getLedgerByHash(uLedger); if (!lrLedger)
if (!ledger)
return SLE::pointer(); return SLE::pointer();
else else
return ledger->getGenerator(qry, uGeneratorID); return lrLedger->getGenerator(qry, uGeneratorID);
} }
// //
@@ -323,14 +324,14 @@ SLE::pointer NetworkOPs::getGenerator(const uint256& uLedger, const uint160& uGe
// <-- false : no entrieS // <-- false : no entrieS
STVector256 NetworkOPs::getDirNodeInfo( STVector256 NetworkOPs::getDirNodeInfo(
const uint256& uLedger, Ledger::ref lrLedger,
const uint256& uNodeIndex, const uint256& uNodeIndex,
uint64& uNodePrevious, uint64& uNodePrevious,
uint64& uNodeNext) uint64& uNodeNext)
{ {
STVector256 svIndexes; STVector256 svIndexes;
LedgerStateParms lspNode = lepNONE; LedgerStateParms lspNode = lepNONE;
SLE::pointer sleNode = mLedgerMaster->getLedgerByHash(uLedger)->getDirNode(lspNode, uNodeIndex); SLE::pointer sleNode = lrLedger->getDirNode(lspNode, uNodeIndex);
if (sleNode) if (sleNode)
{ {
@@ -357,6 +358,7 @@ STVector256 NetworkOPs::getDirNodeInfo(
return svIndexes; return svIndexes;
} }
#if 0
// //
// Nickname functions // Nickname functions
// //
@@ -365,16 +367,12 @@ NicknameState::pointer NetworkOPs::getNicknameState(const uint256& uLedger, cons
{ {
return mLedgerMaster->getLedgerByHash(uLedger)->getNicknameState(strNickname); return mLedgerMaster->getLedgerByHash(uLedger)->getNicknameState(strNickname);
} }
#endif
// //
// Owner functions // Owner functions
// //
Json::Value NetworkOPs::getOwnerInfo(const uint256& uLedger, const RippleAddress& naAccount)
{
return getOwnerInfo(mLedgerMaster->getLedgerByHash(uLedger), naAccount);
}
Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const RippleAddress& naAccount) Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const RippleAddress& naAccount)
{ {
Json::Value jvObjects(Json::objectValue); Json::Value jvObjects(Json::objectValue);

View File

@@ -156,8 +156,10 @@ public:
{ return processTransaction(transaction, stCallback()); } { return processTransaction(transaction, stCallback()); }
Transaction::pointer findTransactionByID(const uint256& transactionID); Transaction::pointer findTransactionByID(const uint256& transactionID);
#if 0
int findTransactionsBySource(const uint256& uLedger, std::list<Transaction::pointer>&, const RippleAddress& sourceAccount, int findTransactionsBySource(const uint256& uLedger, std::list<Transaction::pointer>&, const RippleAddress& sourceAccount,
uint32 minSeq, uint32 maxSeq); uint32 minSeq, uint32 maxSeq);
#endif
int findTransactionsByDestination(std::list<Transaction::pointer>&, const RippleAddress& destinationAccount, int findTransactionsByDestination(std::list<Transaction::pointer>&, const RippleAddress& destinationAccount,
uint32 startLedgerSeq, uint32 endLedgerSeq, int maxTransactions); uint32 startLedgerSeq, uint32 endLedgerSeq, int maxTransactions);
@@ -165,27 +167,28 @@ public:
// Account functions // Account functions
// //
AccountState::pointer getAccountState(const uint256& uLedger, const RippleAddress& accountID); AccountState::pointer getAccountState(Ledger::ref lrLedger, const RippleAddress& accountID);
SLE::pointer getGenerator(const uint256& uLedger, const uint160& uGeneratorID); SLE::pointer getGenerator(Ledger::ref lrLedger, const uint160& uGeneratorID);
// //
// Directory functions // Directory functions
// //
STVector256 getDirNodeInfo(const uint256& uLedger, const uint256& uRootIndex, STVector256 getDirNodeInfo(Ledger::ref lrLedger, const uint256& uRootIndex,
uint64& uNodePrevious, uint64& uNodeNext); uint64& uNodePrevious, uint64& uNodeNext);
#if 0
// //
// Nickname functions // Nickname functions
// //
NicknameState::pointer getNicknameState(const uint256& uLedger, const std::string& strNickname); NicknameState::pointer getNicknameState(const uint256& uLedger, const std::string& strNickname);
#endif
// //
// Owner functions // Owner functions
// //
Json::Value getOwnerInfo(const uint256& uLedger, const RippleAddress& naAccount);
Json::Value getOwnerInfo(Ledger::pointer lpLedger, const RippleAddress& naAccount); Json::Value getOwnerInfo(Ledger::pointer lpLedger, const RippleAddress& naAccount);
// raw object operations // raw object operations

View File

@@ -34,47 +34,10 @@ RPCHandler::RPCHandler(NetworkOPs* netOps, InfoSub* infoSub)
mInfoSub=infoSub; mInfoSub=infoSub;
} }
int RPCHandler::getParamCount(Json::Value params)
{ // If non-array, only counts strings
if (params.isNull()) return 0;
if (params.isArray()) return params.size();
if (!params.isConvertibleTo(Json::stringValue))
return 0;
return 1;
}
bool RPCHandler::extractString(std::string& param, const Json::Value& params, int index)
{
if (params.isNull()) return false;
if (index!=0)
{
if (!params.isArray() || !params.isValidIndex(index))
return false;
Json::Value p(params.get(index, Json::nullValue));
if (p.isNull() || !p.isConvertibleTo(Json::stringValue))
return false;
param = p.asString();
return true;
}
if (params.isArray())
{
if ( (!params.isValidIndex(0)) || (!params[0u].isConvertibleTo(Json::stringValue)) )
return false;
param = params[0u].asString();
return true;
}
if (!params.isConvertibleTo(Json::stringValue))
return false;
param = params.asString();
return true;
}
// Look up the master public generator for a regular seed so we may index source accounts ids. // Look up the master public generator for a regular seed so we may index source accounts ids.
// --> naRegularSeed // --> naRegularSeed
// <-- naMasterGenerator // <-- naMasterGenerator
Json::Value RPCHandler::getMasterGenerator(const uint256& uLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator) Json::Value RPCHandler::getMasterGenerator(Ledger::ref lrLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator)
{ {
RippleAddress na0Public; // To find the generator's index. RippleAddress na0Public; // To find the generator's index.
RippleAddress na0Private; // To decrypt the master generator's cipher. RippleAddress na0Private; // To decrypt the master generator's cipher.
@@ -83,7 +46,7 @@ Json::Value RPCHandler::getMasterGenerator(const uint256& uLedger, const RippleA
na0Public.setAccountPublic(naGenerator, 0); na0Public.setAccountPublic(naGenerator, 0);
na0Private.setAccountPrivate(naGenerator, naRegularSeed, 0); na0Private.setAccountPrivate(naGenerator, naRegularSeed, 0);
SLE::pointer sleGen = mNetOps->getGenerator(uLedger, na0Public.getAccountID()); SLE::pointer sleGen = mNetOps->getGenerator(lrLedger, na0Public.getAccountID());
if (!sleGen) if (!sleGen)
{ {
@@ -112,14 +75,14 @@ Json::Value RPCHandler::getMasterGenerator(const uint256& uLedger, const RippleA
// <-- saSrcBalance: Balance minus fee. // <-- saSrcBalance: Balance minus fee.
// --> naVerifyGenerator : If provided, the found master public generator must match. // --> naVerifyGenerator : If provided, the found master public generator must match.
// XXX Be more lenient, allow use of master generator on claimed accounts. // XXX Be more lenient, allow use of master generator on claimed accounts.
Json::Value RPCHandler::authorize(const uint256& uLedger, Json::Value RPCHandler::authorize(Ledger::ref lrLedger,
const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID, const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID,
RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate, RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate,
STAmount& saSrcBalance, const STAmount& saFee, AccountState::pointer& asSrc, STAmount& saSrcBalance, const STAmount& saFee, AccountState::pointer& asSrc,
const RippleAddress& naVerifyGenerator) const RippleAddress& naVerifyGenerator)
{ {
// Source/paying account must exist. // Source/paying account must exist.
asSrc = mNetOps->getAccountState(uLedger, naSrcAccountID); asSrc = mNetOps->getAccountState(lrLedger, naSrcAccountID);
if (!asSrc) if (!asSrc)
{ {
return rpcError(rpcSRC_ACT_MISSING); return rpcError(rpcSRC_ACT_MISSING);
@@ -129,7 +92,7 @@ Json::Value RPCHandler::authorize(const uint256& uLedger,
if (asSrc->bHaveAuthorizedKey()) if (asSrc->bHaveAuthorizedKey())
{ {
Json::Value obj = getMasterGenerator(uLedger, naRegularSeed, naMasterGenerator); Json::Value obj = getMasterGenerator(lrLedger, naRegularSeed, naMasterGenerator);
if (!obj.empty()) if (!obj.empty())
return obj; return obj;
@@ -202,7 +165,7 @@ Json::Value RPCHandler::authorize(const uint256& uLedger,
// --> strIdent: public key, account ID, or regular seed. // --> strIdent: public key, account ID, or regular seed.
// <-- bIndex: true if iIndex > 0 and used the index. // <-- bIndex: true if iIndex > 0 and used the index.
Json::Value RPCHandler::accountFromString(const uint256& uLedger, RippleAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex) Json::Value RPCHandler::accountFromString(Ledger::ref lrLedger, RippleAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex)
{ {
RippleAddress naSeed; RippleAddress naSeed;
@@ -229,7 +192,7 @@ Json::Value RPCHandler::accountFromString(const uint256& uLedger, RippleAddress&
naRegular0Private.setAccountPrivate(naGenerator, naSeed, 0); naRegular0Private.setAccountPrivate(naGenerator, naSeed, 0);
// uint160 uGeneratorID = naRegular0Public.getAccountID(); // uint160 uGeneratorID = naRegular0Public.getAccountID();
SLE::pointer sleGen = mNetOps->getGenerator(uLedger, naRegular0Public.getAccountID()); SLE::pointer sleGen = mNetOps->getGenerator(lrLedger, naRegular0Public.getAccountID());
if (!sleGen) if (!sleGen)
{ {
// Didn't find a generator map, assume it is a master generator. // Didn't find a generator map, assume it is a master generator.
@@ -269,49 +232,40 @@ Json::Value RPCHandler::doAcceptLedger(Json::Value jvRequest)
} }
// { // {
// 'ident' : <indent>, // ident : <indent>,
// 'index' : <index> // optional // account_index : <index> // optional
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// } // }
Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest) Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest)
{ {
// cLog(lsDEBUG) << "doAccountInfo: " << jvRequest; Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
if (!jvRequest.isMember("ident")) if (!jvRequest.isMember("ident"))
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
std::string strIdent = jvRequest["ident"].asString(); std::string strIdent = jvRequest["ident"].asString();
bool bIndex; bool bIndex;
int iIndex = jvRequest.isMember("index") ? jvRequest["index"].asUInt() : 0; int iIndex = jvRequest.isMember("account_index") ? jvRequest["account_index"].asUInt() : 0;
RippleAddress naAccount; RippleAddress naAccount;
Json::Value jvResult;
// Get info on account. // Get info on account.
uint256 uAccepted = mNetOps->getClosedLedgerHash(); Json::Value jAccepted = accountFromString(lpLedger, naAccount, bIndex, strIdent, iIndex);
Json::Value jAccepted = accountFromString(uAccepted, naAccount, bIndex, strIdent, iIndex);
if (jAccepted.empty()) if (jAccepted.empty())
{ {
AccountState::pointer asAccepted = mNetOps->getAccountState(uAccepted, naAccount); AccountState::pointer asAccepted = mNetOps->getAccountState(lpLedger, naAccount);
if (asAccepted) if (asAccepted)
asAccepted->addJson(jAccepted); asAccepted->addJson(jAccepted);
} }
jvResult["accepted"] = jAccepted; jvResult["account_data"] = jAccepted;
Json::Value jCurrent = accountFromString(uint256(0), naAccount, bIndex, strIdent, iIndex);
if (jCurrent.empty())
{
AccountState::pointer asCurrent = mNetOps->getAccountState(uint256(0), naAccount);
if (asCurrent)
asCurrent->addJson(jCurrent);
}
jvResult["current"] = jCurrent;
#if 0 #if 0
if (!jAccepted && !asCurrent) if (!jAccepted && !asCurrent)
@@ -319,7 +273,7 @@ Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest)
jvResult["account"] = naAccount.humanAccountID(); jvResult["account"] = naAccount.humanAccountID();
jvResult["status"] = "NotFound"; jvResult["status"] = "NotFound";
if (bIndex) if (bIndex)
jvResult["index"] = iIndex; jvResult["account_index"] = iIndex;
} }
#endif #endif
return jvResult; return jvResult;
@@ -406,6 +360,7 @@ Json::Value RPCHandler::doDataStore(Json::Value jvRequest)
return ret; return ret;
} }
#if 0
// XXX Needs to be revised for new paradigm // XXX Needs to be revised for new paradigm
// nickname_info <nickname> // nickname_info <nickname>
// Note: Nicknames are not automatically looked up by commands as they are advisory and can be changed. // Note: Nicknames are not automatically looked up by commands as they are advisory and can be changed.
@@ -433,31 +388,31 @@ Json::Value RPCHandler::doNicknameInfo(Json::Value params)
return ret; return ret;
} }
#endif
// { // {
// 'ident' : <indent>, // 'ident' : <indent>,
// 'index' : <index> // optional // 'account_index' : <index> // optional
// } // }
// XXX This would be better if it too the ledger.
Json::Value RPCHandler::doOwnerInfo(Json::Value jvRequest) Json::Value RPCHandler::doOwnerInfo(Json::Value jvRequest)
{ {
std::string strIdent = jvRequest["ident"].asString(); std::string strIdent = jvRequest["ident"].asString();
bool bIndex; bool bIndex;
int iIndex = jvRequest.isMember("index") ? jvRequest["index"].asUInt() : 0; int iIndex = jvRequest.isMember("account_index") ? jvRequest["account_index"].asUInt() : 0;
RippleAddress raAccount; RippleAddress raAccount;
Json::Value ret; Json::Value ret;
// Get info on account. // Get info on account.
uint256 uAccepted = mNetOps->getClosedLedgerHash(); Json::Value jAccepted = accountFromString(mNetOps->getClosedLedger(), raAccount, bIndex, strIdent, iIndex);
Json::Value jAccepted = accountFromString(uAccepted, raAccount, bIndex, strIdent, iIndex);
ret["accepted"] = jAccepted.empty() ? mNetOps->getOwnerInfo(uAccepted, raAccount) : jAccepted; ret["accepted"] = jAccepted.empty() ? mNetOps->getOwnerInfo(mNetOps->getClosedLedger(), raAccount) : jAccepted;
Json::Value jCurrent = accountFromString(uint256(0), raAccount, bIndex, strIdent, iIndex); Json::Value jCurrent = accountFromString(mNetOps->getCurrentLedger(), raAccount, bIndex, strIdent, iIndex);
ret["current"] = jCurrent.empty() ? mNetOps->getOwnerInfo(uint256(0), raAccount) : jCurrent; ret["current"] = jCurrent.empty() ? mNetOps->getOwnerInfo(mNetOps->getCurrentLedger(), raAccount) : jCurrent;
return ret; return ret;
} }
@@ -476,10 +431,10 @@ Json::Value RPCHandler::doPeers(Json::Value)
// issuer is the offering account // issuer is the offering account
// --> submit: 'submit|true|false': defaults to false // --> submit: 'submit|true|false': defaults to false
// Prior to running allow each to have a credit line of what they will be getting from the other account. // Prior to running allow each to have a credit line of what they will be getting from the other account.
Json::Value RPCHandler::doProfile(Json::Value params) Json::Value RPCHandler::doProfile(Json::Value jvRequest)
{ {
/* need to fix now that sharedOfferCreate is gone /* need to fix now that sharedOfferCreate is gone
int iArgs = params.size(); int iArgs = jvRequest.size();
RippleAddress naSeedA; RippleAddress naSeedA;
RippleAddress naAccountA; RippleAddress naAccountA;
uint160 uCurrencyOfferA; uint160 uCurrencyOfferA;
@@ -489,26 +444,26 @@ Json::Value RPCHandler::doProfile(Json::Value params)
uint32 iCount = 100; uint32 iCount = 100;
bool bSubmit = false; bool bSubmit = false;
if (iArgs < 6 || "offers" != params[0u].asString()) if (iArgs < 6 || "offers" != jvRequest[0u].asString())
{ {
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
} }
if (!naSeedA.setSeedGeneric(params[1u].asString())) // <pass_a> if (!naSeedA.setSeedGeneric(jvRequest[1u].asString())) // <pass_a>
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
naAccountA.setAccountID(params[2u].asString()); // <account_a> naAccountA.setAccountID(jvRequest[2u].asString()); // <account_a>
if (!STAmount::currencyFromString(uCurrencyOfferA, params[3u].asString())) // <currency_offer_a> if (!STAmount::currencyFromString(uCurrencyOfferA, jvRequest[3u].asString())) // <currency_offer_a>
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
naAccountB.setAccountID(params[4u].asString()); // <account_b> naAccountB.setAccountID(jvRequest[4u].asString()); // <account_b>
if (!STAmount::currencyFromString(uCurrencyOfferB, params[5u].asString())) // <currency_offer_b> if (!STAmount::currencyFromString(uCurrencyOfferB, jvRequest[5u].asString())) // <currency_offer_b>
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
iCount = lexical_cast_s<uint32>(params[6u].asString()); iCount = lexical_cast_s<uint32>(jvRequest[6u].asString());
if (iArgs >= 8 && "false" != params[7u].asString()) if (iArgs >= 8 && "false" != jvRequest[7u].asString())
bSubmit = true; bSubmit = true;
Log::setMinSeverity(lsFATAL,true); Log::setMinSeverity(lsFATAL,true);
@@ -566,18 +521,24 @@ Json::Value RPCHandler::doProfile(Json::Value params)
// { // {
// account: <account>|<nickname>|<account_public_key> [<index>] // account: <account>|<nickname>|<account_public_key> [<index>]
// index: <number> // optional, defaults to 0. // index: <number> // optional, defaults to 0.
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// } // }
Json::Value RPCHandler::doAccountLines(Json::Value jvRequest) Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
{ {
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
std::string strIdent = jvRequest["account"].asString(); std::string strIdent = jvRequest["account"].asString();
bool bIndex = jvRequest.isMember("index"); bool bIndex = jvRequest.isMember("account_index");
int iIndex = bIndex ? jvRequest["index"].asUInt() : 0; int iIndex = bIndex ? jvRequest["account_index"].asUInt() : 0;
RippleAddress raAccount; RippleAddress raAccount;
Json::Value jvResult; jvResult = accountFromString(lpLedger, raAccount, bIndex, strIdent, iIndex);
jvResult = accountFromString(uint256(0), raAccount, bIndex, strIdent, iIndex);
if (!jvResult.empty()) if (!jvResult.empty())
return jvResult; return jvResult;
@@ -586,11 +547,13 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
jvResult["account"] = raAccount.humanAccountID(); jvResult["account"] = raAccount.humanAccountID();
if (bIndex) if (bIndex)
jvResult["index"] = iIndex; jvResult["account_index"] = iIndex;
AccountState::pointer as = mNetOps->getAccountState(uint256(0), raAccount); AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount);
if (as) if (as)
{ {
cLog(lsDEBUG) << "AccountState: ";
as->dump();
Json::Value jsonLines(Json::arrayValue); Json::Value jsonLines(Json::arrayValue);
jvResult["account"] = raAccount.humanAccountID(); jvResult["account"] = raAccount.humanAccountID();
@@ -599,6 +562,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
// We access a committed ledger and need not worry about changes. // We access a committed ledger and need not worry about changes.
AccountItems rippleLines(raAccount.getAccountID(), AccountItem::pointer(new RippleState())); AccountItems rippleLines(raAccount.getAccountID(), AccountItem::pointer(new RippleState()));
BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems()) BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems())
{ {
RippleState* line=(RippleState*)item.get(); RippleState* line=(RippleState*)item.get();
@@ -609,7 +573,6 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
Json::Value jPeer = Json::Value(Json::objectValue); Json::Value jPeer = Json::Value(Json::objectValue);
jPeer["account"] = line->getAccountIDPeer().humanAccountID(); jPeer["account"] = line->getAccountIDPeer().humanAccountID();
// Amount reported is positive if current account holds other account's IOUs. // Amount reported is positive if current account holds other account's IOUs.
// Amount reported is negative if other account holds current account's IOUs. // Amount reported is negative if other account holds current account's IOUs.
@@ -635,18 +598,24 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
// { // {
// account: <account>|<nickname>|<account_public_key> [<index>] // account: <account>|<nickname>|<account_public_key> [<index>]
// index: <number> // optional, defaults to 0. // index: <number> // optional, defaults to 0.
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// } // }
Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest) Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
{ {
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
std::string strIdent = jvRequest["account"].asString(); std::string strIdent = jvRequest["account"].asString();
bool bIndex = jvRequest.isMember("index"); bool bIndex = jvRequest.isMember("account_index");
int iIndex = bIndex ? jvRequest["index"].asUInt() : 0; int iIndex = bIndex ? jvRequest["account_index"].asUInt() : 0;
RippleAddress raAccount; RippleAddress raAccount;
Json::Value jvResult; jvResult = accountFromString(lpLedger, raAccount, bIndex, strIdent, iIndex);
jvResult = accountFromString(uint256(0), raAccount, bIndex, strIdent, iIndex);
if (!jvResult.empty()) if (!jvResult.empty())
return jvResult; return jvResult;
@@ -655,9 +624,9 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
jvResult["account"] = raAccount.humanAccountID(); jvResult["account"] = raAccount.humanAccountID();
if (bIndex) if (bIndex)
jvResult["index"] = iIndex; jvResult["account_index"] = iIndex;
AccountState::pointer as = mNetOps->getAccountState(uint256(0), raAccount); AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount);
if (as) if (as)
{ {
Json::Value jsonLines(Json::arrayValue); Json::Value jsonLines(Json::arrayValue);
@@ -908,8 +877,6 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
Json::Value txJSON = jvRequest["tx_json"]; Json::Value txJSON = jvRequest["tx_json"];
if (!naSeed.setSeedGeneric(jvRequest["secret"].asString())) if (!naSeed.setSeedGeneric(jvRequest["secret"].asString()))
{ {
return rpcError(rpcBAD_SEED); return rpcError(rpcBAD_SEED);
@@ -923,7 +890,7 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
return rpcError(rpcSRC_ACT_MALFORMED); return rpcError(rpcSRC_ACT_MALFORMED);
} }
AccountState::pointer asSrc = mNetOps->getAccountState(uint256(0), raSrcAddressID); AccountState::pointer asSrc = mNetOps->getAccountState(mNetOps->getCurrentLedger(), raSrcAddressID);
if (!asSrc) return rpcError(rpcSRC_ACT_MALFORMED); if (!asSrc) return rpcError(rpcSRC_ACT_MALFORMED);
if (!txJSON.isMember("Fee") if (!txJSON.isMember("Fee")
@@ -950,7 +917,7 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
if (!txJSON.isMember("Fee")) if (!txJSON.isMember("Fee"))
{ {
if (mNetOps->getAccountState(uint256(0), dstAccountID)) if (mNetOps->getAccountState(mNetOps->getCurrentLedger(), dstAccountID))
txJSON["Fee"] = (int) theConfig.FEE_DEFAULT; txJSON["Fee"] = (int) theConfig.FEE_DEFAULT;
else else
txJSON["Fee"] = (int) theConfig.FEE_ACCOUNT_CREATE; txJSON["Fee"] = (int) theConfig.FEE_ACCOUNT_CREATE;
@@ -1218,13 +1185,16 @@ Json::Value RPCHandler::doLedgerClosed(Json::Value)
jvResult["ledger_index"] = mNetOps->getLedgerID(uLedger); jvResult["ledger_index"] = mNetOps->getLedgerID(uLedger);
jvResult["ledger_hash"] = uLedger.ToString(); jvResult["ledger_hash"] = uLedger.ToString();
//jvResult["ledger_time"] = uLedger. //jvResult["ledger_time"] = uLedger.
return jvResult; return jvResult;
} }
Json::Value RPCHandler::doLedgerCurrent(Json::Value) Json::Value RPCHandler::doLedgerCurrent(Json::Value)
{ {
Json::Value jvResult; Json::Value jvResult;
jvResult["ledger_current_index"] = mNetOps->getCurrentLedgerID(); jvResult["ledger_current_index"] = mNetOps->getCurrentLedgerID();
return jvResult; return jvResult;
} }
@@ -1391,7 +1361,7 @@ Json::Value RPCHandler::doValidationSeed(Json::Value jvRequest) {
return obj; return obj;
} }
Json::Value RPCHandler::accounts(const uint256& uLedger, const RippleAddress& naMasterGenerator) Json::Value RPCHandler::accounts(Ledger::ref lrLedger, const RippleAddress& naMasterGenerator)
{ {
Json::Value jsonAccounts(Json::arrayValue); Json::Value jsonAccounts(Json::arrayValue);
@@ -1404,7 +1374,7 @@ Json::Value RPCHandler::accounts(const uint256& uLedger, const RippleAddress& na
naAccount.setAccountPublic(naMasterGenerator, uIndex++); naAccount.setAccountPublic(naMasterGenerator, uIndex++);
AccountState::pointer as = mNetOps->getAccountState(uLedger, naAccount); AccountState::pointer as = mNetOps->getAccountState(lrLedger, naAccount);
if (as) if (as)
{ {
Json::Value jsonAccount(Json::objectValue); Json::Value jsonAccount(Json::objectValue);
@@ -1424,9 +1394,17 @@ Json::Value RPCHandler::accounts(const uint256& uLedger, const RippleAddress& na
// { // {
// seed: <string> // seed: <string>
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// } // }
Json::Value RPCHandler::doWalletAccounts(Json::Value jvRequest) Json::Value RPCHandler::doWalletAccounts(Json::Value jvRequest)
{ {
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
RippleAddress naSeed; RippleAddress naSeed;
if (!jvRequest.isMember("seed") || !naSeed.setSeedGeneric(jvRequest["seed"].asString())) if (!jvRequest.isMember("seed") || !naSeed.setSeedGeneric(jvRequest["seed"].asString()))
@@ -1437,17 +1415,17 @@ Json::Value RPCHandler::doWalletAccounts(Json::Value jvRequest)
// Try the seed as a master seed. // Try the seed as a master seed.
RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic(naSeed); RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic(naSeed);
Json::Value jsonAccounts = accounts(uint256(0), naMasterGenerator); Json::Value jsonAccounts = accounts(lpLedger, naMasterGenerator);
if (jsonAccounts.empty()) if (jsonAccounts.empty())
{ {
// No account via seed as master, try seed a regular. // No account via seed as master, try seed a regular.
Json::Value ret = getMasterGenerator(uint256(0), naSeed, naMasterGenerator); Json::Value ret = getMasterGenerator(lpLedger, naSeed, naMasterGenerator);
if (!ret.empty()) if (!ret.empty())
return ret; return ret;
ret["accounts"] = accounts(uint256(0), naMasterGenerator); ret["accounts"] = accounts(lpLedger, naMasterGenerator);
return ret; return ret;
} }
@@ -1667,7 +1645,7 @@ Json::Value RPCHandler::doUnlDelete(Json::Value jvRequest)
} }
} }
Json::Value RPCHandler::doUnlList(Json::Value params) Json::Value RPCHandler::doUnlList(Json::Value)
{ {
Json::Value obj(Json::objectValue); Json::Value obj(Json::objectValue);
@@ -1677,7 +1655,7 @@ Json::Value RPCHandler::doUnlList(Json::Value params)
} }
// Populate the UNL from a local validators.txt file. // Populate the UNL from a local validators.txt file.
Json::Value RPCHandler::doUnlLoad(Json::Value params) Json::Value RPCHandler::doUnlLoad(Json::Value)
{ {
if (theConfig.VALIDATORS_FILE.empty() || !theApp->getUNL().nodeLoad(theConfig.VALIDATORS_FILE)) if (theConfig.VALIDATORS_FILE.empty() || !theApp->getUNL().nodeLoad(theConfig.VALIDATORS_FILE))
{ {
@@ -1689,7 +1667,7 @@ Json::Value RPCHandler::doUnlLoad(Json::Value params)
// Populate the UNL from ripple.com's validators.txt file. // Populate the UNL from ripple.com's validators.txt file.
Json::Value RPCHandler::doUnlNetwork(Json::Value params) Json::Value RPCHandler::doUnlNetwork(Json::Value jvRequest)
{ {
theApp->getUNL().nodeNetwork(); theApp->getUNL().nodeNetwork();
@@ -1697,7 +1675,7 @@ Json::Value RPCHandler::doUnlNetwork(Json::Value params)
} }
// unl_reset // unl_reset
Json::Value RPCHandler::doUnlReset(Json::Value params) Json::Value RPCHandler::doUnlReset(Json::Value jvRequest)
{ {
theApp->getUNL().nodeReset(); theApp->getUNL().nodeReset();
@@ -1705,7 +1683,7 @@ Json::Value RPCHandler::doUnlReset(Json::Value params)
} }
// unl_score // unl_score
Json::Value RPCHandler::doUnlScore(Json::Value params) Json::Value RPCHandler::doUnlScore(Json::Value)
{ {
theApp->getUNL().nodeScore(); theApp->getUNL().nodeScore();
@@ -1737,16 +1715,27 @@ Json::Value RPCHandler::doLedgerAccept(Json::Value)
return jvResult; return jvResult;
} }
// {
// ledger_hash : <ledger>,
// ledger_index : <ledger_index>
// }
// XXX In this case, not specify either ledger does not mean ledger current. It means any ledger.
Json::Value RPCHandler::doTransactionEntry(Json::Value jvRequest) Json::Value RPCHandler::doTransactionEntry(Json::Value jvRequest)
{ {
Json::Value jvResult; Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
if (!jvRequest.isMember("tx_hash")) if (!jvRequest.isMember("tx_hash"))
{ {
jvResult["error"] = "fieldNotFoundTransaction"; jvResult["error"] = "fieldNotFoundTransaction";
} }
if (!jvRequest.isMember("ledger_hash")) else if (!jvRequest.isMember("ledger_hash") && !jvRequest.isMember("ledger_index"))
{ {
// We don't work on ledger current.
jvResult["error"] = "notYetImplemented"; // XXX We don't support any transaction yet. jvResult["error"] = "notYetImplemented"; // XXX We don't support any transaction yet.
} }
else else
@@ -1755,12 +1744,6 @@ Json::Value RPCHandler::doTransactionEntry(Json::Value jvRequest)
// XXX Relying on trusted WSS client. Would be better to have a strict routine, returning success or failure. // XXX Relying on trusted WSS client. Would be better to have a strict routine, returning success or failure.
uTransID.SetHex(jvRequest["tx_hash"].asString()); uTransID.SetHex(jvRequest["tx_hash"].asString());
uint256 uLedgerID;
// XXX Relying on trusted WSS client. Would be better to have a strict routine, returning success or failure.
uLedgerID.SetHex(jvRequest["ledger_hash"].asString());
Ledger::pointer lpLedger = theApp->getLedgerMaster().getLedgerByHash(uLedgerID);
if (!lpLedger) { if (!lpLedger) {
jvResult["error"] = "ledgerNotFound"; jvResult["error"] = "ledgerNotFound";
} }
@@ -1787,6 +1770,7 @@ Json::Value RPCHandler::doTransactionEntry(Json::Value jvRequest)
return jvResult; return jvResult;
} }
// XXX ledger_index needs to be allowed as a string (32-bits is to small).
Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger) Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger)
{ {
Json::Value jvResult; Json::Value jvResult;
@@ -1839,6 +1823,10 @@ Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpL
return jvResult; return jvResult;
} }
// {
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// }
Json::Value RPCHandler::doLedgerEntry(Json::Value jvRequest) Json::Value RPCHandler::doLedgerEntry(Json::Value jvRequest)
{ {
Ledger::pointer lpLedger; Ledger::pointer lpLedger;
@@ -2042,6 +2030,10 @@ Json::Value RPCHandler::doLedgerEntry(Json::Value jvRequest)
return jvResult; return jvResult;
} }
// {
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// }
Json::Value RPCHandler::doLedgerHeader(Json::Value jvRequest) Json::Value RPCHandler::doLedgerHeader(Json::Value jvRequest)
{ {
Ledger::pointer lpLedger; Ledger::pointer lpLedger;

View File

@@ -21,19 +21,17 @@ class RPCHandler
// Utilities // Utilities
void addSubmitPath(Json::Value& txJSON); void addSubmitPath(Json::Value& txJSON);
boost::unordered_set<RippleAddress> parseAccountIds(const Json::Value& jvArray); boost::unordered_set<RippleAddress> parseAccountIds(const Json::Value& jvArray);
int getParamCount(Json::Value params);
bool extractString(std::string& param, const Json::Value& params, int index);
Json::Value lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger); Json::Value lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger);
Json::Value getMasterGenerator(const uint256& uLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator); Json::Value getMasterGenerator(Ledger::ref lrLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator);
Json::Value authorize(const uint256& uLedger, const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID, Json::Value authorize(Ledger::ref lrLedger, const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID,
RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate, RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate,
STAmount& saSrcBalance, const STAmount& saFee, AccountState::pointer& asSrc, STAmount& saSrcBalance, const STAmount& saFee, AccountState::pointer& asSrc,
const RippleAddress& naVerifyGenerator); const RippleAddress& naVerifyGenerator);
Json::Value accounts(const uint256& uLedger, const RippleAddress& naMasterGenerator); Json::Value accounts(Ledger::ref lrLedger, const RippleAddress& naMasterGenerator);
Json::Value accountFromString(const uint256& uLedger, RippleAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex); Json::Value accountFromString(Ledger::ref lrLedger, RippleAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex);
Json::Value doAcceptLedger(Json::Value jvRequest); Json::Value doAcceptLedger(Json::Value jvRequest);

View File

@@ -692,44 +692,44 @@ Remote.prototype.request_unsubscribe = function (streams) {
return request; return request;
}; };
Remote.prototype.request_transaction_entry = function (hash) { // --> current: true, for the current ledger.
Remote.prototype.request_transaction_entry = function (hash, current) {
//utils.assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol. //utils.assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
return (new Request(this, 'transaction_entry')) return (new Request(this, 'transaction_entry'))
.ledger_choose(current)
.tx_hash(hash); .tx_hash(hash);
}; };
Remote.prototype.request_account_lines = function (accountID, index) { // --> account_index: sub_account index (optional)
// --> current: true, for the current ledger.
Remote.prototype.request_account_lines = function (accountID, account_index, current) {
// XXX Does this require the server to be trusted? // XXX Does this require the server to be trusted?
//utils.assert(this.trusted); //utils.assert(this.trusted);
var request = new Request(this, 'account_lines'); var request = new Request(this, 'account_lines');
request.message.account = accountID; request.message.account = UInt160.json_rewrite(accountID);
if (index) if (account_index)
request.message.index = index; request.message.index = account_index;
return request; return request
.ledger_choose(current);
}; };
Remote.prototype.request_account_offers = function (accountID) { // --> account_index: sub_account index (optional)
// --> current: true, for the current ledger.
Remote.prototype.request_account_offers = function (accountID, account_index, current) {
var request = new Request(this, 'account_offers'); var request = new Request(this, 'account_offers');
request.message.account = accountID; request.message.account = UInt160.json_rewrite(accountID);
return request; if (account_index)
}; request.message.index = account_index;
Remote.prototype.request_wallet_accounts = function (seed) { return request
utils.assert(this.trusted); // Don't send secrets. .ledger_choose(current);
var request = new Request(this, 'wallet_accounts');
request.message.seed = seed;
return request;
}; };
Remote.prototype.request_account_tx = function (accountID, ledger_min, ledger_max) { Remote.prototype.request_account_tx = function (accountID, ledger_min, ledger_max) {
@@ -751,6 +751,27 @@ Remote.prototype.request_account_tx = function (accountID, ledger_min, ledger_ma
return request; return request;
}; };
Remote.prototype.request_ledger = function (ledger, full) {
var request = new Request(this, 'ledger');
request.message.ledger = ledger;
if (full)
request.message.full = true;
return request;
};
Remote.prototype.request_wallet_accounts = function (seed) {
utils.assert(this.trusted); // Don't send secrets.
var request = new Request(this, 'wallet_accounts');
request.message.seed = seed;
return request;
};
// Submit a transaction. // Submit a transaction.
Remote.prototype.submit = function (transaction) { Remote.prototype.submit = function (transaction) {
var self = this; var self = this;