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 ripple {
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) &&
36 (ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
37 {
38 return temBAD_REGKEY;
39 }
40
41 return tesSUCCESS;
42}
43
44TER
46{
47 auto const sle = view().peek(keylet::account(account_));
48 if (!sle)
49 return tefINTERNAL; // LCOV_EXCL_LINE
50
51 if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags()))
52 sle->setFlag(lsfPasswordSpent);
53
54 if (ctx_.tx.isFieldPresent(sfRegularKey))
55 {
56 sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
57 }
58 else
59 {
60 // Account has disabled master key and no multi-signer signer list.
61 if (sle->isFlag(lsfDisableMaster) &&
64
65 sle->makeFieldAbsent(sfRegularKey);
66 }
67
68 ctx_.view().update(sle);
69
70 return tesSUCCESS;
71}
72
73} // namespace ripple
ApplyView & view()
Application & app
XRPAmount const baseFee
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:43
A view into a ledger.
Definition ReadView.h:32
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
Blob getSigningPubKey() const
Definition STTx.h:224
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
static NotTEC preflight(PreflightContext const &ctx)
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
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...
AccountID const account_
Definition Transactor.h:128
ApplyView & view()
Definition Transactor.h:144
ApplyContext & ctx_
Definition Transactor.h:124
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:311
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ lsfPasswordSpent
@ lsfDisableMaster
AccountID calcAccountID(PublicKey const &pk)
@ tefINTERNAL
Definition TER.h:154
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
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:225
@ tecNO_ALTERNATIVE_KEY
Definition TER.h:278
@ tesSUCCESS
Definition TER.h:226
@ temBAD_REGKEY
Definition TER.h:79
State information when preflighting a tx.
Definition Transactor.h:16