1#include <xrpld/app/main/Application.h>
2#include <xrpld/app/paths/TrustLine.h>
3#include <xrpld/rpc/Context.h>
4#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/RPCErr.h>
10#include <xrpl/protocol/jss.h>
11#include <xrpl/resource/Fees.h>
37 auto& params = context.
params;
46 if (!(params.isMember(jss::account) || params.isMember(jss::ident)))
50 params.isMember(jss::account) ? params[jss::account].asString()
51 : params[jss::ident].asString());
54 auto id = parseBase58<AccountID>(strIdent);
57 auto const accountID{std::move(
id.value())};
60 result[jss::account] =
toBase58(accountID);
71 if (params.isMember(jss::hotwallet))
73 auto addHotWallet = [&hotWallets](
Json::Value const& j) {
76 if (
auto id = parseBase58<AccountID>(j.asString()); id)
78 hotWallets.
insert(std::move(
id.value()));
92 for (
unsigned i = 0; i < hw.
size(); ++i)
93 valid &= addHotWallet(hw[i]);
97 valid &= addHotWallet(hw);
132 if (sle->getType() == ltESCROW)
134 auto const& escrow = sle->getFieldAmount(sfAmount);
135 auto& bal = locked[escrow.getCurrency()];
136 if (bal == beast::zero)
166 int balSign = rs->getBalance().signum();
170 auto const& peer = rs->getAccountIDPeer();
176 if (hotWallets.
count(peer) > 0)
179 hotBalances[peer].push_back(-rs->getBalance());
181 else if (balSign > 0)
184 assets[peer].push_back(rs->getBalance());
186 else if (rs->getFreeze())
189 frozenBalances[peer].push_back(-rs->getBalance());
194 auto& bal = sums[rs->getBalance().getCurrency()];
195 if (bal == beast::zero)
198 bal = -rs->getBalance();
204 bal -= rs->getBalance();
225 for (
auto const& [k, v] : sums)
229 result[jss::obligations] = std::move(j);
232 auto populateResult =
239 for (
auto const& [accId, accBalances] : array)
242 for (
auto const& balance : accBalances)
245 entry[jss::currency] =
247 entry[jss::value] = balance.getText();
248 balanceArray.
append(std::move(entry));
250 j[
to_string(accId)] = std::move(balanceArray);
252 result[name] = std::move(j);
256 populateResult(hotBalances, jss::balances);
257 populateResult(frozenBalances, jss::frozen_balances);
258 populateResult(assets, jss::assets);
264 for (
auto const& [k, v] : locked)
268 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
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
static int const cMaxOffset
static std::uint64_t const cMaxValue
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Json::Value missing_field_error(std::string const &name)
Charge const feeHeavyBurdenRPC
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Keylet account(AccountID const &id) noexcept
AccountID root.
Json::Value entry(jtx::Env &env, jtx::Account const &account, jtx::Account const &authorize)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Json::Value rpcError(int iError)
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Json::Value doGatewayBalances(RPC::JsonContext &context)
Resource::Charge & loadType