1#include <xrpl/tx/transactors/token/ConfidentialMPTMergeInbox.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/ledger/helpers/TokenHelpers.h>
9#include <xrpl/protocol/ConfidentialTransfer.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>
47 if (!sleIssuance->isFlag(lsfMPTCanHoldConfidentialBalance))
52 if (sleIssuance->getAccountID(sfIssuer) == ctx.
tx[sfAccount])
56 "xrpl::ConfidentialMPTMergeInbox::preclaim : issuer derived from the MPT ID must "
57 "match the ledger's stored issuer");
62 auto const sleMptoken =
67 if (!sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) ||
68 !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
69 !sleMptoken->isFieldPresent(sfHolderEncryptionKey))
75 auto const account = ctx.
tx[sfAccount];
76 MPTIssue const mptIssue(ctx.
tx[sfMPTokenIssuanceID]);
90 auto const mptIssuanceID =
ctx_.tx[sfMPTokenIssuanceID];
96 "xrpl::ConfidentialMPTMergeInbox::doApply : preclaim already validated the "
103 if (!sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
104 !sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) ||
105 !sleMptoken->isFieldPresent(sfHolderEncryptionKey))
109 "xrpl::ConfidentialMPTMergeInbox::doApply : preclaim already validated these "
110 "fields are present");
119 (*sleMptoken)[sfConfidentialBalanceSpending], (*sleMptoken)[sfConfidentialBalanceInbox]);
123 JLOG(
ctx_.journal.error())
124 <<
"ConfidentialMPTMergeInbox failed homomorphic add for inbox merge.";
129 (*sleMptoken)[sfConfidentialBalanceSpending] = std::move(*
sum);
133 auto zeroEncryption =
140 "xrpl::ConfidentialMPTMergeInbox::doApply : canonical zero encryption cannot fail "
141 "for an already-valid holder public key");
146 (*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.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) 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.