This commit is contained in:
dangell7
2023-01-19 12:56:44 -05:00
committed by Richard Holland
parent c008c1e951
commit 6f43313393
2 changed files with 130 additions and 197 deletions

View File

@@ -30,11 +30,10 @@
#include <ripple/ledger/View.h> #include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h> #include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Rate.h>
#include <ripple/protocol/TxFlags.h> #include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/digest.h> #include <ripple/protocol/digest.h>
#include <ripple/protocol/st.h> #include <ripple/protocol/st.h>
#include <ripple/protocol/Rate.h>
// During an EscrowFinish, the transaction must specify both // During an EscrowFinish, the transaction must specify both
// a condition and a fulfillment. We track whether that // a condition and a fulfillment. We track whether that
@@ -95,8 +94,8 @@ after(NetClock::time_point now, std::uint32_t mark)
TxConsequences TxConsequences
EscrowCreate::makeTxConsequences(PreflightContext const& ctx) EscrowCreate::makeTxConsequences(PreflightContext const& ctx)
{ {
return TxConsequences{ctx.tx, return TxConsequences{
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero}; ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
} }
NotTEC NotTEC
@@ -247,8 +246,7 @@ EscrowCreate::doApply()
// check if the escrow is capable of being // check if the escrow is capable of being
// finished before we allow it to be created // finished before we allow it to be created
{ {
TER result = TER result = trustTransferAllowed(
trustTransferAllowed(
ctx_.view(), ctx_.view(),
{account, ctx_.tx[sfDestination]}, {account, ctx_.tx[sfDestination]},
amount.issue(), amount.issue(),
@@ -276,17 +274,12 @@ EscrowCreate::doApply()
} }
{ {
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, amount, 1, ctx_.journal, DryRun);
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
DryRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "EscrowCreate::doApply trustAdjustLockedBalance (dry) result=" << "EscrowCreate::doApply trustAdjustLockedBalance (dry) "
"result="
<< result; << result;
if (!isTesSuccess(result)) if (!isTesSuccess(result))
@@ -306,8 +299,8 @@ EscrowCreate::doApply()
// Obeying the lsfDissalowXRP flag was a bug. Piggyback on // Obeying the lsfDissalowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug. // featureDepositAuth to remove the bug.
if (!ctx_.view().rules().enabled(featureDepositAuth) && if (!ctx_.view().rules().enabled(featureDepositAuth) && isXRP(amount) &&
isXRP(amount) && ((*sled)[sfFlags] & lsfDisallowXRP)) ((*sled)[sfFlags] & lsfDisallowXRP))
return tecNO_TARGET; return tecNO_TARGET;
} }
@@ -352,18 +345,13 @@ EscrowCreate::doApply()
(*sle)[sfBalance] = (*sle)[sfBalance] - ctx_.tx[sfAmount]; (*sle)[sfBalance] = (*sle)[sfBalance] - ctx_.tx[sfAmount];
else else
{ {
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens) || !sleLine) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens) ||
!sleLine)
return temDISABLED; return temDISABLED;
// do the lock-up for real now // do the lock-up for real now
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "EscrowCreate::doApply trustAdjustLockedBalance (wet) result=" << "EscrowCreate::doApply trustAdjustLockedBalance (wet) result="
@@ -586,7 +574,6 @@ EscrowFinish::doApply()
} }
} }
if (!isXRP(amount)) if (!isXRP(amount))
{ {
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
@@ -594,8 +581,7 @@ EscrowFinish::doApply()
// perform a dry run of the transfer before we // perform a dry run of the transfer before we
// change anything on-ledger // change anything on-ledger
TER result = TER result = trustTransferLockedBalance(
trustTransferLockedBalance(
ctx_.view(), ctx_.view(),
account_, // txn signing account account_, // txn signing account
sle, // src account sle, // src account
@@ -636,8 +622,6 @@ EscrowFinish::doApply()
} }
} }
if (isXRP(amount)) if (isXRP(amount))
(*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount]; (*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount];
else else
@@ -645,8 +629,7 @@ EscrowFinish::doApply()
// all the significant complexity of checking the validity of this // all the significant complexity of checking the validity of this
// transfer and ensuring the lines exist etc is hidden away in 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. // function, all we need to do is call it and return if unsuccessful.
TER result = TER result = trustTransferLockedBalance(
trustTransferLockedBalance(
ctx_.view(), ctx_.view(),
account_, // txn signing account account_, // txn signing account
sle, // src account sle, // src account
@@ -745,19 +728,12 @@ EscrowCancel::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED; return temDISABLED;
sleLine = sleLine = ctx_.view().peek(
ctx_.view().peek(
keylet::line(account, amount.getIssuer(), amount.getCurrency())); keylet::line(account, amount.getIssuer(), amount.getCurrency()));
// dry run before we make any changes to ledger // dry run before we make any changes to ledger
if (TER result = if (TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, -amount, -1, ctx_.journal, DryRun);
ctx_.view(),
sleLine,
-amount,
-1,
ctx_.journal,
DryRun);
result != tesSUCCESS) result != tesSUCCESS)
return result; return result;
} }
@@ -796,14 +772,8 @@ EscrowCancel::doApply()
return temDISABLED; return temDISABLED;
// unlock previously locked tokens from source line // unlock previously locked tokens from source line
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, -amount, -1, ctx_.journal, WetRun);
ctx_.view(),
sleLine,
-amount,
-1,
ctx_.journal,
WetRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "EscrowCancel::doApply trustAdjustLockedBalance (wet) result=" << "EscrowCancel::doApply trustAdjustLockedBalance (wet) result="

