Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement MPT changes #1147

Open
wants to merge 78 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3c98a06
Refactoring currency (WIP)
shawnxie999 Jan 10, 2024
f8bbf0c
compile
shawnxie999 Jan 10, 2024
924dd72
remove static cast
shawnxie999 Jan 10, 2024
59bcb97
wip
shawnxie999 Jan 9, 2024
f182a1d
Working account_objects and Ledger_entry
shawnxie999 Jan 11, 2024
b908b4e
Synthetic MPT ID
shawnxie999 Jan 11, 2024
2e297fa
reafactor
shawnxie999 Jan 11, 2024
efc839c
Working ledger entry
shawnxie999 Jan 13, 2024
5bc4ca5
use translation
shawnxie999 Jan 13, 2024
5bbf673
ledger_entry tests
shawnxie999 Jan 15, 2024
9ac779d
account object test
shawnxie999 Jan 15, 2024
a97d549
initial
shawnxie999 Jan 26, 2024
0dae3cb
compile
shawnxie999 Jan 26, 2024
f9b494e
working marker
shawnxie999 Jan 26, 2024
0adc32e
tests
shawnxie999 Jan 31, 2024
1d7e49f
typo
shawnxie999 Jan 31, 2024
a700caa
cmake
shawnxie999 Jan 31, 2024
7052364
comments
shawnxie999 Jan 31, 2024
ac5f48e
ledgerdata
shawnxie999 Jan 31, 2024
2decaa8
ledgerdata test
shawnxie999 Jan 31, 2024
880d036
clang
shawnxie999 Jan 31, 2024
412fa2e
change order
shawnxie999 Jan 31, 2024
18a8a4a
improve condition
shawnxie999 Feb 1, 2024
75eddfd
tests
shawnxie999 Feb 1, 2024
5fa9182
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Feb 1, 2024
96288d0
add deletion blocker
shawnxie999 Feb 1, 2024
c453391
Merge branch 'develop' into mpt-holders
shawnxie999 Feb 2, 2024
e6d34fa
Merge branch 'develop' into mpt-holders
shawnxie999 Feb 2, 2024
b6691bd
refactor validators and add tests
shawnxie999 Feb 5, 2024
62b01fe
remove comment
shawnxie999 Feb 5, 2024
eb138d2
Merge remote-tracking branch 'upstream/develop' into mpt-holders-bk
shawnxie999 Feb 5, 2024
f3d7f0d
template parameter type checking
shawnxie999 Feb 5, 2024
203fa8d
clang
shawnxie999 Feb 5, 2024
b368864
clang
shawnxie999 Feb 5, 2024
494f56f
doxygen and end of file line
shawnxie999 Feb 8, 2024
9a378b0
revert issue changes
shawnxie999 Feb 29, 2024
38804f6
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Feb 29, 2024
4d85852
update
shawnxie999 Feb 29, 2024
f224555
revert
shawnxie999 Feb 29, 2024
d28b21f
comment
shawnxie999 Feb 29, 2024
66a4fe7
improvements
shawnxie999 Mar 1, 2024
63b4f7c
remove rvalue ref
shawnxie999 Mar 1, 2024
5630132
clang
shawnxie999 Mar 1, 2024
1d166a7
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Mar 4, 2024
d316375
use copyif
shawnxie999 Mar 4, 2024
b988f2d
comment
shawnxie999 Mar 4, 2024
aac1e0c
use getaccountid
shawnxie999 Mar 4, 2024
90dc297
comment
shawnxie999 Mar 4, 2024
19b268f
Merge branch 'develop' into mpt-holders
shawnxie999 Mar 4, 2024
f4852a8
update libxrpl
shawnxie999 Mar 5, 2024
e7c77d3
doc
shawnxie999 Mar 5, 2024
d9c54be
comment
shawnxie999 Mar 5, 2024
8d798a6
doc
shawnxie999 Mar 5, 2024
55386e8
change var name
shawnxie999 Mar 5, 2024
0087ff5
var name
shawnxie999 Mar 5, 2024
01453ee
use toJson
shawnxie999 Mar 5, 2024
87838f6
clang
shawnxie999 Mar 5, 2024
cee9cd5
change libxrpl
shawnxie999 Mar 5, 2024
26ca942
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Mar 12, 2024
d2f40a9
revert libxrpl
shawnxie999 Mar 12, 2024
c4dbd11
libxrpl
shawnxie999 Mar 12, 2024
a39c90a
Delete CMake/deps/libxrpl.cmake
shawnxie999 Mar 12, 2024
3defe87
add renamed libxrpl
shawnxie999 Mar 12, 2024
57020c2
Merge branch 'develop' into mpt-holders
shawnxie999 Mar 13, 2024
e75e2cf
comments
shawnxie999 Mar 26, 2024
5df2068
predicate const ref
shawnxie999 Mar 28, 2024
a464fba
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Jul 8, 2024
703500f
clang
shawnxie999 Jul 8, 2024
8b8cc9b
add MPT amendment
shawnxie999 Jul 8, 2024
ca079a5
Merge branch 'develop' into mpt-holders
godexsoft Jul 18, 2024
1a03ae0
make compile
shawnxie999 Sep 5, 2024
1c271f4
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Sep 5, 2024
2fc2536
Merge remote-tracking branch 'upstream/develop' into mpt-holders
shawnxie999 Oct 7, 2024
d877e5d
update clio to compile with latest rippled
shawnxie999 Oct 8, 2024
cce63dc
comments
shawnxie999 Oct 9, 2024
a9b1430
fix API response discrepancies
shawnxie999 Oct 17, 2024
7bd4472
ledger entry test
shawnxie999 Oct 17, 2024
2ea0cb8
Merge branch 'develop' into mpt-holders
shawnxie999 Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/data/BackendInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ class BackendInterface {
*
* @param mptID MPTIssuanceID you wish you query.
* @param limit Paging limit.
* @param cursorIn Optional cursor to allow us to pick up from where we
* last left off.
* @param cursorIn Optional cursor to allow us to pick up from where we last left off.
* @param ledgerSequence The ledger sequence to fetch for
* @param yield Currently executing coroutine.
* @return std::vector<Blob> of MPToken balances and an optional marker
Expand Down Expand Up @@ -591,7 +590,7 @@ class BackendInterface {
* @param data A vector of MPT ID and account pairs
*/
virtual void
writeMPTHolders(std::vector<std::pair<ripple::uint192, ripple::AccountID>> const& data) = 0;
writeMPTHolders(std::vector<MPTHolderData> const& data) = 0;

/**
* @brief Write a new successor.
Expand Down
26 changes: 10 additions & 16 deletions src/data/CassandraBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,17 @@ class BasicCassandraBackend : public BackendInterface {
cursor = holder;
}

auto const mptObjects = doFetchLedgerObjects(mptKeys, ledgerSequence, yield);
auto mptObjects = doFetchLedgerObjects(mptKeys, ledgerSequence, yield);

// need to filter out the objs that don't exist at the ledger seq because these MPT are in no particular time
// order. The MPToken at the specified ledger index may not exist.
std::vector<Blob> filteredMpt;
std::copy_if(mptObjects.begin(), mptObjects.end(), std::back_inserter(filteredMpt), [](Blob mpt) {
return mpt.size() != 0;
});
auto it = std::remove_if(mptObjects.begin(), mptObjects.end(), [](Blob mpt) { return mpt.size() == 0; });
shawnxie999 marked this conversation as resolved.
Show resolved Hide resolved

mptObjects.erase(it, mptObjects.end());

ASSERT(mptKeys.size() <= limit, "Number of keys can't exceed the limit");
if (mptKeys.size() == limit)
shawnxie999 marked this conversation as resolved.
Show resolved Hide resolved
return {filteredMpt, cursor};
return {mptObjects, cursor};

return {filteredMpt, {}};
return {mptObjects, {}};
}

std::optional<Blob>
Expand Down Expand Up @@ -891,15 +889,11 @@ class BasicCassandraBackend : public BackendInterface {
}

void
writeMPTHolders(std::vector<std::pair<ripple::uint192, ripple::AccountID>> const& data) override
writeMPTHolders(std::vector<MPTHolderData> const& data) override
{
std::vector<Statement> statements;
for (auto const& record : data) {
auto const mptId = record.first;
auto const holder = record.second;

statements.push_back(schema_->insertMPTHolder.bind(mptId, holder));
}
for (auto [mptId, holder] : data)
statements.push_back(schema_->insertMPTHolder.bind(std::move(mptId), std::move(holder)));

executor_.write(std::move(statements));
}
Expand Down
8 changes: 8 additions & 0 deletions src/data/DBHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ struct NFTsData {
}
};

/**
* @brief Represents an MPT and holder pair
*/
struct MPTHolderData {
ripple::uint192 mptID;
ripple::AccountID holder;
};

/**
* @brief Check whether the supplied object is an offer.
*
Expand Down
2 changes: 1 addition & 1 deletion src/data/cassandra/Schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Schema {
(
mpt_id blob,
holder blob,
PRIMARY KEY (mpt_id, holder)
PRIMARY KEY (mpt_id, holder)
)
WITH CLUSTERING ORDER BY (holder ASC)
AND default_time_to_live = {}
Expand Down
10 changes: 5 additions & 5 deletions src/etl/MPTHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace etl {
* @param txMeta Transaction metadata
* @return MPT and holder account pair
*/
static std::optional<std::pair<ripple::uint192, ripple::AccountID>>
static std::optional<MPTHolderData>
getMPTokenAuthorize(ripple::TxMeta const& txMeta)
{
for (ripple::STObject const& node : txMeta.getNodes()) {
Expand All @@ -45,13 +45,13 @@ getMPTokenAuthorize(ripple::TxMeta const& txMeta)

if (node.getFName() == ripple::sfCreatedNode) {
auto const& newMPT = node.peekAtField(ripple::sfNewFields).downcast<ripple::STObject>();
return std::make_pair(newMPT[ripple::sfMPTokenIssuanceID], newMPT.getAccountID(ripple::sfAccount));
return MPTHolderData{newMPT[ripple::sfMPTokenIssuanceID], newMPT.getAccountID(ripple::sfAccount)};
}
}
return {};
}

std::optional<std::pair<ripple::uint192, ripple::AccountID>>
std::optional<MPTHolderData>
getMPTHolderFromTx(ripple::TxMeta const& txMeta, ripple::STTx const& sttx)
{
if (txMeta.getResultTER() != ripple::tesSUCCESS || sttx.getTxnType() != ripple::TxType::ttMPTOKEN_AUTHORIZE)
cindyyan317 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -60,7 +60,7 @@ getMPTHolderFromTx(ripple::TxMeta const& txMeta, ripple::STTx const& sttx)
return getMPTokenAuthorize(txMeta);
cindyyan317 marked this conversation as resolved.
Show resolved Hide resolved
}

std::optional<std::pair<ripple::uint192, ripple::AccountID>>
std::optional<MPTHolderData>
getMPTHolderFromObj(std::string const& key, std::string const& blob)
{
ripple::STLedgerEntry const sle =
Expand All @@ -72,7 +72,7 @@ getMPTHolderFromObj(std::string const& key, std::string const& blob)
auto const mptIssuanceID = sle[ripple::sfMPTokenIssuanceID];
auto const holder = sle.getAccountID(ripple::sfAccount);

return std::make_pair(mptIssuanceID, holder);
return MPTHolderData{mptIssuanceID, holder};
}

} // namespace etl
4 changes: 2 additions & 2 deletions src/etl/MPTHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace etl {
* @param sttx The transaction
* @return The MPTIssuanceID and holder pair as a optional
*/
std::optional<std::pair<ripple::uint192, ripple::AccountID>>
std::optional<MPTHolderData>
getMPTHolderFromTx(ripple::TxMeta const& txMeta, ripple::STTx const& sttx);

/**
Expand All @@ -44,7 +44,7 @@ getMPTHolderFromTx(ripple::TxMeta const& txMeta, ripple::STTx const& sttx);
* @param blob Object data as blob
* @return The MPTIssuanceID and holder pair as a optional
*/
std::optional<std::pair<ripple::uint192, ripple::AccountID>>
std::optional<MPTHolderData>
getMPTHolderFromObj(std::string const& key, std::string const& blob);

} // namespace etl
4 changes: 2 additions & 2 deletions src/etl/impl/LedgerLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct FormattedTransactionsData {
std::vector<AccountTransactionsData> accountTxData;
std::vector<NFTTransactionsData> nfTokenTxData;
std::vector<NFTsData> nfTokensData;
std::vector<std::pair<ripple::uint192, ripple::AccountID>> mptHoldersData;
std::vector<MPTHolderData> mptHoldersData;
};

namespace etl::impl {
Expand Down Expand Up @@ -262,7 +262,7 @@ class LedgerLoader {
backend_->writeAccountTransactions(std::move(insertTxResult.accountTxData));
backend_->writeNFTs(insertTxResult.nfTokensData);
backend_->writeNFTTransactions(insertTxResult.nfTokenTxData);
backend_->writeMPTHolders(std::move(insertTxResult.mptHoldersData));
backend_->writeMPTHolders(insertTxResult.mptHoldersData);
}

backend_->finishWrites(sequence);
Expand Down
2 changes: 1 addition & 1 deletion src/etl/impl/Transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Transformer {
backend_->writeAccountTransactions(std::move(insertTxResultOp->accountTxData));
backend_->writeNFTs(insertTxResultOp->nfTokensData);
backend_->writeNFTTransactions(insertTxResultOp->nfTokenTxData);
backend_->writeMPTHolders(std::move(insertTxResultOp->mptHoldersData));
backend_->writeMPTHolders(insertTxResultOp->mptHoldersData);

auto [success, duration] =
::util::timed<std::chrono::duration<double>>([&]() { return backend_->finishWrites(lgrInfo.seq); });
Expand Down
6 changes: 4 additions & 2 deletions src/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input input, Context const& ctx)
auto const mptIssuanceID = ripple::uint192{std::string_view(*(input.mptIssuance))};
key = ripple::keylet::mptIssuance(mptIssuanceID).key;
} else if (input.mptoken) {
auto const holder = ripple::parseBase58<ripple::AccountID>(input.mptoken->at(JS(account)).as_string().c_str());
auto const holder =
ripple::parseBase58<ripple::AccountID>(boost::json::value_to<std::string>(input.mptoken->at(JS(account))));
auto const mptIssuanceID =
ripple::uint192{std::string_view(input.mptoken->at(JS(mpt_issuance_id)).as_string().c_str())};
ripple::uint192{std::string_view(boost::json::value_to<std::string>(input.mptoken->at(JS(mpt_issuance_id))))
};
key = ripple::keylet::mptoken(mptIssuanceID, *holder).key;
} else {
// Must specify 1 of the following fields to indicate what type
Expand Down
5 changes: 0 additions & 5 deletions src/rpc/handlers/MPTHolders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ MPTHoldersHandler::process(MPTHoldersHandler::Input input, Context const& ctx) c
return Error{*status};

auto const lgrInfo = std::get<LedgerInfo>(lgrInfoOrStatus);

auto const limit = input.limit.value_or(MPTHoldersHandler::LIMIT_DEFAULT);

auto const mptID = ripple::uint192{input.mptID.c_str()};

auto const issuanceLedgerObject =
sharedPtrBackend_->fetchLedgerObject(ripple::keylet::mptIssuance(mptID).key, lgrInfo.seq, ctx.yield);

if (!issuanceLedgerObject)
return Error{Status{RippledError::rpcOBJECT_NOT_FOUND, "objectNotFound"}};

Expand All @@ -71,9 +68,7 @@ MPTHoldersHandler::process(MPTHoldersHandler::Input input, Context const& ctx) c
cursor = ripple::AccountID{input.marker->c_str()};

auto const dbResponse = sharedPtrBackend_->fetchMPTHolders(mptID, limit, cursor, lgrInfo.seq, ctx.yield);

auto output = MPTHoldersHandler::Output{};

output.mptID = to_string(mptID);
output.limit = limit;
output.ledgerIndex = lgrInfo.seq;
Expand Down
2 changes: 1 addition & 1 deletion unittests/rpc/handlers/AccountObjectsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,4 +1720,4 @@ TEST_F(RPCAccountObjectsHandlerTest, TypeFilterMPTokenType)
ASSERT_EQ(accountObjects.size(), 1);
EXPECT_EQ(accountObjects.front().at("LedgerEntryType").as_string(), "MPToken");
});
}
}
2 changes: 1 addition & 1 deletion unittests/rpc/handlers/LedgerDataTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,4 @@ TEST_F(RPCLedgerDataHandlerTest, TypeFilterMPToken)
auto const& objects = output->as_object().at("state").as_array();
EXPECT_EQ(objects.front().at("LedgerEntryType").as_string(), "MPToken");
});
}
}
7 changes: 1 addition & 6 deletions unittests/util/MockBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,7 @@ struct MockBackend : public BackendInterface {

MOCK_METHOD(bool, doFinishWrites, (), (override));

MOCK_METHOD(
void,
writeMPTHolders,
((std::vector<std::pair<ripple::uint192, ripple::AccountID>> const&)),
(override)
);
MOCK_METHOD(void, writeMPTHolders, ((std::vector<MPTHolderData> const&)), (override));

MOCK_METHOD(
MPTHoldersAndCursor,
Expand Down
2 changes: 1 addition & 1 deletion unittests/util/TestObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,4 @@ CreateMPTokenObject(
mptoken.setFieldU64(ripple::sfLockedAmount, lockedAmount);

return mptoken;
}
}