xrpld
Loading...
Searching...
No Matches
OwnerInfo.cpp
1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/rpc/Context.h>
3
4#include <xrpl/json/json_value.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/RPCErr.h>
8#include <xrpl/protocol/jss.h>
9#include <xrpl/server/NetworkOPs.h>
10
11#include <optional>
12#include <string>
13
14namespace xrpl {
15
16// {
17// 'ident' : <indent>,
18// }
19json::Value
21{
22 if (!context.params.isMember(jss::account) && !context.params.isMember(jss::ident))
23 {
24 return RPC::missingFieldError(jss::account);
25 }
26
27 std::string const strIdent = context.params.isMember(jss::account)
28 ? context.params[jss::account].asString()
29 : context.params[jss::ident].asString();
30 json::Value ret;
31
32 // Get info on account.
33 auto const& closedLedger = context.ledgerMaster.getClosedLedger();
34 std::optional<AccountID> const accountID = parseBase58<AccountID>(strIdent);
35 ret[jss::accepted] = accountID.has_value()
36 ? context.netOps.getOwnerInfo(closedLedger, accountID.value())
38
39 auto const& currentLedger = context.ledgerMaster.getCurrentLedger();
40 ret[jss::current] = accountID.has_value()
41 ? context.netOps.getOwnerInfo(currentLedger, *accountID)
43 return ret;
44}
45
46} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
std::shared_ptr< Ledger const > getClosedLedger()
std::shared_ptr< ReadView const > getCurrentLedger()
virtual json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account)=0
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:231
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcActMalformed
Definition ErrorCodes.h:72
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
json::Value doOwnerInfo(RPC::JsonContext &context)
Definition OwnerInfo.cpp:20
T has_value(T... args)
LedgerMaster & ledgerMaster
Definition Context.h:24
NetworkOPs & netOps
Definition Context.h:23
json::Value params
Definition Context.h:43
T value(T... args)