Skip to content

Commit

Permalink
Fix clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jan 4, 2024
1 parent ed90cdd commit 6a02476
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/ripple/app/ledger/impl/LedgerToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <ripple/protocol/jss.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <ripple/rpc/MPTokenIssuanceID.h>
#include <ripple/rpc/impl/RPCHelpers.h>

namespace ripple {

Expand Down Expand Up @@ -158,7 +158,7 @@ fillJsonTx(
fill.ledger,
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});

// If applicable, insert mpt issuance id
RPC::insertMPTokenIssuanceID(
txJson[jss::meta],
Expand Down Expand Up @@ -197,7 +197,7 @@ fillJsonTx(
fill.ledger,
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});

// If applicable, insert mpt issuance id
RPC::insertMPTokenIssuanceID(
txJson[jss::metaData],
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
#include <ripple/resource/ResourceManager.h>
#include <ripple/rpc/BookChanges.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/MPTokenIssuanceID.h>
#include <ripple/rpc/ServerHandler.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <boost/asio/ip/host_name.hpp>
#include <boost/asio/steady_timer.hpp>
#include <ripple/rpc/MPTokenIssuanceID.h>

#include <algorithm>
#include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/paths/impl/AmountSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#ifndef RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED
#define RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED

#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/IOUAmount.h>
#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/protocol/STAmount.h>

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ MPTokenIssuanceCreate::doApply()
(*mptIssuance)[sfOutstandingAmount] = 0;
(*mptIssuance)[sfOwnerNode] = *ownerNode;
(*mptIssuance)[sfSequence] = ctx_.tx.getSeqProxy().value();

if (auto const max = ctx_.tx[~sfMaximumAmount])
(*mptIssuance)[sfMaximumAmount] = *max;

Expand Down
8 changes: 4 additions & 4 deletions src/ripple/app/tx/impl/applySteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#include <ripple/app/tx/impl/AMMVote.h>
#include <ripple/app/tx/impl/AMMWithdraw.h>
#include <ripple/app/tx/impl/ApplyContext.h>
#include <ripple/app/tx/impl/MPTokenAuthorize.h>
#include <ripple/app/tx/impl/MPTokenIssuanceCreate.h>
#include <ripple/app/tx/impl/MPTokenIssuanceDestroy.h>
#include <ripple/app/tx/impl/MPTokenIssuanceSet.h>
#include <ripple/app/tx/impl/CancelCheck.h>
#include <ripple/app/tx/impl/CancelOffer.h>
#include <ripple/app/tx/impl/CashCheck.h>
Expand All @@ -41,6 +37,10 @@
#include <ripple/app/tx/impl/DeleteAccount.h>
#include <ripple/app/tx/impl/DepositPreauth.h>
#include <ripple/app/tx/impl/Escrow.h>
#include <ripple/app/tx/impl/MPTokenAuthorize.h>
#include <ripple/app/tx/impl/MPTokenIssuanceCreate.h>
#include <ripple/app/tx/impl/MPTokenIssuanceDestroy.h>
#include <ripple/app/tx/impl/MPTokenIssuanceSet.h>
#include <ripple/app/tx/impl/NFTokenAcceptOffer.h>
#include <ripple/app/tx/impl/NFTokenBurn.h>
#include <ripple/app/tx/impl/NFTokenCancelOffer.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/AmountConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#ifndef RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED
#define RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED

#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/IOUAmount.h>
#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/protocol/STAmount.h>

Expand Down
9 changes: 3 additions & 6 deletions src/ripple/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@ class Asset
return asset_;
}

