Skip to content

Commit

Permalink
Cleanup for consistency with develop and refactoring (mostly XChainBr…
Browse files Browse the repository at this point in the history
…idge.cpp)
  • Loading branch information
gregtatcam committed Jul 23, 2024
1 parent 4528a13 commit eca2d61
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
6 changes: 2 additions & 4 deletions src/xrpld/app/tx/detail/CashCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,13 @@ CashCheck::doApply()
return tecNO_LINE;

SF_AMOUNT const& tweakedLimit = destLow ? sfLowLimit : sfHighLimit;
STAmount const savedLimit =
get<STAmount>(sleTrustLine->at(tweakedLimit));
STEitherAmount const savedLimit = sleTrustLine->at(tweakedLimit);

// Make sure the tweaked limits are restored when we leave scope.
scope_exit fixup(
[&psb, &trustLineKey, &tweakedLimit, &savedLimit]() {
if (auto const sleTrustLine = psb.peek(trustLineKey))
sleTrustLine->at(tweakedLimit) =
STEitherAmount{savedLimit};
sleTrustLine->at(tweakedLimit) = savedLimit;
});

if (checkCashMakesTrustLine)
Expand Down
5 changes: 0 additions & 5 deletions src/xrpld/app/tx/detail/Clawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
//==============================================================================

#include <xrpld/app/tx/detail/Clawback.h>
//#include <xrpl/protocol/Feature.h>
//#include <xrpl/protocol/Indexes.h>
//#include <xrpl/protocol/Protocol.h>
//#include <xrpl/protocol/STEitherAmount.h>
#include <xrpl/protocol/TxFlags.h>
//#include <xrpl/protocol/st.h>

namespace ripple {

Expand Down
20 changes: 9 additions & 11 deletions src/xrpld/app/tx/detail/XChainBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,8 @@ XChainCreateBridge::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;

auto const account = ctx.tx[sfAccount];
auto const reward = get<STAmount>(ctx.tx[sfSignatureReward]);
auto const minAccountCreate =
get<STAmount>(ctx.tx[~sfMinAccountCreateAmount]);
auto const reward = ctx.tx[sfSignatureReward];
auto const minAccountCreate = ctx.tx[~sfMinAccountCreateAmount];
auto const bridgeSpec = ctx.tx[sfXChainBridge];
// Doors must be distinct to help prevent transaction replay attacks
if (bridgeSpec.lockingChainDoor() == bridgeSpec.issuingChainDoor())
Expand Down Expand Up @@ -1569,9 +1568,8 @@ BridgeModify::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;

auto const account = ctx.tx[sfAccount];
auto const reward = get<STAmount>(ctx.tx[~sfSignatureReward]);
auto const minAccountCreate =
get<STAmount>(ctx.tx[~sfMinAccountCreateAmount]);
auto const reward = ctx.tx[~sfSignatureReward];
auto const minAccountCreate = ctx.tx[~sfMinAccountCreateAmount];
auto const bridgeSpec = ctx.tx[sfXChainBridge];
bool const clearAccountCreate =
ctx.tx.getFlags() & tfClearAccountCreateAmount;
Expand Down Expand Up @@ -2033,7 +2031,7 @@ XChainCreateClaimID::preflight(PreflightContext const& ctx)
if (ctx.tx.getFlags() & tfUniversalMask)
return temINVALID_FLAG;

auto const reward = get<STAmount>(ctx.tx[sfSignatureReward]);
auto const reward = ctx.tx[sfSignatureReward];

if (!isXRP(reward) || reward.signum() < 0 || !isLegalNet(reward))
return temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT;
Expand All @@ -2054,9 +2052,9 @@ XChainCreateClaimID::preclaim(PreclaimContext const& ctx)
}

// Check that the reward matches
auto const reward = get<STAmount>(ctx.tx[sfSignatureReward]);
auto const reward = ctx.tx[sfSignatureReward];

if (reward != get<STAmount>((*sleBridge)[sfSignatureReward]))
if (reward != (*sleBridge)[sfSignatureReward])
{
return tecXCHAIN_REWARD_MISMATCH;
}
Expand Down Expand Up @@ -2208,15 +2206,15 @@ XChainCreateAccountCommit::preclaim(PreclaimContext const& ctx)
{
STXChainBridge const bridgeSpec = ctx.tx[sfXChainBridge];
STAmount const amount = get<STAmount>(ctx.tx[sfAmount]);
STAmount const reward = get<STAmount>(ctx.tx[sfSignatureReward]);
STEitherAmount const reward = ctx.tx[sfSignatureReward];

auto const sleBridge = readBridge(ctx.view, bridgeSpec);
if (!sleBridge)
{
return tecNO_ENTRY;
}

if (reward != get<STAmount>((*sleBridge)[sfSignatureReward]))
if (reward != (*sleBridge)[sfSignatureReward])
{
return tecXCHAIN_REWARD_MISMATCH;
}
Expand Down
9 changes: 5 additions & 4 deletions src/xrpld/ledger/detail/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,9 @@ trustCreate(
bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
sleRippleState->setFieldAmount(
bSetHigh ? sfLowLimit : sfHighLimit,
STAmount(Issue{
saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
STAmount(
{saBalance.getCurrency(),
bSetDst ? uSrcAccountID : uDstAccountID}));

if (uQualityIn)
sleRippleState->setFieldU32(
Expand Down Expand Up @@ -1135,7 +1136,7 @@ rippleCredit(
return tesSUCCESS;
}

STAmount const saReceiverLimit(Issue{currency, uReceiverID});
STAmount const saReceiverLimit({currency, uReceiverID});
STAmount saBalance{saAmount};

saBalance.setIssuer(noAccount());
Expand Down Expand Up @@ -1533,7 +1534,7 @@ issueIOU(
// NIKB TODO: The limit uses the receiver's account as the issuer and
// this is unnecessarily inefficient as copying which could be avoided
// is now required. Consider available options.
STAmount const limit(Issue{issue.currency, account});
STAmount const limit({issue.currency, account});
STAmount final_balance = amount;

final_balance.setIssuer(noAccount());
Expand Down

0 comments on commit eca2d61

Please sign in to comment.