diff --git a/src/ripple/app/tx/impl/Escrow.cpp b/src/ripple/app/tx/impl/Escrow.cpp index 5db9f1f8c..d0354de90 100644 --- a/src/ripple/app/tx/impl/Escrow.cpp +++ b/src/ripple/app/tx/impl/Escrow.cpp @@ -216,7 +216,8 @@ EscrowCreate::doApply() std::shared_ptr sleLine; auto const balance = STAmount((*sle)[sfBalance]).xrp(); - auto const reserve = ctx_.view().fees().accountReserve((*sle)[sfOwnerCount] + 1); + auto const reserve = + ctx_.view().fees().accountReserve((*sle)[sfOwnerCount] + 1); bool isIssuer = amount.getIssuer() == account; if (balance < reserve) @@ -248,8 +249,7 @@ EscrowCreate::doApply() ctx_.journal); JLOG(ctx_.journal.trace()) - << "EscrowCreate::doApply trustTransferAllowed result=" - << result; + << "EscrowCreate::doApply trustTransferAllowed result=" << result; // perform the lock as a dry run before // we modify anything on-ledger @@ -272,8 +272,8 @@ 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( @@ -281,7 +281,7 @@ EscrowCreate::doApply() JLOG(ctx_.journal.trace()) << "EscrowCreate::doApply trustAdjustLockedBalance (dry) " - "result=" + "result=" << result; if (!isTesSuccess(result)) @@ -362,7 +362,8 @@ EscrowCreate::doApply() ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun); JLOG(ctx_.journal.trace()) - << "EscrowCreate::doApply trustAdjustLockedBalance (wet) result=" + << "EscrowCreate::doApply trustAdjustLockedBalance (wet) " + "result=" << result; if (!isTesSuccess(result)) @@ -741,10 +742,13 @@ EscrowCancel::doApply() // issuer does not need to lock anything if (!isIssuer) { - 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); result != tesSUCCESS) + if (TER result = trustAdjustLockedBalance( + ctx_.view(), sleLine, -amount, -1, ctx_.journal, DryRun); + result != tesSUCCESS) return result; } } @@ -790,7 +794,8 @@ EscrowCancel::doApply() ctx_.view(), sleLine, -amount, -1, ctx_.journal, WetRun); JLOG(ctx_.journal.trace()) - << "EscrowCancel::doApply trustAdjustLockedBalance (wet) result=" + << "EscrowCancel::doApply trustAdjustLockedBalance (wet) " + "result=" << result; if (!isTesSuccess(result)) diff --git a/src/ripple/app/tx/impl/PayChan.cpp b/src/ripple/app/tx/impl/PayChan.cpp index e8609ab00..7780727df 100644 --- a/src/ripple/app/tx/impl/PayChan.cpp +++ b/src/ripple/app/tx/impl/PayChan.cpp @@ -285,9 +285,13 @@ PayChanCreate::preclaim(PreclaimContext const& ctx) { if (!isIssuer) { - 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; } @@ -385,17 +389,19 @@ 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 && !isIssuer) return tecNO_LINE; - + if (!isIssuer) { TER result = trustAdjustLockedBalance( - ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun); + ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun); JLOG(ctx_.journal.trace()) - << "PayChanCreate::doApply trustAdjustLockedBalance(wet) result=" + << "PayChanCreate::doApply trustAdjustLockedBalance(wet) " + "result=" << result; if (!isTesSuccess(result)) @@ -470,7 +476,8 @@ PayChanFund::doApply() // issuer does not need to lock anything if (!isIssuer) { - 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); @@ -547,7 +554,7 @@ PayChanFund::doApply() if (!isIssuer) { TER result = trustAdjustLockedBalance( - ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun); + ctx_.view(), sleLine, amount, 1, ctx_.journal, WetRun); JLOG(ctx_.journal.trace()) << "PayChanFund::doApply trustAdjustLockedBalance(wet) result=" diff --git a/src/ripple/ledger/View.h b/src/ripple/ledger/View.h index 413d51143..5efece528 100644 --- a/src/ripple/ledger/View.h +++ b/src/ripple/ledger/View.h @@ -1009,8 +1009,7 @@ trustTransferLockedBalance( return tecPRECISION_LOSS; finalBalance = isIssuer ? -finalBalance - : dstHigh - ? -finalBalance + : dstHigh ? -finalBalance : finalBalance; if constexpr (!dryRun) sleDstLine->setFieldAmount(sfBalance, finalBalance); diff --git a/src/test/app/Escrow_test.cpp b/src/test/app/Escrow_test.cpp index c8448f259..80fdb040a 100644 --- a/src/test/app/Escrow_test.cpp +++ b/src/test/app/Escrow_test.cpp @@ -1932,8 +1932,7 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, george, USD(5000))); env.close(); env(fset(george, asfDisallowXRP)); - env(escrow(bob, george, USD(10)), - finish_time(env.now() + 1s)); + env(escrow(bob, george, USD(10)), finish_time(env.now() + 1s)); } { // Ignore the "asfDisallowXRP" account flag, which we should @@ -2152,8 +2151,7 @@ struct Escrow_test : public beast::unit_test::suite // Removed 3 Account Reserve/Increment XRP tests // See line 602 - env(escrow(daniel, bob, USD(10)), - finish_time(env.now() + 1s)); + env(escrow(daniel, bob, USD(10)), finish_time(env.now() + 1s)); env.close(); env(escrow(daniel, bob, USD(51)), finish_time(env.now() + 1s), @@ -2224,7 +2222,7 @@ struct Escrow_test : public beast::unit_test::suite auto const seq = env.seq(alice); env(escrow(alice, alice, USD(1000)), finish_time(env.now() + 5s)); - + auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); env.require(balance(alice, USD(5000))); @@ -2264,7 +2262,7 @@ struct Escrow_test : public beast::unit_test::suite auto const seq = env.seq(alice); env(escrow(alice, bob, USD(1000)), finish_time(env.now() + 5s)); - + // Verify amounts auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); @@ -2313,7 +2311,7 @@ struct Escrow_test : public beast::unit_test::suite auto const seq = env.seq(alice); env(escrow(alice, bob, USD(1000)), finish_time(env.now() + 5s)); - + // Verify amounts auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); @@ -2414,7 +2412,7 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, alice, USD(5000))); env(pay(gw, bob, USD(5000))); env.close(); - + auto const seq = env.seq(alice); env(escrow(alice, alice, USD(1000)), condition(cb2), @@ -2470,17 +2468,17 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, alice, USD(5000))); env(pay(gw, bob, USD(5000))); env.close(); - + auto const seq = env.seq(alice); env(escrow(alice, alice, USD(1000)), condition(cb3), finish_time(env.now() + 5s)); - + auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); BEAST_EXPECT(preLocked == USD(1000)); env.require(balance(alice, USD(5000))); - + env.close(); // Finish is now possible but requires the cryptocondition. @@ -2523,17 +2521,17 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, bob, USD(5000))); env(pay(gw, carol, USD(5000))); env.close(); - + auto const seq = env.seq(alice); env(escrow(alice, alice, USD(1000)), condition(cb3), finish_time(env.now() + 5s)); - + auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); BEAST_EXPECT(preLocked == USD(1000)); env.require(balance(alice, USD(5000))); - + env.close(); // Alice preauthorizes Zelda for deposit, even though Alice has @@ -2592,13 +2590,13 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, bob, USD(5000))); env(pay(gw, carol, USD(5000))); env.close(); - + auto const seq = env.seq(alice); BEAST_EXPECT((*env.le(alice))[sfOwnerCount] == 1); env(escrow(alice, carol, USD(1000)), condition(cb1), cancel_time(env.now() + 1s)); - + BEAST_EXPECT((*env.le(alice))[sfOwnerCount] == 2); auto const preLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); @@ -2682,7 +2680,7 @@ struct Escrow_test : public beast::unit_test::suite env(pay(gw, bob, USD(5000))); env(pay(gw, carol, USD(5000))); env.close(); - + auto const seq = env.seq(alice); BEAST_EXPECT((*env.le(alice))[sfOwnerCount] == 1); env(escrow(alice, carol, USD(1000)), @@ -2695,7 +2693,7 @@ struct Escrow_test : public beast::unit_test::suite env.require(balance(alice, USD(5000))); // balance restored on cancel env(cancel(bob, alice, seq)); - + auto const postLocked = lockedAmount(env, alice, gw, USD); env.require(balance(alice, XRP(5000) - drops(10))); BEAST_EXPECT(postLocked == USD(0)); @@ -3019,9 +3017,7 @@ struct Escrow_test : public beast::unit_test::suite // Assemble finish that is missing the Condition or the Fulfillment // since either both must be present, or neither can: env(finish(bob, alice, seq), condition(cb3), ter(temMALFORMED)); - env(finish(bob, alice, seq), - fulfillment(fb3), - ter(temMALFORMED)); + env(finish(bob, alice, seq), fulfillment(fb3), ter(temMALFORMED)); // Now finish it. env(finish(bob, alice, seq), @@ -3035,7 +3031,6 @@ struct Escrow_test : public beast::unit_test::suite env.require(balance(alice, USD(4000))); env.require(balance(carol, XRP(5000))); env.require(balance(carol, USD(6000))); - } { // Test a condition other than PreimageSha256, which // would require a separate amendment @@ -3506,11 +3501,18 @@ struct Escrow_test : public beast::unit_test::suite env.close(); auto const seq1 = env.seq(gw); auto const preAlice = env.balance(alice, USD.issue()); - env(escrow(gw, alice, USD(1000)), condition(cb1), finish_time(env.now() + 1s), fee(1500)); + env(escrow(gw, alice, USD(1000)), + condition(cb1), + finish_time(env.now() + 1s), + fee(1500)); env.close(); - env(finish(alice, gw, seq1), condition(cb1), fulfillment(fb1), fee(1500)); + env(finish(alice, gw, seq1), + condition(cb1), + fulfillment(fb1), + fee(1500)); env.close(); - BEAST_EXPECT(env.balance(alice, USD.issue()) == preAlice + USD(1000)); + BEAST_EXPECT( + env.balance(alice, USD.issue()) == preAlice + USD(1000)); } { // setup env @@ -3521,12 +3523,19 @@ struct Escrow_test : public beast::unit_test::suite // test create escrow from issuer with ic no dest tl auto const seq1 = env.seq(gw); auto const preAlice = env.balance(alice, USD.issue()); - env(escrow(gw, alice, USD(1000)), condition(cb1), finish_time(env.now() + 1s), fee(1500)); + env(escrow(gw, alice, USD(1000)), + condition(cb1), + finish_time(env.now() + 1s), + fee(1500)); env.close(); // test finish from dest account - env(finish(alice, gw, seq1), condition(cb1), fulfillment(fb1), fee(1500)); + env(finish(alice, gw, seq1), + condition(cb1), + fulfillment(fb1), + fee(1500)); env.close(); - BEAST_EXPECT(env.balance(alice, USD.issue()) == preAlice + USD(1000)); + BEAST_EXPECT( + env.balance(alice, USD.issue()) == preAlice + USD(1000)); } } @@ -3561,7 +3570,7 @@ struct Escrow_test : public beast::unit_test::suite public: void run() override - { + { using namespace test::jtx; FeatureBitset const all{supported_amendments()}; testWithFeats(all); diff --git a/src/test/app/PayChan_test.cpp b/src/test/app/PayChan_test.cpp index 45534b0b0..f8fa255f0 100644 --- a/src/test/app/PayChan_test.cpp +++ b/src/test/app/PayChan_test.cpp @@ -3604,7 +3604,7 @@ struct PayChan_test : public beast::unit_test::suite .asString(); } - // Try to authorize without specifying a key type, expect an + // Try to authorize without specifying a key type, expect an // error: auto const rs = env.rpc( "channel_authorize", @@ -4655,7 +4655,7 @@ struct PayChan_test : public beast::unit_test::suite auto const chan = channel(gw, alice, env.seq(gw)); env(create(gw, alice, USD(1000), settleDelay, pk)); env.close(); - + // gw can not claim auto const preAlice = env.balance(alice, USD.issue()); auto chanBal = channelBalance(*env.current(), chan); @@ -4677,7 +4677,7 @@ struct PayChan_test : public beast::unit_test::suite auto const chan = channel(gw, alice, env.seq(gw)); env(create(gw, alice, USD(1000), settleDelay, pk)); env.close(); - + // alice can claim auto const preAlice = env.balance(alice, USD.issue()); auto chanBal = channelBalance(*env.current(), chan); @@ -4707,7 +4707,7 @@ struct PayChan_test : public beast::unit_test::suite auto const chan = channel(gw, alice, env.seq(gw)); env(create(gw, alice, USD(1000), settleDelay, pk)); env.close(); - + // gw can claim auto const preAlice = env.balance(alice, USD.issue()); auto chanBal = channelBalance(*env.current(), chan); @@ -4739,7 +4739,7 @@ struct PayChan_test : public beast::unit_test::suite env.close(); env(fund(gw, chan, USD(1000))); - + // gw can claim auto const preAlice = env.balance(alice, USD.issue()); auto chanBal = channelBalance(*env.current(), chan); @@ -4765,7 +4765,7 @@ struct PayChan_test : public beast::unit_test::suite auto const bob = Account("bob"); auto const carol = Account("carol"); auto const gw = Account{"gateway"}; - auto const USD = gw["USD"]; + auto const USD = gw["USD"]; auto const aliceUSD = alice["USD"]; auto const bobUSD = bob["USD"]; @@ -4805,7 +4805,8 @@ struct PayChan_test : public beast::unit_test::suite // bob can claim, increasing the limit amount auto const preBobLimit = limitAmount(env, bob, gw, USD); - auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt); + auto const sig = + signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt); env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk())); env.close(); auto const postBobLimit = limitAmount(env, bob, gw, USD); @@ -4854,9 +4855,9 @@ struct PayChan_test : public beast::unit_test::suite env(claim(alice, chan, reqBal, authAmt)); env.close(); // bob can claim - // auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt); - // env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk())); - // env.close(); + // auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, + // authAmt); env(claim(bob, chan, reqBal, authAmt, Slice(sig), + // alice.pk())); env.close(); } // test TransferRate { @@ -4896,20 +4897,21 @@ struct PayChan_test : public beast::unit_test::suite // bob can claim, increasing the limit amount // auto const preBobLimit = limitAmount(env, bob, gw, USD); - // auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt); - // env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk())); - // env.close(); + // auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, + // authAmt); env(claim(bob, chan, reqBal, authAmt, Slice(sig), + // alice.pk())); env.close(); auto const postLocked = lockedAmount(env, alice, gw, USD); auto const aliceLimit = limitAmount(env, alice, gw, USD); auto const bobLimit = limitAmount(env, bob, gw, USD); - // std::cout << "ALICE AMOUNT: " << env.balance(alice, USD.issue()) << "\n"; - // std::cout << "BOB AMOUNT: " << env.balance(bob, USD.issue()) << "\n"; - // std::cout << "ALICE LIMIT: " << aliceLimit << "\n"; - // std::cout << "BOB LIMIT: " << bobLimit << "\n"; + // std::cout << "ALICE AMOUNT: " << env.balance(alice, USD.issue()) + // << "\n"; std::cout << "BOB AMOUNT: " << env.balance(bob, + // USD.issue()) << "\n"; std::cout << "ALICE LIMIT: " << aliceLimit + // << "\n"; std::cout << "BOB LIMIT: " << bobLimit << "\n"; // std::cout << "POST LOCKED: " << postLocked << "\n"; - // std::cout << "CHAN BAL: " << channelBalance(*env.current(), chan) << "\n"; - // std::cout << "CHAN AUTH: " << channelAmount(*env.current(), chan) << "\n"; + // std::cout << "CHAN BAL: " << channelBalance(*env.current(), chan) + // << "\n"; std::cout << "CHAN AUTH: " << + // channelAmount(*env.current(), chan) << "\n"; } // test Global Freeze { @@ -4952,7 +4954,8 @@ struct PayChan_test : public beast::unit_test::suite env(claim(alice, chan, reqBal, authAmt), ter(tecFROZEN)); // bob cannot claim - tl global freeze auto sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt); - env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk()), ter(tecFROZEN)); + env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk()), + ter(tecFROZEN)); env.close(); env(fclear(gw, asfGlobalFreeze));