diff --git a/src/ripple/app/tx/impl/Escrow.cpp b/src/ripple/app/tx/impl/Escrow.cpp index 3ce08b010..9adf55692 100644 --- a/src/ripple/app/tx/impl/Escrow.cpp +++ b/src/ripple/app/tx/impl/Escrow.cpp @@ -30,11 +30,10 @@ #include #include #include +#include #include #include #include -#include - // 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)) @@ -219,7 +218,7 @@ EscrowCreate::doApply() if (!sle) return temDISABLED; - STAmount const amount {ctx_.tx[sfAmount]}; + STAmount const amount{ctx_.tx[sfAmount]}; std::shared_ptr sleLine; @@ -247,12 +246,11 @@ EscrowCreate::doApply() // check if the escrow is capable of being // finished before we allow it to be created { - TER result = - trustTransferAllowed( - ctx_.view(), - {account, ctx_.tx[sfDestination]}, - amount.issue(), - ctx_.journal); + TER result = trustTransferAllowed( + ctx_.view(), + {account, ctx_.tx[sfDestination]}, + amount.issue(), + ctx_.journal); JLOG(ctx_.journal.trace()) << "EscrowCreate::doApply trustTransferAllowed result=" @@ -276,17 +274,12 @@ EscrowCreate::doApply() } { - 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)) @@ -306,8 +299,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; } @@ -350,21 +343,16 @@ EscrowCreate::doApply() // Deduct owner's balance, increment owner count if (isXRP(amount)) (*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; // 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=" << result; @@ -586,25 +574,23 @@ EscrowFinish::doApply() } } - if (!isXRP(amount)) { if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) return temDISABLED; - - // perform a dry run of the transfer before we + + // perform a dry run of the transfer before we // change anything on-ledger - TER result = - trustTransferLockedBalance( - ctx_.view(), - account_, // txn signing account - sle, // src account - sled, // dst account - amount, // xfer amount - -1, - j_, - DryRun // dry run - ); + TER result = trustTransferLockedBalance( + ctx_.view(), + account_, // txn signing account + sle, // src account + sled, // dst account + amount, // xfer amount + -1, + j_, + DryRun // dry run + ); JLOG(j_.trace()) << "EscrowFinish::doApply trustTransferLockedBalance (dry) result=" @@ -636,26 +622,23 @@ EscrowFinish::doApply() } } - - if (isXRP(amount)) (*sled)[sfBalance] = (*sled)[sfBalance] + (*slep)[sfAmount]; - else + else { // 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( - ctx_.view(), - account_, // txn signing account - sle, // src account - sled, // dst account - amount, // xfer amount - -1, - j_, - WetRun // wet run; - ); + TER result = trustTransferLockedBalance( + ctx_.view(), + account_, // txn signing account + sle, // src account + sled, // dst account + amount, // xfer amount + -1, + j_, + WetRun // wet run; + ); JLOG(j_.trace()) << "EscrowFinish::doApply trustTransferLockedBalance (wet) result=" @@ -745,19 +728,12 @@ EscrowCancel::doApply() if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) return temDISABLED; - sleLine = - ctx_.view().peek( - keylet::line(account, amount.getIssuer(), amount.getCurrency())); + 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; } @@ -796,19 +772,13 @@ 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=" << result; - + if (!isTesSuccess(result)) return result; } diff --git a/src/ripple/app/tx/impl/PayChan.cpp b/src/ripple/app/tx/impl/PayChan.cpp index c86c34620..5f20f3ec6 100644 --- a/src/ripple/app/tx/impl/PayChan.cpp +++ b/src/ripple/app/tx/impl/PayChan.cpp @@ -129,22 +129,15 @@ closeChannel( if (!view.rules().enabled(featurePaychanAndEscrowForTokens)) return temDISABLED; - sleLine = - view.peek(keylet::line(src, amount.getIssuer(), amount.getCurrency())); - - // dry run - TER result = - trustAdjustLockedBalance( - view, - sleLine, - -amount, - -1, - j, - DryRun); + sleLine = view.peek( + keylet::line(src, amount.getIssuer(), amount.getCurrency())); - JLOG(j.trace()) - << "closeChannel: trustAdjustLockedBalance(dry) result=" - << result; + // dry run + TER result = + trustAdjustLockedBalance(view, sleLine, -amount, -1, j, DryRun); + + JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(dry) result=" + << result; if (!isTesSuccess(result)) return result; @@ -185,18 +178,11 @@ closeChannel( (*sle)[sfBalance] = (*sle)[sfBalance] + amount; else { - TER result = - trustAdjustLockedBalance( - view, - sleLine, - -amount, - -1, - j, - WetRun); + TER result = + trustAdjustLockedBalance(view, sleLine, -amount, -1, j, WetRun); - JLOG(j.trace()) - << "closeChannel: trustAdjustLockedBalance(wet) result=" - << result; + JLOG(j.trace()) << "closeChannel: trustAdjustLockedBalance(wet) result=" + << result; if (!isTesSuccess(result)) return result; @@ -214,9 +200,9 @@ 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,21 +290,14 @@ 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); - - JLOG(ctx.j.trace()) - << "PayChanCreate::preclaim trustAdjustLockedBalance(dry) result=" - << result; + 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=" + << result; if (!isTesSuccess(result)) return result; @@ -346,8 +322,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; } @@ -364,7 +340,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. // @@ -418,20 +394,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=" @@ -440,7 +410,7 @@ PayChanCreate::doApply() if (!isTesSuccess(result)) return result; } - + adjustOwnerCount(ctx_.view(), sle, 1, ctx_.journal); ctx_.view().update(sle); @@ -452,8 +422,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 @@ -465,7 +435,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)) @@ -498,30 +468,21 @@ PayChanFund::doApply() auto const slep = ctx_.view().peek(k); if (!slep) return tecNO_ENTRY; - - STAmount const amount {ctx_.tx[sfAmount]}; - std::shared_ptr sleLine; // if XRP or featurePaychanAndEscrowForTokens - // not enabled this remains null + STAmount const amount{ctx_.tx[sfAmount]}; + + std::shared_ptr sleLine; // if XRP or featurePaychanAndEscrowForTokens + // not enabled this remains null // if this is a Fund operation on an IOU then perform a dry run here if (!isXRP(amount) && - ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens)) + 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=" @@ -594,15 +555,9 @@ 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=" << result; @@ -628,7 +583,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) @@ -639,7 +595,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) @@ -684,7 +641,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; @@ -749,7 +711,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. @@ -771,7 +734,7 @@ PayChanClaim::doApply() assert(reqDelta >= beast::zero); if (isXRP(reqDelta)) (*sled)[sfBalance] = (*sled)[sfBalance] + reqDelta; - else + else { // xfer locked tokens to satisfy claim // RH NOTE: there's no ledger modification before this point so @@ -780,19 +743,19 @@ PayChanClaim::doApply() return temDISABLED; auto sleSrcAcc = ctx_.view().peek(keylet::account(src)); - TER result = - trustTransferLockedBalance( - ctx_.view(), - txAccount, - sleSrcAcc, - sled, - reqDelta, - 0, - ctx_.journal, - WetRun); - + TER result = trustTransferLockedBalance( + ctx_.view(), + txAccount, + sleSrcAcc, + sled, + reqDelta, + 0, + ctx_.journal, + WetRun); + JLOG(ctx_.journal.trace()) - << "PayChanClaim::doApply trustTransferLockedBalance(wet) result=" + << "PayChanClaim::doApply trustTransferLockedBalance(wet) " + "result=" << result; if (!isTesSuccess(result))