mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-30 02:20:39 +00:00
103 lines
2.4 KiB
C++
103 lines
2.4 KiB
C++
#include <xrpl/tx/transactors/account/SetRegularKey.h>
|
|
|
|
#include <xrpl/basics/Slice.h>
|
|
#include <xrpl/beast/utility/Journal.h>
|
|
#include <xrpl/ledger/ReadView.h>
|
|
#include <xrpl/protocol/Indexes.h>
|
|
#include <xrpl/protocol/LedgerFormats.h>
|
|
#include <xrpl/protocol/PublicKey.h>
|
|
#include <xrpl/protocol/SField.h>
|
|
#include <xrpl/protocol/STLedgerEntry.h>
|
|
#include <xrpl/protocol/STTx.h>
|
|
#include <xrpl/protocol/TER.h>
|
|
#include <xrpl/protocol/XRPAmount.h>
|
|
#include <xrpl/tx/Transactor.h>
|
|
|
|
#include <memory>
|
|
|
|
namespace xrpl {
|
|
|
|
XRPAmount
|
|
SetRegularKey::calculateBaseFee(ReadView const& view, STTx const& tx)
|
|
{
|
|
auto const id = tx.getAccountID(sfAccount);
|
|
auto const spk = tx.getSigningPubKey();
|
|
|
|
if (publicKeyType(makeSlice(spk)))
|
|
{
|
|
if (calcAccountID(PublicKey(makeSlice(spk))) == id)
|
|
{
|
|
auto const sle = view.read(keylet::account(id));
|
|
|
|
if (sle && ((sle->getFlags() & lsfPasswordSpent) == 0u))
|
|
{
|
|
// flag is armed and they signed with the right account
|
|
return XRPAmount{0};
|
|
}
|
|
}
|
|
}
|
|
|
|
return Transactor::calculateBaseFee(view, tx);
|
|
}
|
|
|
|
NotTEC
|
|
SetRegularKey::preflight(PreflightContext const& ctx)
|
|
{
|
|
if (ctx.tx.isFieldPresent(sfRegularKey) &&
|
|
(ctx.tx.getAccountID(sfRegularKey) == ctx.tx.getAccountID(sfAccount)))
|
|
{
|
|
return temBAD_REGKEY;
|
|
}
|
|
|
|
return tesSUCCESS;
|
|
}
|
|
|
|
TER
|
|
SetRegularKey::doApply()
|
|
{
|
|
auto const sle = view().peek(keylet::account(account_));
|
|
if (!sle)
|
|
return tefINTERNAL; // LCOV_EXCL_LINE
|
|
|
|
if (!minimumFee(ctx_.registry, ctx_.baseFee, view().fees(), view().flags()))
|
|
sle->setFlag(lsfPasswordSpent);
|
|
|
|
if (ctx_.tx.isFieldPresent(sfRegularKey))
|
|
{
|
|
sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
|
|
}
|
|
else
|
|
{
|
|
// Account has disabled master key and no multi-signer signer list.
|
|
if (sle->isFlag(lsfDisableMaster) && !view().peek(keylet::signers(account_)))
|
|
return tecNO_ALTERNATIVE_KEY;
|
|
|
|
sle->makeFieldAbsent(sfRegularKey);
|
|
}
|
|
|
|
ctx_.view().update(sle);
|
|
|
|
return tesSUCCESS;
|
|
}
|
|
|
|
void
|
|
SetRegularKey::visitInvariantEntry(
|
|
bool,
|
|
std::shared_ptr<SLE const> const&,
|
|
std::shared_ptr<SLE const> const&)
|
|
{
|
|
}
|
|
|
|
bool
|
|
SetRegularKey::finalizeInvariants(
|
|
STTx const&,
|
|
TER,
|
|
XRPAmount,
|
|
ReadView const&,
|
|
beast::Journal const&)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
} // namespace xrpl
|