mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
41
src/rpc/Amendments.h
Normal file
41
src/rpc/Amendments.h
Normal file
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2023, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ripple/basics/base_uint.h>
|
||||
|
||||
#include <ripple/protocol/digest.h>
|
||||
|
||||
namespace RPC {
|
||||
|
||||
#define REGISTER_AMENDMENT(name) inline static const ripple::uint256 name = GetAmendmentId(#name);
|
||||
|
||||
struct Amendments
|
||||
{
|
||||
static ripple::uint256 const
|
||||
GetAmendmentId(std::string_view const name)
|
||||
{
|
||||
return ripple::sha512Half(ripple::Slice(name.data(), name.size()));
|
||||
}
|
||||
|
||||
REGISTER_AMENDMENT(DisallowIncoming)
|
||||
REGISTER_AMENDMENT(Clawback)
|
||||
};
|
||||
} // namespace RPC
|
||||
@@ -1325,4 +1325,21 @@ getNFTID(boost::json::object const& request)
|
||||
return tokenid;
|
||||
}
|
||||
|
||||
bool
|
||||
isAmendmentEnabled(
|
||||
std::shared_ptr<Backend::BackendInterface const> const& backend,
|
||||
boost::asio::yield_context yield,
|
||||
uint32_t seq,
|
||||
ripple::uint256 amendmentId)
|
||||
{
|
||||
// the amendments should always be present in ledger
|
||||
auto const& amendments = backend->fetchLedgerObject(ripple::keylet::amendments().key, seq, yield);
|
||||
|
||||
ripple::SLE amendmentsSLE{
|
||||
ripple::SerialIter{amendments->data(), amendments->size()}, ripple::keylet::amendments().key};
|
||||
|
||||
auto const listAmendments = amendmentsSLE.getFieldV256(ripple::sfAmendments);
|
||||
return std::find(listAmendments.begin(), listAmendments.end(), amendmentId) != listAmendments.end();
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/Amendments.h>
|
||||
#include <rpc/JS.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <util/JsonUtils.h>
|
||||
@@ -216,6 +217,13 @@ specifiesCurrentOrClosedLedger(boost::json::object const& request);
|
||||
std::variant<ripple::uint256, Status>
|
||||
getNFTID(boost::json::object const& request);
|
||||
|
||||
bool
|
||||
isAmendmentEnabled(
|
||||
std::shared_ptr<Backend::BackendInterface const> const& backend,
|
||||
boost::asio::yield_context yield,
|
||||
uint32_t seq,
|
||||
ripple::uint256 amendmentId);
|
||||
|
||||
template <class T>
|
||||
void
|
||||
logDuration(Web::Context const& ctx, T const& dur)
|
||||
|
||||
@@ -50,6 +50,12 @@ AccountInfoHandler::process(AccountInfoHandler::Input input, Context const& ctx)
|
||||
if (!accountKeylet.check(sle))
|
||||
return Error{Status{RippledError::rpcDB_DESERIALIZATION}};
|
||||
|
||||
auto const isDisallowIncomingEnabled =
|
||||
RPC::isAmendmentEnabled(sharedPtrBackend_, ctx.yield, lgrInfo.seq, RPC::Amendments::DisallowIncoming);
|
||||
|
||||
auto const isClawbackEnabled =
|
||||
RPC::isAmendmentEnabled(sharedPtrBackend_, ctx.yield, lgrInfo.seq, RPC::Amendments::Clawback);
|
||||
|
||||
// Return SignerList(s) if that is requested.
|
||||
if (input.signerLists)
|
||||
{
|
||||
@@ -73,10 +79,11 @@ AccountInfoHandler::process(AccountInfoHandler::Input input, Context const& ctx)
|
||||
signerList.push_back(sleSigners);
|
||||
}
|
||||
|
||||
return Output(lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, signerList);
|
||||
return Output(
|
||||
lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, isDisallowIncomingEnabled, isClawbackEnabled, signerList);
|
||||
}
|
||||
|
||||
return Output(lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle);
|
||||
return Output(lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, isDisallowIncomingEnabled, isClawbackEnabled);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -89,7 +96,7 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, AccountInfoHandl
|
||||
{JS(validated), output.validated},
|
||||
};
|
||||
|
||||
static constexpr std::array<std::pair<std::string_view, ripple::LedgerSpecificFlags>, 9> lsFlags{{
|
||||
std::vector<std::pair<std::string_view, ripple::LedgerSpecificFlags>> lsFlags{{
|
||||
{"defaultRipple", ripple::lsfDefaultRipple},
|
||||
{"depositAuth", ripple::lsfDepositAuth},
|
||||
{"disableMasterKey", ripple::lsfDisableMaster},
|
||||
@@ -98,14 +105,25 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, AccountInfoHandl
|
||||
{"noFreeze", ripple::lsfNoFreeze},
|
||||
{"passwordSpent", ripple::lsfPasswordSpent},
|
||||
{"requireAuthorization", ripple::lsfRequireAuth},
|
||||
{"requireDestinationTag", ripple::lsfRequireDestTag}
|
||||
// TODO: wait for conan integration
|
||||
// {"disallowIncomingNFTokenOffer", ripple::lsfDisallowIncomingNFTokenOffer},
|
||||
// {"disallowIncomingCheck", ripple::lsfDisallowIncomingCheck},
|
||||
// {"disallowIncomingPayChan", ripple::lsfDisallowIncomingPayChan},
|
||||
// {"disallowIncomingTrustline", ripple::lsfDisallowIncomingTrustline}
|
||||
{"requireDestinationTag", ripple::lsfRequireDestTag},
|
||||
}};
|
||||
|
||||
if (output.isDisallowIncomingEnabled)
|
||||
{
|
||||
std::vector<std::pair<std::string_view, ripple::LedgerSpecificFlags>> const disallowIncomingFlags = {
|
||||
{"disallowIncomingNFTokenOffer", ripple::lsfDisallowIncomingNFTokenOffer},
|
||||
{"disallowIncomingCheck", ripple::lsfDisallowIncomingCheck},
|
||||
{"disallowIncomingPayChan", ripple::lsfDisallowIncomingPayChan},
|
||||
{"disallowIncomingTrustline", ripple::lsfDisallowIncomingTrustline},
|
||||
};
|
||||
lsFlags.insert(lsFlags.end(), disallowIncomingFlags.begin(), disallowIncomingFlags.end());
|
||||
}
|
||||
|
||||
if (output.isClawbackEnabled)
|
||||
{
|
||||
lsFlags.push_back({"allowTrustLineClawback", ripple::lsfAllowTrustLineClawback});
|
||||
}
|
||||
|
||||
boost::json::object acctFlags;
|
||||
for (auto const& lsf : lsFlags)
|
||||
acctFlags[lsf.first.data()] = output.accountData.isFlag(lsf.second);
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
uint32_t ledgerIndex;
|
||||
std::string ledgerHash;
|
||||
ripple::STLedgerEntry accountData;
|
||||
bool isDisallowIncomingEnabled = false;
|
||||
bool isClawbackEnabled = false;
|
||||
std::optional<std::vector<ripple::STLedgerEntry>> signerLists;
|
||||
// validated should be sent via framework
|
||||
bool validated = true;
|
||||
@@ -50,18 +52,17 @@ public:
|
||||
uint32_t ledgerId,
|
||||
std::string ledgerHash,
|
||||
ripple::STLedgerEntry sle,
|
||||
std::vector<ripple::STLedgerEntry> signerLists)
|
||||
bool isDisallowIncomingEnabled,
|
||||
bool isClawbackEnabled,
|
||||
std::optional<std::vector<ripple::STLedgerEntry>> signerLists = std::nullopt)
|
||||
: ledgerIndex(ledgerId)
|
||||
, ledgerHash(std::move(ledgerHash))
|
||||
, accountData(std::move(sle))
|
||||
, isDisallowIncomingEnabled(isDisallowIncomingEnabled)
|
||||
, isClawbackEnabled(isClawbackEnabled)
|
||||
, signerLists(std::move(signerLists))
|
||||
{
|
||||
}
|
||||
|
||||
Output(uint32_t ledgerId, std::string ledgerHash, ripple::STLedgerEntry sle)
|
||||
: ledgerIndex(ledgerId), ledgerHash(std::move(ledgerHash)), accountData(std::move(sle))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// "queue" is not available in Reporting mode
|
||||
|
||||
Reference in New Issue
Block a user