rippled
Loading...
Searching...
No Matches
OwnerInfo.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/misc/NetworkOPs.h>
22#include <xrpld/rpc/Context.h>
23
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/RPCErr.h>
27#include <xrpl/protocol/jss.h>
28
29namespace ripple {
30
31// {
32// 'ident' : <indent>,
33// }
36{
37 if (!context.params.isMember(jss::account) &&
38 !context.params.isMember(jss::ident))
39 {
40 return RPC::missing_field_error(jss::account);
41 }
42
43 std::string strIdent = context.params.isMember(jss::account)
44 ? context.params[jss::account].asString()
45 : context.params[jss::ident].asString();
46 Json::Value ret;
47
48 // Get info on account.
49 auto const& closedLedger = context.ledgerMaster.getClosedLedger();
50 std::optional<AccountID> const accountID = parseBase58<AccountID>(strIdent);
51 ret[jss::accepted] = accountID.has_value()
52 ? context.netOps.getOwnerInfo(closedLedger, accountID.value())
54
55 auto const& currentLedger = context.ledgerMaster.getCurrentLedger();
56 ret[jss::current] = accountID.has_value()
57 ? context.netOps.getOwnerInfo(currentLedger, *accountID)
59 return ret;
60}
61
62} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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< ReadView const > getCurrentLedger()
std::shared_ptr< Ledger const > getClosedLedger()
virtual Json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account)=0
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:283
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcACT_MALFORMED
Definition ErrorCodes.h:90
Json::Value rpcError(int iError)
Definition RPCErr.cpp:31
Json::Value doOwnerInfo(RPC::JsonContext &)
Definition OwnerInfo.cpp:35
T has_value(T... args)
LedgerMaster & ledgerMaster
Definition Context.h:44
NetworkOPs & netOps
Definition Context.h:43
T value(T... args)