Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Jan 3, 2025
1 parent 4d7de85 commit 3444dcf
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 57 deletions.
3 changes: 2 additions & 1 deletion include/xrpl/basics/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ to_uint64(std::string const& s);
domain, as this function may reject domains that are otherwise valid and
doesn't check whether the TLD is valid.
*/
bool isProperlyFormedTomlDomain(std::string_view domain);
bool
isProperlyFormedTomlDomain(std::string_view domain);

template <
typename T,
Expand Down
8 changes: 6 additions & 2 deletions include/xrpl/protocol/TxMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ class TxMeta
CtorHelper);

public:
TxMeta(uint256 const& transactionID, std::uint32_t ledger, std::optional<uint256> batchId = std::nullopt);
TxMeta(
uint256 const& transactionID,
std::uint32_t ledger,
std::optional<uint256> batchId = std::nullopt);
TxMeta(uint256 const& txID, std::uint32_t ledger, Blob const&);
TxMeta(uint256 const& txID, std::uint32_t ledger, std::string const&);
TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&);

std::optional<uint256 const> const& getBatchId() const
std::optional<uint256 const> const&
getBatchId() const
{
return mBatchId;
}
Expand Down
7 changes: 5 additions & 2 deletions src/libxrpl/protocol/TxMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ TxMeta::TxMeta(
{
}

TxMeta::TxMeta(uint256 const& transactionID, std::uint32_t ledger, std::optional<uint256> batchId)
TxMeta::TxMeta(
uint256 const& transactionID,
std::uint32_t ledger,
std::optional<uint256> batchId)
: mTransactionID(transactionID)
, mLedger(ledger)
, mIndex(static_cast<std::uint32_t>(-1))
Expand Down Expand Up @@ -216,7 +219,7 @@ TxMeta::getAsObject() const
XRPL_ASSERT(mResult != 255, "ripple::TxMeta::getAsObject : result is set");
if (mBatchId)
metaData.setFieldH256(sfBatchTransactionID, mBatchId.value());
metaData.setFieldU8(sfTransactionResult, mResult);
metaData.setFieldU8(sfTransactionResult, mResult);
metaData.setFieldU32(sfTransactionIndex, mIndex);
metaData.emplace_back(mNodes);
if (hasDeliveredAmount())
Expand Down
99 changes: 70 additions & 29 deletions src/test/app/Batch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,21 @@ class Batch_test : public beast::unit_test::suite
auto txn1 = jv[jss::RawTransactions][0u][jss::RawTransaction];
STParsedJSONObject parsed1(std::string(jss::tx_json), txn1);
STTx const stx1 = STTx{std::move(parsed1.object.value())};
jv[sfTransactionIDs.jsonName].append(to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx1.getTransactionID()));

// Tx 2
Json::Value const tx2 = pay(bob, alice, XRP(5));
jv = addBatchTx(jv, tx2, env.seq(bob));
auto txn2 = jv[jss::RawTransactions][1u][jss::RawTransaction];
STParsedJSONObject parsed2(std::string(jss::tx_json), txn2);
STTx const stx2 = STTx{std::move(parsed2.object.value())};
jv[sfTransactionIDs.jsonName].append(to_string(stx2.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx2.getTransactionID()));

// Add another txn hash to the TxIDs array
jv[sfTransactionIDs.jsonName].append(to_string(stx2.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx2.getTransactionID()));

env(jv, batch::sig(bob), ter(temMALFORMED));
env.close();
Expand Down Expand Up @@ -337,15 +340,17 @@ class Batch_test : public beast::unit_test::suite
auto txn1 = jv[jss::RawTransactions][0u][jss::RawTransaction];
STParsedJSONObject parsed1(std::string(jss::tx_json), txn1);
STTx const stx1 = STTx{std::move(parsed1.object.value())};
jv[sfTransactionIDs.jsonName].append(to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx1.getTransactionID()));

