mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-23 23:30:54 +00:00
Supplement ShareTotal in ledger_entry, ledger_data and account_objects.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <xrpl/protocol/SField.h>
|
||||
#include <xrpl/protocol/STBase.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
#include <xrpl/protocol/STNumber.h>
|
||||
#include <xrpl/protocol/STObject.h>
|
||||
#include <xrpl/protocol/Serializer.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
@@ -144,8 +145,7 @@ STLedgerEntry::getJson(JsonOptions options) const
|
||||
else if (getType() == ltVAULT)
|
||||
{
|
||||
// Replace "MPTokenIssuanceID" with functionally equivalent "Share"
|
||||
const char* const fieldMptIssue = sfMPTokenIssuanceID.fieldName.c_str();
|
||||
ret.removeMember(fieldMptIssue);
|
||||
ret.removeMember(sfMPTokenIssuanceID.fieldName.c_str());
|
||||
ret[jss::Share] = to_json(MPTIssue(getFieldH192(sfMPTokenIssuanceID)));
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,26 @@ isRelatedToAccount(
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
void
|
||||
supplementJson<ltVAULT>(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& vault,
|
||||
Json::Value& node)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
vault->getType() == ltVAULT,
|
||||
"ripple::RPC::supplementJson<ltVAULT> : matching type");
|
||||
|
||||
auto const share = vault->at(sfMPTokenIssuanceID);
|
||||
auto const sleIssuance = view.read(keylet::mptIssuance(share));
|
||||
if (!sleIssuance)
|
||||
return;
|
||||
|
||||
node[jss::ShareTotal] =
|
||||
Number(sleIssuance->getFieldU64(sfOutstandingAmount));
|
||||
}
|
||||
|
||||
bool
|
||||
getAccountObjects(
|
||||
ReadView const& ledger,
|
||||
@@ -300,7 +320,10 @@ getAccountObjects(
|
||||
if (!typeFilter.has_value() ||
|
||||
typeMatchesFilter(typeFilter.value(), sleNode->getType()))
|
||||
{
|
||||
jvObjects.append(sleNode->getJson(JsonOptions::none));
|
||||
auto& entry =
|
||||
jvObjects.append(sleNode->getJson(JsonOptions::none));
|
||||
if (sleNode->getType() == ltVAULT)
|
||||
RPC::supplementJson<ltVAULT>(ledger, sleNode, entry);
|
||||
}
|
||||
|
||||
if (++i == mlimit)
|
||||
|
||||
@@ -269,6 +269,29 @@ keypairForSignature(
|
||||
Json::Value const& params,
|
||||
Json::Value& error,
|
||||
unsigned int apiVersion = apiVersionIfUnspecified);
|
||||
|
||||
/**
|
||||
* Supplement JSON of a ledger object with additional data read from a view
|
||||
*
|
||||
* To be specialized per ledger object type as needed; any specialization of
|
||||
* this function must be declared below and defined in RPCHelpers.cpp
|
||||
*
|
||||
* The general template is never used, hence it is only declared but not defined
|
||||
*/
|
||||
template <LedgerEntryType Type>
|
||||
inline void
|
||||
supplementJson(
|
||||
ReadView const&,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
Json::Value&);
|
||||
|
||||
template <>
|
||||
void
|
||||
supplementJson<ltVAULT>(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& vault,
|
||||
Json::Value& node);
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace ripple
|
||||
|
||||
|
||||
@@ -124,6 +124,8 @@ doLedgerData(RPC::JsonContext& context)
|
||||
{
|
||||
Json::Value& entry =
|
||||
nodes.append(sle->getJson(JsonOptions::none));
|
||||
if (sle->getType() == ltVAULT)
|
||||
RPC::supplementJson<ltVAULT>(*lpLedger, sle, entry);
|
||||
entry[jss::index] = to_string(sle->key());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,37 +894,6 @@ struct LedgerEntry
|
||||
LedgerEntryType expectedType;
|
||||
};
|
||||
|
||||
template <LedgerEntryType Type>
|
||||
static void
|
||||
supplementJson(
|
||||
ReadView const&,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
Json::Value&)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
sle->getType() == Type, "ripple::supplementJson : matching type");
|
||||
}
|
||||
|
||||
template <>
|
||||
void
|
||||
supplementJson<ltVAULT>(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& vault,
|
||||
Json::Value& node)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
vault->getType() == ltVAULT,
|
||||
"ripple::supplementJson<ltVAULT> : matching type");
|
||||
|
||||
auto const share = vault->at(sfMPTokenIssuanceID);
|
||||
auto const sleIssuance = view.read(keylet::mptIssuance(share));
|
||||
if (!sleIssuance)
|
||||
return;
|
||||
|
||||
node[jss::ShareTotal] =
|
||||
Number(sleIssuance->getFieldU64(sfOutstandingAmount));
|
||||
}
|
||||
|
||||
// {
|
||||
// ledger_hash : <ledger>
|
||||
// ledger_index : <ledger_index>
|
||||
@@ -1065,7 +1034,8 @@ doLedgerEntry(RPC::JsonContext& context)
|
||||
{
|
||||
jvResult[jss::node] = sleNode->getJson(JsonOptions::none);
|
||||
if (sleNode->getType() == ltVAULT)
|
||||
supplementJson<ltVAULT>(*lpLedger, sleNode, jvResult[jss::node]);
|
||||
RPC::supplementJson<ltVAULT>(
|
||||
*lpLedger, sleNode, jvResult[jss::node]);
|
||||
jvResult[jss::index] = to_string(uNodeIndex);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user