mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-28 07:35:52 +00:00
impliments account RPC handlers
This commit is contained in:
@@ -36,7 +36,7 @@ addChannel(boost::json::array& jsonLines, ripple::SLE const& line)
|
||||
if (auto const& v = line[~ripple::sfDestinationTag])
|
||||
jDst["destination_tag"] = *v;
|
||||
|
||||
jsonLines.push_back(Json::objectValue);
|
||||
jsonLines.push_back(jDst);
|
||||
}
|
||||
|
||||
boost::json::object
|
||||
@@ -95,46 +95,72 @@ doAccountChannels(
|
||||
}
|
||||
}
|
||||
|
||||
auto const rootIndex = ripple::keylet::ownerDir(accountID);
|
||||
auto currentIndex = rootIndex;
|
||||
|
||||
std::vector<ripple::uint256> keys;
|
||||
|
||||
for (;;)
|
||||
std::uint32_t limit = 200;
|
||||
if (request.contains("limit"))
|
||||
{
|
||||
auto ownedNode =
|
||||
backend.fetchLedgerObject(currentIndex.key, *ledgerSequence);
|
||||
if(!request.at("limit").is_int64())
|
||||
{
|
||||
response["error"] = "limit must be integer";
|
||||
return response;
|
||||
}
|
||||
|
||||
ripple::SerialIter it{ownedNode->data(), ownedNode->size()};
|
||||
ripple::SLE dir{it, currentIndex.key};
|
||||
for (auto const& key : dir.getFieldV256(ripple::sfIndexes))
|
||||
keys.push_back(key);
|
||||
|
||||
auto const uNodeNext = dir.getFieldU64(ripple::sfIndexNext);
|
||||
if (uNodeNext == 0)
|
||||
break;
|
||||
|
||||
currentIndex = ripple::keylet::page(rootIndex, uNodeNext);
|
||||
limit = request.at("limit").as_int64();
|
||||
if (limit <= 0)
|
||||
{
|
||||
response["error"] = "limit must be positive";
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
auto objects = backend.fetchLedgerObjects(keys, *ledgerSequence);
|
||||
ripple::uint256 cursor = beast::zero;
|
||||
if (request.contains("cursor"))
|
||||
{
|
||||
if(!request.at("cursor").is_string())
|
||||
{
|
||||
response["error"] = "limit must be string";
|
||||
return response;
|
||||
}
|
||||
|
||||
auto bytes = ripple::strUnHex(request.at("cursor").as_string().c_str());
|
||||
if (bytes and bytes->size() == 32)
|
||||
{
|
||||
response["error"] = "invalid cursor";
|
||||
return response;
|
||||
}
|
||||
|
||||
cursor = ripple::uint256::fromVoid(bytes->data());
|
||||
}
|
||||
|
||||
response["channels"] = boost::json::value(boost::json::array_kind);
|
||||
boost::json::array& jsonChannels = response.at("channels").as_array();
|
||||
|
||||
for (auto i = 0; i < objects.size(); ++i)
|
||||
{
|
||||
ripple::SerialIter it{objects[i].data(), objects[i].size()};
|
||||
ripple::SLE sle{it, keys[i]};
|
||||
|
||||
auto const addToResponse = [&](ripple::SLE const& sle) {
|
||||
if (sle.getType() == ripple::ltPAYCHAN &&
|
||||
sle.getAccountID(ripple::sfAccount) == accountID &&
|
||||
(!destAccount ||
|
||||
*destAccount == sle.getAccountID(ripple::sfDestination)))
|
||||
{
|
||||
if (limit-- == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
addChannel(jsonChannels, sle);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto nextCursor =
|
||||
traverseOwnedNodes(
|
||||
backend,
|
||||
accountID,
|
||||
*ledgerSequence,
|
||||
cursor,
|
||||
addToResponse);
|
||||
|
||||
if (nextCursor)
|
||||
response["next_cursor"] = ripple::strHex(*nextCursor);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user