// Tx 2
Json::Value const tx2 = pay(bob, alice, XRP(5));
jv = addBatchTx(jv, tx2, env.seq(bob));
auto txn2 = jv[jss::RawTransactions][1u][jss::RawTransaction];
STParsedJSONObject parsed2(std::string(jss::tx_json), txn2);
STTx const stx2 = STTx{std::move(parsed2.object.value())};
jv[sfTransactionIDs.jsonName].append(to_string(stx2.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx2.getTransactionID()));

for (auto const& signer : signers)
{
Expand Down Expand Up @@ -392,8 +397,10 @@ class Batch_test : public beast::unit_test::suite
jv = addBatchTx(jv, tx2, env.seq(bob));

// Add a duplicate hash
jv[sfTransactionIDs.jsonName].append(to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx1.getTransactionID()));

env(jv, batch::sig(bob), ter(temMALFORMED));
env.close();
Expand Down Expand Up @@ -421,8 +428,10 @@ class Batch_test : public beast::unit_test::suite
STTx const stx2 = STTx{std::move(parsed2.object.value())};

// Add the hashes out of order
jv[sfTransactionIDs.jsonName].append(to_string(stx2.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(to_string(stx1.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx2.getTransactionID()));
jv[sfTransactionIDs.jsonName].append(
to_string(stx1.getTransactionID()));

env(jv, batch::sig(bob), ter(temMALFORMED));
env.close();
Expand Down Expand Up @@ -735,15 +744,16 @@ class Batch_test : public beast::unit_test::suite
auto const preBob = env.balance(bob);

auto const seq = env.seq(alice);
auto const ammCreate = [&alice](STAmount const& amount, STAmount const& amount2) {
Json::Value jv;
jv[jss::Account] = alice.human();
jv[jss::Amount] = amount.getJson(JsonOptions::none);
jv[jss::Amount2] = amount2.getJson(JsonOptions::none);
jv[jss::TradingFee] = 0;
jv[jss::TransactionType] = jss::AMMCreate;
return jv;
};
auto const ammCreate =
[&alice](STAmount const& amount, STAmount const& amount2) {
Json::Value jv;
jv[jss::Account] = alice.human();
jv[jss::Amount] = amount.getJson(JsonOptions::none);
jv[jss::Amount2] = amount2.getJson(JsonOptions::none);
jv[jss::TradingFee] = 0;
jv[jss::TransactionType] = jss::AMMCreate;
return jv;
};

auto const batchFee = calcBatchFee(env, 0, 2);
env(batch::batch(alice, seq, batchFee, tfAllOrNothing),
Expand Down Expand Up @@ -1283,10 +1293,11 @@ class Batch_test : public beast::unit_test::suite
env.close();

// auto dumpCL = [this,&env]() {
// log << "Full Ledger:\n" << env.rpc("ledger", "closed", "tx")[jss::result].toStyledString() << "\n";
// log << "Full Ledger:\n" << env.rpc("ledger", "closed",
// "tx")[jss::result].toStyledString() << "\n";
// };

{ // All or Nothing: all succeed
{ // All or Nothing: all succeed
auto const preAlice = env.balance(alice);
auto const preBob = env.balance(bob);
auto const preCarol = env.balance(carol);
Expand All @@ -1304,7 +1315,7 @@ class Batch_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(carol) == preCarol + XRP(100));
}

{ // All or Nothing: one fails
{ // All or Nothing: one fails
auto const preAlice = env.balance(alice);
auto const preBob = env.balance(bob);
auto const preCarol = env.balance(carol);
Expand All @@ -1322,7 +1333,7 @@ class Batch_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(carol) == preCarol);
}

{ // Independent (one fails)
{ // Independent (one fails)
auto const preAlice = env.balance(alice);
auto const preBob = env.balance(bob);
auto const preCarol = env.balance(carol);
Expand All @@ -1331,7 +1342,13 @@ class Batch_test : public beast::unit_test::suite
env(batch::batch(alice, seq, batchFee, tfIndependent),
batch::add(pay(alice, bob, XRP(100)), seq + 1),
batch::add(pay(alice, carol, XRP(100)), seq + 2),
batch::add(offer(alice, alice["USD"](100), XRP(100),tfImmediateOrCancel), seq + 3));
batch::add(
offer(
alice,
alice["USD"](100),
XRP(100),
tfImmediateOrCancel),
seq + 3));
env.close();

// dumpCL();
Expand All @@ -1341,7 +1358,7 @@ class Batch_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(carol) == preCarol + XRP(100));
}

{ // Until Failure: one fails, one is not executed
{ // Until Failure: one fails, one is not executed
auto const preAlice = env.balance(alice);
auto const preBob = env.balance(bob);
auto const preCarol = env.balance(carol);
Expand All @@ -1350,7 +1367,13 @@ class Batch_test : public beast::unit_test::suite
env(batch::batch(alice, seq, batchFee, tfUntilFailure),
batch::add(pay(alice, bob, XRP(100)), seq + 1),
batch::add(pay(alice, carol, XRP(100)), seq + 2),
batch::add(offer(alice, alice["USD"](100), XRP(100),tfImmediateOrCancel), seq + 3),
batch::add(
offer(
alice,
alice["USD"](100),
XRP(100),
tfImmediateOrCancel),
seq + 3),
batch::add(pay(alice, eve, XRP(100)), seq + 4));
env.close();

Expand All @@ -1361,16 +1384,34 @@ class Batch_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(carol) == preCarol + XRP(100));
}

{ // Only one: the fourth succeeds
{ // Only one: the fourth succeeds
auto const preAlice = env.balance(alice);
auto const preBob = env.balance(bob);
auto const preCarol = env.balance(carol);
auto const seq = env.seq(alice);
auto const batchFee = calcBatchFee(env, 0, 6);
env(batch::batch(alice, seq, batchFee, tfOnlyOne),
batch::add(offer(alice, alice["USD"](100), XRP(100),tfImmediateOrCancel), seq + 1),
batch::add(offer(alice, alice["USD"](100), XRP(100),tfImmediateOrCancel), seq + 2),
batch::add(offer(alice, alice["USD"](100), XRP(100),tfImmediateOrCancel), seq + 3),
batch::add(
offer(
alice,
alice["USD"](100),
XRP(100),
tfImmediateOrCancel),
seq + 1),
batch::add(
offer(
alice,
alice["USD"](100),
XRP(100),
tfImmediateOrCancel),
seq + 2),
batch::add(
offer(
alice,
alice["USD"](100),
XRP(100),
tfImmediateOrCancel),
seq + 3),
batch::add(pay(alice, bob, XRP(100)), seq + 4),
batch::add(pay(alice, carol, XRP(100)), seq + 5),
batch::add(pay(alice, eve, XRP(100)), seq + 6));
Expand Down
3 changes: 2 additions & 1 deletion src/test/jtx/impl/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ add::operator()(Env& env, JTx& jt) const
std::optional<STObject> st =
parse(jt.jv[jss::RawTransactions][index][jss::RawTransaction]);
STTx const stx = STTx{std::move(*st)};
jt.jv[sfTransactionIDs.jsonName][index] = to_string(stx.getTransactionID());
jt.jv[sfTransactionIDs.jsonName][index] =
to_string(stx.getTransactionID());
}
catch (parse_error const&)
{
Expand Down
4 changes: 3 additions & 1 deletion src/xrpld/app/ledger/detail/OpenLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ OpenLedger::accept(
// skip batch txns
if (tx->isFlag(tfInnerBatchTxn))
{
assert(txpair.second && txpair.second->isFieldPresent(sfBatchTransactionID));
assert(
txpair.second &&
txpair.second->isFieldPresent(sfBatchTransactionID));
continue;
}

Expand Down
9 changes: 3 additions & 6 deletions src/xrpld/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,9 @@ NetworkOPsImp::processTransaction(
app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
return;
}

auto const [validity, reason] = checkValidity(
app_.getHashRouter(),
tx,
view->rules(),
app_.config());

auto const [validity, reason] =
checkValidity(app_.getHashRouter(), tx, view->rules(), app_.config());
XRPL_ASSERT(
validity == Validity::Valid,
"ripple::NetworkOPsImp::processTransaction : valid validity");
Expand Down
9 changes: 5 additions & 4 deletions src/xrpld/app/tx/detail/Batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Batch::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;
}

if (std::popcount(flags & (tfAllOrNothing | tfOnlyOne | tfUntilFailure | tfIndependent)) != 1)
if (std::popcount(
flags &
(tfAllOrNothing | tfOnlyOne | tfUntilFailure | tfIndependent)) != 1)
{
JLOG(ctx.j.trace()) << "Batch: too many flags.";
return temMALFORMED;
Expand Down Expand Up @@ -198,9 +200,8 @@ Batch::preflight(PreflightContext const& ctx)
if (ctx.tx.isFieldPresent(sfBatchSigners) &&
batchSignersSet.find(innerAccount) != batchSignersSet.end())
{
JLOG(ctx.j.trace())
<< "Batch: outer signature for inner txn."
<< "index: " << i;
JLOG(ctx.j.trace()) << "Batch: outer signature for inner txn."
<< "index: " << i;
return temBAD_SIGNER;
}
continue;
Expand Down
1 change: 0 additions & 1 deletion src/xrpld/app/tx/detail/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,6 @@ removeDeletedTrustLines(
}
}


/** Reset the context, discarding any changes made and adjust the fee.
@param fee The transaction fee to be charged.
Expand Down
10 changes: 8 additions & 2 deletions src/xrpld/app/tx/detail/Transactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ struct PreflightContext
Rules const& rules_,
ApplyFlags flags_,
beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()})
: app(app_), tx(tx_), rules(rules_), flags(flags_), batchId(batchId_), j(j_)
: app(app_)
, tx(tx_)
, rules(rules_)
, flags(flags_)
, batchId(batchId_)
, j(j_)
{
assert((flags_ & tapBATCH) == tapBATCH);
}
Expand Down Expand Up @@ -252,7 +257,8 @@ class Transactor

/// The sole purpose of this function is to provide a convenient, named
/// location to set a breakpoint, to be used when replaying transactions.
void trapTransaction(uint256 const&) const noexcept;
void
trapTransaction(uint256 const&) const noexcept;
};

/** Performs early sanity checks on the txid */
Expand Down
17 changes: 11 additions & 6 deletions src/xrpld/app/tx/detail/apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ apply(
});
}

static
bool
static bool
applyBatchTransactions(
Application& app,
OpenView& batchView,
STTx const& txn,
beast::Journal j)
{
assert(txn.getTxnType() == ttBATCH && !txn.getFieldArray(sfRawTransactions).empty());
assert(
txn.getTxnType() == ttBATCH &&
!txn.getFieldArray(sfRawTransactions).empty());

auto const batchId = txn.getTransactionID();
auto const mode = txn.getFlags();
Expand All @@ -179,7 +180,8 @@ applyBatchTransactions(
<< batchId << ")";

auto const ret = apply(app, perTxBatchView, batchId, tx, tapBATCH, j);
assert(ret.second == (isTesSuccess(ret.first) || isTecClaim(ret.first)));
assert(
ret.second == (isTesSuccess(ret.first) || isTecClaim(ret.first)));

JLOG(j.debug()) << "Transaction "
<< (ret.second ? "applied" : "failure") << ": "
Expand All @@ -198,7 +200,9 @@ applyBatchTransactions(
for (STObject rb : txn.getFieldArray(sfRawTransactions))
{
auto const result = applyOneTransaction(STTx{std::move(rb)});
assert(result.second == (isTesSuccess(result.first) || isTecClaim(result.first)));
assert(
result.second ==
(isTesSuccess(result.first) || isTecClaim(result.first)));

if (result.second)
++applied;
Expand Down Expand Up @@ -232,7 +236,8 @@ applyTransaction(
if (retryAssured)
flags = flags | tapRETRY;

JLOG(j.debug()) << "TXN " << txn.getTransactionID() << (retryAssured ? "/retry" : "/final");
JLOG(j.debug()) << "TXN " << txn.getTransactionID()
<< (retryAssured ? "/retry" : "/final");

try
{
Expand Down
Loading

0 comments on commit 3444dcf

Please sign in to comment.