bool constexpr
isMPT() const
bool constexpr isMPT() const
{
return std::holds_alternative<MPT>(asset_);
}
bool constexpr
isCurrency() const
bool constexpr isCurrency() const
{
return std::holds_alternative<Currency>(asset_);
}
bool constexpr
isXRP() const
bool constexpr isXRP() const
{
return isCurrency() && ripple::isXRP(std::get<Currency>(asset_));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#ifndef RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED
#define RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED

#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/CountedObject.h>
#include <ripple/basics/IOUAmount.h>
#include <ripple/basics/LocalValue.h>
#include <ripple/basics/MPTAmount.h>
#include <ripple/basics/Number.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/protocol/Issue.h>
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ mptoken(MPT const& mptID, AccountID const& holder) noexcept
Keylet
mptoken(uint256 const& issuanceKey, AccountID const& holder) noexcept
{
return {ltMPTOKEN, indexHash(LedgerNameSpace::MPTOKEN, issuanceKey, holder)};
return {
ltMPTOKEN, indexHash(LedgerNameSpace::MPTOKEN, issuanceKey, holder)};
}

Keylet
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include <ripple/resource/Fees.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/Role.h>
#include <ripple/rpc/MPTokenIssuanceID.h>
#include <ripple/rpc/Role.h>

#include <grpcpp/grpcpp.h>

Expand Down Expand Up @@ -362,7 +362,8 @@ populateJsonResponse(
insertDeliveredAmount(
jvObj[jss::meta], context, txn, *txnMeta);
insertNFTSyntheticInJson(jvObj, sttx, *txnMeta);
RPC::insertMPTokenIssuanceID(jvObj[jss::meta], sttx, *txnMeta);
RPC::insertMPTokenIssuanceID(
jvObj[jss::meta], sttx, *txnMeta);
}
else
assert(false && "Missing transaction medatata");
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ doLedgerEntry(RPC::JsonContext& context)
else if (context.params.isMember(jss::mpt_issuance_id))
{
expectedType = ltMPTOKEN_ISSUANCE;
auto const unparsedMPTIssuanceID = context.params[jss::mpt_issuance_id];
auto const unparsedMPTIssuanceID =
context.params[jss::mpt_issuance_id];
if (unparsedMPTIssuanceID.isString())
{
uint192 mptIssuanceID;
Expand Down
16 changes: 10 additions & 6 deletions src/ripple/rpc/handlers/MPTHolders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ appendMPTHolderJson(
obj[jss::mptoken_index] = to_string(mpt->key());
obj[jss::flags] = (*mpt)[sfFlags];
obj[jss::account] = toBase58(mpt->getAccountID(sfAccount));
obj[jss::mpt_amount] = STUInt64{(*mpt)[sfMPTAmount]}.getJson(JsonOptions::none);

if((*mpt)[sfLockedAmount])
obj[jss::locked_amount] = STUInt64{(*mpt)[sfLockedAmount]}.getJson(JsonOptions::none);
obj[jss::mpt_amount] =
STUInt64{(*mpt)[sfMPTAmount]}.getJson(JsonOptions::none);

if ((*mpt)[sfLockedAmount])
obj[jss::locked_amount] =
STUInt64{(*mpt)[sfLockedAmount]}.getJson(JsonOptions::none);
}

// {
Expand Down Expand Up @@ -151,10 +153,12 @@ doMPTHolders(RPC::JsonContext& context)

uint192 mptIssuanceID;

if (!mptIssuanceID.parseHex(context.params[jss::mpt_issuance_id].asString()))
if (!mptIssuanceID.parseHex(
context.params[jss::mpt_issuance_id].asString()))
return RPC::invalid_field_error(jss::mpt_issuance_id);

return enumerateMPTHolders(context, mptIssuanceID, keylet::mpt_dir(mptIssuanceID));
return enumerateMPTHolders(
context, mptIssuanceID, keylet::mpt_dir(mptIssuanceID));
}

} // namespace ripple
2 changes: 1 addition & 1 deletion src/ripple/rpc/handlers/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/GRPCHandlers.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <ripple/rpc/MPTokenIssuanceID.h>
#include <ripple/rpc/impl/RPCHelpers.h>

#include <charconv>
#include <regex>
Expand Down
8 changes: 5 additions & 3 deletions src/ripple/rpc/impl/MPTokenIssuanceID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ getIDFromCreatedIssuance(TxMeta const& transactionMeta)
if (node.getFieldU16(sfLedgerEntryType) != ltMPTOKEN_ISSUANCE ||
node.getFName() != sfCreatedNode)
continue;

auto const& mptNode = node.peekAtField(sfNewFields).downcast<STObject>();
return getMptID(mptNode.getAccountID(sfIssuer), mptNode.getFieldU32(sfSequence));

auto const& mptNode =
node.peekAtField(sfNewFields).downcast<STObject>();
return getMptID(
mptNode.getAccountID(sfIssuer), mptNode.getFieldU32(sfSequence));
}

