diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 949f93d2..0c78eb55 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 388fa5a9..5eed3f73 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -66,6 +66,7 @@ add_library( graphene_chain fba_object.cpp proposal_object.cpp vesting_balance_object.cpp + transaction_history_object.cpp small_objects.cpp block_database.cpp diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 4e1cf289..8360149f 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include #include @@ -816,8 +816,8 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx //Insert transaction into unique transactions database. if( !(skip & skip_transaction_dupe_check) ) { - create([&trx_id,&trx](transaction_object& transaction) { - transaction.trx_id = trx_id; + create([&trx](transaction_history_object& transaction) { + transaction.trx_id = trx.id(); transaction.trx = trx; }); } diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 5d67bd8e..0de70a0b 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include @@ -132,8 +132,8 @@ const uint8_t operation_history_object::type_id; const uint8_t proposal_object::space_id; const uint8_t proposal_object::type_id; -const uint8_t transaction_object::space_id; -const uint8_t transaction_object::type_id; +const uint8_t transaction_history_object::space_id; +const uint8_t transaction_history_object::type_id; const uint8_t vesting_balance_object::space_id; const uint8_t vesting_balance_object::type_id; diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index ad4d92c0..c1873ccd 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include @@ -366,7 +366,6 @@ void get_relevant_accounts( const object* obj, flat_set& accoun { case null_object_type: case base_object_type: - case OBJECT_TYPE_COUNT: return; case account_object_type:{ accounts.insert( obj->id ); @@ -445,9 +444,9 @@ void get_relevant_accounts( const object* obj, flat_set& accoun break; case impl_reserved0_object_type: break; - case impl_asset_dynamic_data_type: + case impl_asset_dynamic_data_object_type: break; - case impl_asset_bitasset_data_type: + case impl_asset_bitasset_data_object_type: break; case impl_account_balance_object_type:{ const auto& aobj = dynamic_cast(obj); @@ -459,9 +458,9 @@ void get_relevant_accounts( const object* obj, flat_set& accoun assert( aobj != nullptr ); accounts.insert( aobj->owner ); break; - } case impl_transaction_object_type:{ - const auto& aobj = dynamic_cast(obj); - assert( aobj != nullptr ); + } case impl_transaction_history_object_type:{ + const auto& aobj = dynamic_cast(obj); + FC_ASSERT( aobj != nullptr ); transaction_get_impacted_accounts( aobj->trx, accounts ); break; } case impl_blinded_balance_object_type:{ diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 1e9a0c51..acac1b91 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -153,7 +153,8 @@ void database::clear_expired_transactions() { try { //Look for expired transactions in the deduplication list, and remove them. //Transactions must have expired by at least two forking windows in order to be removed. - auto& transaction_idx = static_cast(get_mutable_index(implementation_ids, impl_transaction_object_type)); + auto& transaction_idx = static_cast(get_mutable_index(implementation_ids, + impl_transaction_history_object_type)); const auto& dedupe_index = transaction_idx.indices().get(); while( (!dedupe_index.empty()) && (head_block_time() > dedupe_index.begin()->trx.expiration) ) transaction_idx.remove(*dedupe_index.begin()); diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 5e149447..02a25db5 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -60,7 +60,7 @@ namespace graphene { namespace chain { { public: static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_asset_dynamic_data_type; + static const uint8_t type_id = impl_asset_dynamic_data_object_type; /// The number of shares currently in existence share_type current_supply; @@ -193,7 +193,7 @@ namespace graphene { namespace chain { { public: static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_asset_bitasset_data_type; + static const uint8_t type_id = impl_asset_bitasset_data_object_type; /// The asset this object belong to asset_id_type asset_id; diff --git a/libraries/chain/include/graphene/chain/transaction_object.hpp b/libraries/chain/include/graphene/chain/transaction_history_object.hpp similarity index 70% rename from libraries/chain/include/graphene/chain/transaction_object.hpp rename to libraries/chain/include/graphene/chain/transaction_history_object.hpp index a613e07c..6bed7920 100644 --- a/libraries/chain/include/graphene/chain/transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/transaction_history_object.hpp @@ -39,14 +39,14 @@ namespace graphene { namespace chain { using namespace boost::multi_index; /** * The purpose of this object is to enable the detection of duplicate transactions. When a transaction is included - * in a block a transaction_object is added. At the end of block processing all transaction_objects that have - * expired can be removed from the index. + * in a block a transaction_history_object is added. At the end of block processing all transaction_history_objects that + * have expired can be removed from the index. */ - class transaction_object : public abstract_object + class transaction_history_object : public abstract_object { public: static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_transaction_object_type; + static const uint8_t type_id = impl_transaction_history_object_type; signed_transaction trx; transaction_id_type trx_id; @@ -57,19 +57,21 @@ namespace graphene { namespace chain { struct by_expiration; struct by_trx_id; typedef multi_index_container< - transaction_object, + transaction_history_object, indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, - hashed_unique< tag, BOOST_MULTI_INDEX_MEMBER(transaction_object, transaction_id_type, trx_id), std::hash >, - ordered_non_unique< tag, const_mem_fun > + hashed_unique< tag, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_id_type, trx_id), + std::hash >, + ordered_non_unique< tag, const_mem_fun< transaction_history_object, time_point_sec, + &transaction_history_object::get_expiration > > > > transaction_multi_index_type; - typedef generic_index transaction_index; + typedef generic_index transaction_index; } } -MAP_OBJECT_ID_TO_TYPE(graphene::chain::transaction_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::transaction_history_object) -FC_REFLECT_DERIVED( graphene::chain::transaction_object, (graphene::db::object), (trx)(trx_id) ) +FC_REFLECT_DERIVED( graphene::chain::transaction_history_object, (graphene::db::object), (trx)(trx_id) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transaction_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transaction_history_object ) diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp index c84608a2..050672ad 100644 --- a/libraries/chain/include/graphene/chain/types.hpp +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -25,82 +25,31 @@ #include -namespace graphene { namespace chain { +namespace graphene { namespace chain { using namespace protocol; } } -using namespace graphene::protocol; - -enum impl_object_type { - impl_global_property_object_type, - impl_dynamic_global_property_object_type, - impl_reserved0_object_type, // formerly index_meta_object_type, TODO: delete me - impl_asset_dynamic_data_type, - impl_asset_bitasset_data_type, - impl_account_balance_object_type, - impl_account_statistics_object_type, - impl_transaction_object_type, - impl_block_summary_object_type, - impl_account_transaction_history_object_type, - impl_blinded_balance_object_type, - impl_chain_property_object_type, - impl_witness_schedule_object_type, - impl_budget_record_object_type, - impl_special_authority_object_type, - impl_buyback_object_type, - impl_fba_accumulator_object_type, - impl_collateral_bid_object_type -}; - -using global_property_id_type = object_id; -using dynamic_global_property_id_type = object_id; -using asset_dynamic_data_id_type = object_id; -using asset_bitasset_data_id_type = object_id; -using account_balance_id_type = object_id; -using account_statistics_id_type = object_id; -using transaction_obj_id_type = object_id; -using block_summary_id_type = object_id; -using account_transaction_history_id_type = object_id; -using chain_property_id_type = object_id; -using witness_schedule_id_type = object_id; -using budget_record_id_type = object_id; -using blinded_balance_id_type = object_id; -using special_authority_id_type = object_id; -using buyback_id_type = object_id; -using fba_accumulator_id_type = object_id; -using collateral_bid_id_type = object_id; - -} } - -FC_REFLECT_ENUM(graphene::chain::impl_object_type, - (impl_global_property_object_type) - (impl_dynamic_global_property_object_type) - (impl_reserved0_object_type) - (impl_asset_dynamic_data_type) - (impl_asset_bitasset_data_type) - (impl_account_balance_object_type) - (impl_account_statistics_object_type) - (impl_transaction_object_type) - (impl_block_summary_object_type) - (impl_account_transaction_history_object_type) - (impl_blinded_balance_object_type) - (impl_chain_property_object_type) - (impl_witness_schedule_object_type) - (impl_budget_record_object_type) - (impl_special_authority_object_type) - (impl_buyback_object_type) - (impl_fba_accumulator_object_type) - (impl_collateral_bid_object_type)) - -FC_REFLECT_TYPENAME(graphene::chain::global_property_id_type) -FC_REFLECT_TYPENAME(graphene::chain::dynamic_global_property_id_type) -FC_REFLECT_TYPENAME(graphene::chain::asset_dynamic_data_id_type) -FC_REFLECT_TYPENAME(graphene::chain::asset_bitasset_data_id_type) -FC_REFLECT_TYPENAME(graphene::chain::account_balance_id_type) -FC_REFLECT_TYPENAME(graphene::chain::account_statistics_id_type) -FC_REFLECT_TYPENAME(graphene::chain::transaction_obj_id_type) -FC_REFLECT_TYPENAME(graphene::chain::block_summary_id_type) -FC_REFLECT_TYPENAME(graphene::chain::account_transaction_history_id_type) -FC_REFLECT_TYPENAME(graphene::chain::budget_record_id_type) -FC_REFLECT_TYPENAME(graphene::chain::special_authority_id_type) -FC_REFLECT_TYPENAME(graphene::chain::buyback_id_type) -FC_REFLECT_TYPENAME(graphene::chain::fba_accumulator_id_type) -FC_REFLECT_TYPENAME(graphene::chain::collateral_bid_id_type) +GRAPHENE_DEFINE_IDS(chain, implementation_ids, impl_, + (global_property) + (dynamic_global_property) + (reserved0) + (asset_dynamic_data) + (asset_bitasset_data) + (account_balance) + (account_statistics) + (transaction_history) + (block_summary) + (account_transaction_history) + (blinded_balance) + (chain_property) + (witness_schedule) + (budget_record) + (special_authority) + (buyback) + (fba_accumulator) + (asset_dividend_data) + (pending_dividend_payout_balance_for_holder_object) + (distributed_dividend_balance_data) + (betting_market_position_object) + (global_betting_statistics_object) + (lottery_balance_object) + (sweeps_vesting_balance_object) + (offer_history_object)) diff --git a/libraries/chain/transaction_object.cpp b/libraries/chain/transaction_history_object.cpp similarity index 71% rename from libraries/chain/transaction_object.cpp rename to libraries/chain/transaction_history_object.cpp index fb4f75df..e242b6c3 100644 --- a/libraries/chain/transaction_object.cpp +++ b/libraries/chain/transaction_history_object.cpp @@ -21,19 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include namespace graphene { namespace chain { const object* transaction_index::create(const std::function& constructor, object_id_type) { - transaction_object obj; + transaction_history_object obj; obj.id = get_next_available_id(); constructor(&obj); auto result = _index.insert(std::move(obj)); - FC_ASSERT(result.second, "Could not create transaction_object! Most likely a uniqueness constraint is violated."); + FC_ASSERT(result.second, "Could not create transaction_history_object! Most likely a uniqueness constraint is violated."); return &*result.first; } @@ -43,28 +43,28 @@ void transaction_index::modify(const object* obj, assert(obj != nullptr); FC_ASSERT(obj->id < _index.size()); - const transaction_object* t = dynamic_cast(obj); + const transaction_history_object* t = dynamic_cast(obj); assert(t != nullptr); auto itr = _index.find(obj->id.instance()); assert(itr != _index.end()); - _index.modify(itr, [&m](transaction_object& o) { m(&o); }); + _index.modify(itr, [&m](transaction_history_object& o) { m(&o); }); } void transaction_index::add(unique_ptr o) { assert(o); object_id_type id = o->id; - assert(id.space() == transaction_object::space_id); - assert(id.type() == transaction_object::type_id); + assert(id.space() == transaction_history_object::space_id); + assert(id.type() == transaction_history_object::type_id); assert(id.instance() == size()); - auto trx = dynamic_cast(o.get()); + auto trx = dynamic_cast(o.get()); assert(trx != nullptr); o.release(); auto result = _index.insert(std::move(*trx)); - FC_ASSERT(result.second, "Could not insert transaction_object! Most likely a uniqueness constraint is violated."); + FC_ASSERT(result.second, "Could not insert transaction_history_object! Most likely a uniqueness constraint is violated."); } void transaction_index::remove(object_id_type id) @@ -74,16 +74,16 @@ void transaction_index::remove(object_id_type id) if( itr == index.end() ) return; - assert(id.space() == transaction_object::space_id); - assert(id.type() == transaction_object::type_id); + assert(id.space() == transaction_history_object::space_id); + assert(id.type() == transaction_history_object::type_id); index.erase(itr); } const object*transaction_index::get(object_id_type id) const { - if( id.type() != transaction_object::type_id || - id.space() != transaction_object::space_id ) + if( id.type() != transaction_history_object::type_id || + id.space() != transaction_history_object::space_id ) return nullptr; auto itr = _index.find(id.instance()); diff --git a/libraries/protocol/include/graphene/protocol/types.hpp b/libraries/protocol/include/graphene/protocol/types.hpp index 260b904c..c3a63db3 100644 --- a/libraries/protocol/include/graphene/protocol/types.hpp +++ b/libraries/protocol/include/graphene/protocol/types.hpp @@ -22,6 +22,14 @@ * THE SOFTWARE. */ #pragma once + +#include +#include +#include +#include +#include +#include + #include #include #include @@ -51,6 +59,28 @@ #include +#define GRAPHENE_NAME_TO_OBJECT_TYPE(x, prefix, name) BOOST_PP_CAT(prefix, BOOST_PP_CAT(name, _object_type)) +#define GRAPHENE_NAME_TO_ID_TYPE(x, y, name) BOOST_PP_CAT(name, _id_type) +#define GRAPHENE_DECLARE_ID(x, space_prefix_seq, name) \ + using BOOST_PP_CAT(name, _id_type) = object_id; +#define GRAPHENE_REFLECT_ID(x, id_namespace, name) FC_REFLECT_TYPENAME(graphene::id_namespace::name) + +#define GRAPHENE_DEFINE_IDS(id_namespace, object_space, object_type_prefix, names_seq) \ + namespace graphene { namespace id_namespace { \ + \ + enum BOOST_PP_CAT(object_type_prefix, object_type) { \ + BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \ + }; \ + \ + BOOST_PP_SEQ_FOR_EACH(GRAPHENE_DECLARE_ID, (object_space, object_type_prefix), names_seq) \ + \ + } } \ + \ + FC_REFLECT_ENUM(graphene::id_namespace::BOOST_PP_CAT(object_type_prefix, object_type), \ + BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \ + BOOST_PP_SEQ_FOR_EACH(GRAPHENE_REFLECT_ID, id_namespace, BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_ID_TYPE, , names_seq)) + namespace graphene { namespace protocol { using namespace graphene::db; @@ -124,65 +154,6 @@ enum reserved_spaces { inline bool is_relative(object_id_type o) { return o.space() == 0; } -/** - * List all object types from all namespaces here so they can - * be easily reflected and displayed in debug output. If a 3rd party - * wants to extend the core code then they will have to change the - * packed_object::type field from enum_type to uint16 to avoid - * warnings when converting packed_objects to/from json. - */ -enum object_type { - null_object_type, - base_object_type, - account_object_type, - asset_object_type, - force_settlement_object_type, - committee_member_object_type, - witness_object_type, - limit_order_object_type, - call_order_object_type, - custom_object_type, - proposal_object_type, - operation_history_object_type, - withdraw_permission_object_type, - vesting_balance_object_type, - worker_object_type, - balance_object_type, - tournament_object_type, - tournament_details_object_type, - match_object_type, - game_object_type, - sport_object_type, - event_group_object_type, - event_object_type, - betting_market_rules_object_type, - betting_market_group_object_type, - betting_market_object_type, - bet_object_type, - custom_permission_object_type, - custom_account_authority_object_type, - offer_object_type, - nft_metadata_type, - nft_object_type, -OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types -}; - -using account_id_type = object_id; -using asset_id_type = object_id; -using force_settlement_id_type = object_id; -using committee_member_id_type = object_id; -using witness_id_type = object_id; -using limit_order_id_type = object_id; -using call_order_id_type = object_id; -using custom_id_type = object_id; -using proposal_id_type = object_id; -using operation_history_id_type = object_id; -using withdraw_permission_id_type = object_id; -using vesting_balance_id_type = object_id; -using worker_id_type = object_id; -using balance_id_type = object_id; -using htlc_id_type = object_id; - using block_id_type = fc::ripemd160; using checksum_type = fc::ripemd160; using transaction_id_type = fc::ripemd160; @@ -237,71 +208,39 @@ void from_variant( const fc::variant& var, std::shared_ptr