1#include <xrpl/ledger/ApplyView.h>
2#include <xrpl/ledger/helpers/AccountRootHelpers.h>
3#include <xrpl/ledger/helpers/DirectoryHelpers.h>
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/STArray.h>
7#include <xrpl/protocol/STObject.h>
8#include <xrpl/protocol/STTx.h>
9#include <xrpl/protocol/TxFlags.h>
10#include <xrpl/tx/transactors/account/SignerListSet.h>
27 auto const quorum = tx[sfSignerQuorum];
32 if ((quorum != 0u) && hasSignerEntries)
39 std::sort(signers->begin(), signers->end());
42 sign = std::move(*signers);
45 else if ((quorum == 0) && !hasSignerEntries)
71 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Invalid signer set list format.";
106 UNREACHABLE(
"xrpl::SignerListSet::doApply : invalid operation");
118 "xrpl::SignerListSet::preCompute : result is tesSUCCESS");
121 "xrpl::SignerListSet::preCompute : result is known operation");
152 "xrpl::signerCountBasedOwnerCountDelta : minimum signers");
155 "xrpl::signerCountBasedOwnerCountDelta : maximum signers");
156 return 2 +
static_cast<int>(entryCount);
163 Keylet const& accountKeylet,
164 Keylet const& ownerDirKeylet,
165 Keylet const& signerListKeylet,
179 int removeFromOwnerCount = -1;
180 if ((signers->getFlags() & lsfOneOwnerCount) == 0)
182 STArray const& actualList = signers->getFieldArray(sfSignerEntries);
183 removeFromOwnerCount =
188 auto const hint = (*signers)[sfOwnerNode];
190 if (!view.
dirRemove(ownerDirKeylet, hint, signerListKeylet.
key,
false))
193 JLOG(j.
fatal()) <<
"Unable to delete SignerList from owner.";
199 view, view.
peek(accountKeylet), removeFromOwnerCount, registry.
getJournal(
"View"));
218 registry,
view, accountKeylet, ownerDirKeylet, signerListKeylet, j);
234 JLOG(j.
trace()) <<
"Too many or too few signers in signer list.";
242 "xrpl::SignerListSet::validateQuorumAndSignerEntries : sorted "
246 JLOG(j.
trace()) <<
"Duplicate signers in signer list";
253 for (
auto const& signer : signers)
258 JLOG(j.
trace()) <<
"Every signer must have a positive weight.";
262 allSignersWeight += signer.weight;
264 if (signer.account == account)
266 JLOG(j.
trace()) <<
"A signer may not self reference account.";
272 if ((quorum <= 0) || (allSignersWeight < quorum))
274 JLOG(j.
trace()) <<
"Quorum is unreachable";
294 auto const sle =
view().
peek(accountKeylet);
301 constexpr int addedOwnerCount = 1;
323 << (page ?
"success" :
"failure");
328 signerList->setFieldU64(sfOwnerNode, *page);
346 if ((ledgerEntry->isFlag(lsfDisableMaster)) && (!ledgerEntry->isFieldPresent(sfRegularKey)))
361 ledgerEntry->setAccountID(sfOwner,
account_);
363 ledgerEntry->setFieldU32(sfSignerQuorum,
quorum_);
366 ledgerEntry->setFieldU32(sfFlags, flags);
375 obj[sfAccount] = entry.account;
376 obj[sfSignerWeight] = entry.weight;
385 ledgerEntry->setFieldArray(sfSignerEntries, toLedger);
T adjacent_find(T... args)
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
std::reference_wrapper< ServiceRegistry > registry
Writeable view to a ledger, for applying a transaction.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void push_back(STObject const &object)
void reserve(std::size_t n)
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
AccountID getAccountID(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
static constexpr std::size_t minMultiSigners
static constexpr std::size_t maxMultiSigners
Service registry for dependency injection.
virtual beast::Journal getJournal(std::string const &name)=0
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
static NotTEC preflight(PreflightContext const &ctx)
void preCompute() override
static std::tuple< NotTEC, std::uint32_t, std::vector< SignerEntries::SignerEntry >, Operation > determineOperation(STTx const &tx, ApplyFlags flags, beast::Journal j)
static NotTEC validateQuorumAndSignerEntries(std::uint32_t quorum, std::vector< SignerEntries::SignerEntry > const &signers, AccountID const &account, beast::Journal j, Rules const &)
std::vector< SignerEntries::SignerEntry > signers_
static TER removeFromLedger(ServiceRegistry ®istry, ApplyView &view, AccountID const &account, beast::Journal j)
void writeSignersToSLE(SLE::pointer const &ledgerEntry, std::uint32_t flags) const
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
virtual void preCompute()
Keylet signers(AccountID const &account) noexcept
A SignerList.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
static int signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const &rules)
bool isTesSuccess(TER x) noexcept
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
@ tecINSUFFICIENT_RESERVE
static std::uint32_t const DEFAULT_SIGNER_LIST_ID
constexpr FlagValue tfUniversalMask
static TER removeSignersFromLedger(ServiceRegistry ®istry, ApplyView &view, Keylet const &accountKeylet, Keylet const &ownerDirKeylet, Keylet const &signerListKeylet, beast::Journal j)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when preflighting a tx.