rippled
Loading...
Searching...
No Matches
SetRegularKey.cpp
1#include <xrpld/app/tx/detail/SetRegularKey.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/TxFlags.h>
6
7namespace xrpl {
8
9XRPAmount
11{
12 auto const id = tx.getAccountID(sfAccount);
13 auto const spk = tx.getSigningPubKey();
14
15 if (publicKeyType(makeSlice(spk)))
16 {
17 if (calcAccountID(PublicKey(makeSlice(spk))) == id)
18 {
19 auto const sle = view.read(keylet::account(id));
20
21 if (sle && (!(sle->getFlags() & lsfPasswordSpent)))
22 {
23 // flag is armed and they signed with the right account
24 return XRPAmount{0};
25 }
26 }
27 }
28
30}
31
34{
35 if (ctx.tx.isFieldPresent(sfRegularKey) && (ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
36 {
37 return temBAD_REGKEY;
38 }
39
40 return tesSUCCESS;
41}
42
43TER
45{
46 auto const sle = view().peek(keylet::account(account_));
47 if (!sle)
48 return tefINTERNAL; // LCOV_EXCL_LINE
49
50 if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags()))
51 sle->setFlag(lsfPasswordSpent);
52
53 if (ctx_.tx.isFieldPresent(sfRegularKey))
54 {
55 sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
56 }
57 else
58 {
59 // Account has disabled master key and no multi-signer signer list.
60 if (sle->isFlag(lsfDisableMaster) && !view().peek(keylet::signers(account_)))
62
63 sle->makeFieldAbsent(sfRegularKey);
64 }
65
66 ctx_.view().update(sle);
67
68 return tesSUCCESS;
69}
70
71} // namespace xrpl
STTx const & tx
XRPAmount const baseFee
ApplyView & view()
Application & app
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > 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
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
Blob getSigningPubKey() const
Definition STTx.h:186
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const account_
Definition Transactor.h:112
static XRPAmount minimumFee(Application &app, 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:128
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
ApplyContext & ctx_
Definition Transactor.h:108
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:287
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:153
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
AccountID calcAccountID(PublicKey const &pk)
@ temBAD_REGKEY
Definition TER.h:78
@ tecNO_ALTERNATIVE_KEY
Definition TER.h:277
@ lsfPasswordSpent
@ lsfDisableMaster
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:213
@ tesSUCCESS
Definition TER.h:225
State information when preflighting a tx.
Definition Transactor.h:15