rippled
ripple
rpc
handlers
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/net/RPCErr.h>
24
#include <ripple/protocol/ErrorCodes.h>
25
#include <ripple/protocol/jss.h>
26
#include <ripple/rpc/Context.h>
27
#include <ripple/rpc/impl/RPCHelpers.h>
28
29
namespace
ripple
{
30
31
// {
32
// 'ident' : <indent>,
33
// }
34
Json::Value
35
doOwnerInfo
(
RPC::JsonContext
& context)
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
())
53
:
rpcError
(
rpcACT_MALFORMED
);
54
55
auto
const
& currentLedger = context.
ledgerMaster
.
getCurrentLedger
();
56
ret[jss::current] = accountID.
has_value
()
57
? context.
netOps
.
getOwnerInfo
(currentLedger, *accountID)
58
:
rpcError
(
rpcACT_MALFORMED
);
59
return
ret;
60
}
61
62
}
// namespace ripple
std::optional::has_value
T has_value(T... args)
ripple::RPC::JsonContext
Definition:
Context.h:53
std::string
STL class.
ripple::doOwnerInfo
Json::Value doOwnerInfo(RPC::JsonContext &)
Definition:
OwnerInfo.cpp:35
ripple::rpcError
Json::Value rpcError(int iError)
Definition:
RPCErr.cpp:29
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:262
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:1654
ripple::RPC::Context::netOps
NetworkOPs & netOps
Definition:
Context.h:44
std::optional::value
T value(T... args)
ripple::LedgerMaster::getClosedLedger
std::shared_ptr< Ledger const > getClosedLedger()
Definition:
LedgerMaster.h:98
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::rpcACT_MALFORMED
@ rpcACT_MALFORMED
Definition:
ErrorCodes.h:90
std::optional
ripple::RPC::JsonContext::params
Json::Value params
Definition:
Context.h:64
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
Generated by
1.8.17