@@ -133,7 +133,7 @@ closeChannel(
133
133
keylet::line (src, amount.getIssuer (), amount.getCurrency ()));
134
134
135
135
// dry run
136
- TER result =
136
+ TER const result =
137
137
trustAdjustLockedBalance (view, sleLine, -amount, -1 , j, DryRun);
138
138
139
139
JLOG (j.trace ()) << " closeChannel: trustAdjustLockedBalance(dry) result="
@@ -178,7 +178,7 @@ closeChannel(
178
178
(*sle)[sfBalance] = (*sle)[sfBalance] + amount;
179
179
else
180
180
{
181
- TER result =
181
+ TER const result =
182
182
trustAdjustLockedBalance (view, sleLine, -amount, -1 , j, WetRun);
183
183
184
184
JLOG (j.trace ()) << " closeChannel: trustAdjustLockedBalance(wet) result="
@@ -257,7 +257,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
257
257
return tecINSUFFICIENT_RESERVE;
258
258
259
259
auto const dst = ctx.tx [sfDestination];
260
- bool isIssuer = amount.getIssuer () == account;
260
+ bool const isIssuer = amount.getIssuer () == account;
261
261
262
262
// Check reserve and funds availability
263
263
if (isXRP (amount) && balance < reserve + amount)
@@ -272,7 +272,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
272
272
// check for any possible bars to a channel existing
273
273
// between these accounts for this asset
274
274
{
275
- TER result = trustTransferAllowed (
275
+ TER const result = trustTransferAllowed (
276
276
ctx.view , {account, dst}, amount.issue (), ctx.j );
277
277
JLOG (ctx.j .trace ())
278
278
<< " PayChanCreate::preclaim trustTransferAllowed result="
@@ -287,7 +287,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
287
287
{
288
288
auto sleLine = ctx.view .read (keylet::line (
289
289
account, amount.getIssuer (), amount.getCurrency ()));
290
- TER result = trustAdjustLockedBalance (
290
+ TER const result = trustAdjustLockedBalance (
291
291
ctx.view , sleLine, amount, 1 , ctx.j , DryRun);
292
292
JLOG (ctx.j .trace ()) << " PayChanCreate::preclaim "
293
293
" trustAdjustLockedBalance(dry) result="
@@ -334,8 +334,7 @@ PayChanCreate::doApply()
334
334
auto const dst = ctx_.tx [sfDestination];
335
335
336
336
STAmount const amount{ctx_.tx [sfAmount]};
337
- bool isIssuer = amount.getIssuer () == account;
338
- auto xferRate = transferRate (view (), amount.getIssuer ());
337
+ bool const isIssuer = amount.getIssuer () == account;
339
338
340
339
// Create PayChan in ledger.
341
340
//
@@ -353,12 +352,17 @@ PayChanCreate::doApply()
353
352
(*slep)[sfAccount] = account;
354
353
(*slep)[sfDestination] = dst;
355
354
(*slep)[sfSettleDelay] = ctx_.tx [sfSettleDelay];
356
- (*slep)[sfTransferRate] = xferRate.value ;
357
355
(*slep)[sfPublicKey] = ctx_.tx [sfPublicKey];
358
356
(*slep)[~sfCancelAfter] = ctx_.tx [~sfCancelAfter];
359
357
(*slep)[~sfSourceTag] = ctx_.tx [~sfSourceTag];
360
358
(*slep)[~sfDestinationTag] = ctx_.tx [~sfDestinationTag];
361
359
360
+ if (ctx_.view ().rules ().enabled (featurePaychanAndEscrowForTokens))
361
+ {
362
+ auto xferRate = transferRate (view (), amount.getIssuer ());
363
+ (*slep)[~sfTransferRate] = xferRate.value ;
364
+ }
365
+
362
366
ctx_.view ().insert (slep);
363
367
364
368
// Add PayChan to owner directory
@@ -398,7 +402,7 @@ PayChanCreate::doApply()
398
402
if (!sleLine)
399
403
return tecNO_LINE;
400
404
401
- TER result = trustAdjustLockedBalance (
405
+ TER const result = trustAdjustLockedBalance (
402
406
ctx_.view (), sleLine, amount, 1 , ctx_.journal , WetRun);
403
407
404
408
JLOG (ctx_.journal .trace ())
@@ -470,24 +474,28 @@ PayChanFund::doApply()
470
474
AccountID const src = (*slep)[sfAccount];
471
475
auto const txAccount = ctx_.tx [sfAccount];
472
476
auto const expiration = (*slep)[~sfExpiration];
473
- bool isIssuer = amount.getIssuer () == txAccount;
474
- // auto const chanFunds = (*slep)[sfAmount];
475
-
476
- // adjust transfer rate
477
- Rate lockedRate = ripple::Rate (slep->getFieldU32 (sfTransferRate));
478
- auto issuerAccID = amount.getIssuer ();
479
- auto const xferRate = transferRate (view (), issuerAccID);
480
- // update if issuer rate less than locked rate
481
- if (xferRate < lockedRate)
482
- (*slep)[sfTransferRate] = xferRate.value ;
483
- // throw if issuer rate greater than locked rate
484
- if (xferRate > lockedRate)
485
- return temBAD_TRANSFER_RATE;
477
+ bool const isIssuer = amount.getIssuer () == txAccount;
486
478
487
479
// if this is a Fund operation on an IOU then perform a dry run here
488
480
if (!isXRP (amount) &&
489
481
ctx_.view ().rules ().enabled (featurePaychanAndEscrowForTokens))
490
482
{
483
+ // adjust transfer rate
484
+ if (!slep->isFieldPresent (sfTransferRate))
485
+ return tecINTERNAL;
486
+
487
+ Rate lockedRate = ripple::Rate (slep->getFieldU32 (sfTransferRate));
488
+ auto const issuerAccID = amount.getIssuer ();
489
+ auto const xferRate = transferRate (view (), issuerAccID);
490
+
491
+ // update if issuer rate less than locked rate
492
+ if (xferRate < lockedRate)
493
+ (*slep)[~sfTransferRate] = xferRate.value ;
494
+
495
+ // throw if issuer rate greater than locked rate
496
+ if (xferRate > lockedRate)
497
+ return temBAD_TRANSFER_RATE;
498
+
491
499
// issuer does not need to lock anything
492
500
if (!isIssuer)
493
501
{
@@ -497,7 +505,7 @@ PayChanFund::doApply()
497
505
sleLine = ctx_.view ().peek (keylet::line (
498
506
(*slep)[sfAccount], amount.getIssuer (), amount.getCurrency ()));
499
507
500
- TER result = trustAdjustLockedBalance (
508
+ TER const result = trustAdjustLockedBalance (
501
509
ctx_.view (), sleLine, amount, 1 , ctx_.journal , DryRun);
502
510
503
511
JLOG (ctx_.journal .trace ())
@@ -571,7 +579,7 @@ PayChanFund::doApply()
571
579
// issuer does not need to lock anything
572
580
if (!isIssuer)
573
581
{
574
- TER result = trustAdjustLockedBalance (
582
+ TER const result = trustAdjustLockedBalance (
575
583
ctx_.view (), sleLine, amount, 1 , ctx_.journal , WetRun);
576
584
577
585
JLOG (ctx_.journal .trace ())
@@ -715,11 +723,11 @@ PayChanClaim::doApply()
715
723
}
716
724
717
725
if (reqBalance > chanFunds)
718
- return tecINSUFFICIENT_FUNDS ;
726
+ return tecUNFUNDED_PAYMENT ;
719
727
720
728
if (reqBalance <= chanBalance)
721
729
// nothing requested
722
- return tecINSUFFICIENT_FUNDS ;
730
+ return tecUNFUNDED_PAYMENT ;
723
731
724
732
auto sled = ctx_.view ().peek (keylet::account (dst));
725
733
if (!sled)
@@ -746,17 +754,6 @@ PayChanClaim::doApply()
746
754
}
747
755
}
748
756
749
- // compute transfer fee, if any
750
- Rate lockedRate = ripple::Rate (slep->getFieldU32 (sfTransferRate));
751
- auto issuerAccID = chanFunds.getIssuer ();
752
- auto const xferRate = transferRate (view (), issuerAccID);
753
- // update if issuer rate is less than locked rate
754
- if (xferRate < lockedRate)
755
- {
756
- (*slep)[sfTransferRate] = xferRate.value ;
757
- lockedRate = xferRate;
758
- }
759
-
760
757
(*slep)[sfBalance] = ctx_.tx [sfBalance];
761
758
STAmount const reqDelta = reqBalance - chanBalance;
762
759
assert (reqDelta >= beast::zero);
@@ -770,8 +767,22 @@ PayChanClaim::doApply()
770
767
if (!ctx_.view ().rules ().enabled (featurePaychanAndEscrowForTokens))
771
768
return temDISABLED;
772
769
770
+ // compute transfer fee, if any
771
+ if (!slep->isFieldPresent (sfTransferRate))
772
+ return tecINTERNAL;
773
+
774
+ Rate lockedRate = ripple::Rate (slep->getFieldU32 (sfTransferRate));
775
+ auto const issuerAccID = chanFunds.getIssuer ();
776
+ auto const xferRate = transferRate (view (), issuerAccID);
777
+ // update if issuer rate is less than locked rate
778
+ if (xferRate < lockedRate)
779
+ {
780
+ (*slep)[~sfTransferRate] = xferRate.value ;
781
+ lockedRate = xferRate;
782
+ }
783
+
773
784
auto sleSrcAcc = ctx_.view ().peek (keylet::account (src));
774
- TER result = trustTransferLockedBalance (
785
+ TER const result = trustTransferLockedBalance (
775
786
ctx_.view (),
776
787
txAccount,
777
788
sleSrcAcc,
0 commit comments