rippled
Loading...
Searching...
No Matches
SetRegularKey.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/SetRegularKey.h>
21
22#include <xrpl/basics/Log.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25
26namespace ripple {
27
28XRPAmount
30{
31 auto const id = tx.getAccountID(sfAccount);
32 auto const spk = tx.getSigningPubKey();
33
34 if (publicKeyType(makeSlice(spk)))
35 {
36 if (calcAccountID(PublicKey(makeSlice(spk))) == id)
37 {
38 auto const sle = view.read(keylet::account(id));
39
40 if (sle && (!(sle->getFlags() & lsfPasswordSpent)))
41 {
42 // flag is armed and they signed with the right account
43 return XRPAmount{0};
44 }
45 }
46 }
47
49}
50
53{
54 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
55 return ret;
56
57 std::uint32_t const uTxFlags = ctx.tx.getFlags();
58
59 if (uTxFlags & tfUniversalMask)
60 {
61 JLOG(ctx.j.trace()) << "Malformed transaction: Invalid flags set.";
62
63 return temINVALID_FLAG;
64 }
65
66 if (ctx.rules.enabled(fixMasterKeyAsRegularKey) &&
67 ctx.tx.isFieldPresent(sfRegularKey) &&
68 (ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
69 {
70 return temBAD_REGKEY;
71 }
72
73 return preflight2(ctx);
74}
75
76TER
78{
79 auto const sle = view().peek(keylet::account(account_));
80 if (!sle)
81 return tefINTERNAL;
82
83 if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags()))
84 sle->setFlag(lsfPasswordSpent);
85
86 if (ctx_.tx.isFieldPresent(sfRegularKey))
87 {
88 sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
89 }
90 else
91 {
92 // Account has disabled master key and no multi-signer signer list.
93 if (sle->isFlag(lsfDisableMaster) &&
96
97 sle->makeFieldAbsent(sfRegularKey);
98 }
99
100 ctx_.view().update(sle);
101
102 return tesSUCCESS;
103}
104
105} // namespace ripple
Stream trace() const
Severity stream access functions.
Definition: Journal.h:322
ApplyView & view()
Definition: ApplyContext.h:78
Application & app
Definition: ApplyContext.h:71
XRPAmount const baseFee
Definition: ApplyContext.h:74
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:61
A view into a ledger.
Definition: ReadView.h:52
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:651
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:484
std::uint32_t getFlags() const
Definition: STObject.cpp:537
Blob getSigningPubKey() const
Definition: STTx.h:213
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
TER doApply() override
static NotTEC preflight(PreflightContext const &ctx)
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:230
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...
Definition: Transactor.cpp:248
AccountID const account_
Definition: Transactor.h:143
ApplyView & view()
Definition: Transactor.h:159
ApplyContext & ctx_
Definition: Transactor.h:140
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:184
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition: Indexes.cpp:330
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
@ lsfPasswordSpent
@ lsfDisableMaster
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:91
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:168
@ tefINTERNAL
Definition: TER.h:173
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:223
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:160
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:244
@ tecNO_ALTERNATIVE_KEY
Definition: TER.h:296
@ tesSUCCESS
Definition: TER.h:244
bool isTesSuccess(TER x) noexcept
Definition: TER.h:674
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:63
@ temBAD_REGKEY
Definition: TER.h:98
@ temINVALID_FLAG
Definition: TER.h:111
State information when preflighting a tx.
Definition: Transactor.h:34
beast::Journal const j
Definition: Transactor.h:41