1#include <xrpl/tx/transactors/token/ConfidentialMPTMergeInbox.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/helpers/TokenHelpers.h>
8#include <xrpl/protocol/ConfidentialTransfer.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/XRPAmount.h>
17#include <xrpl/tx/Transactor.h>
50 if (!sleIssuance->isFlag(lsfMPTCanHoldConfidentialBalance))
55 if (sleIssuance->getAccountID(sfIssuer) == ctx.
tx[sfAccount])
58 auto const sleMptoken =
63 if (!sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) ||
64 !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
65 !sleMptoken->isFieldPresent(sfHolderEncryptionKey))
71 auto const account = ctx.
tx[sfAccount];
72 MPTIssue const mptIssue(ctx.
tx[sfMPTokenIssuanceID]);
86 auto const mptIssuanceID =
ctx_.tx[sfMPTokenIssuanceID];
92 if (!sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
93 !sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) ||
94 !sleMptoken->isFieldPresent(sfHolderEncryptionKey))
103 (*sleMptoken)[sfConfidentialBalanceSpending], (*sleMptoken)[sfConfidentialBalanceInbox]);
107 JLOG(
ctx_.journal.error())
108 <<
"ConfidentialMPTMergeInbox failed homomorphic add for inbox merge.";
113 (*sleMptoken)[sfConfidentialBalanceSpending] = std::move(*
sum);
117 auto zeroEncryption =
123 (*sleMptoken)[sfConfidentialBalanceInbox] = std::move(*zeroEncryption);
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
static TER preclaim(PreclaimContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
void visitInvariantEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after) override
static NotTEC preflight(PreflightContext const &ctx)
AccountID const & getIssuer() const
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static auto sum(TCollection const &col)
std::optional< Buffer > encryptCanonicalZeroAmount(Slice const &pubKeySlice, AccountID const &account, MPTID const &mptId)
Generates the canonical zero encryption for a specific MPToken.
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
TERSubset< CanCvtToNotTEC > NotTEC
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
void incrementConfidentialVersion(STObject &mptoken)
Increments the confidential balance version counter on an MPToken.
std::optional< Buffer > homomorphicAdd(Slice const &a, Slice const &b)
Homomorphically adds two ElGamal ciphertexts.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.