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#include <xrpl/basics/Log.h>
22#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/TxFlags.h>
24
25namespace ripple {
26
27XRPAmount
29{
30 auto const id = tx.getAccountID(sfAccount);
31 auto const spk = tx.getSigningPubKey();
32
33 if (publicKeyType(makeSlice(spk)))
34 {
35 if (calcAccountID(PublicKey(makeSlice(spk))) == id)
36 {
37 auto const sle = view.read(keylet::account(id));
38
39 if (sle && (!(sle->getFlags() & lsfPasswordSpent)))
40 {
41 // flag is armed and they signed with the right account
42 return XRPAmount{0};
43 }
44 }
45 }
46
48}
49
52{
53 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
54 return ret;
55
56 std::uint32_t const uTxFlags = ctx.tx.getFlags();
57
58 if (uTxFlags & tfUniversalMask)
59 {
60 JLOG(ctx.j.trace()) << "Malformed transaction: Invalid flags set.";
61
62 return temINVALID_FLAG;
63 }
64
65 if (ctx.rules.enabled(fixMasterKeyAsRegularKey) &&
66 ctx.tx.isFieldPresent(sfRegularKey) &&
67 (ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
68 {
69 return temBAD_REGKEY;
70 }
71
72 return preflight2(ctx);
73}
74
75TER
77{
78 auto const sle = view().peek(keylet::account(account_));
79 if (!sle)
80 return tefINTERNAL;
81
82 if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags()))
83 sle->setFlag(lsfPasswordSpent);
84
85 if (ctx_.tx.isFieldPresent(sfRegularKey))
86 {
87 sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
88 }
89 else
90 {
91 // Account has disabled master key and no multi-signer signer list.
92 if (sle->isFlag(lsfDisableMaster) &&
95
96 sle->makeFieldAbsent(sfRegularKey);
97 }
98
99 ctx_.view().update(sle);
100
101 return tesSUCCESS;
102}
103
104} // namespace ripple
Stream trace() const
Severity stream access functions.
Definition: Journal.h:311
ApplyView & view()
Definition: ApplyContext.h:54
Application & app
Definition: ApplyContext.h:47
XRPAmount const baseFee
Definition: ApplyContext.h:50
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:62
A view into a ledger.
Definition: ReadView.h:55
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:122
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:621
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:454
std::uint32_t getFlags() const
Definition: STObject.cpp:507
Blob getSigningPubKey() const
Definition: STTx.h:187
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:194
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:212
AccountID const account_
Definition: Transactor.h:91
ApplyView & view()
Definition: Transactor.h:107
ApplyContext & ctx_
Definition: Transactor.h:88
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:160
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition: Indexes.cpp:306
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ lsfPasswordSpent
@ lsfDisableMaster
bool isTesSuccess(TER x)
Definition: TER.h:656
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:82
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:160
@ tefINTERNAL
Definition: TER.h:173
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:134
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:243
@ tecNO_ALTERNATIVE_KEY
Definition: TER.h:283
@ tesSUCCESS
Definition: TER.h:242
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:62
@ temBAD_REGKEY
Definition: TER.h:98
@ temINVALID_FLAG
Definition: TER.h:111
State information when preflighting a tx.
Definition: Transactor.h:32
beast::Journal const j
Definition: Transactor.h:38