mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-26 16:40:09 +00:00
clang-format
This commit is contained in:
@@ -768,7 +768,7 @@ PayChanClaim::doApply()
|
||||
// no reason to do a dry run first
|
||||
if (!ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
|
||||
return temDISABLED;
|
||||
|
||||
|
||||
auto sleSrcAcc = ctx_.view().peek(keylet::account(src));
|
||||
TER result = trustTransferLockedBalance(
|
||||
ctx_.view(),
|
||||
|
||||
@@ -835,11 +835,7 @@ trustTransferLockedBalance(
|
||||
{
|
||||
// compute transfer fee, if any
|
||||
auto const xferFee = amount.value() -
|
||||
divideRound(
|
||||
amount,
|
||||
lXferRate,
|
||||
amount.issue(),
|
||||
true);
|
||||
divideRound(amount, lXferRate, amount.issue(), true);
|
||||
// compute balance to transfer
|
||||
dstAmt = amount.value() - xferFee;
|
||||
}
|
||||
@@ -934,7 +930,7 @@ trustTransferLockedBalance(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check for a destination line
|
||||
Keylet klDstLine = keylet::line(dstAccID, issuerAccID, currency);
|
||||
SLEPtr sleDstLine = peek(klDstLine);
|
||||
@@ -955,7 +951,7 @@ trustTransferLockedBalance(
|
||||
if (std::uint32_t const ownerCount = {sleDstAcc->at(sfOwnerCount)};
|
||||
dstBalanceDrops < view.fees().accountReserve(ownerCount + 1))
|
||||
return tecNO_LINE_INSUF_RESERVE;
|
||||
|
||||
|
||||
// create destination trust line
|
||||
if constexpr (!dryRun)
|
||||
{
|
||||
@@ -988,12 +984,12 @@ trustTransferLockedBalance(
|
||||
// checked NoRipple and Freeze flags in trustTransferAllowed
|
||||
|
||||
// check the limit
|
||||
STAmount dstLimit =
|
||||
dstHigh ? (*sleDstLine)[sfHighLimit] : (*sleDstLine)[sfLowLimit];
|
||||
STAmount dstLimit = dstHigh ? (*sleDstLine)[sfHighLimit]
|
||||
: (*sleDstLine)[sfLowLimit];
|
||||
|
||||
// get prior balance
|
||||
STAmount priorBalance =
|
||||
dstHigh ? -((*sleDstLine)[sfBalance]) : (*sleDstLine)[sfBalance];
|
||||
STAmount priorBalance = dstHigh ? -((*sleDstLine)[sfBalance])
|
||||
: (*sleDstLine)[sfBalance];
|
||||
|
||||
// combine prior with dest amount for final
|
||||
STAmount finalBalance = priorBalance + dstAmt;
|
||||
@@ -1002,15 +998,17 @@ trustTransferLockedBalance(
|
||||
if (finalBalance < priorBalance)
|
||||
{
|
||||
JLOG(j.warn()) << "trustTransferLockedBalance resulted in a "
|
||||
"lower/equal final balance on dest line";
|
||||
"lower/equal final balance on dest line";
|
||||
return tecINTERNAL;
|
||||
}
|
||||
|
||||
// if final is more than dest limit and tx acct is not dest acct - fail
|
||||
// if final is more than dest limit and tx acct is not dest acct -
|
||||
// fail
|
||||
if (finalBalance > dstLimit && actingAccID != dstAccID)
|
||||
{
|
||||
JLOG(j.trace()) << "trustTransferLockedBalance would increase dest "
|
||||
"line above limit without permission";
|
||||
JLOG(j.trace())
|
||||
<< "trustTransferLockedBalance would increase dest "
|
||||
"line above limit without permission";
|
||||
return tecPATH_DRY;
|
||||
}
|
||||
|
||||
@@ -1020,7 +1018,7 @@ trustTransferLockedBalance(
|
||||
|
||||
// compute final balance to send - reverse sign for high dest
|
||||
finalBalance = dstHigh ? -finalBalance : finalBalance;
|
||||
|
||||
|
||||
// if not dry run - set dst line field
|
||||
if constexpr (!dryRun)
|
||||
sleDstLine->setFieldAmount(sfBalance, finalBalance);
|
||||
|
||||
@@ -257,12 +257,12 @@ accountHolds(
|
||||
|
||||
// If tokens can be escrowed then they can be locked in the trustline
|
||||
// which means we must never spend them until the escrow is released.
|
||||
if (view.rules().enabled(featurePaychanAndEscrowForTokens)
|
||||
&& sle->isFieldPresent(sfLockedBalance))
|
||||
if (view.rules().enabled(featurePaychanAndEscrowForTokens) &&
|
||||
sle->isFieldPresent(sfLockedBalance))
|
||||
{
|
||||
STAmount lockedBalance = sle->getFieldAmount(sfLockedBalance);
|
||||
STAmount spendableBalance = amount -
|
||||
(account > issuer ? -lockedBalance : lockedBalance);
|
||||
STAmount spendableBalance =
|
||||
amount - (account > issuer ? -lockedBalance : lockedBalance);
|
||||
|
||||
// RH NOTE: this is defensively programmed, it should never fire
|
||||
// if something bad does happen the trustline acts as a frozen line.
|
||||
@@ -912,7 +912,8 @@ trustDelete(
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
bool isTrustDefault(
|
||||
bool
|
||||
isTrustDefault(
|
||||
std::shared_ptr<SLE> const& acc,
|
||||
std::shared_ptr<SLE> const& line)
|
||||
{
|
||||
@@ -921,7 +922,7 @@ bool isTrustDefault(
|
||||
uint32_t tlFlags = line->getFieldU32(sfFlags);
|
||||
|
||||
AccountID highAccID = line->getFieldAmount(sfHighLimit).issue().account;
|
||||
AccountID lowAccID = line->getFieldAmount(sfLowLimit ).issue().account;
|
||||
AccountID lowAccID = line->getFieldAmount(sfLowLimit).issue().account;
|
||||
|
||||
AccountID accID = acc->getAccountID(sfAccount);
|
||||
|
||||
@@ -931,8 +932,8 @@ bool isTrustDefault(
|
||||
|
||||
uint32_t acFlags = line->getFieldU32(sfFlags);
|
||||
|
||||
const auto fNoRipple {high ? lsfHighNoRipple : lsfLowNoRipple};
|
||||
const auto fFreeze {high ? lsfHighFreeze : lsfLowFreeze};
|
||||
const auto fNoRipple{high ? lsfHighNoRipple : lsfLowNoRipple};
|
||||
const auto fFreeze{high ? lsfHighFreeze : lsfLowFreeze};
|
||||
|
||||
if (tlFlags & fFreeze)
|
||||
return false;
|
||||
@@ -949,17 +950,19 @@ bool isTrustDefault(
|
||||
if (line->getFieldAmount(high ? sfHighLimit : sfLowLimit) != beast::zero)
|
||||
return false;
|
||||
|
||||
uint32_t qualityIn = line->getFieldU32(high ? sfHighQualityIn : sfLowQualityIn);
|
||||
uint32_t qualityOut = line->getFieldU32(high ? sfHighQualityOut : sfLowQualityOut);
|
||||
uint32_t qualityIn =
|
||||
line->getFieldU32(high ? sfHighQualityIn : sfLowQualityIn);
|
||||
uint32_t qualityOut =
|
||||
line->getFieldU32(high ? sfHighQualityOut : sfLowQualityOut);
|
||||
|
||||
if (qualityIn && qualityIn != QUALITY_ONE)
|
||||
if (qualityIn && qualityIn != QUALITY_ONE)
|
||||
return false;
|
||||
|
||||
if (qualityOut && qualityOut != QUALITY_ONE)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TER
|
||||
offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j)
|
||||
|
||||
@@ -154,7 +154,8 @@ private:
|
||||
static Json::Value
|
||||
jvParseSTAmount(std::string const& strIC)
|
||||
{
|
||||
static boost::regex reCurIss("\\`(0|[1-9][0-9]*)(?:/([[:alpha:]]{3}))(?:/(.+))?\\'");
|
||||
static boost::regex reCurIss(
|
||||
"\\`(0|[1-9][0-9]*)(?:/([[:alpha:]]{3}))(?:/(.+))?\\'");
|
||||
|
||||
boost::smatch icMatch;
|
||||
|
||||
@@ -820,7 +821,8 @@ private:
|
||||
return parseAccountRaw2(jvParams, jss::destination_account);
|
||||
}
|
||||
|
||||
// channel_authorize: <private_key> [<key_type>] <channel_id> <drops | amount>
|
||||
// channel_authorize: <private_key> [<key_type>] <channel_id> <drops |
|
||||
// amount>
|
||||
Json::Value
|
||||
parseChannelAuthorize(Json::Value const& jvParams)
|
||||
{
|
||||
@@ -857,14 +859,16 @@ private:
|
||||
// validate amount string | json
|
||||
if (!jvParams[index].isString())
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
|
||||
// parse string
|
||||
Json::Value amountJson = jvParseSTAmount(jvParams[index].asString());
|
||||
if (!amountJson) {
|
||||
Json::Value amountJson =
|
||||
jvParseSTAmount(jvParams[index].asString());
|
||||
if (!amountJson)
|
||||
{
|
||||
// amount is string
|
||||
if (!to_uint64(jvParams[index].asString()))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
|
||||
jvRequest[jss::amount] = jvParams[index].asString();
|
||||
}
|
||||
else
|
||||
@@ -874,7 +878,7 @@ private:
|
||||
bool isAmount = amountFromJsonNoThrow(amount, amountJson);
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
}
|
||||
}
|
||||
@@ -910,11 +914,12 @@ private:
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
// parse string
|
||||
Json::Value amountJson = jvParseSTAmount(jvParams[2u].asString());
|
||||
if (!amountJson) {
|
||||
if (!amountJson)
|
||||
{
|
||||
// amount is string
|
||||
if (!to_uint64(jvParams[2u].asString()))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
|
||||
jvRequest[jss::amount] = jvParams[2u].asString();
|
||||
}
|
||||
else
|
||||
@@ -924,7 +929,7 @@ private:
|
||||
bool isAmount = amountFromJsonNoThrow(amount, amountJson);
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ serializePayChanAuthorization(
|
||||
else if (amt.signum() == -1) // 512 = not native
|
||||
msg.add64(
|
||||
amt.mantissa() |
|
||||
(static_cast<std::uint64_t>(amt.exponent() + 512 + 97) << (64 - 10)));
|
||||
(static_cast<std::uint64_t>(amt.exponent() + 512 + 97)
|
||||
<< (64 - 10)));
|
||||
else // 256 = positive
|
||||
msg.add64(
|
||||
amt.mantissa() |
|
||||
|
||||
@@ -524,9 +524,10 @@ isFakeXRP(STAmount const& amount)
|
||||
return false;
|
||||
|
||||
return isFakeXRP(amount.issue().currency);
|
||||
}
|
||||
}
|
||||
|
||||
/** returns true iff adding or subtracting results in less than or equal to 0.01% precision loss **/
|
||||
/** returns true iff adding or subtracting results in less than or equal to
|
||||
* 0.01% precision loss **/
|
||||
inline bool
|
||||
isAddable(STAmount const& amt1, STAmount const& amt2)
|
||||
{
|
||||
@@ -540,13 +541,13 @@ isAddable(STAmount const& amt1, STAmount const& amt2)
|
||||
{
|
||||
XRPAmount A = (amt1.signum() == -1 ? -(amt1.xrp()) : amt1.xrp());
|
||||
XRPAmount B = (amt2.signum() == -1 ? -(amt2.xrp()) : amt2.xrp());
|
||||
|
||||
|
||||
XRPAmount finalAmt = A + B;
|
||||
return (finalAmt >= A && finalAmt >= B);
|
||||
}
|
||||
|
||||
static const STAmount one {IOUAmount{1, 0}, noIssue()};
|
||||
static const STAmount maxLoss {IOUAmount{1, -4}, noIssue()};
|
||||
static const STAmount one{IOUAmount{1, 0}, noIssue()};
|
||||
static const STAmount maxLoss{IOUAmount{1, -4}, noIssue()};
|
||||
|
||||
STAmount A = amt1;
|
||||
STAmount B = amt2;
|
||||
@@ -563,10 +564,10 @@ isAddable(STAmount const& amt1, STAmount const& amt2)
|
||||
STAmount lhs = divide((A - B) + B, A, noIssue()) - one;
|
||||
STAmount rhs = divide((B - A) + A, B, noIssue()) - one;
|
||||
|
||||
return ((rhs.negative() ? -rhs : rhs) + (lhs.negative() ? -lhs : lhs)) <= maxLoss;
|
||||
return ((rhs.negative() ? -rhs : rhs) + (lhs.negative() ? -lhs : lhs)) <=
|
||||
maxLoss;
|
||||
}
|
||||
|
||||
|
||||
// Since `canonicalize` does not have access to a ledger, this is needed to put
|
||||
// the low-level routine stAmountCanonicalize on an amendment switch. Only
|
||||
// transactions need to use this switchover. Outside of a transaction it's safe
|
||||
|
||||
@@ -324,8 +324,7 @@ Keylet
|
||||
payChan(AccountID const& src, AccountID const& dst, std::uint32_t seq) noexcept
|
||||
{
|
||||
return {
|
||||
ltPAYCHAN,
|
||||
indexHash(LedgerNameSpace::PAYMENT_CHANNEL, src, dst, seq)};
|
||||
ltPAYCHAN, indexHash(LedgerNameSpace::PAYMENT_CHANNEL, src, dst, seq)};
|
||||
}
|
||||
|
||||
Keylet
|
||||
|
||||
@@ -183,8 +183,7 @@ doAccountChannels(RPC::JsonContext& context)
|
||||
nextHint = RPC::getStartHint(sleCur, visitData.accountID);
|
||||
}
|
||||
|
||||
if (count <= limit &&
|
||||
(*sleCur)[sfAccount] == accountID &&
|
||||
if (count <= limit && (*sleCur)[sfAccount] == accountID &&
|
||||
(!visitData.hasDst ||
|
||||
visitData.raDstAccount == (*sleCur)[sfDestination]))
|
||||
{
|
||||
|
||||
@@ -61,8 +61,7 @@ addLine(Json::Value& jsonLines, RPCTrustLine const& line)
|
||||
jPeer[jss::balance] = saBalance.getText();
|
||||
|
||||
if (saLockedBalance)
|
||||
jPeer[jss::locked_balance] =
|
||||
saLockedBalance->negative()
|
||||
jPeer[jss::locked_balance] = saLockedBalance->negative()
|
||||
? (-(*saLockedBalance)).getText()
|
||||
: saLockedBalance->getText();
|
||||
|
||||
|
||||
@@ -70,9 +70,10 @@ doChannelAuthorize(RPC::JsonContext& context)
|
||||
|
||||
if (params[jss::amount].isString())
|
||||
{
|
||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
std::optional<std::uint64_t> const optDrops =
|
||||
params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
@@ -92,8 +93,7 @@ doChannelAuthorize(RPC::JsonContext& context)
|
||||
channelId,
|
||||
amount.iou(),
|
||||
amount.getCurrency(),
|
||||
amount.getIssuer()
|
||||
);
|
||||
amount.getIssuer());
|
||||
}
|
||||
|
||||
try
|
||||
@@ -152,9 +152,10 @@ doChannelVerify(RPC::JsonContext& context)
|
||||
|
||||
if (params[jss::amount].isString())
|
||||
{
|
||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
std::optional<std::uint64_t> const optDrops =
|
||||
params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
@@ -175,8 +176,7 @@ doChannelVerify(RPC::JsonContext& context)
|
||||
channelId,
|
||||
amount.iou(),
|
||||
amount.getCurrency(),
|
||||
amount.getIssuer()
|
||||
);
|
||||
amount.getIssuer());
|
||||
}
|
||||
|
||||
auto sig = strUnHex(params[jss::signature].asString());
|
||||
|
||||
@@ -3519,7 +3519,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("bob0");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3543,16 +3543,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(preLocked == postLocked - delta);
|
||||
}
|
||||
// src < dst
|
||||
@@ -3564,7 +3566,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("dan1");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3588,16 +3590,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(preLocked == postLocked + delta);
|
||||
}
|
||||
// dst > src
|
||||
@@ -3609,7 +3613,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3633,16 +3637,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD)== preDst.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(preLocked == postLocked - delta);
|
||||
}
|
||||
// dst < src
|
||||
@@ -3654,7 +3660,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3678,16 +3684,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(preLocked == postLocked + delta);
|
||||
}
|
||||
// src > dst
|
||||
@@ -3699,7 +3707,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("bob0");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3724,16 +3732,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(preLocked == postLocked - delta);
|
||||
}
|
||||
// src < dst
|
||||
@@ -3745,7 +3755,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("dan1");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3770,16 +3780,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(preLocked == postLocked + delta);
|
||||
}
|
||||
// dst > src
|
||||
@@ -3791,7 +3803,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3816,16 +3828,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() - delta);
|
||||
BEAST_EXPECT(preLocked == postLocked - delta);
|
||||
}
|
||||
// dst < src
|
||||
@@ -3837,7 +3851,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const dst = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -3862,16 +3876,18 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// dst can finish escrow
|
||||
auto const preSrc = lineBalance(env, src, gw, USD);
|
||||
auto const preDst = lineBalance(env, dst, gw, USD);
|
||||
|
||||
|
||||
env(finish(dst, src, seq1),
|
||||
condition(cb1),
|
||||
fulfillment(fb1),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
auto postLocked = lockedAmount(env, src, gw, USD);
|
||||
BEAST_EXPECT(lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, src, gw, USD) == preSrc.value() - delta);
|
||||
BEAST_EXPECT(
|
||||
lineBalance(env, dst, gw, USD) == preDst.value() + delta);
|
||||
BEAST_EXPECT(preLocked == postLocked + delta);
|
||||
}
|
||||
}
|
||||
@@ -3922,7 +3938,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -3953,7 +3969,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -3984,7 +4000,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -4050,7 +4066,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -4085,7 +4101,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -4120,7 +4136,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const src = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, gw);
|
||||
env.close();
|
||||
@@ -4187,7 +4203,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const transferRate = escrowRate(env, alice, seq1);
|
||||
BEAST_EXPECT(
|
||||
transferRate.value == std::uint32_t(1000000000 * 1.25));
|
||||
|
||||
|
||||
// bob can finish escrow
|
||||
env(finish(bob, alice, seq1),
|
||||
condition(cb1),
|
||||
@@ -4211,7 +4227,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
env(pay(gw, alice, USD(10000)));
|
||||
env(pay(gw, bob, USD(10000)));
|
||||
env.close();
|
||||
|
||||
|
||||
// alice can create escrow w/ xfer rate
|
||||
auto const preAlice = env.balance(alice, USD.issue());
|
||||
auto const seq1 = env.seq(alice);
|
||||
@@ -4252,7 +4268,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
env(pay(gw, alice, USD(10000)));
|
||||
env(pay(gw, bob, USD(10000)));
|
||||
env.close();
|
||||
|
||||
|
||||
// alice can create escrow w/ xfer rate
|
||||
auto const preAlice = env.balance(alice, USD.issue());
|
||||
auto const seq1 = env.seq(alice);
|
||||
@@ -4395,7 +4411,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
auto const carol = Account("carol");
|
||||
auto const gw = Account{"gateway"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
// test Global Freeze
|
||||
{
|
||||
Env env{*this, features};
|
||||
@@ -4425,7 +4441,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// clear global freeze
|
||||
env(fclear(gw, asfGlobalFreeze));
|
||||
env.close();
|
||||
|
||||
|
||||
// create escrow success
|
||||
seq1 = env.seq(alice);
|
||||
env(escrow(alice, bob, delta),
|
||||
@@ -4473,7 +4489,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// set freeze on alice trustline
|
||||
env(trust(gw, USD(10000), alice, tfSetFreeze));
|
||||
env.close();
|
||||
|
||||
|
||||
// setup transaction
|
||||
auto seq1 = env.seq(alice);
|
||||
auto const delta = USD(125);
|
||||
@@ -4497,11 +4513,11 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
finish_time(env.now() + 1s),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
// set freeze on bob trustline
|
||||
env(trust(gw, USD(10000), bob, tfSetFreeze));
|
||||
env.close();
|
||||
|
||||
|
||||
// bob finish escrow fails - frozen trustline
|
||||
env(finish(bob, alice, seq1),
|
||||
condition(cb1),
|
||||
@@ -4569,14 +4585,14 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
env(pay(gw, alice, USD(10000)));
|
||||
env(pay(gw, bob, USD(10000)));
|
||||
env.close();
|
||||
|
||||
|
||||
auto const delta = USD(1000);
|
||||
env(escrow(alice, bob, delta),
|
||||
condition(cb1),
|
||||
finish_time(env.now() + 1s),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
BEAST_EXPECT(-lockedAmount(env, alice, gw, USD) == delta);
|
||||
env(escrow(alice, bob, USD(10000)),
|
||||
condition(cb1),
|
||||
@@ -4614,14 +4630,14 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
// setup tx
|
||||
auto const seq1 = env.seq(alice);
|
||||
auto const delta = USD(10000000000000000);
|
||||
|
||||
|
||||
// create escrow success
|
||||
env(escrow(alice, bob, delta),
|
||||
condition(cb1),
|
||||
finish_time(env.now() + 1s),
|
||||
fee(1500));
|
||||
env.close();
|
||||
|
||||
|
||||
// create escrow fails - precision loss
|
||||
env(escrow(alice, bob, USD(1)),
|
||||
condition(cb1),
|
||||
@@ -4629,7 +4645,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
fee(1500),
|
||||
ter(tecPRECISION_LOSS));
|
||||
env.close();
|
||||
|
||||
|
||||
// bob finish escrow success
|
||||
env(finish(bob, alice, seq1),
|
||||
condition(cb1),
|
||||
@@ -4679,7 +4695,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
fee(1500),
|
||||
ter(tecPRECISION_LOSS));
|
||||
env.close();
|
||||
|
||||
|
||||
auto const seq1 = env.seq(alice);
|
||||
// alice can create escrow for 1000 token
|
||||
env(escrow(alice, bob, USD(1000)),
|
||||
|
||||
@@ -4676,7 +4676,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("bob0");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4724,7 +4724,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("dan1");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4772,7 +4772,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4820,7 +4820,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(5000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4868,7 +4868,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("bob0");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(10000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4921,7 +4921,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("dan1");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(10000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -4974,7 +4974,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("alice2");
|
||||
auto const gw = Account{"gw0"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(10000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -5027,7 +5027,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const dst = Account("carol0");
|
||||
auto const gw = Account{"gw1"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(10000), src, dst, gw);
|
||||
env.close();
|
||||
@@ -5079,7 +5079,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
testcase("IC Gateway");
|
||||
using namespace test::jtx;
|
||||
using namespace std::literals;
|
||||
|
||||
|
||||
// issuer -> src
|
||||
// src > issuer
|
||||
// dest no trustline
|
||||
@@ -5389,13 +5389,15 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const delta = USD(500);
|
||||
auto const reqBal = chanBal + delta;
|
||||
auto const authAmt = reqBal + USD(100);
|
||||
auto const sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt);
|
||||
auto const sig =
|
||||
signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt);
|
||||
env(claim(gw, chan, reqBal, authAmt, Slice(sig), alice.pk()));
|
||||
env.close();
|
||||
BEAST_EXPECT(preAlice == USD(10000));
|
||||
BEAST_EXPECT(env.balance(alice, USD.issue()) == preAlice - delta);
|
||||
std::cout << "PRE ALICE: " << preAlice << "\n";
|
||||
std::cout << "POST ALICE: " << env.balance(alice, USD.issue()) << "\n";
|
||||
std::cout << "POST ALICE: " << env.balance(alice, USD.issue())
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5423,7 +5425,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
env(pay(gw, alice, USD(10000)));
|
||||
env(pay(gw, bob, USD(10000)));
|
||||
env.close();
|
||||
|
||||
|
||||
// alice can create paychan w/ xfer rate
|
||||
auto const preAlice = env.balance(alice, USD.issue());
|
||||
auto const pk = alice.pk();
|
||||
@@ -5641,7 +5643,8 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto chan = channel(alice, bob, env.seq(alice));
|
||||
// alice cannot create because bob's trustline is not authorized
|
||||
// all parties must be authorized
|
||||
env(create(alice, bob, USD(1000), settleDelay, pk), ter(tecNO_AUTH));
|
||||
env(create(alice, bob, USD(1000), settleDelay, pk),
|
||||
ter(tecNO_AUTH));
|
||||
env.close();
|
||||
|
||||
env(trust(gw, bobUSD(10000)), txflags(tfSetfAuth));
|
||||
@@ -5671,7 +5674,8 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const newAuthAmt = newReqBal + USD(100);
|
||||
auto const sig =
|
||||
signClaimICAuth(alice.pk(), alice.sk(), chan, newAuthAmt);
|
||||
env(claim(bob, chan, newReqBal, newAuthAmt, Slice(sig), alice.pk()));
|
||||
env(claim(
|
||||
bob, chan, newReqBal, newAuthAmt, Slice(sig), alice.pk()));
|
||||
env.close();
|
||||
}
|
||||
}
|
||||
@@ -5753,7 +5757,7 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
// set freeze on alice trustline
|
||||
env(trust(gw, USD(100000), alice, tfSetFreeze));
|
||||
env.close();
|
||||
|
||||
|
||||
// setup transaction
|
||||
auto const pk = alice.pk();
|
||||
auto const settleDelay = 100s;
|
||||
@@ -5771,18 +5775,18 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
chan = channel(alice, bob, env.seq(alice));
|
||||
env(create(alice, bob, USD(1000), settleDelay, pk));
|
||||
env.close();
|
||||
|
||||
|
||||
// set freeze on alice trustline
|
||||
env(trust(gw, USD(100000), alice, tfSetFreeze));
|
||||
env.close();
|
||||
|
||||
|
||||
// paychan fields
|
||||
auto chanBal = channelBalance(*env.current(), chan);
|
||||
auto chanAmt = channelAmount(*env.current(), chan);
|
||||
auto const delta = USD(10);
|
||||
auto reqBal = chanBal + delta;
|
||||
auto authAmt = reqBal + USD(100);
|
||||
|
||||
|
||||
// alice claim paychan fails - frozen trustline
|
||||
env(claim(alice, chan, reqBal, authAmt), ter(tecFROZEN));
|
||||
|
||||
@@ -5950,20 +5954,20 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
env(pay(gw, alice, USD(10000000000000000)));
|
||||
env(pay(gw, bob, USD(10000000000000000)));
|
||||
env.close();
|
||||
|
||||
|
||||
// setup tx
|
||||
auto const pk = alice.pk();
|
||||
auto const settleDelay = 100s;
|
||||
auto const chan = channel(alice, bob, env.seq(alice));
|
||||
|
||||
|
||||
// create paychan fails - precision loss
|
||||
env(create(alice, bob, USD(10000000000000000), settleDelay, pk));
|
||||
env.close();
|
||||
|
||||
|
||||
// alice cannot fund again - precision loss
|
||||
env(fund(alice, chan, USD(1)), ter(tecPRECISION_LOSS));
|
||||
env.close();
|
||||
|
||||
|
||||
// setup tx
|
||||
auto const preAlice = env.balance(alice, USD.issue());
|
||||
auto const preLocked = -lockedAmount(env, alice, gw, USD);
|
||||
@@ -5971,13 +5975,13 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto chanAmt = channelAmount(*env.current(), chan);
|
||||
auto const delta = USD(10000000000000000);
|
||||
auto reqBal = chanBal + delta;
|
||||
|
||||
|
||||
// create paychan success
|
||||
env(claim(alice, chan, reqBal, reqBal));
|
||||
env.close();
|
||||
auto postLocked = -lockedAmount(env, alice, gw, USD);
|
||||
BEAST_EXPECT(postLocked == USD(0));
|
||||
|
||||
|
||||
// alice can fund again
|
||||
env(pay(gw, alice, USD(1)));
|
||||
env.close();
|
||||
@@ -6000,7 +6004,8 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const pk = alice.pk();
|
||||
auto const settleDelay = 100s;
|
||||
// alice cannot create paychan for 1/10/100 token - precision loss
|
||||
env(create(alice, bob, USD(1), settleDelay, pk), ter(tecPRECISION_LOSS));
|
||||
env(create(alice, bob, USD(1), settleDelay, pk),
|
||||
ter(tecPRECISION_LOSS));
|
||||
env.close();
|
||||
// alice can create paychan for 1000 token
|
||||
auto const chan = channel(alice, bob, env.seq(alice));
|
||||
@@ -6012,7 +6017,8 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto reqBal = USD(1000);
|
||||
auto authAmt = reqBal + USD(1000);
|
||||
auto sig = signClaimICAuth(alice.pk(), alice.sk(), chan, authAmt);
|
||||
env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk()), ter(tecPRECISION_LOSS));
|
||||
env(claim(bob, chan, reqBal, authAmt, Slice(sig), alice.pk()),
|
||||
ter(tecPRECISION_LOSS));
|
||||
|
||||
reqBal = USD(10000);
|
||||
authAmt = reqBal + USD(10000);
|
||||
|
||||
Reference in New Issue
Block a user