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)))
66 if (params.isMember(jss::account) && !params[jss::account].isString())
69 if (params.isMember(jss::ident) && !params[jss::ident].isString())
73 params.isMember(jss::account) ? params[jss::account].asString()
74 : params[jss::ident].asString());
80 auto const accountID{
id.value()};
83 result[jss::account] =
toBase58(accountID);
94 if (params.isMember(jss::hotwallet))
96 auto addHotWallet = [&hotWallets](
json::Value const& j) {
101 hotWallets.
insert(
id.value());
115 for (
auto const& wallet : hw)
116 valid &= addHotWallet(wallet);
120 valid &= addHotWallet(hw);
154 if (sle->getType() == ltESCROW)
156 auto const& escrow = sle->getFieldAmount(sfAmount);
161 auto& bal = locked[escrow.get<
Issue>().currency];
189 int const balSign = rs->getBalance().signum();
193 auto const& peer = rs->getAccountIDPeer();
202 hotBalances[peer].push_back(-rs->getBalance());
204 else if (balSign > 0)
207 assets[peer].push_back(rs->getBalance());
209 else if (rs->getFreeze())
212 frozenBalances[peer].push_back(-rs->getBalance());
217 auto& bal = sums[rs->getBalance().get<
Issue>().currency];
221 bal = -rs->getBalance();
227 bal -= rs->getBalance();
245 for (
auto const& [k, v] : sums)
249 result[jss::obligations] = std::move(j);
252 auto populateResult = [&result](
258 for (
auto const& [accId, accBalances] : array)
261 for (
auto const& balance : accBalances)
265 entry[jss::value] = balance.getText();
266 balanceArray.
append(std::move(entry));
268 j[
to_string(accId)] = std::move(balanceArray);
270 result[name] = std::move(j);
274 populateResult(hotBalances, jss::balances);
275 populateResult(frozenBalances, jss::frozen_balances);
276 populateResult(assets, jss::assets);
282 for (
auto const& [k, v] : locked)
286 result[jss::locked] = std::move(j);
Lightweight wrapper to tag static string.
Value & append(Value const &value)
Append value to array at the end.
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
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Keylet account(AccountID const &id) noexcept
AccountID root.
Charge const kFeeHeavyBurdenRpc
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value invalidFieldError(std::string const &name)
json::Value missingFieldError(std::string const &name)
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.
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.
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
json::Value doGatewayBalances(rpc::JsonContext &context)
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