View File

@@ -129,21 +129,14 @@ closeChannel(
if (!view.rules().enabled(featurePaychanAndEscrowForTokens)) if (!view.rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED; return temDISABLED;
sleLine = sleLine = view.peek(
view.peek(keylet::line(src, amount.getIssuer(), amount.getCurrency())); keylet::line(src, amount.getIssuer(), amount.getCurrency()));
// dry run // dry run
TER result = TER result =
trustAdjustLockedBalance( trustAdjustLockedBalance(view, sleLine, -amount, -1, j, DryRun);
view,
sleLine,
-amount,
-1,
j,
DryRun);
JLOG(j.trace()) JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(dry) result="
<< "closeChannel: trustAdjustLockedBalance(dry) result="
<< result; << result;
if (!isTesSuccess(result)) if (!isTesSuccess(result))
@@ -186,16 +179,9 @@ closeChannel(
else else
{ {
TER result = TER result =
trustAdjustLockedBalance( trustAdjustLockedBalance(view, sleLine, -amount, -1, j, WetRun);
view,
sleLine,
-amount,
-1,
j,
WetRun);
JLOG(j.trace()) JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(wet) result="
<< "closeChannel: trustAdjustLockedBalance(wet) result="
<< result; << result;
if (!isTesSuccess(result)) if (!isTesSuccess(result))
@@ -215,8 +201,8 @@ closeChannel(
TxConsequences TxConsequences
PayChanCreate::makeTxConsequences(PreflightContext const& ctx) PayChanCreate::makeTxConsequences(PreflightContext const& ctx)
{ {
return TxConsequences{ctx.tx, return TxConsequences{
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero}; ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
} }
NotTEC NotTEC
@@ -284,19 +270,16 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
{ {
return tecUNFUNDED; return tecUNFUNDED;
} }
else if (!isXRP(amount)) { else if (!isXRP(amount))
{
if (!ctx.view.rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx.view.rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED; return temDISABLED;
// check for any possible bars to a channel existing // check for any possible bars to a channel existing
// between these accounts for this asset // between these accounts for this asset
{ {
TER result = TER result = trustTransferAllowed(
trustTransferAllowed( ctx.view, {account, dst}, amount.issue(), ctx.j);
ctx.view,
{account, dst},
amount.issue(),
ctx.j);
JLOG(ctx.j.trace()) JLOG(ctx.j.trace())
<< "PayChanCreate::preclaim trustTransferAllowed result=" << "PayChanCreate::preclaim trustTransferAllowed result="
<< result; << result;
@@ -307,20 +290,13 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
// check if the amount can be locked // check if the amount can be locked
{ {
auto sleLine = auto sleLine = ctx.view.read(keylet::line(
ctx.view.read( account, amount.getIssuer(), amount.getCurrency()));
keylet::line(account, amount.getIssuer(), amount.getCurrency())); TER result = trustAdjustLockedBalance(
TER result = ctx.view, sleLine, amount, 1, ctx.j, DryRun);
trustAdjustLockedBalance(
ctx.view,
sleLine,
amount,
1,
ctx.j,
DryRun);
JLOG(ctx.j.trace()) JLOG(ctx.j.trace()) << "PayChanCreate::preclaim "
<< "PayChanCreate::preclaim trustAdjustLockedBalance(dry) result=" "trustAdjustLockedBalance(dry) result="
<< result; << result;
if (!isTesSuccess(result)) if (!isTesSuccess(result))
@@ -346,8 +322,8 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on // Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug. // featureDepositAuth to remove the bug.
if (!ctx.view.rules().enabled(featureDepositAuth) && if (!ctx.view.rules().enabled(featureDepositAuth) && isXRP(amount) &&
isXRP(amount) && ((*sled)[sfFlags] & lsfDisallowXRP)) ((*sled)[sfFlags] & lsfDisallowXRP))
return tecNO_TARGET; return tecNO_TARGET;
} }
@@ -418,20 +394,14 @@ PayChanCreate::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED; return temDISABLED;
auto sleLine = auto sleLine = ctx_.view().peek(
ctx_.view().peek(keylet::line(account, amount.getIssuer(), amount.getCurrency())); keylet::line(account, amount.getIssuer(), amount.getCurrency()));
if (!sleLine) if (!sleLine)
return tecNO_LINE; return tecNO_LINE;
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "PayChanCreate::doApply trustAdjustLockedBalance(wet) result=" << "PayChanCreate::doApply trustAdjustLockedBalance(wet) result="
@@ -452,8 +422,8 @@ PayChanCreate::doApply()
TxConsequences TxConsequences
PayChanFund::makeTxConsequences(PreflightContext const& ctx) PayChanFund::makeTxConsequences(PreflightContext const& ctx)
{ {
return TxConsequences{ctx.tx, return TxConsequences{
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero}; ctx.tx, isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
} }
NotTEC NotTEC
@@ -508,20 +478,11 @@ PayChanFund::doApply()
if (!isXRP(amount) && if (!isXRP(amount) &&
ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
{ {
sleLine = ctx_.view().peek( sleLine = ctx_.view().peek(keylet::line(
keylet::line( (*slep)[sfAccount], amount.getIssuer(), amount.getCurrency()));
(*slep)[sfAccount],
amount.getIssuer(),
amount.getCurrency()));
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, amount, 1, ctx_.journal, DryRun);
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
DryRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "PayChanFund::doApply trustAdjustLockedBalance(dry) result=" << "PayChanFund::doApply trustAdjustLockedBalance(dry) result="
@@ -594,14 +555,8 @@ PayChanFund::doApply()
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
return temDISABLED; return temDISABLED;
TER result = TER result = trustAdjustLockedBalance(
trustAdjustLockedBalance( ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun);
ctx_.view(),
sleLine,
amount,
1,
ctx_.journal,
WetRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "PayChanFund::doApply trustAdjustLockedBalance(wet) result=" << "PayChanFund::doApply trustAdjustLockedBalance(wet) result="
@@ -628,7 +583,8 @@ PayChanClaim::preflight(PreflightContext const& ctx)
auto const bal = ctx.tx[~sfBalance]; auto const bal = ctx.tx[~sfBalance];
if (bal) if (bal)
{ {
if (!isXRP(*bal) && !ctx.rules.enabled(featurePaychanAndEscrowForTokens)) if (!isXRP(*bal) &&
!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
return temBAD_AMOUNT; return temBAD_AMOUNT;
if (*bal <= beast::zero) if (*bal <= beast::zero)
@@ -639,7 +595,8 @@ PayChanClaim::preflight(PreflightContext const& ctx)
if (amt) if (amt)
{ {
if (!isXRP(*amt) && !ctx.rules.enabled(featurePaychanAndEscrowForTokens)) if (!isXRP(*amt) &&
!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
return temBAD_AMOUNT; return temBAD_AMOUNT;
if (*amt <= beast::zero) if (*amt <= beast::zero)
@@ -684,7 +641,12 @@ PayChanClaim::preflight(PreflightContext const& ctx)
if (isXRP(authAmt)) if (isXRP(authAmt))
serializePayChanAuthorization(msg, k.key, authAmt.xrp()); serializePayChanAuthorization(msg, k.key, authAmt.xrp());
else 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)) if (!verify(pk, msg.slice(), *sig, /*canonical*/ true))
return temBAD_SIGNATURE; return temBAD_SIGNATURE;
@@ -749,7 +711,8 @@ PayChanClaim::doApply()
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on // Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug. // featureDepositAuth to remove the bug.
bool const depositAuth{ctx_.view().rules().enabled(featureDepositAuth)}; 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; return tecNO_TARGET;
// Check whether the destination account requires deposit authorization. // Check whether the destination account requires deposit authorization.
@@ -780,8 +743,7 @@ PayChanClaim::doApply()
return temDISABLED; return temDISABLED;
auto sleSrcAcc = ctx_.view().peek(keylet::account(src)); auto sleSrcAcc = ctx_.view().peek(keylet::account(src));
TER result = TER result = trustTransferLockedBalance(
trustTransferLockedBalance(
ctx_.view(), ctx_.view(),
txAccount, txAccount,
sleSrcAcc, sleSrcAcc,
@@ -792,7 +754,8 @@ PayChanClaim::doApply()
WetRun); WetRun);
JLOG(ctx_.journal.trace()) JLOG(ctx_.journal.trace())
<< "PayChanClaim::doApply trustTransferLockedBalance(wet) result=" << "PayChanClaim::doApply trustTransferLockedBalance(wet) "
"result="
<< result; << result;
if (!isTesSuccess(result)) if (!isTesSuccess(result))