Skip to content

Commit

Permalink
Ref bitshares#1506/bitshares#1737: Macro-fy ID type definitions
Browse files Browse the repository at this point in the history
Define macros to fully de-boilerplate ID type definitions.

Externalities:
 - Rename transaction_object -> transaction_history_object
 - Rename impl_asset_dynamic_data_type ->
impl_asset_dynamic_data_object_type
 - Rename impl_asset_bitasset_data_type ->
impl_asset_bitasset_data_object_type

The first is to avoid a naming collision on transaction_id_type, and the
other two are to maintain consistency with the naming of the other
types.
  • Loading branch information
nathanielhourt committed May 4, 2019
1 parent 29d4dde commit 4bd61ab
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 184 deletions.
2 changes: 1 addition & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <graphene/protocol/fee_schedule.hpp>
#include <graphene/chain/confidential_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/transaction_history_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/worker_object.hpp>

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <graphene/chain/operation_history_object.hpp>

#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/transaction_history_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/evaluator.hpp>
Expand Down Expand Up @@ -678,7 +678,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
//Insert transaction into unique transactions database.
if( !(skip & skip_transaction_dupe_check) )
{
create<transaction_object>([&trx](transaction_object& transaction) {
create<transaction_history_object>([&trx](transaction_history_object& transaction) {
transaction.trx_id = trx.id();
transaction.trx = trx;
});
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/special_authority_object.hpp>
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/transaction_history_object.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/witness_object.hpp>
Expand Down Expand Up @@ -110,8 +110,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;
Expand Down
11 changes: 5 additions & 6 deletions libraries/chain/db_notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/transaction_history_object.hpp>
#include <graphene/chain/impacted.hpp>

using namespace fc;
Expand Down Expand Up @@ -303,7 +303,6 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
{
case null_object_type:
case base_object_type:
case OBJECT_TYPE_COUNT:
return;
case account_object_type:{
accounts.insert( obj->id );
Expand Down Expand Up @@ -388,9 +387,9 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& 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<const account_balance_object*>(obj);
Expand All @@ -402,8 +401,8 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
FC_ASSERT( aobj != nullptr );
accounts.insert( aobj->owner );
break;
} case impl_transaction_object_type:{
const auto& aobj = dynamic_cast<const transaction_object*>(obj);
} case impl_transaction_history_object_type:{
const auto& aobj = dynamic_cast<const transaction_history_object*>(obj);
FC_ASSERT( aobj != nullptr );
transaction_get_impacted_accounts( aobj->trx, accounts );
break;
Expand Down
5 changes: 3 additions & 2 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <graphene/chain/htlc_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/transaction_history_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/witness_object.hpp>

Expand Down Expand Up @@ -145,7 +145,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<transaction_index&>(get_mutable_index(implementation_ids, impl_transaction_object_type));
auto& transaction_idx = static_cast<transaction_index&>(get_mutable_index(implementation_ids,
impl_transaction_history_object_type));
const auto& dedupe_index = transaction_idx.indices().get<by_expiration>();
while( (!dedupe_index.empty()) && (head_block_time() > dedupe_index.begin()->trx.expiration) )
transaction_idx.remove(*dedupe_index.begin());
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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;
Expand Down Expand Up @@ -176,7 +176,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,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<transaction_object>
class transaction_history_object : public abstract_object<transaction_history_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;
Expand All @@ -59,17 +59,19 @@ 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<by_id>, member< object, object_id_type, &object::id > >,
hashed_unique< tag<by_trx_id>, BOOST_MULTI_INDEX_MEMBER(transaction_object, transaction_id_type, trx_id), std::hash<transaction_id_type> >,
ordered_non_unique< tag<by_expiration>, const_mem_fun<transaction_object, time_point_sec, &transaction_object::get_expiration > >
hashed_unique< tag<by_trx_id>, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_id_type, trx_id),
std::hash<transaction_id_type> >,
ordered_non_unique< tag<by_expiration>, const_mem_fun< transaction_history_object, time_point_sec,
&transaction_history_object::get_expiration > >
>
> transaction_multi_index_type;

typedef generic_index<transaction_object, transaction_multi_index_type> transaction_index;
typedef generic_index<transaction_history_object, transaction_multi_index_type> 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) )
100 changes: 21 additions & 79 deletions libraries/chain/include/graphene/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,82 +25,24 @@

#include <graphene/protocol/types.hpp>

namespace graphene { namespace chain {

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<implementation_ids, impl_global_property_object_type>;
using dynamic_global_property_id_type = object_id<implementation_ids, impl_dynamic_global_property_object_type>;
using asset_dynamic_data_id_type = object_id<implementation_ids, impl_asset_dynamic_data_type>;
using asset_bitasset_data_id_type = object_id<implementation_ids, impl_asset_bitasset_data_type>;
using account_balance_id_type = object_id<implementation_ids, impl_account_balance_object_type>;
using account_statistics_id_type = object_id<implementation_ids, impl_account_statistics_object_type>;
using transaction_obj_id_type = object_id<implementation_ids, impl_transaction_object_type>;
using block_summary_id_type = object_id<implementation_ids, impl_block_summary_object_type>;
using account_transaction_history_id_type = object_id<implementation_ids, impl_account_transaction_history_object_type>;
using chain_property_id_type = object_id<implementation_ids, impl_chain_property_object_type>;
using witness_schedule_id_type = object_id<implementation_ids, impl_witness_schedule_object_type>;
using budget_record_id_type = object_id<implementation_ids, impl_budget_record_object_type>;
using blinded_balance_id_type = object_id<implementation_ids, impl_blinded_balance_object_type>;
using special_authority_id_type = object_id<implementation_ids, impl_special_authority_object_type>;
using buyback_id_type = object_id<implementation_ids, impl_buyback_object_type>;
using fba_accumulator_id_type = object_id<implementation_ids, impl_fba_accumulator_object_type>;
using collateral_bid_id_type = object_id<implementation_ids, impl_collateral_bid_object_type>;

} }

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)
namespace graphene { namespace chain { using namespace protocol; } }

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)
(collateral_bid))
Loading

0 comments on commit 4bd61ab

Please sign in to comment.