xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
account
AccountCurrencies.cpp
1
#include <xrpld/rpc/Context.h>
2
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
3
#include <xrpld/rpc/detail/TrustLine.h>
4
5
#include <xrpl/json/json_value.h>
6
#include <xrpl/ledger/ReadView.h>
7
#include <xrpl/protocol/AccountID.h>
8
#include <xrpl/protocol/ErrorCodes.h>
9
#include <xrpl/protocol/Indexes.h>
10
#include <xrpl/protocol/RPCErr.h>
11
#include <xrpl/protocol/STAmount.h>
12
#include <xrpl/protocol/UintTypes.h>
13
#include <xrpl/protocol/jss.h>
14
15
#include <
memory
>
16
#include <
set
>
17
#include <
string
>
18
19
namespace
xrpl
{
20
21
json::Value
22
doAccountCurrencies
(
rpc::JsonContext
& context)
23
{
24
auto
& params = context.
params
;
25
26
if
(!(params.isMember(jss::account) || params.isMember(jss::ident)))
27
return
rpc::missingFieldError
(jss::account);
28
29
std::string
strIdent;
30
if
(params.isMember(jss::account))
31
{
32
if
(!params[jss::account].isString())
33
return
rpc::invalidFieldError
(jss::account);
34
strIdent = params[jss::account].asString();
35
}
36
else
if
(params.isMember(jss::ident))
37
{
38
if
(!params[jss::ident].isString())
39
return
rpc::invalidFieldError
(jss::ident);
40
strIdent = params[jss::ident].asString();
41
}
42
43
// Get the current ledger
44
std::shared_ptr<ReadView const>
ledger;
45
auto
result =
rpc::lookupLedger
(ledger, context);
46
if
(!ledger)
47
return
result;
48
49
// Get info on account.
50
auto
id
=
parseBase58<AccountID>
(strIdent);
51
if
(!
id
)
52
{
53
rpc::injectError
(
RpcActMalformed
, result);
54
return
result;
55
}
56
auto
const
accountID{
id
.value()};
57
58
if
(!ledger->exists(
keylet::account
(accountID)))
59
return
rpcError
(
RpcActNotFound
);
60
61
std::set<Currency>
send, receive;
62
for
(
auto
const
& rspEntry :
RPCTrustLine::getItems
(accountID, *ledger))
63
{
64
STAmount
const
& saBalance = rspEntry.getBalance();
65
66
if
(saBalance < rspEntry.getLimit())
67
receive.
insert
(saBalance.
get
<
Issue
>().
currency
);
68
if
((-saBalance) < rspEntry.getLimitPeer())
69
send.
insert
(saBalance.
get
<
Issue
>().
currency
);
70
}
71
72
send.
erase
(
badCurrency
());
73
receive.
erase
(
badCurrency
());
74
75
json::Value
& sendCurrencies = (result[jss::send_currencies] =
json::ValueType::Array
);
76
for
(
auto
const
& c : send)
77
sendCurrencies.
append
(
to_string
(c));
78
79
json::Value
& recvCurrencies = (result[jss::receive_currencies] =
json::ValueType::Array
);
80
for
(
auto
const
& c : receive)
81
recvCurrencies.
append
(
to_string
(c));
82
83
return
result;
84
}
85
86
}
// namespace xrpl
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::append
Value & append(Value const &value)
Append value to array at the end.
Definition
json_value.cpp:997
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::Issue::currency
Currency currency
Definition
Issue.h:20
xrpl::RPCTrustLine::getItems
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition
TrustLine.cpp:95
xrpl::STAmount
Definition
STAmount.h:46
xrpl::STAmount::get
constexpr TIss const & get() const
std::set::erase
T erase(T... args)
std::set::insert
T insert(T... args)
memory
json::ValueType::Array
@ Array
array value (ordered list)
Definition
json_value.h:28
xrpl::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition
Indexes.cpp:220
xrpl::rpc::injectError
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
Definition
ErrorCodes.cpp:164
xrpl::rpc::invalidFieldError
json::Value invalidFieldError(std::string const &name)
Definition
ErrorCodes.h:285
xrpl::rpc::missingFieldError
json::Value missingFieldError(std::string const &name)
Definition
ErrorCodes.h:243
xrpl::rpc::lookupLedger
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, json::Value &result)
Looks up a ledger from a request and fills a json::Value with ledger data.
Definition
RPCLedgerHelpers.cpp:390
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::RpcActNotFound
@ RpcActNotFound
Definition
ErrorCodes.h:53
xrpl::RpcActMalformed
@ RpcActMalformed
Definition
ErrorCodes.h:73
xrpl::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition
AccountID.cpp:105
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::rpcError
json::Value rpcError(ErrorCodeI iError)
Definition
RPCErr.cpp:13
xrpl::doAccountCurrencies
json::Value doAccountCurrencies(rpc::JsonContext &context)
Definition
AccountCurrencies.cpp:22
xrpl::badCurrency
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
Definition
UintTypes.cpp:113
set
std::shared_ptr
string
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::params
json::Value params
Definition
Context.h:51
Generated by
1.17.0