return std::nullopt;
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/rpc/impl/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ getAccountObjects(
{
auto sleJson = sleNode->getJson(JsonOptions::none);
if (sleNode->getType() == ltMPTOKEN_ISSUANCE)
sleJson[jss::mpt_issuance_id] = to_string(getMptID(sleNode->getAccountID(sfIssuer), (*sleNode)[sfSequence]));

sleJson[jss::mpt_issuance_id] = to_string(getMptID(
sleNode->getAccountID(sfIssuer),
(*sleNode)[sfSequence]));

jvObjects.append(sleJson);
}

Expand Down
45 changes: 24 additions & 21 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,14 +967,13 @@ class MPToken_test : public beast::unit_test::suite

auto const id = getMptID(alice.id(), env.seq(alice));

env(mpt::create(alice));
env(mpt::create(alice));
env.close();

std::string const txHash{
env.tx()->getJson(JsonOptions::none)[jss::hash].asString()};

Json::Value const meta =
env.rpc("tx", txHash)[jss::result][jss::meta];
Json::Value const meta = env.rpc("tx", txHash)[jss::result][jss::meta];

// Expect mpt_issuance_id field
BEAST_EXPECT(meta.isMember(jss::mpt_issuance_id));
Expand All @@ -987,28 +986,29 @@ class MPToken_test : public beast::unit_test::suite
testcase("MPT Holders");
using namespace test::jtx;

// a lambda that checks API correctness given different numbers of MPToken
auto checkMPTokens =[&](int expectCount,
int expectMarkerCount,
int line){
// a lambda that checks API correctness given different numbers of
// MPToken
auto checkMPTokens = [&](int expectCount,
int expectMarkerCount,
int line) {
Env env{*this, features};
Account const alice("alice"); // issuer

env.fund(XRP(10000), alice);
env.close();

auto const id = getMptID(alice.id(), env.seq(alice));

env(mpt::create(alice));
env(mpt::create(alice));
env.close();

// create accounts that will create MPTokens
for (auto i = 0; i < expectCount; i++)
{
Account const bob{std::string("bob") + std::to_string(i)};
env.fund(XRP(1000), bob);
env.close();

// a holder creates a mptoken
env(mpt::authorize(bob, id, std::nullopt));
env.close();
Expand All @@ -1029,7 +1029,8 @@ class MPToken_test : public beast::unit_test::suite

if (!marker.empty())
params[jss::marker] = marker;
return env.rpc("json", "mpt_holders", to_string(params));
return env.rpc(
"json", "mpt_holders", to_string(params));
}();

// If there are mptokens we get an error
Expand All @@ -1042,14 +1043,15 @@ class MPToken_test : public beast::unit_test::suite
line))
{
if (expect(
mptHolders[jss::result].isMember(jss::error),
mptHolders[jss::result].isMember(
jss::error),
"expected \"error\"",
__FILE__,
line))
{
expect(
mptHolders[jss::result][jss::error].asString() ==
"objectNotFound",
mptHolders[jss::result][jss::error]
.asString() == "objectNotFound",
"expected \"objectNotFound\"",
__FILE__,
line);
Expand Down Expand Up @@ -1127,11 +1129,11 @@ class MPToken_test : public beast::unit_test::suite
holderAddresses.size() == expectCount,
"Duplicate addresses returned?",
__FILE__,
line);
line);
}
};
// Test 1 MPToken

