xrpld
Loading...
Searching...
No Matches
SetRegularKey.cpp
1#include <xrpl/tx/transactors/account/SetRegularKey.h>
2
3#include <xrpl/basics/Slice.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/Indexes.h>
7#include <xrpl/protocol/LedgerFormats.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/STTx.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/XRPAmount.h>
14#include <xrpl/tx/Transactor.h>
15
16namespace xrpl {
17
20{
21 auto const id = tx.getAccountID(sfAccount);
22 auto const spk = tx.getSigningPubKey();
23
24 if (publicKeyType(makeSlice(spk)))
25 {
26 if (calcAccountID(PublicKey(makeSlice(spk))) == id)
27 {
28 auto const sle = view.read(keylet::account(id));
29
30 if (sle && !sle->isFlag(lsfPasswordSpent))
31 {
32 // flag is armed and they signed with the right account
33 return XRPAmount{0};
34 }
35 }
36 }
37
39}
40
43{
44 if (ctx.tx.isFieldPresent(sfRegularKey) &&
45 (ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
46 {
47 return temBAD_REGKEY;
48 }
49
50 return tesSUCCESS;
51}
52
53TER
55{
56 auto const sle = view().peek(keylet::account(accountID_));
57 if (!sle)
58 return tefINTERNAL; // LCOV_EXCL_LINE
59
60 if (!minimumFee(ctx_.registry, ctx_.baseFee, view().fees(), view().flags()))
61 sle->setFlag(lsfPasswordSpent);
62
63 if (ctx_.tx.isFieldPresent(sfRegularKey))
64 {
65 sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
66 }
67 else
68 {
69 // Account has disabled master key and no multi-signer signer list.
70 if (sle->isFlag(lsfDisableMaster) && !view().peek(keylet::signerList(accountID_)))
72
73 sle->makeFieldAbsent(sfRegularKey);
74 }
75
76 ctx_.view().update(sle);
77
78 return tesSUCCESS;
79}
80
81void
83{
84 // No transaction-specific invariants yet (future work).
85}
86
87bool
89 STTx const&,
90 TER,
92 ReadView const&,
93 beast::Journal const&)
94{
95 // No transaction-specific invariants yet (future work).
96 return true;
97}
98
99} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
A public key.
Definition PublicKey.h:42
A view into a ledger.
Definition ReadView.h:31
std::shared_ptr< STLedgerEntry const > const & const_ref
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:454
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:633
Blob getSigningPubKey() const
Definition STTx.h:194
static NotTEC preflight(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
TER doApply() override
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
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 minimumFee(ServiceRegistry &registry, XRPAmount baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
ApplyView & view()
Definition Transactor.h:136
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Definition Transactor.h:120
ApplyContext & ctx_
Definition Transactor.h:116
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:316
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:163
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
AccountID calcAccountID(PublicKey const &pk)
@ temBAD_REGKEY
Definition TER.h:84
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecNO_ALTERNATIVE_KEY
Definition TER.h:294
@ tesSUCCESS
Definition TER.h:240
std::enable_if_t< std::is_same_v< T, char >||std::is_same_v< T, unsigned char >, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:215
State information when preflighting a tx.
Definition Transactor.h:18