This commit is contained in:
dangell7
2023-01-19 12:56:44 -05:00
parent b99e445c56
commit 4c633995f5
2 changed files with 132 additions and 198 deletions

View File

@@ -30,11 +30,10 @@
#include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Rate.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/st.h>
#include <ripple/protocol/Rate.h>
// During an EscrowFinish, the transaction must specify both
// a condition and a fulfillment. We track whether that
@@ -95,8 +94,8 @@ after(NetClock::time_point now, std::uint32_t mark)
TxConsequences
EscrowCreate::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx,
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
return TxConsequences{
ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
}
NotTEC
@@ -108,7 +107,7 @@ EscrowCreate::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;
STAmount const amount {ctx.tx[sfAmount]};
STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount))
{
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -218,7 +217,7 @@ EscrowCreate::doApply()
if (!sle)
return temDISABLED;
STAmount const amount {ctx_.tx[sfAmount]};
STAmount const amount{ctx_.tx[sfAmount]};
std::shared_ptr<SLE> sleLine;
@@ -246,8 +245,7 @@ EscrowCreate::doApply()
// check if the escrow is capable of being
// finished before we allow it to be created
{
TER result =
trustTransferAllowed(
TER result = trustTransferAllowed(
ctx_.view(),
{account, ctx_.tx[sfDestination]},
amount.issue(),
@@ -263,20 +261,16 @@ EscrowCreate::doApply()
// perform the lock as a dry run before
// we modify anything on-ledger
sleLine = ctx_.view().peek(keylet::line(account, amount.getIssuer(), amount.getCurrency()));
sleLine = ctx_.view().peek(
keylet::line(account, amount.getIssuer(), amount.getCurrency()));
{
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
DryRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, amount, 1, ctx_.journal, DryRun);
JLOG(ctx_.journal.trace())
<< "EscrowCreate::doApply trustAdjustLockedBalance (dry) result="
<< "EscrowCreate::doApply trustAdjustLockedBalance (dry) "
"result="
<< result;
if (!isTesSuccess(result))
@@ -296,8 +290,8 @@ EscrowCreate::doApply()
// Obeying the lsfDissalowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
if (!ctx_.view().rules().enabled(featureDepositAuth) &&
isXRP(amount) && ((*sled)[sfFlags] & lsfDisallowXRP))
if (!ctx_.view().rules().enabled(featureDepositAuth) && isXRP(amount) &&
((*sled)[sfFlags] & lsfDisallowXRP))
return tecNO_TARGET;
}
@@ -341,18 +335,13 @@ EscrowCreate::doApply()
(*sle)[sfBalance] = (*sle)[sfBalance] - ctx_.tx[sfAmount];
else
{
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens) || !sleLine)
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens) ||
!sleLine)
return temDISABLED;
// do the lock-up for real now
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
JLOG(ctx_.journal.trace())
<< "EscrowCreate::doApply trustAdjustLockedBalance (wet) result="
@@ -561,7 +550,6 @@ EscrowFinish::doApply()
}
}
if (!isXRP(amount))
{
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
@@ -569,8 +557,7 @@ EscrowFinish::doApply()
// perform a dry run of the transfer before we
// change anything on-ledger
TER result =
trustTransferLockedBalance(
TER result = trustTransferLockedBalance(
ctx_.view(),
account_, // txn signing account
sle, // src account
@@ -611,8 +598,6 @@ EscrowFinish::doApply()
}
}
if (isXRP(amount))
(*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount];
else
@@ -620,8 +605,7 @@ EscrowFinish::doApply()
// all the significant complexity of checking the validity of this
// transfer and ensuring the lines exist etc is hidden away in this
// function, all we need to do is call it and return if unsuccessful.
TER result =
trustTransferLockedBalance(
TER result = trustTransferLockedBalance(
ctx_.view(),
account_, // txn signing account
sle, // src account
@@ -706,19 +690,12 @@ EscrowCancel::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED;
sleLine =
ctx_.view().peek(
sleLine = ctx_.view().peek(
keylet::line(account, amount.getIssuer(), amount.getCurrency()));
// dry run before we make any changes to ledger
if (TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
-amount,
-1,
ctx_.journal,
DryRun);
if (TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, -amount, -1, ctx_.journal, DryRun);
result != tesSUCCESS)
return result;
}
@@ -757,14 +734,8 @@ EscrowCancel::doApply()
return temDISABLED;
// unlock previously locked tokens from source line
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
-amount,
-1,
ctx_.journal,
WetRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, -amount, -1, ctx_.journal, WetRun);
JLOG(ctx_.journal.trace())
<< "EscrowCancel::doApply trustAdjustLockedBalance (wet) result="

View File

@@ -129,21 +129,14 @@ closeChannel(
if (!view.rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED;
sleLine =
view.peek(keylet::line(src, amount.getIssuer(), amount.getCurrency()));
sleLine = view.peek(
keylet::line(src, amount.getIssuer(), amount.getCurrency()));
// dry run
TER result =
trustAdjustLockedBalance(
view,
sleLine,
-amount,
-1,
j,
DryRun);
trustAdjustLockedBalance(view, sleLine, -amount, -1, j, DryRun);
JLOG(j.trace())
<< "closeChannel: trustAdjustLockedBalance(dry) result="
JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(dry) result="
<< result;
if (!isTesSuccess(result))
@@ -186,16 +179,9 @@ closeChannel(
else
{
TER result =
trustAdjustLockedBalance(
view,
sleLine,
-amount,
-1,
j,
WetRun);
trustAdjustLockedBalance(view, sleLine, -amount, -1, j, WetRun);
JLOG(j.trace())
<< "closeChannel: trustAdjustLockedBalance(wet) result="
JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(wet) result="
<< result;
if (!isTesSuccess(result))
@@ -215,8 +201,8 @@ closeChannel(
TxConsequences
PayChanCreate::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx,
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
return TxConsequences{
ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
}
NotTEC
@@ -228,7 +214,7 @@ PayChanCreate::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;
STAmount const amount {ctx.tx[sfAmount]};
STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount))
{
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -268,7 +254,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
if (!sle)
return terNO_ACCOUNT;
STAmount const amount {ctx.tx[sfAmount]};
STAmount const amount{ctx.tx[sfAmount]};
auto const balance = (*sle)[sfBalance];
auto const reserve =
@@ -284,19 +270,16 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
{
return tecUNFUNDED;
}
else if (!isXRP(amount)) {
else if (!isXRP(amount))
{
if (!ctx.view.rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED;
// check for any possible bars to a channel existing
// between these accounts for this asset
{
TER result =
trustTransferAllowed(
ctx.view,
{account, dst},
amount.issue(),
ctx.j);
TER result = trustTransferAllowed(
ctx.view, {account, dst}, amount.issue(), ctx.j);
JLOG(ctx.j.trace())
<< "PayChanCreate::preclaim trustTransferAllowed result="
<< result;
@@ -307,20 +290,13 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
// check if the amount can be locked
{
auto sleLine =
ctx.view.read(
keylet::line(account, amount.getIssuer(), amount.getCurrency()));
TER result =
trustAdjustLockedBalance(
ctx.view,
sleLine,
amount,
1,
ctx.j,
DryRun);
auto sleLine = ctx.view.read(keylet::line(
account, amount.getIssuer(), amount.getCurrency()));
TER result = trustAdjustLockedBalance(
ctx.view, sleLine, amount, 1, ctx.j, DryRun);
JLOG(ctx.j.trace())
<< "PayChanCreate::preclaim trustAdjustLockedBalance(dry) result="
JLOG(ctx.j.trace()) << "PayChanCreate::preclaim "
"trustAdjustLockedBalance(dry) result="
<< result;
if (!isTesSuccess(result))
@@ -339,8 +315,8 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
if (!ctx.view.rules().enabled(featureDepositAuth) &&
isXRP(amount) && ((*sled)[sfFlags] & lsfDisallowXRP))
if (!ctx.view.rules().enabled(featureDepositAuth) && isXRP(amount) &&
((*sled)[sfFlags] & lsfDisallowXRP))
return tecNO_TARGET;
}
@@ -357,7 +333,7 @@ PayChanCreate::doApply()
auto const dst = ctx_.tx[sfDestination];
STAmount const amount {ctx_.tx[sfAmount]};
STAmount const amount{ctx_.tx[sfAmount]};
// Create PayChan in ledger.
//
@@ -410,20 +386,14 @@ PayChanCreate::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED;
auto sleLine =
ctx_.view().peek(keylet::line(account, amount.getIssuer(), amount.getCurrency()));
auto sleLine = ctx_.view().peek(
keylet::line(account, amount.getIssuer(), amount.getCurrency()));
if (!sleLine)
return tecNO_LINE;
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
JLOG(ctx_.journal.trace())
<< "PayChanCreate::doApply trustAdjustLockedBalance(wet) result="
@@ -444,8 +414,8 @@ PayChanCreate::doApply()
TxConsequences
PayChanFund::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx,
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
return TxConsequences{
ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
}
NotTEC
@@ -457,7 +427,7 @@ PayChanFund::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;
STAmount const amount {ctx.tx[sfAmount]};
STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount))
{
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -491,7 +461,7 @@ PayChanFund::doApply()
if (!slep)
return tecNO_ENTRY;
STAmount const amount {ctx_.tx[sfAmount]};
STAmount const amount{ctx_.tx[sfAmount]};
std::shared_ptr<SLE> sleLine; // if XRP or featurePaychanAndEscrowForTokens
// not enabled this remains null
@@ -500,20 +470,11 @@ PayChanFund::doApply()
if (!isXRP(amount) &&
ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
{
sleLine = ctx_.view().peek(
keylet::line(
(*slep)[sfAccount],
amount.getIssuer(),
amount.getCurrency()));
sleLine = ctx_.view().peek(keylet::line(
(*slep)[sfAccount], amount.getIssuer(), amount.getCurrency()));
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
DryRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, amount, 1, ctx_.journal, DryRun);
JLOG(ctx_.journal.trace())
<< "PayChanFund::doApply trustAdjustLockedBalance(dry) result="
@@ -586,14 +547,8 @@ PayChanFund::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED;
TER result =
trustAdjustLockedBalance(
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
TER result = trustAdjustLockedBalance(
ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
JLOG(ctx_.journal.trace())
<< "PayChanFund::doApply trustAdjustLockedBalance(wet) result="
@@ -620,7 +575,8 @@ PayChanClaim::preflight(PreflightContext const& ctx)
auto const bal = ctx.tx[~sfBalance];
if (bal)
{
if (!isXRP(*bal) && !ctx.rules.enabled(featurePaychanAndEscrowForTokens))
if (!isXRP(*bal) &&
!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
return temBAD_AMOUNT;
if (*bal <= beast::zero)
@@ -631,7 +587,8 @@ PayChanClaim::preflight(PreflightContext const& ctx)
if (amt)
{
if (!isXRP(*amt) && !ctx.rules.enabled(featurePaychanAndEscrowForTokens))
if (!isXRP(*amt) &&
!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
return temBAD_AMOUNT;
if (*amt <= beast::zero)
@@ -676,7 +633,12 @@ PayChanClaim::preflight(PreflightContext const& ctx)
if (isXRP(authAmt))
serializePayChanAuthorization(msg, k.key, authAmt.xrp());
else
serializePayChanAuthorization(msg, k.key, authAmt.iou(), authAmt.getCurrency(), authAmt.getIssuer());
serializePayChanAuthorization(
msg,
k.key,
authAmt.iou(),
authAmt.getCurrency(),
authAmt.getIssuer());
if (!verify(pk, msg.slice(), *sig, /*canonical*/ true))
return temBAD_SIGNATURE;
@@ -741,7 +703,8 @@ PayChanClaim::doApply()
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
bool const depositAuth{ctx_.view().rules().enabled(featureDepositAuth)};
if (!depositAuth && chanBalance.native() && (txAccount == src && (sled->getFlags() & lsfDisallowXRP)))
if (!depositAuth && chanBalance.native() &&
(txAccount == src && (sled->getFlags() & lsfDisallowXRP)))
return tecNO_TARGET;
// Check whether the destination account requires deposit authorization.
@@ -772,8 +735,7 @@ PayChanClaim::doApply()
return temDISABLED;
auto sleSrcAcc = ctx_.view().peek(keylet::account(src));
TER result =
trustTransferLockedBalance(
TER result = trustTransferLockedBalance(
ctx_.view(),
txAccount,
sleSrcAcc,
@@ -784,7 +746,8 @@ PayChanClaim::doApply()
WetRun);
JLOG(ctx_.journal.trace())
<< "PayChanClaim::doApply trustTransferLockedBalance(wet) result="
<< "PayChanClaim::doApply trustTransferLockedBalance(wet) "
"result="
<< result;
if (!isTesSuccess(result))