From 32a044658376dd9e88e1fdcdf244bae8e0ec833d Mon Sep 17 00:00:00 2001 From: SparkPlug0025 Date: Wed, 13 Oct 2021 09:53:09 -0400 Subject: [PATCH 1/3] Add member createdAt --- contracts/eden/src/eden-micro-chain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/eden/src/eden-micro-chain.cpp b/contracts/eden/src/eden-micro-chain.cpp index 607cca006..7cab69a4d 100644 --- a/contracts/eden/src/eden-micro-chain.cpp +++ b/contracts/eden/src/eden-micro-chain.cpp @@ -302,6 +302,7 @@ struct member eden::new_member_profile profile; std::string inductionVideo; bool participating = false; + eosio::block_timestamp createdAt; }; struct member_object : public chainbase::object @@ -637,6 +638,7 @@ struct Member const eden::new_member_profile* profile() const { return member ? &member->profile : nullptr; } const std::string* inductionVideo() const { return member ? &member->inductionVideo : nullptr; } bool participating() const { return member && member->participating; } + eosio::block_timestamp createdAt() const { return member->createdAt; } MemberElectionConnection elections(std::optional gt, std::optional ge, @@ -664,6 +666,7 @@ EOSIO_REFLECT2( profile, inductionVideo, participating, + createdAt, method(elections, "gt", "ge", "lt", "le", "first", "last", "before", "after"), method(distributionFunds, "gt", "ge", "lt", "le", "first", "last", "before", "after")) @@ -1256,6 +1259,7 @@ void inductdonate(const action_context& context, obj.member.inductionWitnesses = induction.induction.witnesses; obj.member.profile = induction.induction.profile; obj.member.inductionVideo = induction.induction.video; + obj.member.createdAt = eosio::block_timestamp(context.block.timestamp); }); transfer_funds(context.block.timestamp, payer, master_pool, quantity, history_desc::inductdonate); From 2e6c8782874cf92289e73596959db020e3da59f6 Mon Sep 17 00:00:00 2001 From: SparkPlug0025 Date: Thu, 14 Oct 2021 09:06:35 -0400 Subject: [PATCH 2/3] Add membersByCreatedAt query --- contracts/eden/src/eden-micro-chain.cpp | 50 ++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/contracts/eden/src/eden-micro-chain.cpp b/contracts/eden/src/eden-micro-chain.cpp index 7cab69a4d..8067ed774 100644 --- a/contracts/eden/src/eden-micro-chain.cpp +++ b/contracts/eden/src/eden-micro-chain.cpp @@ -26,6 +26,11 @@ constexpr eosio::name pool_account(eosio::name pool) constexpr eosio::name master_pool = pool_account("master"_n); eosio::name distribution_fund; +const eosio::name account_min = eosio::name{0}; +const eosio::name account_max = eosio::name{~uint64_t(0)}; +const eosio::block_timestamp block_timestamp_min = eosio::block_timestamp{0}; +const eosio::block_timestamp block_timestamp_max = eosio::block_timestamp{~uint32_t(0)}; + // TODO: switch to uint64_t (js BigInt) after we upgrade to nodejs >= 15 extern "C" void __wasm_call_ctors(); [[clang::export_name("initialize")]] void initialize(uint32_t eden_account_low, @@ -89,6 +94,7 @@ struct by_pk; struct by_invitee; struct by_group; struct by_round; +struct by_createdAt; template using mic = boost:: @@ -119,6 +125,11 @@ using ordered_by_round = boost::multi_index::ordered_unique< // boost::multi_index::tag, boost::multi_index::key<&T::by_round>>; +template +using ordered_by_createdAt = boost::multi_index::ordered_unique< // + boost::multi_index::tag, + boost::multi_index::key<&T::by_createdAt>>; + uint64_t available_pk(const auto& table, const auto& first) { auto& idx = table.template get(); @@ -294,6 +305,8 @@ using induction_index = mic, ordered_by_invitee>; +using MemberCreatedAtKey = std::pair; + struct member { eosio::name account; @@ -313,8 +326,14 @@ struct member_object : public chainbase::object member member; eosio::name by_pk() const { return member.account; } + MemberCreatedAtKey by_createdAt() const { + return {member.createdAt, member.account}; + } }; -using member_index = mic, ordered_by_pk>; +using member_index = mic, + ordered_by_pk, + ordered_by_createdAt>; struct election_object : public chainbase::object { @@ -1777,6 +1796,34 @@ struct Query [](auto& members, auto key) { return members.upper_bound(key); }); } + MemberConnection membersByCreatedAt(std::optional gt, + std::optional ge, + std::optional lt, + std::optional le, + std::optional first, + std::optional last, + std::optional before, + std::optional after) const + { + return clchain::make_connection( + gt ? std::optional{MemberCreatedAtKey{*gt, account_min}} // + : std::nullopt, // + ge ? std::optional{MemberCreatedAtKey{*ge, account_min}} // + : std::optional{MemberCreatedAtKey{block_timestamp_min, account_min}}, // + lt ? std::optional{MemberCreatedAtKey{*lt, account_max}} // + : std::nullopt, // + le ? std::optional{MemberCreatedAtKey{*le, account_max}} // + : std::optional{MemberCreatedAtKey{block_timestamp_max, account_max}}, // + first, last, before, after, // + db.members.get(), // + [](auto& obj) { return obj.by_createdAt(); }, // + [](auto& obj) { + return Member{obj.member.account, &obj.member}; + }, + [](auto& members, auto key) { return members.lower_bound(key); }, + [](auto& members, auto key) { return members.upper_bound(key); }); + } + ElectionConnection elections(std::optional gt, std::optional ge, std::optional lt, @@ -1820,6 +1867,7 @@ EOSIO_REFLECT2(Query, distributionFund, method(balances, "gt", "ge", "lt", "le", "first", "last", "before", "after"), method(members, "gt", "ge", "lt", "le", "first", "last", "before", "after"), + method(membersByCreatedAt, "gt", "ge", "lt", "le", "first", "last", "before", "after"), method(elections, "gt", "ge", "lt", "le", "first", "last", "before", "after"), method(distributions, "gt", "ge", "lt", "le", "first", "last", "before", "after")) From 4fe3125078fdb6e0c024b6cfc973e7ac495b0166 Mon Sep 17 00:00:00 2001 From: SparkPlug0025 Date: Thu, 14 Oct 2021 10:13:38 -0400 Subject: [PATCH 3/3] Fix query ranges --- contracts/eden/src/eden-micro-chain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/eden/src/eden-micro-chain.cpp b/contracts/eden/src/eden-micro-chain.cpp index 8067ed774..54d24ede2 100644 --- a/contracts/eden/src/eden-micro-chain.cpp +++ b/contracts/eden/src/eden-micro-chain.cpp @@ -1806,14 +1806,14 @@ struct Query std::optional after) const { return clchain::make_connection( - gt ? std::optional{MemberCreatedAtKey{*gt, account_min}} // + gt ? std::optional{MemberCreatedAtKey{*gt, account_max}} // : std::nullopt, // ge ? std::optional{MemberCreatedAtKey{*ge, account_min}} // - : std::optional{MemberCreatedAtKey{block_timestamp_min, account_min}}, // - lt ? std::optional{MemberCreatedAtKey{*lt, account_max}} // + : std::nullopt, // + lt ? std::optional{MemberCreatedAtKey{*lt, account_min}} // : std::nullopt, // le ? std::optional{MemberCreatedAtKey{*le, account_max}} // - : std::optional{MemberCreatedAtKey{block_timestamp_max, account_max}}, // + : std::nullopt, // first, last, before, after, // db.members.get(), // [](auto& obj) { return obj.by_createdAt(); }, //