mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 12:05:53 +00:00
Refactor RPC ripple_lines_get.
This commit is contained in:
@@ -156,6 +156,26 @@ Json::Value RPCParser::parseLedger(const Json::Value& jvParams)
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
// ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]
|
||||
Json::Value RPCParser::parseRippleLinesGet(const Json::Value& jvParams)
|
||||
{
|
||||
std::string strIdent = jvParams[0u].asString();
|
||||
bool bIndex = 2 == jvParams.size();
|
||||
int iIndex = bIndex ? lexical_cast_s<int>(jvParams[1u].asString()) : 0;
|
||||
|
||||
if (bIndex && !iIndex) // Don't send default.
|
||||
bIndex = false;
|
||||
|
||||
// Get info on account.
|
||||
Json::Value jvRequest(Json::objectValue);
|
||||
|
||||
jvRequest["account"] = strIdent;
|
||||
if (bIndex)
|
||||
jvRequest["index"] = iIndex;
|
||||
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
// submit any transaction to the network
|
||||
// submit private_key json
|
||||
Json::Value RPCParser::parseSubmit(const Json::Value& jvParams)
|
||||
@@ -248,7 +268,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||
// { "owner_info", &RPCParser::doOwnerInfo, 1, 2, false, false, optCurrent },
|
||||
{ "peers", &RPCParser::parseAsIs, 0, 0 },
|
||||
// { "profile", &RPCParser::doProfile, 1, 9, false, false, optCurrent },
|
||||
// { "ripple_lines_get", &RPCParser::doRippleLinesGet, 1, 2, false, false, optCurrent },
|
||||
{ "ripple_lines_get", &RPCParser::parseRippleLinesGet, 1, 2 },
|
||||
// { "ripple_path_find", &RPCParser::doRipplePathFind, -1, -1, false, false, optCurrent },
|
||||
{ "submit", &RPCParser::parseSubmit, 2, 2 },
|
||||
{ "server_info", &RPCParser::parseAsIs, 0, 0 },
|
||||
|
||||
@@ -17,6 +17,7 @@ protected:
|
||||
Json::Value parseConnect(const Json::Value& jvParams);
|
||||
Json::Value parseEvented(const Json::Value& jvParams);
|
||||
Json::Value parseLedger(const Json::Value& jvParams);
|
||||
Json::Value parseRippleLinesGet(const Json::Value& jvParams);
|
||||
Json::Value parseSubmit(const Json::Value& jvParams);
|
||||
Json::Value parseUnlAdd(const Json::Value& jvParams);
|
||||
Json::Value parseUnlDelete(const Json::Value& jvParams);
|
||||
|
||||
@@ -549,42 +549,42 @@ Json::Value RPCHandler::doProfile(Json::Value params)
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]
|
||||
Json::Value RPCHandler::doRippleLinesGet(Json::Value params)
|
||||
// {
|
||||
// account: <account>|<nickname>|<account_public_key> [<index>]
|
||||
// index: <number> // optional, defaults to 0.
|
||||
// }
|
||||
Json::Value RPCHandler::doRippleLinesGet(Json::Value jvRequest)
|
||||
{
|
||||
// uint256 uAccepted = mNetOps->getClosedLedgerHash();
|
||||
std::string strIdent = jvRequest["account"].asString();
|
||||
bool bIndex = jvRequest.isMember("index");
|
||||
int iIndex = bIndex ? jvRequest["index"].asUInt() : 0;
|
||||
|
||||
std::string strIdent = params[0u].asString();
|
||||
bool bIndex;
|
||||
int iIndex = 2 == params.size() ? lexical_cast_s<int>(params[1u].asString()) : 0;
|
||||
RippleAddress raAccount;
|
||||
|
||||
RippleAddress naAccount;
|
||||
Json::Value jvResult;
|
||||
|
||||
Json::Value ret;
|
||||
jvResult = accountFromString(uint256(0), raAccount, bIndex, strIdent, iIndex);
|
||||
|
||||
ret = accountFromString(uint256(0), naAccount, bIndex, strIdent, iIndex);
|
||||
|
||||
if (!ret.empty())
|
||||
return ret;
|
||||
if (!jvResult.empty())
|
||||
return jvResult;
|
||||
|
||||
// Get info on account.
|
||||
ret = Json::Value(Json::objectValue);
|
||||
|
||||
ret["account"] = naAccount.humanAccountID();
|
||||
jvResult["account"] = raAccount.humanAccountID();
|
||||
if (bIndex)
|
||||
ret["index"] = iIndex;
|
||||
jvResult["index"] = iIndex;
|
||||
|
||||
AccountState::pointer as = mNetOps->getAccountState(uint256(0), naAccount);
|
||||
AccountState::pointer as = mNetOps->getAccountState(uint256(0), raAccount);
|
||||
if (as)
|
||||
{
|
||||
Json::Value jsonLines(Json::arrayValue);
|
||||
|
||||
ret["account"] = naAccount.humanAccountID();
|
||||
jvResult["account"] = raAccount.humanAccountID();
|
||||
|
||||
// XXX This is wrong, we do access the current ledger and do need to worry about changes.
|
||||
// We access a committed ledger and need not worry about changes.
|
||||
|
||||
RippleLines rippleLines(naAccount.getAccountID());
|
||||
RippleLines rippleLines(raAccount.getAccountID());
|
||||
BOOST_FOREACH(RippleState::pointer line, rippleLines.getLines())
|
||||
{
|
||||
STAmount saBalance = line->getBalance();
|
||||
@@ -607,14 +607,14 @@ Json::Value RPCHandler::doRippleLinesGet(Json::Value params)
|
||||
|
||||
jsonLines.append(jPeer);
|
||||
}
|
||||
ret["lines"] = jsonLines;
|
||||
jvResult["lines"] = jsonLines;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = rpcError(rpcACT_NOT_FOUND);
|
||||
jvResult = rpcError(rpcACT_NOT_FOUND);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
|
||||
@@ -698,14 +698,16 @@ Remote.prototype.request_transaction_entry = function (hash) {
|
||||
.tx_hash(hash);
|
||||
};
|
||||
|
||||
Remote.prototype.request_ripple_lines_get = function (accountID) {
|
||||
Remote.prototype.request_ripple_lines_get = function (accountID, index) {
|
||||
// XXX Does this require the server to be trusted?
|
||||
//assert(this.trusted);
|
||||
|
||||
var request = new Request(this, 'ripple_lines_get');
|
||||
|
||||
// XXX Convert API call to JSON
|
||||
request.message.params = [accountID];
|
||||
request.message.account = accountID;
|
||||
|
||||
if (index)
|
||||
request.message.index = index;
|
||||
|
||||
return request;
|
||||
};
|
||||
@@ -1001,10 +1003,13 @@ Remote.prototype.request_unl_list = function () {
|
||||
return new Request(this, 'unl_list');
|
||||
};
|
||||
|
||||
Remote.prototype.request_unl_add = function (addr, note) {
|
||||
Remote.prototype.request_unl_add = function (addr, comment) {
|
||||
var request = new Request(this, 'unl_add');
|
||||
|
||||
request.message.params = [addr, note];
|
||||
request.message.node = addr;
|
||||
|
||||
if (comment !== undefined)
|
||||
request.message.comment = note;
|
||||
|
||||
return request;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user