xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
tx
transactors
account
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
16
namespace
xrpl
{
17
18
XRPAmount
19
SetRegularKey::calculateBaseFee
(
ReadView
const
&
view
,
STTx
const
& tx)
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
38
return
Transactor::calculateBaseFee
(
view
, tx);
39
}
40
41
NotTEC
42
SetRegularKey::preflight
(
PreflightContext
const
& ctx)
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
53
TER
54
SetRegularKey::doApply
()
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_
)))
71
return
tecNO_ALTERNATIVE_KEY
;
72
73
sle->makeFieldAbsent(sfRegularKey);
74
}
75
76
ctx_
.view().update(sle);
77
78
return
tesSUCCESS
;
79
}
80
81
void
82
SetRegularKey::visitInvariantEntry
(
bool
,
SLE::ConstRef
,
SLE::ConstRef
)
83
{
84
// No transaction-specific invariants yet (future work).
85
}
86
87
bool
88
SetRegularKey::finalizeInvariants
(
89
STTx
const
&,
90
TER
,
91
XRPAmount
,
92
ReadView
const
&,
93
beast::Journal
const
&)
94
{
95
// No transaction-specific invariants yet (future work).
96
return
true
;
97
}
98
99
}
// namespace xrpl
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
xrpl::ApplyView::peek
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
xrpl::PublicKey
A public key.
Definition
PublicKey.h:53
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::STLedgerEntry::ConstRef
std::shared_ptr< STLedgerEntry const > const & ConstRef
Definition
STLedgerEntry.h:37
xrpl::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition
STObject.cpp:464
xrpl::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition
STObject.cpp:643
xrpl::STTx
Definition
STTx.h:43
xrpl::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition
STTx.h:256
xrpl::SetRegularKey::visitInvariantEntry
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
Definition
SetRegularKey.cpp:82
xrpl::SetRegularKey::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition
SetRegularKey.cpp:42
xrpl::SetRegularKey::doApply
TER doApply() override
Definition
SetRegularKey.cpp:54
xrpl::SetRegularKey::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition
SetRegularKey.cpp:19
xrpl::SetRegularKey::finalizeInvariants
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.
Definition
SetRegularKey.cpp:88
xrpl::Transactor::minimumFee
static XRPAmount minimumFee(ServiceRegistry ®istry, 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:507
xrpl::Transactor::view
ApplyView & view()
Definition
Transactor.h:184
xrpl::Transactor::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition
Transactor.cpp:450
xrpl::Transactor::accountID_
AccountID const accountID_
Definition
Transactor.h:166
xrpl::Transactor::ctx_
ApplyContext & ctx_
Definition
Transactor.h:162
xrpl::XRPAmount
Definition
XRPAmount.h:28
xrpl::keylet::signerList
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition
Indexes.cpp:348
xrpl::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition
Indexes.cpp:220
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::tefINTERNAL
@ tefINTERNAL
Definition
TER.h:168
xrpl::publicKeyType
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition
PublicKey.cpp:209
xrpl::makeSlice
Slice makeSlice(std::array< T, N > const &a)
Definition
Slice.h:228
xrpl::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition
TER.h:614
xrpl::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition
AccountID.cpp:149
xrpl::temBAD_REGKEY
@ temBAD_REGKEY
Definition
TER.h:86
xrpl::TER
TERSubset< CanCvtToTER > TER
Definition
TER.h:654
xrpl::tecNO_ALTERNATIVE_KEY
@ tecNO_ALTERNATIVE_KEY
Definition
TER.h:304
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:250
xrpl::PreflightContext
State information when preflighting a tx.
Definition
Transactor.h:39
xrpl::PreflightContext::tx
STTx const & tx
Definition
Transactor.h:42
Generated by
1.17.0