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/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
@@ -108,7 +107,7 @@ EscrowCreate::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret; return ret;
STAmount const amount {ctx.tx[sfAmount]}; STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount)) if (!isXRP(amount))
{ {
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens)) if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -218,7 +217,7 @@ EscrowCreate::doApply()
if (!sle) if (!sle)
return temDISABLED; return temDISABLED;
STAmount const amount {ctx_.tx[sfAmount]}; STAmount const amount{ctx_.tx[sfAmount]};
std::shared_ptr<SLE> sleLine; std::shared_ptr<SLE> sleLine;
@@ -246,8 +245,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(),
@@ -263,20 +261,16 @@ EscrowCreate::doApply()
// perform the lock as a dry run before // perform the lock as a dry run before
// we modify anything on-ledger // 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 = 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))
@@ -296,8 +290,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;
} }
@@ -341,18 +335,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="
@@ -561,7 +550,6 @@ EscrowFinish::doApply()
} }
} }
if (!isXRP(amount)) if (!isXRP(amount))
{ {
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
@@ -569,8 +557,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
@@ -611,8 +598,6 @@ EscrowFinish::doApply()
} }
} }
if (isXRP(amount)) if (isXRP(amount))
(*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount]; (*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount];
else else
@@ -620,8 +605,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
@@ -706,19 +690,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;
} }
@@ -757,14 +734,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
@@ -228,7 +214,7 @@ PayChanCreate::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret; return ret;
STAmount const amount {ctx.tx[sfAmount]}; STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount)) if (!isXRP(amount))
{ {
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens)) if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -268,7 +254,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
if (!sle) if (!sle)
return terNO_ACCOUNT; return terNO_ACCOUNT;
STAmount const amount {ctx.tx[sfAmount]}; STAmount const amount{ctx.tx[sfAmount]};
auto const balance = (*sle)[sfBalance]; auto const balance = (*sle)[sfBalance];
auto const reserve = auto const reserve =
@@ -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))
@@ -339,8 +315,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;
} }
@@ -357,7 +333,7 @@ PayChanCreate::doApply()
auto const dst = ctx_.tx[sfDestination]; auto const dst = ctx_.tx[sfDestination];
STAmount const amount {ctx_.tx[sfAmount]}; STAmount const amount{ctx_.tx[sfAmount]};
// Create PayChan in ledger. // Create PayChan in ledger.
// //
@@ -410,20 +386,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="
@@ -444,8 +414,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
@@ -457,7 +427,7 @@ PayChanFund::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret; return ret;
STAmount const amount {ctx.tx[sfAmount]}; STAmount const amount{ctx.tx[sfAmount]};
if (!isXRP(amount)) if (!isXRP(amount))
{ {
if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens)) if (!ctx.rules.enabled(featurePaychanAndEscrowForTokens))
@@ -491,7 +461,7 @@ PayChanFund::doApply()
if (!slep) if (!slep)
return tecNO_ENTRY; return tecNO_ENTRY;
STAmount const amount {ctx_.tx[sfAmount]}; STAmount const amount{ctx_.tx[sfAmount]};
std::shared_ptr<SLE> sleLine; // if XRP or featurePaychanAndEscrowForTokens std::shared_ptr<SLE> sleLine; // if XRP or featurePaychanAndEscrowForTokens
// not enabled this remains null // not enabled this remains null
@@ -500,20 +470,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="
@@ -586,14 +547,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="
@@ -620,7 +575,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)
@@ -631,7 +587,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)
@@ -676,7 +633,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;
@@ -741,7 +703,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.
@@ -772,8 +735,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,
@@ -784,7 +746,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))