Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly typed wrapper for Checks Ledger Object #19

Open
wants to merge 1 commit into
base: wrapper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/ripple/app/tx/impl/CancelCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ CancelCheck::preflight(PreflightContext const& ctx)
TER
CancelCheck::preclaim(PreclaimContext const& ctx)
{
auto const sleCheck = ctx.view.readSLE(keylet::check(ctx.tx[sfCheckID]));
if (!sleCheck)
auto const check = ctx.view.read(keylet::check(ctx.tx[sfCheckID]));
if (!check)
{
JLOG(ctx.j.warn()) << "Check does not exist.";
return tecNO_ENTRY;
}

using duration = NetClock::duration;
using timepoint = NetClock::time_point;
auto const optExpiry = (*sleCheck)[~sfExpiration];
auto const optExpiry = check->getCheckExpiration();

// Expiration is defined in terms of the close time of the parent
// ledger, because we definitively know the time that it closed but
Expand All @@ -74,8 +74,8 @@ CancelCheck::preclaim(PreclaimContext const& ctx)
// If the check is not yet expired, then only the creator or the
// destination may cancel the check.
AccountID const acctId{ctx.tx[sfAccount]};
if (acctId != (*sleCheck)[sfAccount] &&
acctId != (*sleCheck)[sfDestination])
if (acctId != check->getCheckCreator() &&
acctId != check->getCheckRecipient())
{
JLOG(ctx.j.warn()) << "Check is not expired and canceler is "
"neither check source nor destination.";
Expand All @@ -88,34 +88,35 @@ CancelCheck::preclaim(PreclaimContext const& ctx)
TER
CancelCheck::doApply()
{
auto const sleCheck = view().peekSLE(keylet::check(ctx_.tx[sfCheckID]));
if (!sleCheck)
std::optional<Checks> check =
view().peek(keylet::check(ctx_.tx[sfCheckID]));
if (!check)
{
// Error should have been caught in preclaim.
JLOG(j_.warn()) << "Check does not exist.";
return tecNO_ENTRY;
}

AccountID const srcId{sleCheck->getAccountID(sfAccount)};
AccountID const dstId{sleCheck->getAccountID(sfDestination)};
AccountID const srcId{check->getCheckCreator()};
AccountID const dstId{check->getCheckRecipient()};
auto viewJ = ctx_.app.journal("View");

// If the check is not written to self (and it shouldn't be), remove the
// check from the destination account root.
if (srcId != dstId)
{
std::uint64_t const page{(*sleCheck)[sfDestinationNode]};
std::uint64_t const page{check->getDestinationNode()};
if (!view().dirRemove(
keylet::ownerDir(dstId), page, sleCheck->key(), true))
keylet::ownerDir(dstId), page, check->key(), true))
{
JLOG(j_.fatal()) << "Unable to delete check from destination.";
return tefBAD_LEDGER;
}
}
{
std::uint64_t const page{(*sleCheck)[sfOwnerNode]};
std::uint64_t const page{check->getOwnerNode()};
if (!view().dirRemove(
keylet::ownerDir(srcId), page, sleCheck->key(), true))
keylet::ownerDir(srcId), page, check->key(), true))
{
JLOG(j_.fatal()) << "Unable to delete check from owner.";
return tefBAD_LEDGER;
Expand All @@ -127,7 +128,7 @@ CancelCheck::doApply()
adjustOwnerCount(view(), *srcAcctRoot, -1, viewJ);

// Remove check from ledger.
view().erase(sleCheck);
view().erase(*check);
return tesSUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions src/ripple/app/tx/impl/CancelCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define RIPPLE_TX_CANCELCHECK_H_INCLUDED

#include <ripple/app/tx/impl/Transactor.h>
#include <ripple/protocol/Checks.h>

namespace ripple {

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/tx/impl/CreateCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ CreateCheck::doApply()
// Note that we use the value from the sequence or ticket as the
// Check sequence. For more explanation see comments in SeqProxy.h.
std::uint32_t const seq = ctx_.tx.getSeqProxy().value();
Keylet const checkKeylet = keylet::check(account_, seq);
ChecksKeylet const checkKeylet = keylet::check(account_, seq);
auto sleCheck = std::make_shared<SLE>(checkKeylet);

sleCheck->setAccountID(sfAccount, account_);
Expand Down
18 changes: 11 additions & 7 deletions src/ripple/ledger/ApplyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ class ApplyView : public ReadView
erase(std::shared_ptr<SLE> const& sle) = 0;

template <class T>
requires(std::is_convertible_v<
decltype(std::declval<T>().slePtr()),
std::shared_ptr<SLE> const&>) void erase(T& wrapper)
requires(std::is_convertible_v<
decltype(std::declval<T>().slePtr()),
std::shared_ptr<SLE> const&>)
void
erase(T& wrapper)
{
erase(wrapper.slePtr());
}
Expand Down Expand Up @@ -249,9 +251,11 @@ class ApplyView : public ReadView
update(std::shared_ptr<SLE> const& sle) = 0;

template <class T>
requires(std::is_convertible_v<
decltype(std::declval<T>().slePtr()),
std::shared_ptr<SLE> const&>) void update(T& wrapper)
requires(std::is_convertible_v<
decltype(std::declval<T>().slePtr()),
std::shared_ptr<SLE> const&>)
void
update(T& wrapper)
{
update(wrapper.slePtr());
}
Expand Down Expand Up @@ -343,7 +347,7 @@ class ApplyView : public ReadView
std::optional<std::uint64_t>
dirInsert(
Keylet const& directory,
Keylet const& key,
KeyletBase const& key,
std::function<void(std::shared_ptr<SLE> const&)> const& describe)
{
return dirAdd(false, directory, key.key, describe);
Expand Down
69 changes: 46 additions & 23 deletions src/ripple/protocol/AcctRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setSequence(std::uint32_t seq) requires Writable
setSequence(std::uint32_t seq)
requires Writable
{
wrapped_->at(sfSequence) = seq;
}
Expand All @@ -81,7 +82,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setBalance(STAmount const& amount) requires Writable
setBalance(STAmount const& amount)
requires Writable
{
wrapped_->at(sfBalance) = amount;
}
Expand All @@ -93,7 +95,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setOwnerCount(std::uint32_t newCount) requires Writable
setOwnerCount(std::uint32_t newCount)
requires Writable
{
wrapped_->at(sfOwnerCount) = newCount;
}
Expand All @@ -105,7 +108,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setPreviousTxnID(uint256 prevTxID) requires Writable
setPreviousTxnID(uint256 prevTxID)
requires Writable
{
wrapped_->at(sfPreviousTxnID) = prevTxID;
}
Expand All @@ -117,7 +121,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setPreviousTxnLgrSeq(std::uint32_t prevTxLgrSeq) requires Writable
setPreviousTxnLgrSeq(std::uint32_t prevTxLgrSeq)
requires Writable
{
wrapped_->at(sfPreviousTxnLgrSeq) = prevTxLgrSeq;
}
Expand All @@ -129,13 +134,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setAccountTxnID(uint256 const& newAcctTxnID) requires Writable
setAccountTxnID(uint256 const& newAcctTxnID)
requires Writable
{
this->setOptional(sfAccountTxnID, newAcctTxnID);
}

void
clearAccountTxnID() requires Writable
clearAccountTxnID()
requires Writable
{
this->clearOptional(sfAccountTxnID);
}
Expand All @@ -147,13 +154,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setRegularKey(AccountID const& newRegKey) requires Writable
setRegularKey(AccountID const& newRegKey)
requires Writable
{
this->setOptional(sfRegularKey, newRegKey);
}

void
clearRegularKey() requires Writable
clearRegularKey()
requires Writable
{
this->clearOptional(sfRegularKey);
}
Expand All @@ -165,7 +174,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setEmailHash(uint128 const& newEmailHash) requires Writable
setEmailHash(uint128 const& newEmailHash)
requires Writable
{
this->setOrClearBaseUintIfZero(sfEmailHash, newEmailHash);
}
Expand All @@ -177,7 +187,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setWalletLocator(uint256 const& newWalletLocator) requires Writable
setWalletLocator(uint256 const& newWalletLocator)
requires Writable
{
this->setOrClearBaseUintIfZero(sfWalletLocator, newWalletLocator);
}
Expand All @@ -195,7 +206,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setMessageKey(Blob const& newMessageKey) requires Writable
setMessageKey(Blob const& newMessageKey)
requires Writable
{
this->setOrClearVLIfEmpty(sfMessageKey, newMessageKey);
}
Expand All @@ -207,13 +219,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setTransferRate(std::uint32_t newTransferRate) requires Writable
setTransferRate(std::uint32_t newTransferRate)
requires Writable
{
this->setOptional(sfTransferRate, newTransferRate);
}

void
clearTransferRate() requires Writable
clearTransferRate()
requires Writable
{
this->clearOptional(sfTransferRate);
}
Expand All @@ -225,7 +239,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setDomain(Blob const& newDomain) requires Writable
setDomain(Blob const& newDomain)
requires Writable
{
this->setOrClearVLIfEmpty(sfDomain, newDomain);
}
Expand All @@ -237,13 +252,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setTickSize(std::uint8_t newTickSize) requires Writable
setTickSize(std::uint8_t newTickSize)
requires Writable
{
this->setOptional(sfTickSize, newTickSize);
}

void
clearTickSize() requires Writable
clearTickSize()
requires Writable
{
this->clearOptional(sfTickSize);
}
Expand All @@ -255,13 +272,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setTicketCount(std::uint32_t newTicketCount) requires Writable
setTicketCount(std::uint32_t newTicketCount)
requires Writable
{
this->setOptional(sfTicketCount, newTicketCount);
}

void
clearTicketCount() requires Writable
clearTicketCount()
requires Writable
{
this->clearOptional(sfTicketCount);
}
Expand All @@ -273,13 +292,15 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setNFTokenMinter(AccountID const& newMinter) requires Writable
setNFTokenMinter(AccountID const& newMinter)
requires Writable
{
this->setOptional(sfNFTokenMinter, newMinter);
}

void
clearNFTokenMinter() requires Writable
clearNFTokenMinter()
requires Writable
{
this->clearOptional(sfNFTokenMinter);
}
Expand All @@ -291,7 +312,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setMintedNFTokens(std::uint32_t newMintedCount) requires Writable
setMintedNFTokens(std::uint32_t newMintedCount)
requires Writable
{
this->setOptional(sfMintedNFTokens, newMintedCount);
}
Expand All @@ -303,7 +325,8 @@ class AcctRootImpl final : public LedgerEntryWrapper<Writable>
}

void
setBurnedNFTokens(std::uint32_t newBurnedCount) requires Writable
setBurnedNFTokens(std::uint32_t newBurnedCount)
requires Writable
{
this->setOptional(sfBurnedNFTokens, newBurnedCount);
}
Expand Down
Loading