// Test 1 MPToken
checkMPTokens(1, 0, __LINE__);

// Test 10 MPTokens
Expand Down Expand Up @@ -1181,8 +1183,9 @@ class MPToken_test : public beast::unit_test::suite

// Test parsed MPTokenIssuanceID in API response metadata
// TODO: This test exercises the parsing logic of mptID in `tx`, but,
// mptID is also parsed in different places like `account_tx`, `subscribe`, `ledger`.
// We should create test for these occurances (lower prioirity).
// mptID is also parsed in different places like `account_tx`,
// `subscribe`, `ledger`. We should create test for these
// occurances (lower prioirity).
testTxJsonMetaFields(all);

// Test mpt_holders
Expand Down
2 changes: 1 addition & 1 deletion src/test/jtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <test/jtx/acctdelete.h>
#include <test/jtx/amount.h>
#include <test/jtx/balance.h>
#include <test/jtx/mpt.h>
#include <test/jtx/check.h>
#include <test/jtx/delivermin.h>
#include <test/jtx/deposit.h>
Expand All @@ -43,6 +42,7 @@
#include <test/jtx/jtx_json.h>
#include <test/jtx/last_ledger_sequence.h>
#include <test/jtx/memo.h>
#include <test/jtx/mpt.h>
#include <test/jtx/multisign.h>
#include <test/jtx/noop.h>
#include <test/jtx/offer.h>
Expand Down
13 changes: 9 additions & 4 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,18 +885,22 @@ class AccountObjects_test : public beast::unit_test::suite
jvMPTIssuance[jss::TransactionType] = jss::MPTokenIssuanceCreate;
jvMPTIssuance[jss::Flags] = tfUniversal;
jvMPTIssuance[jss::Account] = gw.human();
jvMPTIssuance[sfMPTokenMetadata.jsonName] = strHex(std::string{"metadata"});
jvMPTIssuance[sfMPTokenMetadata.jsonName] =
strHex(std::string{"metadata"});
env(jvMPTIssuance);
env.close();

// Find the MPTokenIssuance.
Json::Value const resp = acct_objs(gw, jss::mpt_issuance);
BEAST_EXPECT(acct_objs_is_size(resp, 1));

auto const& mptIssuance = resp[jss::result][jss::account_objects][0u];
auto const& mptIssuance =
resp[jss::result][jss::account_objects][0u];
BEAST_EXPECT(mptIssuance[jss::mpt_issuance_id] == to_string(id));
BEAST_EXPECT(mptIssuance[sfIssuer.jsonName] == gw.human());
BEAST_EXPECT(mptIssuance[sfMPTokenMetadata.jsonName] == strHex(std::string{"metadata"}));
BEAST_EXPECT(
mptIssuance[sfMPTokenMetadata.jsonName] ==
strHex(std::string{"metadata"}));
}
{
// alice creates MPToken that is going to be used by gw
Expand All @@ -916,7 +920,8 @@ class AccountObjects_test : public beast::unit_test::suite
Json::Value const resp = acct_objs(gw, jss::mptoken);
BEAST_EXPECT(acct_objs_is_size(resp, 1));
auto const& mptoken = resp[jss::result][jss::account_objects][0u];
BEAST_EXPECT(mptoken[sfMPTokenIssuanceID.jsonName] == to_string(issuanceID));
BEAST_EXPECT(
mptoken[sfMPTokenIssuanceID.jsonName] == to_string(issuanceID));
BEAST_EXPECT(mptoken[sfAccount.jsonName] == gw.human());
}
// Make gw multisigning by adding a signerList.
Expand Down
Loading

0 comments on commit 6a02476

Please sign in to comment.