1#include <xrpld/app/main/Application.h>
2#include <xrpld/rpc/Context.h>
3#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
4#include <xrpld/rpc/detail/TrustLine.h>
6#include <xrpl/beast/utility/Zero.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/ledger/helpers/DirectoryHelpers.h>
10#include <xrpl/protocol/AccountID.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/MPTIssue.h>
15#include <xrpl/protocol/RPCErr.h>
16#include <xrpl/protocol/SField.h>
17#include <xrpl/protocol/STAmount.h>
18#include <xrpl/protocol/UintTypes.h>
19#include <xrpl/protocol/jss.h>
20#include <xrpl/resource/Fees.h>
54 auto& params = context.
params;
63 if (!(params.isMember(jss::account) || params.isMember(jss::ident)))
67 params.isMember(jss::account) ? params[jss::account].asString()
68 : params[jss::ident].asString());
74 auto const accountID{
id.value()};
77 result[jss::account] =
toBase58(accountID);
88 if (params.isMember(jss::hotwallet))
90 auto addHotWallet = [&hotWallets](
json::Value const& j) {
95 hotWallets.
insert(
id.value());
109 for (
unsigned i = 0; i < hw.
size(); ++i)
110 valid &= addHotWallet(hw[i]);
114 valid &= addHotWallet(hw);
148 if (sle->getType() == ltESCROW)
150 auto const& escrow = sle->getFieldAmount(sfAmount);
155 auto& bal = locked[escrow.get<
Issue>().currency];
156 if (bal == beast::kZero)
183 int const balSign = rs->getBalance().signum();
187 auto const& peer = rs->getAccountIDPeer();
196 hotBalances[peer].push_back(-rs->getBalance());
198 else if (balSign > 0)
201 assets[peer].push_back(rs->getBalance());
203 else if (rs->getFreeze())
206 frozenBalances[peer].push_back(-rs->getBalance());
211 auto& bal = sums[rs->getBalance().get<
Issue>().currency];
212 if (bal == beast::kZero)
215 bal = -rs->getBalance();
221 bal -= rs->getBalance();
239 for (
auto const& [k, v] : sums)
243 result[jss::obligations] = std::move(j);
246 auto populateResult = [&result](
252 for (
auto const& [accId, accBalances] : array)
255 for (
auto const& balance : accBalances)
259 entry[jss::value] = balance.getText();
260 balanceArray.
append(std::move(entry));
262 j[
to_string(accId)] = std::move(balanceArray);
264 result[name] = std::move(j);
268 populateResult(hotBalances, jss::balances);
269 populateResult(frozenBalances, jss::frozen_balances);
270 populateResult(assets, jss::assets);
276 for (
auto const& [k, v] : locked)
280 result[jss::locked] = std::move(j);
Lightweight wrapper to tag static string.
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
bool isArrayOrNull() const
A currency issued by an account.
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, SLE::const_ref sle)
static constexpr std::uint64_t kMaxValue
static constexpr int kMaxOffset
std::shared_ptr< STLedgerEntry const > const & const_ref
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, json::Value &result)
Looks up a ledger from a request and fills a json::Value with ledger data.
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value missingFieldError(std::string const &name)
Charge const kFeeHeavyBurdenRpc
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
json::Value doGatewayBalances(RPC::JsonContext &context)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::const_ref)> const &f)
Iterate all items in the given directory.
Resource::Charge & loadType