Skip to content

Commit

Permalink
back in
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardAH committed Jan 26, 2025
1 parent 934d45c commit 41b3104
Showing 1 changed file with 58 additions and 25 deletions.
83 changes: 58 additions & 25 deletions src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,12 +2085,6 @@ Transactor::operator()()
break;
}

if (!isXRP(amt))
{
JLOG(j_.trace())
<< "skipping non-native service-fee from " << src << ".";
}

// check if the source exists
auto const& sleSrc = view().read(keylet::account(src));
if (!sleSrc)
Expand All @@ -2112,33 +2106,72 @@ Transactor::operator()()
break;
}

// check if there's enough left in the sender's account
auto srcBal = sleSrc.getFieldAmount(sfBalance);
if (isXRP(amt))
{
// check if there's enough left in the sender's account
auto srcBal = sleSrc.getFieldAmount(sfBalance);

// service fee will only be delivered if the account
// contains adequate balance to cover reserves, otherwise
// it is disregarded
auto after = srcBal - amt;
if (after < view().fees().accountReserve(sleSrc->getFieldU32(sfOwnerCount)))
{
JLOG(j_.trace())
<< "service fee not applied because source "
<< src << " cannot pay it (native).";
break;
}

// action the transfer
if (TER const ter{
view().transferXRP(view(), src, dst, amt, j_))
!isTesSuccess(ter))
{
JLOG(j_.warn())
<< "service fee error transferring "
<< amt << " from " << src << " to " << dst
<< " error: " << ter << ".";
}
break;
}

// execution to here means issued currency service fee

// service fee cannot be used to create trustlines,
// so a line must already exist and the currency must
// be able to be xfer'd to it

auto const& sleLine = view().peek(keylet::line(dst, amt.getIssuer(), amt.getCurrency()));

// service fee will only be delivered if the account
// contains adequate balance to cover reserves, otherwise
// it is disregarded
auto after = srcBal - amt;
if (after < view().fees().accountReserve(sleSrc->getFieldU32(sfOwnerCount)))
if (!sleLine && amt.getIssuer() != dst)
{
JLOG(j_.trace())
<< "service fee not applied because source "
<< src << " cannot pay it (native).";
JLOG(j_.trace())
<< "service fee not applied because destination "
<< dst << " has no trustline for currency: "
<< amt.getCurrency()
<< " issued by: " << amt.getIssuer() << ".";
break;
}

// action the transfer
if (TER const ter{
view().transferXRP(view(), src, dst, amt, j_))
!isTesSuccess(ter))
{
JLOG(j_.warn())
<< "service fee error transferring "
<< amt << " from " << src << " to " << dst
<< " error: " << ter << ".";
PaymentSandbox pv(&view());
auto res = accountSend(
pv, src, dst, amt, j_);

if (res == tesSUCCESS)
{
pv.apply(ctx_.rawView());
break;
}

JLOG(j_.trace())
<< "service fee not sent from " << src << " to " << dst << " for "
<< amt.getCurrency() " issued by " << amt.getIssuer() " because "
<< "accountSend() failed with code " << res << ".";
}

// done featureServiceFee

} while (0);

if (applied)
Expand Down

0 comments on commit 41b3104

Please sign in to comment.