rippled
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 <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/misc/NetworkOPs.h>
22 #include <ripple/json/json_value.h>
23 #include <ripple/protocol/ErrorCodes.h>
24 #include <ripple/protocol/jss.h>
25 #include <ripple/rpc/Context.h>
26 #include <ripple/rpc/impl/RPCHelpers.h>
27 
28 namespace ripple {
29 
30 // {
31 // 'ident' : <indent>,
32 // }
35 {
36  if (!context.params.isMember(jss::account) &&
37  !context.params.isMember(jss::ident))
38  {
39  return RPC::missing_field_error(jss::account);
40  }
41 
42  std::string strIdent = context.params.isMember(jss::account)
43  ? context.params[jss::account].asString()
44  : context.params[jss::ident].asString();
45  Json::Value ret;
46 
47  // Get info on account.
48 
49  auto const& closedLedger = context.ledgerMaster.getClosedLedger();
50  AccountID accountID;
51  auto jAccepted = RPC::accountFromString(accountID, strIdent);
52 
53  ret[jss::accepted] = !jAccepted
54  ? context.netOps.getOwnerInfo(closedLedger, accountID)
55  : jAccepted;
56 
57  auto const& currentLedger = context.ledgerMaster.getCurrentLedger();
58  auto jCurrent = RPC::accountFromString(accountID, strIdent);
59 
60  ret[jss::current] = !jCurrent
61  ? context.netOps.getOwnerInfo(currentLedger, accountID)
62  : jCurrent;
63  return ret;
64 }
65 
66 } // namespace ripple
ripple::RPC::JsonContext
Definition: Context.h:53
std::string
STL class.
ripple::doOwnerInfo
Json::Value doOwnerInfo(RPC::JsonContext &)
Definition: OwnerInfo.cpp:34
ripple::RPC::Context::ledgerMaster
LedgerMaster & ledgerMaster
Definition: Context.h:45
ripple::RPC::missing_field_error
Json::Value missing_field_error(std::string const &name)
Definition: ErrorCodes.h:236
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:73
ripple::NetworkOPs::getOwnerInfo
virtual Json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account)=0
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
ripple::LedgerMaster::getCurrentLedger
std::shared_ptr< ReadView const > getCurrentLedger()
Definition: LedgerMaster.cpp:1528
ripple::RPC::Context::netOps
NetworkOPs & netOps
Definition: Context.h:44
ripple::LedgerMaster::getClosedLedger
std::shared_ptr< Ledger const > getClosedLedger()
Definition: LedgerMaster.h:87
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::RPC::accountFromString
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:82
Json::Value
Represents a JSON value.
Definition: json_value.h:145
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469